/proc/self/cwd/external/libavc/common/ih264_buf_mgr.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/**
21
*******************************************************************************
22
* @file
23
*  ih264_buf_mgr.c
24
*
25
* @brief
26
*  Contains function definitions for buffer management
27
*
28
* @author
29
*  Srinivas T
30
*
31
* @par List of Functions:
32
*   - ih264_buf_mgr_size()
33
*   - ih264_buf_mgr_lock()
34
*   - ih264_buf_mgr_unlock()
35
*   - ih264_buf_mgr_yield()
36
*   - ih264_buf_mgr_free()
37
*   - ih264_buf_mgr_init()
38
*   - ih264_buf_mgr_add()
39
*   - ih264_buf_mgr_get_next_free()
40
*   - ih264_buf_mgr_check_free()
41
*   - ih264_buf_mgr_set_status()
42
*   - ih264_buf_mgr_get_status()
43
*   - ih264_buf_mgr_get_buf()
44
*   - ih264_buf_mgr_get_bufid()
45
*   - ih264_buf_mgr_get_num_active_buf()
46
*
47
* @remarks
48
*  None
49
*
50
*******************************************************************************
51
*/
52
#include <stdio.h>
53
#include <stdlib.h>
54
#include "ih264_typedefs.h"
55
#include "ih264_macros.h"
56
#include "ih264_defs.h"
57
#include "ih264_error.h"
58
#include "ih264_buf_mgr.h"
59
60
#include "ithread.h"
61
62
/**
63
*******************************************************************************
64
*
65
* @brief Returns size for buf queue context. Does not include buf queue buffer
66
* requirements
67
*
68
* @par   Description
69
* Returns size for buf queue context. Does not include buf queue buffer
70
* requirements. Buffer size required to store the bufs should be allocated in
71
* addition to the value returned here.
72
*
73
* @returns Size of the buf queue context
74
*
75
* @remarks
76
*
77
*******************************************************************************
78
*/
79
WORD32 ih264_buf_mgr_size(void)
80
0
{
81
0
    WORD32 size;
82
0
83
0
    size = sizeof(buf_mgr_t);
84
0
    size += ithread_get_mutex_lock_size();
85
0
86
0
    return size;
87
0
}
88
89
/**
90
*******************************************************************************
91
*
92
* @brief
93
*   Locks the buf_mgr context
94
*
95
* @par   Description
96
*   Locks the buf_mgr context by calling ithread_mutex_lock()
97
*
98
* @param[in] ps_buf_mgr
99
*   Job Queue context
100
*
101
* @returns IH264_FAIL if mutex lock fails else IH264_SUCCESS
102
*
103
* @remarks
104
*
105
*******************************************************************************
106
*/
107
IH264_ERROR_T ih264_buf_mgr_lock(buf_mgr_t *ps_buf_mgr)
108
91
{
109
91
    WORD32 retval;
110
91
    retval = ithread_mutex_lock(ps_buf_mgr->pv_mutex);
111
91
    if(retval)
112
0
    {
113
0
        return IH264_FAIL;
114
0
    }
115
91
    return IH264_SUCCESS;
116
91
}
117
118
/**
119
*******************************************************************************
120
*
121
* @brief
122
*   Unlocks the buf_mgr context
123
*
124
* @par   Description
125
*   Unlocks the buf_mgr context by calling ithread_mutex_unlock()
126
*
127
* @param[in] ps_buf_mgr
128
*   Job Queue context
129
*
130
* @returns IH264_FAIL if mutex unlock fails else IH264_SUCCESS
131
*
132
* @remarks
133
*
134
*******************************************************************************
135
*/
136
137
IH264_ERROR_T ih264_buf_mgr_unlock(buf_mgr_t *ps_buf_mgr)
138
91
{
139
91
    WORD32 retval;
140
91
    retval = ithread_mutex_unlock(ps_buf_mgr->pv_mutex);
141
91
    if(retval)
142
0
    {
143
0
        return IH264_FAIL;
144
0
    }
145
91
    return IH264_SUCCESS;
146
91
147
91
}
148
/**
149
*******************************************************************************
150
*
151
* @brief
152
*   Yeilds the thread
153
*
154
* @par   Description
155
*   Unlocks the buf_mgr context by calling
156
* ih264_buf_mgr_unlock(), ithread_yield() and then ih264_buf_mgr_lock()
157
* buf_mgr is unlocked before to ensure the buf_mgr can be accessed by other threads
158
* If unlock is not done before calling yield then no other thread can access
159
* the buf_mgr functions and update buf_mgr.
160
*
161
* @param[in] ps_buf_mgr
162
*   Job Queue context
163
*
164
* @returns IH264_FAIL if mutex lock unlock or yield fails else IH264_SUCCESS
165
*
166
* @remarks
167
*
168
*******************************************************************************
169
*/
170
IH264_ERROR_T ih264_buf_mgr_yield(buf_mgr_t *ps_buf_mgr)
171
0
{
172
0
173
0
    IH264_ERROR_T ret = IH264_SUCCESS;
174
0
175
0
    IH264_ERROR_T rettmp;
176
0
    rettmp = ih264_buf_mgr_unlock(ps_buf_mgr);
177
0
    RETURN_IF((rettmp != IH264_SUCCESS), rettmp);
178
0
179
0
    //ithread_usleep(10);
180
0
    ithread_yield();
181
0
182
0
    rettmp = ih264_buf_mgr_lock(ps_buf_mgr);
183
0
    RETURN_IF((rettmp != IH264_SUCCESS), rettmp);
184
0
    return ret;
185
0
}
186
187
188
/**
189
*******************************************************************************
190
*
191
* @brief free the buf queue pointers
192
*
193
* @par   Description
194
* Frees the buf_mgr context
195
*
196
* @param[in] pv_buf
197
* Memoy for buf queue buffer and buf queue context
198
*
199
* @returns Pointer to buf queue context
200
*
201
* @remarks
202
* Since it will be called only once by master thread this is not thread safe.
203
*
204
*******************************************************************************
205
*/
206
IH264_ERROR_T ih264_buf_mgr_free(buf_mgr_t *ps_buf_mgr)
207
0
{
208
0
    WORD32 ret;
209
0
    ret = ithread_mutex_destroy(ps_buf_mgr->pv_mutex);
210
0
211
0
    if(0 == ret)
212
0
        return IH264_SUCCESS;
213
0
    else
214
0
        return IH264_FAIL;
215
0
}
216
/**
217
*******************************************************************************
218
*
219
* @brief
220
*      Buffer manager initialization function.
221
*
222
* @par Description:
223
*    Initializes the buffer manager structure
224
*
225
* @param[in] ps_buf_mgr
226
*  Pointer to the buffer manager
227
*
228
* @returns
229
*
230
* @remarks
231
*  None
232
*
233
*******************************************************************************
234
*/
235
236
237
void *ih264_buf_mgr_init(void *pv_buf)
238
2
{
239
2
    WORD32 id;
240
2
    UWORD8 *pu1_buf;
241
2
    buf_mgr_t *ps_buf_mgr;
242
2
    pu1_buf = (UWORD8 *)pv_buf;
243
2
244
2
    ps_buf_mgr = (buf_mgr_t *)pu1_buf;
245
2
    pu1_buf += sizeof(buf_mgr_t);
246
2
247
2
    ps_buf_mgr->pv_mutex = pu1_buf;
248
2
    pu1_buf += ithread_get_mutex_lock_size();
249
2
250
2
    ithread_mutex_init(ps_buf_mgr->pv_mutex);
251
2
252
2
    ps_buf_mgr->i4_max_buf_cnt = BUF_MGR_MAX_CNT;
253
2
    ps_buf_mgr->i4_active_buf_cnt = 0;
254
2
255
130
    for(id = 0; id < BUF_MGR_MAX_CNT; id++)
256
128
    {
257
128
        ps_buf_mgr->au4_status[id] = 0;
258
128
        ps_buf_mgr->apv_ptr[id] = NULL;
259
128
    }
260
2
261
2
    return ps_buf_mgr;
262
2
}
263
264
265
/**
266
*******************************************************************************
267
*
268
* @brief
269
*       Adds and increments the buffer and buffer count.
270
*
271
* @par Description:
272
*     Adds a buffer to the buffer manager if it is not already  present and
273
*   increments the  active buffer count
274
*
275
* @param[in] ps_buf_mgr
276
*  Pointer to the buffer manager
277
*
278
* @param[in] pv_ptr
279
*  Pointer to the buffer to be added
280
*
281
* @returns  Returns 0 on success, -1 otherwise
282
*
283
* @remarks
284
*  None
285
*
286
*******************************************************************************
287
*/
288
IH264_ERROR_T ih264_buf_mgr_add(buf_mgr_t *ps_buf_mgr,
289
                                void *pv_ptr,
290
                                WORD32 buf_id)
291
7
{
292
7
293
7
    IH264_ERROR_T ret = IH264_SUCCESS;
294
7
    ret = ih264_buf_mgr_lock(ps_buf_mgr);
295
7
    RETURN_IF((ret != IH264_SUCCESS), ret);
296
7
297
7
    /* Check if buffer ID is within allowed range */
298
7
    if(buf_id >= ps_buf_mgr->i4_max_buf_cnt)
299
0
    {
300
0
        ret = ih264_buf_mgr_unlock(ps_buf_mgr);
301
0
        RETURN_IF((ret != IH264_SUCCESS), ret);
302
0
303
0
        return IH264_FAIL;
304
7
    }
305
7
306
7
    /* Check if the current ID is being used to hold some other buffer */
307
7
    if((ps_buf_mgr->apv_ptr[buf_id] != NULL) &&
308
7
       (ps_buf_mgr->apv_ptr[buf_id] !=pv_ptr))
309
0
    {
310
0
        ret = ih264_buf_mgr_unlock(ps_buf_mgr);
311
0
        RETURN_IF((ret != IH264_SUCCESS), ret);
312
0
313
0
        return IH264_FAIL;
314
7
    }
315
7
    ps_buf_mgr->apv_ptr[buf_id] = pv_ptr;
316
7
    ps_buf_mgr->i4_active_buf_cnt++;
317
7
318
7
    ret = ih264_buf_mgr_unlock(ps_buf_mgr);
319
7
    RETURN_IF((ret != IH264_SUCCESS), ret);
320
7
321
7
    return ret;
322
7
}
323
324
/**
325
*******************************************************************************
326
*
327
* @brief
328
*   Gets the next free buffer.
329
*
330
* @par Description:
331
*     Returns the next free buffer available and sets the  corresponding status
332
*   to DEC
333
*
334
* @param[in] ps_buf_mgr
335
*  Pointer to the buffer manager
336
*
337
* @param[in] pi4_buf_id
338
*  Pointer to the id of the free buffer
339
*
340
* @returns  Pointer to the free buffer
341
*
342
* @remarks
343
*  None
344
*
345
*******************************************************************************
346
*/
347
void* ih264_buf_mgr_get_next_free(buf_mgr_t *ps_buf_mgr, WORD32 *pi4_buf_id)
348
22
{
349
22
    WORD32 id;
350
22
    void *pv_ret_ptr;
351
22
    IH264_ERROR_T ret = IH264_SUCCESS;
352
22
    ret = ih264_buf_mgr_lock(ps_buf_mgr);
353
22
    RETURN_IF((ret != IH264_SUCCESS), NULL);
354
22
355
22
    pv_ret_ptr = NULL;
356
37
    for(id = 0; id < ps_buf_mgr->i4_active_buf_cnt; id++)
357
37
    {
358
37
        /* Check if the buffer is non-null and status is zero */
359
37
        if((ps_buf_mgr->au4_status[id] == 0) && (ps_buf_mgr->apv_ptr[id]))
360
22
        {
361
22
            *pi4_buf_id = id;
362
22
            /* DEC is set to 1 */
363
22
            ps_buf_mgr->au4_status[id] = 1;
364
22
            pv_ret_ptr = ps_buf_mgr->apv_ptr[id];
365
22
            break;
366
22
        }
367
37
    }
368
22
    ret = ih264_buf_mgr_unlock(ps_buf_mgr);
369
22
    RETURN_IF((ret != IH264_SUCCESS), NULL);
370
22
371
22
    return pv_ret_ptr;
372
22
}
373
374
375
/**
376
*******************************************************************************
377
*
378
* @brief
379
*      Checks the buffer manager for free buffers available.
380
*
381
* @par Description:
382
*  Checks if there are any free buffers available
383
*
384
* @param[in] ps_buf_mgr
385
*  Pointer to the buffer manager
386
*
387
* @returns  Returns 0 if available, -1 otherwise
388
*
389
* @remarks
390
*  None
391
*
392
*******************************************************************************
393
*/
394
IH264_ERROR_T ih264_buf_mgr_check_free(buf_mgr_t *ps_buf_mgr)
395
0
{
396
0
    WORD32 id;
397
0
    IH264_ERROR_T ret = IH264_SUCCESS;
398
0
    IH264_ERROR_T rettmp = IH264_SUCCESS;
399
0
    rettmp = ih264_buf_mgr_lock(ps_buf_mgr);
400
0
    RETURN_IF((rettmp != IH264_SUCCESS), ret);
401
0
402
0
    ret = IH264_FAIL;
403
0
    for(id = 0; id < ps_buf_mgr->i4_active_buf_cnt; id++)
404
0
    {
405
0
        if((ps_buf_mgr->au4_status[id] == 0) &&
406
0
           (ps_buf_mgr->apv_ptr[id]))
407
0
        {
408
0
            ret = IH264_SUCCESS;
409
0
            break;
410
0
        }
411
0
    }
412
0
    rettmp = ih264_buf_mgr_unlock(ps_buf_mgr);
413
0
    RETURN_IF((rettmp != IH264_SUCCESS), ret);
414
0
415
0
    return ret;
416
0
417
0
}
418
419
420
/**
421
*******************************************************************************
422
*
423
* @brief
424
*       Resets the status bits.
425
*
426
* @par Description:
427
*     resets the status bits that the mask contains (status  corresponding to
428
*    the id)
429
*
430
* @param[in] ps_buf_mgr
431
*  Pointer to the buffer manager
432
*
433
* @param[in] buf_id
434
*  ID of the buffer status to be released
435
*
436
* @param[in] mask
437
*  Contains the bits that are to be reset
438
*
439
* @returns  0 if success, -1 otherwise
440
*
441
* @remarks
442
*  None
443
*
444
*******************************************************************************
445
*/
446
IH264_ERROR_T ih264_buf_mgr_release(buf_mgr_t *ps_buf_mgr,
447
                                    WORD32 buf_id,
448
                                    UWORD32 mask)
449
29
{
450
29
    IH264_ERROR_T ret = IH264_SUCCESS;
451
29
    ret = ih264_buf_mgr_lock(ps_buf_mgr);
452
29
    RETURN_IF((ret != IH264_SUCCESS), ret);
453
29
454
29
455
29
    /* If the given id is pointing to an id which is not yet added */
456
29
    if(buf_id >= ps_buf_mgr->i4_active_buf_cnt)
457
0
    {
458
0
        ret = ih264_buf_mgr_unlock(ps_buf_mgr);
459
0
        RETURN_IF((ret != IH264_SUCCESS), ret);
460
0
        return IH264_FAIL;
461
29
    }
462
29
463
29
    ps_buf_mgr->au4_status[buf_id] &= ~mask;
464
29
465
29
466
29
/*     If both the REF and DISP are zero, DEC is set to zero */
467
29
    if(ps_buf_mgr->au4_status[buf_id] == 1)
468
19
    {
469
19
        ps_buf_mgr->au4_status[buf_id] = 0;
470
19
    }
471
29
472
29
473
29
    ret = ih264_buf_mgr_unlock(ps_buf_mgr);
474
29
    RETURN_IF((ret != IH264_SUCCESS), ret);
475
29
476
29
    return ret;
477
29
}
478
479
480
/**
481
*******************************************************************************
482
*
483
* @brief
484
*      Sets the status bit.
485
*
486
* @par Description:
487
*     sets the status bits that the mask contains (status  corresponding to the
488
*    id)
489
*
490
*
491
* @param[in] ps_buf_mgr
492
*  Pointer to the buffer manager
493
*
494
* @param[in] buf_id
495
*  ID of the buffer whose status needs to be modified
496
*
497
*
498
* @param[in] mask
499
*  Contains the bits that are to be set
500
*
501
* @returns  0 if success, -1 otherwise
502
*
503
* @remarks
504
*  None
505
*
506
*******************************************************************************
507
*/
508
IH264_ERROR_T ih264_buf_mgr_set_status(buf_mgr_t *ps_buf_mgr,
509
                                       WORD32 buf_id,
510
                                       UWORD32 mask)
511
33
{
512
33
    IH264_ERROR_T ret = IH264_SUCCESS;
513
33
    ret = ih264_buf_mgr_lock(ps_buf_mgr);
514
33
    RETURN_IF((ret != IH264_SUCCESS), ret);
515
33
516
33
    if(buf_id >= ps_buf_mgr->i4_active_buf_cnt)
517
0
    {
518
0
        ret = ih264_buf_mgr_unlock(ps_buf_mgr);
519
0
        RETURN_IF((ret != IH264_SUCCESS), ret);
520
0
        return IH264_FAIL;
521
33
    }
522
33
523
33
524
33
    if((ps_buf_mgr->au4_status[buf_id] & mask) != 0)
525
0
    {
526
0
        ret = ih264_buf_mgr_unlock(ps_buf_mgr);
527
0
        RETURN_IF((ret != IH264_SUCCESS), ret);
528
0
        return IH264_FAIL;
529
33
    }
530
33
531
33
    ps_buf_mgr->au4_status[buf_id] |= mask;
532
33
    ret = ih264_buf_mgr_unlock(ps_buf_mgr);
533
33
    RETURN_IF((ret != IH264_SUCCESS), ret);
534
33
535
33
    return ret;
536
33
}
537
538
539
/**
540
*******************************************************************************
541
*
542
* @brief
543
*   Returns the status of the buffer.
544
*
545
* @par Description:
546
*  Returns the status of the buffer corresponding to the id
547
*
548
* @param[in] ps_buf_mgr
549
*  Pointer to the buffer manager
550
*
551
* @param[in] buf_id
552
*  ID of the buffer status required
553
*
554
* @returns  Status of the buffer corresponding to the id
555
*
556
* @remarks
557
*  None
558
*
559
*******************************************************************************
560
*/
561
WORD32 ih264_buf_mgr_get_status( buf_mgr_t *ps_buf_mgr, WORD32 buf_id )
562
0
{
563
0
    IH264_ERROR_T ret = IH264_SUCCESS;
564
0
    UWORD32 status;
565
0
566
0
    ret = ih264_buf_mgr_lock(ps_buf_mgr);
567
0
    RETURN_IF((ret != IH264_SUCCESS), ret);
568
0
569
0
    status = ps_buf_mgr->au4_status[buf_id];
570
0
571
0
    ret = ih264_buf_mgr_unlock(ps_buf_mgr);
572
0
    RETURN_IF((ret != IH264_SUCCESS), ret);
573
0
574
0
    return status;
575
0
}
576
577
578
/**
579
*******************************************************************************
580
*
581
* @brief
582
*      Gets the buffer from the buffer manager
583
*
584
* @par Description:
585
*        Returns the pointer to the buffer corresponding to the id
586
*
587
* @param[in] ps_buf_mgr
588
*  Pointer to the buffer manager
589
*
590
* @param[in] buf_id
591
*  ID of the buffer required
592
*
593
* @returns  Pointer to the buffer required
594
*
595
* @remarks
596
*  None
597
*
598
*******************************************************************************
599
*/
600
void* ih264_buf_mgr_get_buf(buf_mgr_t *ps_buf_mgr, WORD32 buf_id)
601
0
{
602
0
    IH264_ERROR_T ret = IH264_SUCCESS;
603
0
    void *pv_buf;
604
0
    ret = ih264_buf_mgr_lock(ps_buf_mgr);
605
0
    RETURN_IF((ret != IH264_SUCCESS), NULL);
606
0
607
0
    pv_buf = ps_buf_mgr->apv_ptr[buf_id];
608
0
609
0
    ret = ih264_buf_mgr_unlock(ps_buf_mgr);
610
0
    RETURN_IF((ret != IH264_SUCCESS), NULL);
611
0
612
0
    return pv_buf;
613
0
}
614
615
616
/**
617
*******************************************************************************
618
*
619
* @brief
620
*  Gets the buffer id from the buffer manager if the buffer is added to the
621
*  buffer manager
622
*
623
* @par Description:
624
*  Returns the buffer id corresponding to the given buffer if it exists
625
*
626
* @param[in] ps_buf_mgr
627
*  Pointer to the buffer manager
628
*
629
* @param[in] pv_buf
630
*  Pointer to the buffer
631
*
632
* @returns  Buffer id if exists, else -1
633
*
634
* @remarks
635
*  None
636
*
637
*******************************************************************************
638
*/
639
WORD32 ih264_buf_mgr_get_bufid(buf_mgr_t *ps_buf_mgr, void *pv_buf)
640
0
{
641
0
    WORD32 id;
642
0
    WORD32 buf_id = -1;
643
0
    IH264_ERROR_T ret = IH264_SUCCESS;
644
0
    ret = ih264_buf_mgr_lock(ps_buf_mgr);
645
0
    RETURN_IF((ret != IH264_SUCCESS), ret);
646
0
647
0
    for(id = 0; id < ps_buf_mgr->i4_active_buf_cnt; id++)
648
0
    {
649
0
        if(ps_buf_mgr->apv_ptr[id] == pv_buf)
650
0
        {
651
0
            buf_id = id;
652
0
            break;
653
0
        }
654
0
    }
655
0
    ret = ih264_buf_mgr_unlock(ps_buf_mgr);
656
0
    RETURN_IF((ret != IH264_SUCCESS), ret);
657
0
658
0
    return buf_id;
659
0
}
660
661
662
/**
663
*******************************************************************************
664
*
665
* @brief
666
*        Gets the no.of active buffer
667
*
668
* @par Description:
669
*      Return the number of active buffers in the buffer manager
670
*
671
* @param[in] ps_buf_mgr
672
*  Pointer to the buffer manager
673
*
674
* @returns  number of active buffers
675
*
676
* @remarks
677
*  None
678
*
679
*******************************************************************************
680
*/
681
UWORD32 ih264_buf_mgr_get_num_active_buf(buf_mgr_t *ps_buf_mgr)
682
0
{
683
0
    UWORD32 u4_buf_cnt;
684
0
    IH264_ERROR_T ret = IH264_SUCCESS;
685
0
686
0
    u4_buf_cnt = 0;
687
0
688
0
    ret = ih264_buf_mgr_lock(ps_buf_mgr);
689
0
    RETURN_IF((ret != IH264_SUCCESS), ret);
690
0
    u4_buf_cnt = ps_buf_mgr->i4_active_buf_cnt;
691
0
692
0
    ret = ih264_buf_mgr_unlock(ps_buf_mgr);
693
0
    RETURN_IF((ret != IH264_SUCCESS), ret);
694
0
695
0
    return u4_buf_cnt;
696
0
}
/proc/self/cwd/external/libavc/common/ih264_buf_mgr.h
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/**
21
*******************************************************************************
22
* @file
23
*  ih264_buf_mgr.h
24
*
25
* @brief
26
*  Function declarations used for buffer management
27
*
28
* @remarks
29
*  None
30
*
31
*******************************************************************************
32
*/
33
#ifndef _IH264_BUF_MGR_H_
34
#define _IH264_BUF_MGR_H_
35
36
132
#define BUF_MGR_MAX_CNT 64
37
38
/** Flag for current encoding decoder */
39
#define BUF_MGR_CODEC        (1 << 1)
40
41
/** Flag for reference status */
42
42
#define BUF_MGR_REF          (1 << 2)
43
44
/** Flag for I/O - Display/output in case of decoder, capture/input in case of encoder */
45
20
#define BUF_MGR_IO           (1 << 3)
46
47
typedef struct
48
{
49
    /**
50
     * Mutex used to keep the functions thread-safe
51
     */
52
    void *pv_mutex;
53
54
    /**
55
     * max_buf_cnt
56
     */
57
    WORD32 i4_max_buf_cnt;
58
59
    /**
60
     * active_buf_cnt
61
     */
62
    WORD32 i4_active_buf_cnt;
63
64
    /**
65
     *  au4_status[BUF_MGR_MAX_CNT]
66
     */
67
    UWORD32 au4_status[BUF_MGR_MAX_CNT];
68
69
    /* The last three bit of status are:    */
70
71
    /* Bit 0 - IN USE                       */
72
    /* Bit 1 - CODEC                        */
73
    /* Bit 2 - REF                          */
74
    /* Bit 3 - DISP/IO/RECON                */
75
    void    *apv_ptr[BUF_MGR_MAX_CNT];
76
77
}buf_mgr_t;
78
79
// Returns size of the buffer manager context
80
WORD32 ih264_buf_mgr_size(void);
81
82
//Free buffer manager
83
IH264_ERROR_T ih264_buf_mgr_free(buf_mgr_t *ps_buf_mgr);
84
85
// Initializes the buffer API structure
86
void *ih264_buf_mgr_init(void *pv_buf);
87
88
// Add buffer to buffer manager. 0: success, -1: fail (u4_active_buf_cnt has reached u4_max_buf_cnt)
89
IH264_ERROR_T ih264_buf_mgr_add(buf_mgr_t *ps_buf_mgr,
90
                                void *pv_ptr,
91
                                WORD32 buf_id);
92
93
// this function will set the buffer status to DEC
94
void* ih264_buf_mgr_get_next_free(buf_mgr_t *ps_buf_mgr, WORD32 *pi4_id);
95
96
// this function will check if there are any free buffers
97
IH264_ERROR_T ih264_buf_mgr_check_free(buf_mgr_t *ps_buf_mgr);
98
99
// mask will have who released it: DISP:REF:DEC
100
IH264_ERROR_T ih264_buf_mgr_release(buf_mgr_t *ps_buf_mgr,
101
                                    WORD32 id,
102
                                    UWORD32 mask);
103
104
// sets the status to one or all of DISP:REF:DEC
105
IH264_ERROR_T ih264_buf_mgr_set_status(buf_mgr_t *ps_buf_mgr,
106
                                       WORD32 id,
107
                                       UWORD32 mask);
108
109
// Gets status of the buffer
110
WORD32 ih264_buf_mgr_get_status(buf_mgr_t *ps_buf_mgr, WORD32 id);
111
112
// pass the ID - buffer will be returned
113
void* ih264_buf_mgr_get_buf(buf_mgr_t *ps_buf_mgr, WORD32 id);
114
//Pass buffer to get ID
115
WORD32 ih264_buf_mgr_get_bufid(buf_mgr_t *ps_buf_mgr, void *pv_buf);
116
117
// will return number of active buffers
118
UWORD32 ih264_buf_mgr_get_num_active_buf(buf_mgr_t *ps_buf_mgr);
119
120
121
122
#endif  /* _IH264_BUF_MGR_H_ */
/proc/self/cwd/external/libavc/common/ih264_chroma_intra_pred_filters.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/**
21
*******************************************************************************
22
* @file
23
*  ih264_chroma_intra_pred_filters.c
24
*
25
* @brief
26
*  Contains function definitions for chroma intra prediction  filters
27
*
28
* @author
29
*  Ittiam
30
*
31
* @par List of Functions:
32
*  -ih264_intra_pred_chroma_8x8_mode_dc
33
*  -ih264_intra_pred_chroma_8x8_mode_horz
34
*  -ih264_intra_pred_chroma_8x8_mode_vert
35
*  -ih264_intra_pred_chroma_8x8_mode_plane
36
*
37
* @remarks
38
*  None
39
*
40
*******************************************************************************
41
*/
42
43
/*****************************************************************************/
44
/* File Includes                                                             */
45
/*****************************************************************************/
46
47
/* System include files */
48
#include <stdio.h>
49
#include <stddef.h>
50
#include <string.h>
51
52
/* User include files */
53
#include "ih264_defs.h"
54
#include "ih264_typedefs.h"
55
#include "ih264_macros.h"
56
#include "ih264_platform_macros.h"
57
#include "ih264_intra_pred_filters.h"
58
59
/* Global variables used only in assembly files*/
60
const WORD8  ih264_gai1_intrapred_chroma_plane_coeffs1[] =
61
{ 0x01,0x00,0x01,0x00,
62
  0x02,0x00,0x02,0x00,
63
  0x03,0x00,0x03,0x00,
64
  0x04,0x00,0x04,0x00
65
};
66
 const WORD8  ih264_gai1_intrapred_chroma_plane_coeffs2[] =
67
 { 0xfd,0xff,0xfe,0xff,
68
   0xff,0xff,0x00,0x00,
69
   0x01,0x00,0x02,0x00,
70
   0x03,0x00,0x04,0x00,
71
 };
72
73
/*****************************************************************************/
74
/* Chroma Intra prediction 8x8 filters                                       */
75
/*****************************************************************************/
76
77
/**
78
*******************************************************************************
79
*
80
* ih264_intra_pred_chroma_8x8_mode_dc
81
*
82
* @brief
83
*  Perform Intra prediction for  chroma_8x8 mode:DC
84
*
85
* @par Description:
86
*  Perform Intra prediction for  chroma_8x8 mode:DC ,described in sec 8.3.4.1
87
*
88
* @param[in] pu1_src
89
*  UWORD8 pointer to the source containing alternate U and V samples
90
*
91
* @param[out] pu1_dst
92
*  UWORD8 pointer to the destination with alternate U and V samples
93
*
94
* @param[in] src_strd
95
*  integer source stride
96
*
97
* @param[in] dst_strd
98
*  integer destination stride
99
*
100
** @param[in] ngbr_avail
101
*  availability of neighbouring pixels
102
*
103
* @returns
104
*
105
* @remarks
106
*  None
107
*
108
******************************************************************************
109
*/
110
void ih264_intra_pred_chroma_8x8_mode_dc(UWORD8 *pu1_src,
111
                                         UWORD8 *pu1_dst,
112
                                         WORD32 src_strd,
113
                                         WORD32 dst_strd,
114
                                         WORD32 ngbr_avail)
115
2.45k
{
116
2.45k
    WORD32 left_avail, left_avail1, left_avail2; /* availability of left predictors (only for DC) */
117
2.45k
    WORD32 top_avail; /* availability of top predictors (only for DC) */
118
2.45k
    UWORD8 *pu1_left = NULL; /* Pointer to start of left predictors */
119
2.45k
    UWORD8 *pu1_top = NULL; /* Pointer to start of top predictors */
120
2.45k
121
2.45k
    /* temporary variables to store accumulated first left half,second left half,
122
2.45k
     * first top half,second top half of U and  V values*/
123
2.45k
    WORD32 val_u_l1 = 0, val_u_l2 = 0, val_u_t1 = 0, val_u_t2 = 0;
124
2.45k
    WORD32 val_v_l1 = 0, val_v_l2 = 0, val_v_t1 = 0, val_v_t2 = 0;
125
2.45k
126
2.45k
    WORD32 val_u1 = 0, val_u2 = 0, val_v1 = 0, val_v2 = 0;
127
2.45k
128
2.45k
    WORD32 col, row; /*loop variables*/
129
2.45k
    UNUSED(src_strd);
130
2.45k
131
2.45k
    left_avail = ngbr_avail & 0x11;
132
2.45k
    left_avail1 = ngbr_avail & 1;
133
2.45k
    left_avail2 = (ngbr_avail >> 4) & 1;
134
2.45k
    top_avail = (ngbr_avail >> 2) & 1;
135
2.45k
136
2.45k
    pu1_top = pu1_src + 2 * BLK8x8SIZE + 2;
137
2.45k
    pu1_left = pu1_src + 2 * BLK8x8SIZE - 2;
138
2.45k
139
2.45k
    if(left_avail1)
140
2.24k
    { /* First 4x4 block*/
141
2.24k
        val_u_l1 += *pu1_left;
142
2.24k
        val_v_l1 += *(pu1_left + 1);
143
2.24k
        pu1_left -= 2;
144
2.24k
        val_u_l1 += *pu1_left;
145
2.24k
        val_v_l1 += *(pu1_left + 1);
146
2.24k
        pu1_left -= 2;
147
2.24k
        val_u_l1 += *pu1_left;
148
2.24k
        val_v_l1 += *(pu1_left + 1);
149
2.24k
        pu1_left -= 2;
150
2.24k
        val_u_l1 += *pu1_left + 2;
151
2.24k
        val_v_l1 += *(pu1_left + 1) + 2;
152
2.24k
        pu1_left -= 2;
153
2.24k
    }
154
209
    else
155
209
        pu1_left -= 2 * 4;
156
2.45k
157
2.45k
    if(left_avail2)
158
2.24k
    {
159
2.24k
        /* Second 4x4 block*/
160
2.24k
        val_u_l2 += *pu1_left;
161
2.24k
        val_v_l2 += *(pu1_left + 1);
162
2.24k
        pu1_left -= 2;
163
2.24k
        val_u_l2 += *pu1_left;
164
2.24k
        val_v_l2 += *(pu1_left + 1);
165
2.24k
        pu1_left -= 2;
166
2.24k
        val_u_l2 += *pu1_left;
167
2.24k
        val_v_l2 += *(pu1_left + 1);
168
2.24k
        pu1_left -= 2;
169
2.24k
        val_u_l2 += *pu1_left + 2;
170
2.24k
        val_v_l2 += *(pu1_left + 1) + 2;
171
2.24k
        pu1_left -= 2;
172
2.24k
    }
173
209
    else
174
209
        pu1_left -= 2 * 4;
175
2.45k
176
2.45k
    if(top_avail)
177
2.22k
    {
178
2.22k
        val_u_t1 += *pu1_top + *(pu1_top + 2) + *(pu1_top + 4)
179
2.22k
                        + *(pu1_top + 6) + 2;
180
2.22k
        val_u_t2 += *(pu1_top + 8) + *(pu1_top + 10) + *(pu1_top + 12)
181
2.22k
                        + *(pu1_top + 14) + 2;
182
2.22k
        val_v_t1 += *(pu1_top + 1) + *(pu1_top + 3) + *(pu1_top + 5)
183
2.22k
                        + *(pu1_top + 7) + 2;
184
2.22k
        val_v_t2 += *(pu1_top + 9) + *(pu1_top + 11) + *(pu1_top + 13)
185
2.22k
                        + *(pu1_top + 15) + 2;
186
2.22k
    }
187
2.45k
188
2.45k
    if(left_avail + top_avail)
189
2.44k
    {
190
2.44k
        val_u1 = (left_avail1 + top_avail) ?
191
2.44k
                        ((val_u_l1 + val_u_t1)
192
2.44k
                                        >> (1 + left_avail1 + top_avail)) :128;
193
2.44k
        val_v1 = (left_avail1 + top_avail) ?
194
2.44k
                        ((val_v_l1 + val_v_t1)
195
2.44k
                                        >> (1 + left_avail1 + top_avail)) :128;
196
2.44k
        if(top_avail)
197
2.22k
        {
198
2.22k
            val_u2 = val_u_t2 >> 2;
199
2.22k
            val_v2 = val_v_t2 >> 2;
200
2.22k
        }
201
220
        else if(left_avail1)
202
220
        {
203
220
            val_u2 = val_u_l1 >> 2;
204
220
            val_v2 = val_v_l1 >> 2;
205
220
        }
206
0
        else
207
0
        {
208
0
            val_u2 = val_v2 = 128;
209
0
        }
210
2.44k
211
12.2k
        for(row = 0; row < 4; row++)
212
9.76k
        {
213
9.76k
            /*top left 4x4 block*/
214
48.8k
            for(col = 0; col < 8; col += 2)
215
39.0k
            {
216
39.0k
                *(pu1_dst + row * dst_strd + col) = val_u1;
217
39.0k
                *(pu1_dst + row * dst_strd + col + 1) = val_v1;
218
39.0k
            }
219
9.76k
            /*top right 4x4 block*/
220
48.8k
            for(col = 8; col < 16; col += 2)
221
39.0k
            {
222
39.0k
                *(pu1_dst + row * dst_strd + col) = val_u2;
223
39.0k
                *(pu1_dst + row * dst_strd + col + 1) = val_v2;
224
39.0k
            }
225
9.76k
        }
226
2.44k
227
2.44k
        if(left_avail2)
228
2.24k
        {
229
2.24k
            val_u1 = val_u_l2 >> 2;
230
2.24k
            val_v1 = val_v_l2 >> 2;
231
2.24k
        }
232
198
        else if(top_avail)
233
198
        {
234
198
            val_u1 = val_u_t1 >> 2;
235
198
            val_v1 = val_v_t1 >> 2;
236
198
        }
237
0
        else
238
0
        {
239
0
            val_u1 = val_v1 = 128;
240
0
        }
241
2.44k
        val_u2 = (left_avail2 + top_avail) ?
242
2.44k
                        ((val_u_l2 + val_u_t2)
243
2.44k
                                        >> (1 + left_avail2 + top_avail)) : 128;
244
2.44k
        val_v2 = (left_avail2 + top_avail) ?
245
2.44k
                        ((val_v_l2 + val_v_t2)
246
2.44k
                                        >> (1 + left_avail2 + top_avail)) :  128;
247
2.44k
248
12.2k
        for(row = 4; row < 8; row++)
249
9.76k
        { /*bottom left 4x4 block*/
250
48.8k
            for(col = 0; col < 8; col += 2)
251
39.0k
            {
252
39.0k
                *(pu1_dst + row * dst_strd + col) = val_u1;
253
39.0k
                *(pu1_dst + row * dst_strd + col + 1) = val_v1;
254
39.0k
            }
255
9.76k
            /*bottom right 4x4 block*/
256
48.8k
            for(col = 8; col < 16; col += 2)
257
39.0k
            {
258
39.0k
                *(pu1_dst + row * dst_strd + col) = val_u2;
259
39.0k
                *(pu1_dst + row * dst_strd + col + 1) = val_v2;
260
39.0k
            }
261
9.76k
        }
262
2.44k
    }
263
11
    else
264
11
    {
265
11
        /* Both left and top are unavailable, set the block to 128 */
266
99
        for(row = 0; row < 8; row++)
267
88
        {
268
88
            memset(pu1_dst + row * dst_strd, 128, 8 * sizeof(UWORD16));
269
88
        }
270
11
    }
271
2.45k
}
272
273
/**
274
*******************************************************************************
275
*
276
*ih264_intra_pred_chroma_8x8_mode_horz
277
*
278
* @brief
279
*  Perform Intra prediction for  chroma_8x8 mode:Horizontal
280
*
281
* @par Description:
282
*  Perform Intra prediction for  chroma_8x8 mode:Horizontal ,described in sec 8.3.4.2
283
*
284
* @param[in] pu1_src
285
*  UWORD8 pointer to the source containing alternate U and V samples
286
*
287
* @param[out] pu1_dst
288
*  UWORD8 pointer to the destination with alternate U and V samples
289
*
290
* @param[in] src_strd
291
*  integer source stride
292
*
293
* @param[in] dst_strd
294
*  integer destination stride
295
*
296
* @param[in] ngbr_avail
297
* availability of neighbouring pixels(Not used in this function)
298
*
299
* @returns
300
*
301
* @remarks
302
*  None
303
*
304
******************************************************************************
305
*/
306
void ih264_intra_pred_chroma_8x8_mode_horz(UWORD8 *pu1_src,
307
                                           UWORD8 *pu1_dst,
308
                                           WORD32 src_strd,
309
                                           WORD32 dst_strd,
310
                                           WORD32 ngbr_avail)
311
0
{
312
0
313
0
    UWORD8 *pu1_left = NULL; /* Pointer to start of top predictors */
314
0
    WORD32 rows, cols; /* loop variables*/
315
0
    UNUSED(src_strd);
316
0
    UNUSED(ngbr_avail);
317
0
    pu1_left = pu1_src + 2 * BLK8x8SIZE - 2;
318
0
    for(rows = 0; rows < 8; rows++)
319
0
    {
320
0
        for(cols = 0; cols < 16; cols += 2)
321
0
        {
322
0
            *(pu1_dst + rows * dst_strd + cols) = *pu1_left;
323
0
324
0
            *(pu1_dst + rows * dst_strd + cols + 1) = *(pu1_left + 1);
325
0
        }
326
0
        pu1_left -= 2;
327
0
    }
328
0
329
0
}
330
331
/**
332
*******************************************************************************
333
*
334
*ih264_intra_pred_chroma_8x8_mode_vert
335
*
336
* @brief
337
*  Perform Intra prediction for  chroma_8x8 mode:vertical
338
*
339
* @par Description:
340
*  Perform Intra prediction for  chroma_8x8 mode:vertical ,described in sec 8.3.4.3
341
*
342
* @param[in] pu1_src
343
*  UWORD8 pointer to the source containing alternate U and V samples
344
*
345
* @param[out] pu1_dst
346
*  UWORD8 pointer to the destination with alternate U and V samples
347
*
348
* @param[in] src_strd
349
*  integer source stride
350
*
351
* @param[in] dst_strd
352
*  integer destination stride
353
*
354
* @param[in] ngbr_avail
355
* availability of neighbouring pixels(Not used in this function)
356
*
357
* @returns
358
*
359
* @remarks
360
*  None
361
*
362
*******************************************************************************
363
*/
364
void ih264_intra_pred_chroma_8x8_mode_vert(UWORD8 *pu1_src,
365
                                           UWORD8 *pu1_dst,
366
                                           WORD32 src_strd,
367
                                           WORD32 dst_strd,
368
                                           WORD32 ngbr_avail)
369
0
{
370
0
371
0
    UWORD8 *pu1_top = NULL; /* Pointer to start of top predictors */
372
0
    WORD32 row;/*loop variable*/
373
0
    UNUSED(src_strd);
374
0
    UNUSED(ngbr_avail);
375
0
    pu1_top = pu1_src + 2 * BLK8x8SIZE + 2;
376
0
377
0
    /* 8 bytes are copied from src to dst */
378
0
    for(row = 0; row < 2; row++)
379
0
    {
380
0
        memcpy(pu1_dst, pu1_top, 16);
381
0
382
0
        pu1_dst += dst_strd;
383
0
        memcpy(pu1_dst, pu1_top, 16);
384
0
385
0
        pu1_dst += dst_strd;
386
0
        memcpy(pu1_dst, pu1_top, 16);
387
0
388
0
        pu1_dst += dst_strd;
389
0
        memcpy(pu1_dst, pu1_top, 16);
390
0
391
0
        pu1_dst += dst_strd;
392
0
    }
393
0
}
394
395
/**
396
*******************************************************************************
397
*
398
* ih264_intra_pred_chroma_8x8_mode_plane
399
*
400
* @brief
401
*  Perform Intra prediction for  chroma_8x8 mode:PLANE
402
*
403
* @par Description:
404
*  Perform Intra prediction for  chroma_8x8 mode:PLANE ,described in sec 8.3.4.4
405
*
406
* @param[in] pu1_src
407
*  UWORD8 pointer to the source containing alternate U and V samples
408
*
409
* @param[out] pu1_dst
410
*  UWORD8 pointer to the destination with alternate U and V samples
411
*
412
* @param[in] src_strd
413
*  integer source stride
414
*
415
* @param[in] dst_strd
416
*  integer destination stride
417
*
418
* @param[in] ngbr_avail
419
* availability of neighbouring pixels(Not used in this function)
420
*
421
* @returns
422
*
423
* @remarks
424
*  None
425
*
426
******************************************************************************
427
*/
428
void ih264_intra_pred_chroma_8x8_mode_plane(UWORD8 *pu1_src,
429
                                            UWORD8 *pu1_dst,
430
                                            WORD32 src_strd,
431
                                            WORD32 dst_strd,
432
                                            WORD32 ngbr_avail)
433
0
{
434
0
435
0
    UWORD8 *pu1_left = NULL; /* Pointer to start of left predictors */
436
0
    UWORD8 *pu1_top = NULL; /* Pointer to start of top predictors */
437
0
    WORD32 val = 0;
438
0
    WORD32 rows, cols; /* loop variables*/
439
0
    WORD32 a_u, b_u, c_u, h_u, v_u; /* Implementing section 8.3.4.4 . The variables represent the corresponding variables in the section*/
440
0
    WORD32 a_v, b_v, c_v, h_v, v_v;
441
0
    UNUSED(src_strd);
442
0
    UNUSED(ngbr_avail);
443
0
    a_u = b_u = c_u = h_u = v_u = 0;
444
0
    a_v = b_v = c_v = h_v = v_v = 0;
445
0
    /* As chroma format 4:2:0 is used,xCF = 4 * ( chroma_format_idc = = 3 ) = 0 and
446
0
     yCF = 4 * ( chroma_format_idc != 1  ) = 0   */
447
0
    pu1_top = pu1_src + 2 * BLK8x8SIZE + 2;
448
0
    pu1_left = pu1_src + 2 * BLK8x8SIZE - 2;
449
0
    /* Implementing section 8.3.4.4 */
450
0
    for(cols = 0; cols < 4; cols++)
451
0
    {
452
0
        h_u += (cols + 1) * (pu1_top[8 + 2 * cols] - pu1_top[4 - 2 * cols]);/*section 8.3.4.4   equation (8-144)*/
453
0
        h_v += (cols + 1) * (pu1_top[8 + 2 * cols + 1] - pu1_top[4 - 2 * cols+ 1]);
454
0
455
0
        v_u += (cols + 1) * (pu1_left[(4 + cols) * (-2)] - pu1_left[(2 - cols) * (-2)]);
456
0
        v_v += (cols + 1)  * (pu1_left[(4 + cols) * (-2) + 1]  - pu1_left[(2 - cols) * (-2) + 1]);/*section 8.3.4.4   equation (8-145)*/
457
0
    }
458
0
    a_u = 16 * (pu1_left[7 * (-2)] + pu1_top[14]);
459
0
    a_v = 16 * (pu1_left[7 * (-2) + 1] + pu1_top[15]);/*section 8.3.3.4   equation (8-141)*/
460
0
    b_u = (34 * h_u + 32) >> 6;/*section 8.3.3.4   equation (8-142)*/
461
0
    b_v = (34 * h_v + 32) >> 6;/*section 8.3.3.4   equation (8-142)*/
462
0
    c_u = (34 * v_u + 32) >> 6;/*section 8.3.3.4   equation (8-143)*/
463
0
    c_v = (34 * v_v + 32) >> 6;/*section 8.3.3.4   equation (8-143)*/
464
0
465
0
    for(rows = 0; rows < 8; rows++)
466
0
    {
467
0
        for(cols = 0; cols < 8; cols++)
468
0
        {
469
0
            val = (a_u + b_u * (cols - 3) + c_u * (rows - 3) );/*section 8.3.4.4   equation (8-140)*/
470
0
            val = (val + 16) >> 5;
471
0
            *(pu1_dst + rows * dst_strd + 2 * cols) = CLIP_U8(val);
472
0
            val = (a_v + b_v * (cols - 3) + c_v * (rows - 3) );/*section 8.3.4.4   equation (8-140)*/
473
0
            val = (val + 16) >> 5;
474
0
            *(pu1_dst + rows * dst_strd + 2 * cols + 1) = CLIP_U8(val);
475
0
        }
476
0
    }
477
0
}
478
/proc/self/cwd/external/libavc/common/ih264_deblk_edge_filters.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/**************************************************************************** */
21
/*                                                                            */
22
/*  File Name         : ih264_deblk_edge_filters.c                            */
23
/*                                                                            */
24
/*  Description       : Contains function definitions for deblocking          */
25
/*                                                                            */
26
/*  List of Functions : ih264_deblk_luma_vert_bs4()                           */
27
/*                      ih264_deblk_luma_horz_bs4()                           */
28
/*                      ih264_deblk_luma_vert_bslt4()                         */
29
/*                      ih264_deblk_luma_horz_bslt4()                         */
30
/*                      ih264_deblk_luma_vert_bs4_mbaff()                     */
31
/*                      ih264_deblk_luma_vert_bslt4_mbaff()                   */
32
/*                      ih264_deblk_chroma_vert_bs4_bp()                      */
33
/*                      ih264_deblk_chroma_horz_bs4_bp()                      */
34
/*                      ih264_deblk_chroma_vert_bslt4_bp()                    */
35
/*                      ih264_deblk_chroma_horz_bslt4_bp()                    */
36
/*                      ih264_deblk_chroma_vert_bs4_mbaff_bp()                */
37
/*                      ih264_deblk_chroma_vert_bslt4_mbaff_bp()              */
38
/*                      ih264_deblk_chroma_vert_bs4()                         */
39
/*                      ih264_deblk_chroma_horz_bs4()                         */
40
/*                      ih264_deblk_chroma_vert_bslt4()                       */
41
/*                      ih264_deblk_chroma_horz_bslt4()                       */
42
/*                      ih264_deblk_chroma_vert_bs4_mbaff()                   */
43
/*                      ih264_deblk_chroma_vert_bslt4_mbaff()                 */
44
/*                                                                            */
45
/*  Issues / Problems : None                                                  */
46
/*                                                                            */
47
/*  Revision History  :                                                       */
48
/*                                                                            */
49
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)   */
50
/*         28 11 2013   Ittiam          Draft                                 */
51
/*         29 12 2014   Kaushik         Added double-call vertical            */
52
/*                      Senthoor        deblocking and high profile           */
53
/*                                      deblocking functions                  */
54
/*                                                                            */
55
/******************************************************************************/
56
57
/*****************************************************************************/
58
/* File Includes                                                             */
59
/*****************************************************************************/
60
61
/* System include files */
62
#include <stdio.h>
63
64
/* User include files */
65
#include "ih264_typedefs.h"
66
#include "ih264_platform_macros.h"
67
#include "ih264_deblk_edge_filters.h"
68
#include "ih264_macros.h"
69
70
/*****************************************************************************/
71
/* Function Definitions                                                      */
72
/*****************************************************************************/
73
74
/*****************************************************************************/
75
/*                                                                           */
76
/*  Function Name : ih264_deblk_luma_vert_bs4()                              */
77
/*                                                                           */
78
/*  Description   : This function performs filtering of a luma block         */
79
/*                  vertical edge when the boundary strength is set to 4.    */
80
/*                                                                           */
81
/*  Inputs        : pu1_src    - pointer to the src sample q0                */
82
/*                  src_strd   - source stride                               */
83
/*                  alpha      - alpha value for the boundary                */
84
/*                  beta       - beta value for the boundary                 */
85
/*                                                                           */
86
/*  Globals       : None                                                     */
87
/*                                                                           */
88
/*  Processing    : This operation is described in Sec. 8.7.2.4 under the    */
89
/*                  title "Filtering process for edges for bS equal to 4" in */
90
/*                  ITU T Rec H.264.                                         */
91
/*                                                                           */
92
/*  Outputs       : None                                                     */
93
/*                                                                           */
94
/*  Returns       : None                                                     */
95
/*                                                                           */
96
/*  Issues        : None                                                     */
97
/*                                                                           */
98
/*  Revision History:                                                        */
99
/*                                                                           */
100
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
101
/*         28 11 2013   Ittiam          Draft                                */
102
/*                                                                           */
103
/*****************************************************************************/
104
void ih264_deblk_luma_vert_bs4(UWORD8 *pu1_src,
105
                               WORD32 src_strd,
106
                               WORD32 alpha,
107
                               WORD32 beta)
108
0
{
109
0
    UWORD8 p3, p2, p1, p0, q0, q1, q2, q3;
110
0
    WORD32 pos_p3, pos_p2, pos_p1, pos_p0;
111
0
    WORD32 pos_q0, pos_q1, pos_q2,pos_q3;
112
0
    UWORD8 a_p, a_q; /* threshold variables */
113
0
    WORD32 blk_strd = src_strd << 2; /* block_increment = src_strd * 4 */
114
0
    UWORD8 *pu1_src_temp;
115
0
    WORD8 i = 0, edge;
116
0
117
0
    pos_q0 = 0;
118
0
    pos_q1 = 1;
119
0
    pos_q2 = 2;
120
0
    pos_q3 = 3;
121
0
    pos_p0 = -1;
122
0
    pos_p1 = -2;
123
0
    pos_p2 = -3;
124
0
    pos_p3 = -4;
125
0
126
0
    for(edge = 0; edge < 4; edge++, pu1_src += blk_strd)
127
0
    {
128
0
        pu1_src_temp = pu1_src;
129
0
        for(i = 0; i < 4; ++i, pu1_src_temp += src_strd)
130
0
        {
131
0
            q0 = pu1_src_temp[pos_q0];
132
0
            q1 = pu1_src_temp[pos_q1];
133
0
            p0 = pu1_src_temp[pos_p0];
134
0
            p1 = pu1_src_temp[pos_p1];
135
0
136
0
            /* Filter Decision */
137
0
            if((ABS(p0 - q0) >= alpha) ||
138
0
               (ABS(q1 - q0) >= beta)  ||
139
0
               (ABS(p1 - p0) >= beta))
140
0
                continue;
141
0
142
0
            p2 = pu1_src_temp[pos_p2];
143
0
            p3 = pu1_src_temp[pos_p3];
144
0
            q2 = pu1_src_temp[pos_q2];
145
0
            q3 = pu1_src_temp[pos_q3];
146
0
147
0
            if(ABS(p0 - q0) < ((alpha >> 2) + 2))
148
0
            {
149
0
                /* Threshold Variables */
150
0
                a_p = (UWORD8)ABS(p2 - p0);
151
0
                a_q = (UWORD8)ABS(q2 - q0);
152
0
153
0
                if(a_p < beta)
154
0
                {
155
0
                    /* p0', p1', p2' */
156
0
                    pu1_src_temp[pos_p0] = ((p2 + X2(p1) + X2(p0) + X2(q0) + q1
157
0
                                    + 4) >> 3);
158
0
                    pu1_src_temp[pos_p1] = ((p2 + p1 + p0 + q0 + 2) >> 2);
159
0
                    pu1_src_temp[pos_p2] =
160
0
                                    ((X2(p3) + X3(p2) + p1 + p0 + q0
161
0
                                                    + 4) >> 3);
162
0
                }
163
0
                else
164
0
                {
165
0
                    /* p0'*/
166
0
                    pu1_src_temp[pos_p0] = ((X2(p1) + p0 + q1 + 2) >> 2);
167
0
                }
168
0
169
0
                if(a_q < beta)
170
0
                {
171
0
                    /* q0', q1', q2' */
172
0
                    pu1_src_temp[pos_q0] = (p1 + X2(p0) + X2(q0) + X2(q1) + q2
173
0
                                    + 4) >> 3;
174
0
                    pu1_src_temp[pos_q1] = (p0 + q0 + q1 + q2 + 2) >> 2;
175
0
                    pu1_src_temp[pos_q2] = (X2(q3) + X3(q2) + q1 + q0 + p0 + 4)
176
0
                                    >> 3;
177
0
                }
178
0
                else
179
0
                {
180
0
                    /* q0'*/
181
0
                    pu1_src_temp[pos_q0] = (X2(q1) + q0 + p1 + 2) >> 2;
182
0
                }
183
0
            }
184
0
            else
185
0
            {
186
0
                /* p0', q0'*/
187
0
                pu1_src_temp[pos_p0] = ((X2(p1) + p0 + q1 + 2) >> 2);
188
0
                pu1_src_temp[pos_q0] = (X2(q1) + q0 + p1 + 2) >> 2;
189
0
            }
190
0
        }
191
0
    }
192
0
}
193
194
/*****************************************************************************/
195
/*                                                                           */
196
/*  Function Name : ih264_deblk_luma_horz_bs4()                              */
197
/*                                                                           */
198
/*  Description   : This function performs filtering of a luma block         */
199
/*                  horizontal edge when the boundary strength is set to 4.  */
200
/*                                                                           */
201
/*  Inputs        : pu1_src    - pointer to the src sample q0                */
202
/*                  src_strd   - source stride                               */
203
/*                  alpha      - alpha value for the boundary                */
204
/*                  beta       - beta value for the boundary                 */
205
/*                                                                           */
206
/*  Globals       : None                                                     */
207
/*                                                                           */
208
/*  Processing    : This operation is described in Sec. 8.7.2.4 under the    */
209
/*                  title "Filtering process for edges for bS equal to 4" in */
210
/*                  ITU T Rec H.264.                                         */
211
/*                                                                           */
212
/*  Outputs       : None                                                     */
213
/*                                                                           */
214
/*  Returns       : None                                                     */
215
/*                                                                           */
216
/*  Issues        : None                                                     */
217
/*                                                                           */
218
/*  Revision History:                                                        */
219
/*                                                                           */
220
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
221
/*         28 11 2013   Ittiam          Draft                                */
222
/*                                                                           */
223
/*****************************************************************************/
224
void ih264_deblk_luma_horz_bs4(UWORD8 *pu1_src,
225
                               WORD32 src_strd,
226
                               WORD32 alpha,
227
                               WORD32 beta)
228
0
{
229
0
    UWORD8 p3, p2, p1, p0, q0, q1, q2, q3;
230
0
    WORD32 pos_p3, pos_p2, pos_p1, pos_p0, pos_q0, pos_q1,
231
0
                    pos_q2, pos_q3;
232
0
    UWORD8 a_p, a_q; /* threshold variables */
233
0
    UWORD8 *pu1_p3; /* pointer to the src sample p3 */
234
0
    UWORD8 *pu1_p3_temp;
235
0
    UWORD8 *pu1_src_temp;
236
0
    WORD8 i = 0, edge;
237
0
238
0
    pu1_p3 = pu1_src - (src_strd << 2);
239
0
    pos_q0 = 0;
240
0
    pos_q1 = src_strd;
241
0
    pos_q2 = X2(src_strd);
242
0
    pos_q3 = X3(src_strd);
243
0
    pos_p0 = X3(src_strd);
244
0
    pos_p1 = X2(src_strd);
245
0
    pos_p2 = src_strd;
246
0
    pos_p3 = 0;
247
0
248
0
    for(edge = 0; edge < 4; edge++, pu1_src += 4, pu1_p3 += 4)
249
0
    {
250
0
        pu1_src_temp = pu1_src;
251
0
        pu1_p3_temp = pu1_p3;
252
0
        for(i = 0; i < 4; ++i, pu1_src_temp++, pu1_p3_temp++)
253
0
        {
254
0
            q0 = pu1_src_temp[pos_q0];
255
0
            q1 = pu1_src_temp[pos_q1];
256
0
            p0 = pu1_p3_temp[pos_p0];
257
0
            p1 = pu1_p3_temp[pos_p1];
258
0
259
0
            /* Filter Decision */
260
0
            if((ABS(p0 - q0) >= alpha) ||
261
0
               (ABS(q1 - q0) >= beta) ||
262
0
               (ABS(p1 - p0) >= beta))
263
0
                continue;
264
0
265
0
            p2 = pu1_p3_temp[pos_p2];
266
0
            p3 = pu1_p3_temp[pos_p3];
267
0
            q2 = pu1_src_temp[pos_q2];
268
0
            q3 = pu1_src_temp[pos_q3];
269
0
270
0
            if(ABS(p0 - q0) < ((alpha >> 2) + 2))
271
0
            {
272
0
                /* Threshold Variables */
273
0
                a_p = ABS(p2 - p0);
274
0
                a_q = ABS(q2 - q0);
275
0
276
0
                if((a_p < beta))
277
0
                {
278
0
                    /* p0', p1', p2' */
279
0
                    pu1_p3_temp[pos_p0] = (p2 + X2(p1) + X2(p0) + X2(q0) + q1
280
0
                                    + 4) >> 3;
281
0
                    pu1_p3_temp[pos_p1] = (p2 + p1 + p0 + q0 + 2) >> 2;
282
0
                    pu1_p3_temp[pos_p2] =
283
0
                                    (X2(p3) + X3(p2) + p1 + p0 + q0
284
0
                                                    + 4) >> 3;
285
0
                }
286
0
                else
287
0
                {
288
0
                    /* p0'*/
289
0
                    pu1_p3_temp[pos_p0] = (X2(p1) + p0 + q1 + 2) >> 2;
290
0
                }
291
0
292
0
                if(a_q < beta)
293
0
                {
294
0
                    /* q0', q1', q2' */
295
0
                    pu1_src_temp[pos_q0] = (p1 + X2(p0) + X2(q0) + X2(q1)
296
0
                                    + q2 + 4) >> 3;
297
0
                    pu1_src_temp[pos_q1] = (p0 + q0 + q1 + q2 + 2) >> 2;
298
0
                    pu1_src_temp[pos_q2] = (X2(q3) + X3(q2) + q1 + q0 + p0
299
0
                                    + 4) >> 3;
300
0
                }
301
0
                else
302
0
                {
303
0
                    /* q0'*/
304
0
                    pu1_src_temp[pos_q0] = (X2(q1) + q0 + p1 + 2) >> 2;
305
0
                }
306
0
            }
307
0
            else
308
0
            {
309
0
                /* p0', q0'*/
310
0
                pu1_p3_temp[pos_p0] = (X2(p1) + p0 + q1 + 2) >> 2;
311
0
                pu1_src_temp[pos_q0] = (X2(q1) + q0 + p1 + 2) >> 2;
312
0
            }
313
0
        }
314
0
    }
315
0
}
316
317
/*****************************************************************************/
318
/*                                                                           */
319
/*  Function Name : ih264_deblk_chroma_vert_bs4_bp()                         */
320
/*                                                                           */
321
/*  Description   : This function performs filtering of a chroma block       */
322
/*                  vertical edge when the boundary strength is set to 4.    */
323
/*                                                                           */
324
/*  Inputs        : pu1_src    - pointer to the src sample q0 of U           */
325
/*                  src_strd   - source stride                               */
326
/*                  alpha      - alpha value for the boundary                */
327
/*                  beta       - beta value for the boundary                 */
328
/*                                                                           */
329
/*  Globals       : None                                                     */
330
/*                                                                           */
331
/*  Processing    : This operation is described in Sec. 8.7.2.4 under the    */
332
/*                  title "Filtering process for edges for bS equal to 4" in */
333
/*                  ITU T Rec H.264.                                         */
334
/*                                                                           */
335
/*  Outputs       : None                                                     */
336
/*                                                                           */
337
/*  Returns       : None                                                     */
338
/*                                                                           */
339
/*  Issues        : None                                                     */
340
/*                                                                           */
341
/*  Revision History:                                                        */
342
/*                                                                           */
343
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
344
/*         28 11 2013   Ittiam          Draft                                */
345
/*                                                                           */
346
/*****************************************************************************/
347
void ih264_deblk_chroma_vert_bs4_bp(UWORD8 *pu1_src,
348
                                    WORD32 src_strd,
349
                                    WORD32 alpha,
350
                                    WORD32 beta)
351
0
{
352
0
    UWORD8 *pu1_src_u = pu1_src; /* pointer to the src sample q0 of U */
353
0
    UWORD8 *pu1_src_v = pu1_src + 1; /* pointer to the src sample q0 of V */
354
0
    UWORD8 p1_u, p0_u, q0_u, q1_u, p1_v, p0_v, q0_v, q1_v;
355
0
    WORD32 blk_strd = src_strd << 1; /* block_increment = src_strd * 2 */
356
0
    WORD32 pos_p1, pos_p0, pos_q0, pos_q1;
357
0
    UWORD8 *pu1_src_temp_u, *pu1_src_temp_v;
358
0
    WORD8 i = 0, edge;
359
0
360
0
    pos_q0 = 0;
361
0
    pos_q1 = 2;
362
0
    pos_p0 = -2;
363
0
    pos_p1 = -4;
364
0
365
0
    for(edge = 0; edge < 4;
366
0
                    edge++, pu1_src_u += blk_strd, pu1_src_v += blk_strd)
367
0
    {
368
0
        pu1_src_temp_u = pu1_src_u;
369
0
        pu1_src_temp_v = pu1_src_v;
370
0
        for(i = 0; i < 2; ++i, pu1_src_temp_u += src_strd, pu1_src_temp_v +=
371
0
                        src_strd)
372
0
        {
373
0
            q0_u = pu1_src_temp_u[pos_q0];
374
0
            q1_u = pu1_src_temp_u[pos_q1];
375
0
            p0_u = pu1_src_temp_u[pos_p0];
376
0
            p1_u = pu1_src_temp_u[pos_p1];
377
0
            q0_v = pu1_src_temp_v[pos_q0];
378
0
            q1_v = pu1_src_temp_v[pos_q1];
379
0
            p0_v = pu1_src_temp_v[pos_p0];
380
0
            p1_v = pu1_src_temp_v[pos_p1];
381
0
382
0
            /* Filter Decision */
383
0
            if((ABS(p0_u - q0_u) < alpha) &&
384
0
               (ABS(q1_u - q0_u) < beta) &&
385
0
               (ABS(p1_u - p0_u) < beta))
386
0
            {
387
0
                /* p0' */
388
0
                pu1_src_temp_u[pos_p0] = ((X2(p1_u) + p0_u + q1_u + 2) >> 2);
389
0
                /* q0' */
390
0
                pu1_src_temp_u[pos_q0] = (X2(q1_u) + q0_u + p1_u + 2) >> 2;
391
0
            }
392
0
393
0
            /* Filter Decision */
394
0
            if((ABS(p0_v - q0_v) < alpha) &&
395
0
               (ABS(q1_v - q0_v) < beta) &&
396
0
               (ABS(p1_v - p0_v) < beta))
397
0
            {
398
0
                /* p0' */
399
0
                pu1_src_temp_v[pos_p0] = ((X2(p1_v) + p0_v + q1_v + 2) >> 2);
400
0
                /* q0' */
401
0
                pu1_src_temp_v[pos_q0] = (X2(q1_v) + q0_v + p1_v + 2) >> 2;
402
0
            }
403
0
        }
404
0
    }
405
0
}
406
407
/*****************************************************************************/
408
/*                                                                           */
409
/*  Function Name : ih264_deblk_chroma_horz_bs4_bp()                         */
410
/*                                                                           */
411
/*  Description   : This function performs filtering of a chroma block       */
412
/*                  horizontal edge when the boundary strength is set to 4.  */
413
/*                                                                           */
414
/*  Inputs        : pu1_src    - pointer to the src sample q0 of U           */
415
/*                  src_strd   - source stride                               */
416
/*                  alpha      - alpha value for the boundary                */
417
/*                  beta       - beta value for the boundary                 */
418
/*                                                                           */
419
/*  Globals       : None                                                     */
420
/*                                                                           */
421
/*  Processing    : This operation is described in Sec. 8.7.2.4 under the    */
422
/*                  title "Filtering process for edges for bS equal to 4" in */
423
/*                  ITU T Rec H.264.                                         */
424
/*                                                                           */
425
/*  Outputs       : None                                                     */
426
/*                                                                           */
427
/*  Returns       : None                                                     */
428
/*                                                                           */
429
/*  Issues        : None                                                     */
430
/*                                                                           */
431
/*  Revision History:                                                        */
432
/*                                                                           */
433
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
434
/*         28 11 2013   Ittiam          Draft                                */
435
/*                                                                           */
436
/*****************************************************************************/
437
void ih264_deblk_chroma_horz_bs4_bp(UWORD8 *pu1_src,
438
                                    WORD32 src_strd,
439
                                    WORD32 alpha,
440
                                    WORD32 beta)
441
0
{
442
0
    UWORD8 *pu1_src_u = pu1_src; /* pointer to the src sample q0 of U */
443
0
    UWORD8 *pu1_src_v = pu1_src + 1; /* pointer to the src sample q0 of V */
444
0
    UWORD8 p1_u, p0_u, q0_u, q1_u, p1_v, p0_v, q0_v, q1_v;
445
0
    WORD32 pos_p1, pos_p0, pos_q0, pos_q1;
446
0
    UWORD8 *pu1_src_temp_u, *pu1_src_temp_v;
447
0
    UWORD8 *pu1_p1_u; /* pointer to the src sample p1 of U */
448
0
    UWORD8 *pu1_p1_v; /* pointer to the src sample p1 of U */
449
0
    UWORD8 *pu1_p1_temp_u, *pu1_p1_temp_v;
450
0
    WORD8 i = 0, edge;
451
0
452
0
    pu1_p1_u = pu1_src_u - (src_strd << 1);
453
0
    pu1_p1_v = pu1_src_v - (src_strd << 1);
454
0
    pos_q0 = 0;
455
0
    pos_q1 = src_strd;
456
0
    pos_p0 = src_strd;
457
0
    pos_p1 = 0;
458
0
459
0
    for(edge = 0; edge < 4; edge++, pu1_src_u += 4, pu1_p1_u += 4,
460
0
                    pu1_src_v += 4, pu1_p1_v += 4)
461
0
    {
462
0
        pu1_src_temp_u = pu1_src_u;
463
0
        pu1_p1_temp_u = pu1_p1_u;
464
0
        pu1_src_temp_v = pu1_src_v;
465
0
        pu1_p1_temp_v = pu1_p1_v;
466
0
        for(i = 0; i < 2; ++i, pu1_src_temp_u += 2, pu1_p1_temp_u += 2,
467
0
                    pu1_src_temp_v += 2, pu1_p1_temp_v += 2)
468
0
        {
469
0
            q0_u = pu1_src_temp_u[pos_q0];
470
0
            q1_u = pu1_src_temp_u[pos_q1];
471
0
            p0_u = pu1_p1_temp_u[pos_p0];
472
0
            p1_u = pu1_p1_temp_u[pos_p1];
473
0
474
0
            q0_v = pu1_src_temp_v[pos_q0];
475
0
            q1_v = pu1_src_temp_v[pos_q1];
476
0
            p0_v = pu1_p1_temp_v[pos_p0];
477
0
            p1_v = pu1_p1_temp_v[pos_p1];
478
0
479
0
            /* Filter Decision */
480
0
            if((ABS(p0_u - q0_u) < alpha) &&
481
0
               (ABS(q1_u - q0_u) < beta) &&
482
0
               (ABS(p1_u - p0_u) < beta))
483
0
            {
484
0
                /* p0' */
485
0
                pu1_p1_temp_u[pos_p0] = (X2(p1_u) + p0_u + q1_u + 2) >> 2;
486
0
                /* q0' */
487
0
                pu1_src_temp_u[pos_q0] = (X2(q1_u) + q0_u + p1_u + 2) >> 2;
488
0
            }
489
0
490
0
            /* Filter Decision */
491
0
            if((ABS(p0_v - q0_v) < alpha) &&
492
0
               (ABS(q1_v - q0_v) < beta) &&
493
0
               (ABS(p1_v - p0_v) < beta))
494
0
            {
495
0
                /* p0' */
496
0
                pu1_p1_temp_v[pos_p0] = (X2(p1_v) + p0_v + q1_v + 2) >> 2;
497
0
                /* q0' */
498
0
                pu1_src_temp_v[pos_q0] = (X2(q1_v) + q0_v + p1_v + 2) >> 2;
499
0
            }
500
0
        }
501
0
    }
502
0
}
503
504
/*****************************************************************************/
505
/*                                                                           */
506
/*  Function Name : ih264_deblk_luma_vert_bslt4()                            */
507
/*                                                                           */
508
/*  Description   : This function performs filtering of a luma block         */
509
/*                  vertical edge when the boundary strength is less than 4. */
510
/*                                                                           */
511
/*  Inputs        : pu1_src       - pointer to the src sample q0             */
512
/*                  src_strd      - source stride                            */
513
/*                  alpha         - alpha value for the boundary             */
514
/*                  beta          - beta value for the boundary              */
515
/*                  u4_bs         - packed Boundary strength array           */
516
/*                  pu1_cliptab   - tc0_table                                */
517
/*                                                                           */
518
/*  Globals       : None                                                     */
519
/*                                                                           */
520
/*  Processing    : This operation is described in Sec. 8.7.2.3 under the    */
521
/*                  title "Filtering process for edges for bS less than 4"   */
522
/*                  in ITU T Rec H.264.                                      */
523
/*                                                                           */
524
/*  Outputs       : None                                                     */
525
/*                                                                           */
526
/*  Returns       : None                                                     */
527
/*                                                                           */
528
/*  Issues        : None                                                     */
529
/*                                                                           */
530
/*  Revision History:                                                        */
531
/*                                                                           */
532
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
533
/*         28 11 2013   Ittiam          Draft                                */
534
/*                                                                           */
535
/*****************************************************************************/
536
void ih264_deblk_luma_vert_bslt4(UWORD8 *pu1_src,
537
                                 WORD32 src_strd,
538
                                 WORD32 alpha,
539
                                 WORD32 beta,
540
                                 UWORD32 u4_bs,
541
                                 const UWORD8 *pu1_cliptab)
542
0
{
543
0
    WORD8 i = 0, edge;
544
0
    UWORD8 p2, p1, p0, q0, q1, q2;
545
0
    WORD32 pos_p2, pos_p1, pos_p0, pos_q0, pos_q1, pos_q2;
546
0
    UWORD8 a_p, a_q; /* threshold variables */
547
0
    WORD32 blk_strd = src_strd << 2; /* block_increment = src_strd * 4 */
548
0
    UWORD8 *pu1_src_temp;
549
0
    WORD8 delta;
550
0
    WORD8 tc;
551
0
    WORD16 val;
552
0
    UWORD8 tc0, u1_bs;
553
0
554
0
    pos_q0 = 0;
555
0
    pos_q1 = 1;
556
0
    pos_q2 = 2;
557
0
    pos_p0 = -1;
558
0
    pos_p1 = -2;
559
0
    pos_p2 = -3;
560
0
561
0
    for(edge = 0; edge < 4; edge++, pu1_src += blk_strd)
562
0
    {
563
0
        pu1_src_temp = pu1_src;
564
0
        /* Filter Decision */
565
0
        u1_bs = (UWORD8)((u4_bs >> ((3 - edge) << 3)) & 0x0ff);
566
0
        if(!u1_bs)
567
0
            continue;
568
0
        /* tc0 */
569
0
        tc0 = pu1_cliptab[u1_bs];
570
0
        for(i = 0; i < 4; ++i, pu1_src_temp += src_strd)
571
0
        {
572
0
            q0 = pu1_src_temp[pos_q0];
573
0
            q1 = pu1_src_temp[pos_q1];
574
0
            p0 = pu1_src_temp[pos_p0];
575
0
            p1 = pu1_src_temp[pos_p1];
576
0
577
0
            /* Filter Decision */
578
0
            if((ABS(p0 - q0) >= alpha) ||
579
0
               (ABS(q1 - q0) >= beta) ||
580
0
               (ABS(p1 - p0) >= beta))
581
0
                continue;
582
0
583
0
            q2 = pu1_src_temp[pos_q2];
584
0
            p2 = pu1_src_temp[pos_p2];
585
0
586
0
            a_p = ABS(p2 - p0);
587
0
            a_q = ABS(q2 - q0);
588
0
589
0
            /* tc */
590
0
            tc = tc0 + (a_p < beta) + (a_q < beta);
591
0
592
0
            val = ((((q0 - p0) << 2) + (p1 - q1) + 4) >> 3);
593
0
            delta = CLIP3(-tc, tc, val);
594
0
595
0
            /* p0' */
596
0
            val = p0 + delta;
597
0
            pu1_src_temp[pos_p0] = CLIP_U8(val);
598
0
            /* q0' */
599
0
            val = q0 - delta;
600
0
            pu1_src_temp[pos_q0] = CLIP_U8(val);
601
0
602
0
            /* Luma only */
603
0
            if(a_p < beta)
604
0
            {
605
0
                /* p1' */
606
0
                val = ((p2 + ((p0 + q0 + 1) >> 1) - (p1 << 1)) >> 1);
607
0
                pu1_src_temp[pos_p1] += CLIP3(-tc0, tc0, val);
608
0
            }
609
0
610
0
            if(a_q < beta)
611
0
            {
612
0
                /* q1' */
613
0
                val = ((q2 + ((p0 + q0 + 1) >> 1) - (q1 << 1)) >> 1);
614
0
                pu1_src_temp[pos_q1] += CLIP3(-tc0, tc0, val);
615
0
            }
616
0
        }
617
0
    }
618
0
}
619
620
/*****************************************************************************/
621
/*                                                                           */
622
/*  Function Name : ih264_deblk_chroma_vert_bslt4_bp()                       */
623
/*                                                                           */
624
/*  Description   : This function performs filtering of a chroma block       */
625
/*                  vertical edge when the boundary strength is less than 4. */
626
/*                                                                           */
627
/*  Inputs        : pu1_src       - pointer to the src sample q0 of U        */
628
/*                  src_strd      - source stride                            */
629
/*                  alpha         - alpha value for the boundary             */
630
/*                  beta          - beta value for the boundary              */
631
/*                  u4_bs         - packed Boundary strength array           */
632
/*                  pu1_cliptab   - tc0_table                                */
633
/*                                                                           */
634
/*  Globals       : None                                                     */
635
/*                                                                           */
636
/*  Processing    : This operation is described in Sec. 8.7.2.3 under the    */
637
/*                  title "Filtering process for edges for bS less than 4"   */
638
/*                  in ITU T Rec H.264.                                      */
639
/*                                                                           */
640
/*  Outputs       : None                                                     */
641
/*                                                                           */
642
/*  Returns       : None                                                     */
643
/*                                                                           */
644
/*  Issues        : None                                                     */
645
/*                                                                           */
646
/*  Revision History:                                                        */
647
/*                                                                           */
648
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
649
/*         28 11 2013   Ittiam          Draft                                */
650
/*                                                                           */
651
/*****************************************************************************/
652
void ih264_deblk_chroma_vert_bslt4_bp(UWORD8 *pu1_src,
653
                                      WORD32 src_strd,
654
                                      WORD32 alpha,
655
                                      WORD32 beta,
656
                                      UWORD32 u4_bs,
657
                                      const UWORD8 *pu1_cliptab)
658
0
{
659
0
    UWORD8 *pu1_src_u = pu1_src; /* Pointer to the src sample q0 of plane U*/
660
0
    UWORD8 *pu1_src_v = pu1_src + 1; /* Pointer to the src sample q0 of plane V*/
661
0
    UWORD8 p1_u, p0_u, q0_u, q1_u, p1_v, p0_v, q0_v, q1_v;
662
0
    WORD32 blk_strd = src_strd << 1; /* block_increment = src_strd * (4 >> 1)*/
663
0
    WORD32 pos_p1, pos_p0, pos_q0, pos_q1;
664
0
    UWORD8 *pu1_src_temp_u, *pu1_src_temp_v;
665
0
    WORD8 i = 0, edge;
666
0
    WORD8 delta;
667
0
    WORD8 tc;
668
0
    WORD16 val;
669
0
    UWORD8 tc0, u1_bs;
670
0
671
0
    pos_q0 = 0;
672
0
    pos_q1 = 2;
673
0
    pos_p0 = -2;
674
0
    pos_p1 = -4;
675
0
676
0
    for(edge = 0; edge < 4;
677
0
                    edge++, pu1_src_u += blk_strd, pu1_src_v += blk_strd)
678
0
    {
679
0
        pu1_src_temp_u = pu1_src_u;
680
0
        pu1_src_temp_v = pu1_src_v;
681
0
        /* Filter Decision */
682
0
        u1_bs = (UWORD8)((u4_bs >> ((3 - edge) << 3)) & 0x0ff);
683
0
        if(!u1_bs)
684
0
            continue;
685
0
        /* tc0 */
686
0
        tc0 = pu1_cliptab[u1_bs];
687
0
        tc = tc0 + 1;
688
0
        for(i = 0; i < 2; ++i, pu1_src_temp_u += src_strd, pu1_src_temp_v +=
689
0
                        src_strd)
690
0
        {
691
0
            q0_u = pu1_src_temp_u[pos_q0];
692
0
            q1_u = pu1_src_temp_u[pos_q1];
693
0
            p0_u = pu1_src_temp_u[pos_p0];
694
0
            p1_u = pu1_src_temp_u[pos_p1];
695
0
696
0
            q0_v = pu1_src_temp_v[pos_q0];
697
0
            q1_v = pu1_src_temp_v[pos_q1];
698
0
            p0_v = pu1_src_temp_v[pos_p0];
699
0
            p1_v = pu1_src_temp_v[pos_p1];
700
0
701
0
            /* Filter Decision */
702
0
            if((ABS(p0_u - q0_u) < alpha) &&
703
0
               (ABS(q1_u - q0_u) < beta) &&
704
0
               (ABS(p1_u - p0_u) < beta))
705
0
            {
706
0
                val = ((((q0_u - p0_u) << 2) + (p1_u - q1_u) + 4) >> 3);
707
0
                delta = CLIP3(-tc, tc, val);
708
0
                /* p0' */
709
0
                val = p0_u + delta;
710
0
                pu1_src_temp_u[pos_p0] = CLIP_U8(val);
711
0
                /* q0' */
712
0
                val = q0_u - delta;
713
0
                pu1_src_temp_u[pos_q0] = CLIP_U8(val);
714
0
            }
715
0
716
0
            /* Filter Decision */
717
0
            if((ABS(p0_v - q0_v) < alpha) &&
718
0
               (ABS(q1_v - q0_v) < beta) &&
719
0
               (ABS(p1_v - p0_v) < beta))
720
0
            {
721
0
                val = ((((q0_v - p0_v) << 2) + (p1_v - q1_v) + 4) >> 3);
722
0
                delta = CLIP3(-tc, tc, val);
723
0
                /* p0' */
724
0
                val = p0_v + delta;
725
0
                pu1_src_temp_v[pos_p0] = CLIP_U8(val);
726
0
                /* q0' */
727
0
                val = q0_v - delta;
728
0
                pu1_src_temp_v[pos_q0] = CLIP_U8(val);
729
0
            }
730
0
        }
731
0
    }
732
0
}
733
734
/*****************************************************************************/
735
/*                                                                           */
736
/*  Function Name : ih264_deblk_luma_horz_bslt4()                            */
737
/*                                                                           */
738
/*  Description   : This function performs filtering of a luma block         */
739
/*                  horizontal edge when boundary strength is less than 4.   */
740
/*                                                                           */
741
/*  Inputs        : pu1_src       - pointer to the src sample q0             */
742
/*                  src_strd      - source stride                            */
743
/*                  alpha         - alpha value for the boundary             */
744
/*                  beta          - beta value for the boundary              */
745
/*                  u4_bs         - packed Boundary strength array           */
746
/*                  pu1_cliptab   - tc0_table                                */
747
/*                                                                           */
748
/*  Globals       : None                                                     */
749
/*                                                                           */
750
/*  Processing    : This operation is described in Sec. 8.7.2.3 under the    */
751
/*                  title "Filtering process for edges for bS less than 4"   */
752
/*                  in ITU T Rec H.264.                                      */
753
/*                                                                           */
754
/*  Outputs       : None                                                     */
755
/*                                                                           */
756
/*  Returns       : None                                                     */
757
/*                                                                           */
758
/*  Issues        : None                                                     */
759
/*                                                                           */
760
/*  Revision History:                                                        */
761
/*                                                                           */
762
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
763
/*         28 11 2013   Ittiam          Draft                                */
764
/*                                                                           */
765
/*****************************************************************************/
766
void ih264_deblk_luma_horz_bslt4(UWORD8 *pu1_src,
767
                                 WORD32 src_strd,
768
                                 WORD32 alpha,
769
                                 WORD32 beta,
770
                                 UWORD32 u4_bs,
771
                                 const UWORD8 *pu1_cliptab)
772
0
{
773
0
    UWORD8 p2, p1, p0, q0, q1, q2;
774
0
    WORD32 pos_p2, pos_p1, pos_p0, pos_q0, pos_q1, pos_q2;
775
0
    UWORD8 a_p, a_q; /* Threshold variables */
776
0
    UWORD8 *pu1_p2; /* Pointer to the src sample p2 */
777
0
    UWORD8 *pu1_p2_temp;
778
0
    UWORD8 *pu1_src_temp;
779
0
    WORD8 i = 0, edge;
780
0
    WORD8 delta;
781
0
    WORD8 tc;
782
0
    WORD16 val;
783
0
    UWORD8 tc0, u1_bs;
784
0
785
0
    pu1_p2 = pu1_src - (src_strd << 2);
786
0
    pos_q0 = 0;
787
0
    pos_q1 = src_strd;
788
0
    pos_q2 = X2(src_strd);
789
0
    pos_p0 = X3(src_strd);
790
0
    pos_p1 = X2(src_strd);
791
0
    pos_p2 = src_strd;
792
0
793
0
    for(edge = 0; edge < 4; edge++, pu1_src += 4, pu1_p2 += 4)
794
0
    {
795
0
        pu1_src_temp = pu1_src;
796
0
        pu1_p2_temp = pu1_p2;
797
0
798
0
        /* Filter Decision */
799
0
        u1_bs = (UWORD8)((u4_bs >> ((3 - edge) << 3)) & 0x0ff);
800
0
        if(!u1_bs)
801
0
            continue;
802
0
        /* tc0 */
803
0
        tc0 = pu1_cliptab[u1_bs];
804
0
805
0
        for(i = 0; i < 4; ++i, pu1_src_temp++, pu1_p2_temp++)
806
0
        {
807
0
            q0 = pu1_src_temp[pos_q0];
808
0
            q1 = pu1_src_temp[pos_q1];
809
0
            p0 = pu1_p2_temp[pos_p0];
810
0
            p1 = pu1_p2_temp[pos_p1];
811
0
812
0
            /* Filter Decision */
813
0
            if((ABS(p0 - q0) >= alpha) ||
814
0
               (ABS(q1 - q0) >= beta) ||
815
0
               (ABS(p1 - p0) >= beta))
816
0
                continue;
817
0
818
0
            q2 = pu1_src_temp[pos_q2];
819
0
            p2 = pu1_p2_temp[pos_p2];
820
0
821
0
            a_p = ABS(p2 - p0);
822
0
            a_q = ABS(q2 - q0);
823
0
824
0
            /* tc */
825
0
            tc = tc0 + (a_p < beta) + (a_q < beta);
826
0
            val = ((((q0 - p0) << 2) + (p1 - q1) + 4) >> 3);
827
0
            delta = CLIP3(-tc, tc, val);
828
0
            /* p0' */
829
0
            val = p0 + delta;
830
0
            pu1_p2_temp[pos_p0] = CLIP_U8(val);
831
0
            /* q0' */
832
0
            val = q0 - delta;
833
0
            pu1_src_temp[pos_q0] = CLIP_U8(val);
834
0
835
0
            /* Luma */
836
0
            if(a_p < beta)
837
0
            {
838
0
                /* p1' */
839
0
                val = ((p2 + ((p0 + q0 + 1) >> 1) - (p1 << 1)) >> 1);
840
0
                pu1_p2_temp[pos_p1] += CLIP3(-tc0, tc0, val);
841
0
            }
842
0
843
0
            if(a_q < beta)
844
0
            {
845
0
                /* q1' */
846
0
                val = ((q2 + ((p0 + q0 + 1) >> 1) - (q1 << 1)) >> 1);
847
0
                pu1_src_temp[pos_q1] += CLIP3(-tc0, tc0, val);
848
0
            }
849
0
        }
850
0
    }
851
0
}
852
853
/*****************************************************************************/
854
/*                                                                           */
855
/*  Function Name : ih264_deblk_chroma_horz_bslt4_bp()                       */
856
/*                                                                           */
857
/*  Description   : This function performs filtering of a chroma block       */
858
/*                  horizontal edge when boundary strength is less than 4.   */
859
/*                                                                           */
860
/*  Inputs        : pu1_src       - pointer to the src sample q0 of U        */
861
/*                  src_strd      - source stride                            */
862
/*                  alpha         - alpha value for the boundary             */
863
/*                  beta          - beta value for the boundary              */
864
/*                  u4_bs         - packed Boundary strength array           */
865
/*                  pu1_cliptab   - tc0_table                                */
866
/*                                                                           */
867
/*  Globals       : None                                                     */
868
/*                                                                           */
869
/*  Processing    : This operation is described in Sec. 8.7.2.3 under the    */
870
/*                  title "Filtering process for edges for bS less than 4"   */
871
/*                  in ITU T Rec H.264.                                      */
872
/*                                                                           */
873
/*  Outputs       : None                                                     */
874
/*                                                                           */
875
/*  Returns       : None                                                     */
876
/*                                                                           */
877
/*  Issues        : None                                                     */
878
/*                                                                           */
879
/*  Revision History:                                                        */
880
/*                                                                           */
881
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
882
/*         28 11 2013   Ittiam          Draft                                */
883
/*                                                                           */
884
/*****************************************************************************/
885
void ih264_deblk_chroma_horz_bslt4_bp(UWORD8 *pu1_src,
886
                                      WORD32 src_strd,
887
                                      WORD32 alpha,
888
                                      WORD32 beta,
889
                                      UWORD32 u4_bs,
890
                                      const UWORD8 *pu1_cliptab)
891
0
{
892
0
    UWORD8 *pu1_src_u = pu1_src; /* Pointer to the src sample q0 of plane U*/
893
0
    UWORD8 *pu1_src_v = pu1_src + 1; /* Pointer to the src sample q0 of plane V*/
894
0
    UWORD8 p1_u, p0_u, q0_u, q1_u, p1_v, p0_v, q0_v, q1_v;
895
0
    WORD32 pos_p1, pos_p0, pos_q0, pos_q1;
896
0
    UWORD8 *pu1_src_temp_u, *pu1_src_temp_v;
897
0
    UWORD8 *pu1_p1_u; /* Pointer to the src sample p1 of plane U*/
898
0
    UWORD8 *pu1_p1_v; /* Pointer to the src sample p1 of plane V*/
899
0
    UWORD8 *pu1_p1_temp_u, *pu1_p1_temp_v;
900
0
    WORD8 i = 0, edge;
901
0
    WORD8 delta;
902
0
    WORD8 tc;
903
0
    WORD16 val;
904
0
    UWORD8 u1_bs;
905
0
    UWORD8 tc0;
906
0
907
0
    pu1_p1_u = pu1_src_u - (src_strd << 1);
908
0
    pu1_p1_v = pu1_src_v - (src_strd << 1);
909
0
    pos_q0 = 0;
910
0
    pos_q1 = src_strd;
911
0
    pos_p0 = src_strd;
912
0
    pos_p1 = 0;
913
0
914
0
    for(edge = 0; edge < 4; edge++, pu1_src_u += 4, pu1_p1_u += 4,
915
0
                    pu1_src_v += 4, pu1_p1_v += 4)
916
0
    {
917
0
        pu1_src_temp_u = pu1_src_u;
918
0
        pu1_p1_temp_u = pu1_p1_u;
919
0
        pu1_src_temp_v = pu1_src_v;
920
0
        pu1_p1_temp_v = pu1_p1_v;
921
0
922
0
        /* Filter Decision */
923
0
        u1_bs = (UWORD8)((u4_bs >> ((3 - edge) << 3)) & 0x0ff);
924
0
        if(!u1_bs)
925
0
            continue;
926
0
        /* tc0 */
927
0
        tc0 = pu1_cliptab[u1_bs];
928
0
929
0
        for(i = 0; i < 2; ++i, pu1_src_temp_u += 2, pu1_p1_temp_u += 2,
930
0
                       pu1_src_temp_v += 2, pu1_p1_temp_v += 2)
931
0
        {
932
0
            q0_u = pu1_src_temp_u[pos_q0];
933
0
            q1_u = pu1_src_temp_u[pos_q1];
934
0
            p0_u = pu1_p1_temp_u[pos_p0];
935
0
            p1_u = pu1_p1_temp_u[pos_p1];
936
0
937
0
            q0_v = pu1_src_temp_v[pos_q0];
938
0
            q1_v = pu1_src_temp_v[pos_q1];
939
0
            p0_v = pu1_p1_temp_v[pos_p0];
940
0
            p1_v = pu1_p1_temp_v[pos_p1];
941
0
942
0
            /* tc */
943
0
            tc = tc0 + 1;
944
0
            /* Filter Decision */
945
0
            if(ABS(p0_u - q0_u) < alpha && ABS(q1_u - q0_u) < beta
946
0
                            && ABS(p1_u - p0_u) < beta)
947
0
            {
948
0
                val = ((((q0_u - p0_u) << 2) + (p1_u - q1_u) + 4) >> 3);
949
0
                delta = CLIP3(-tc, tc, val);
950
0
                /* p0' */
951
0
                val = p0_u + delta;
952
0
                pu1_p1_temp_u[pos_p0] = CLIP_U8(val);
953
0
                /* q0' */
954
0
                val = q0_u - delta;
955
0
                pu1_src_temp_u[pos_q0] = CLIP_U8(val);
956
0
            }
957
0
            /* Filter Decision */
958
0
            if(ABS(p0_v - q0_v) < alpha && ABS(q1_v - q0_v) < beta
959
0
                            && ABS(p1_v - p0_v) < beta)
960
0
            {
961
0
                val = ((((q0_v - p0_v) << 2) + (p1_v - q1_v) + 4) >> 3);
962
0
                delta = CLIP3(-tc, tc, val);
963
0
                /* p0' */
964
0
                val = p0_v + delta;
965
0
                pu1_p1_temp_v[pos_p0] = CLIP_U8(val);
966
0
                /* q0' */
967
0
                val = q0_v - delta;
968
0
                pu1_src_temp_v[pos_q0] = CLIP_U8(val);
969
0
            }
970
0
        }
971
0
    }
972
0
}
973
974
/*****************************************************************************/
975
/* Function Definitions for vertical edge deblocking for double-call         */
976
/*****************************************************************************/
977
978
/*****************************************************************************/
979
/*                                                                           */
980
/*  Function Name : ih264_deblk_luma_vert_bs4_mbaff()                        */
981
/*                                                                           */
982
/*  Description   : This function performs filtering of a luma block         */
983
/*                  vertical edge when boundary strength is set to 4.        */
984
/*                                                                           */
985
/*  Inputs        : pu1_src       - pointer to the src sample q0             */
986
/*                  src_strd      - source stride                            */
987
/*                  alpha         - alpha value for the boundary             */
988
/*                  beta          - beta value for the boundary              */
989
/*                                                                           */
990
/*  Globals       : None                                                     */
991
/*                                                                           */
992
/*  Processing    : When the function is called twice, this operation is as  */
993
/*                  described in Sec. 8.7.2.3 under the title "Filtering     */
994
/*                  process for edges for bS equal to 4" in ITU T Rec H.264. */
995
/*                                                                           */
996
/*  Outputs       : None                                                     */
997
/*                                                                           */
998
/*  Returns       : None                                                     */
999
/*                                                                           */
1000
/*  Issues        : None                                                     */
1001
/*                                                                           */
1002
/*  Revision History:                                                        */
1003
/*                                                                           */
1004
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1005
/*         29 12 2014   Kaushik         Draft                                */
1006
/*                      Senthoor                                             */
1007
/*                                                                           */
1008
/*****************************************************************************/
1009
void ih264_deblk_luma_vert_bs4_mbaff(UWORD8 *pu1_src,
1010
                                     WORD32 src_strd,
1011
                                     WORD32 alpha,
1012
                                     WORD32 beta)
1013
0
{
1014
0
    UWORD8 p3, p2, p1, p0, q0, q1, q2, q3;
1015
0
    WORD32 pos_p3, pos_p2, pos_p1, pos_p0;
1016
0
    WORD32 pos_q0, pos_q1, pos_q2, pos_q3;
1017
0
    UWORD8 a_p, a_q; /* threshold variables */
1018
0
    WORD32 blk_strd = src_strd << 1; /* block_increment = src_strd * 2 */
1019
0
    UWORD8 *pu1_src_temp;
1020
0
    WORD8 i = 0, edge;
1021
0
1022
0
    pos_q0 = 0;
1023
0
    pos_q1 = 1;
1024
0
    pos_q2 = 2;
1025
0
    pos_q3 = 3;
1026
0
    pos_p0 = -1;
1027
0
    pos_p1 = -2;
1028
0
    pos_p2 = -3;
1029
0
    pos_p3 = -4;
1030
0
1031
0
    for(edge = 0; edge < 4; edge++, pu1_src += blk_strd)
1032
0
    {
1033
0
        pu1_src_temp = pu1_src;
1034
0
        for(i = 0; i < 2; ++i, pu1_src_temp += src_strd)
1035
0
        {
1036
0
            q0 = pu1_src_temp[pos_q0];
1037
0
            q1 = pu1_src_temp[pos_q1];
1038
0
            p0 = pu1_src_temp[pos_p0];
1039
0
            p1 = pu1_src_temp[pos_p1];
1040
0
1041
0
            /* Filter Decision */
1042
0
            if((ABS(p0 - q0) >= alpha) ||
1043
0
               (ABS(q1 - q0) >= beta) ||
1044
0
               (ABS(p1 - p0) >= beta))
1045
0
                continue;
1046
0
1047
0
            p2 = pu1_src_temp[pos_p2];
1048
0
            p3 = pu1_src_temp[pos_p3];
1049
0
            q2 = pu1_src_temp[pos_q2];
1050
0
            q3 = pu1_src_temp[pos_q3];
1051
0
1052
0
            if(ABS(p0 - q0) < ((alpha >> 2) + 2))
1053
0
            {
1054
0
                /* Threshold Variables */
1055
0
                a_p = (UWORD8)ABS(p2 - p0);
1056
0
                a_q = (UWORD8)ABS(q2 - q0);
1057
0
1058
0
                if(a_p < beta)
1059
0
                {
1060
0
                    /* p0', p1', p2' */
1061
0
                    pu1_src_temp[pos_p0] = ((p2 + X2(p1) + X2(p0) + X2(q0) + q1
1062
0
                                    + 4) >> 3);
1063
0
                    pu1_src_temp[pos_p1] = ((p2 + p1 + p0 + q0 + 2) >> 2);
1064
0
                    pu1_src_temp[pos_p2] =
1065
0
                                    ((X2(p3) + X3(p2) + p1 + p0 + q0
1066
0
                                                    + 4) >> 3);
1067
0
                }
1068
0
                else
1069
0
                {
1070
0
                    /* p0'*/
1071
0
                    pu1_src_temp[pos_p0] = ((X2(p1) + p0 + q1 + 2) >> 2);
1072
0
                }
1073
0
1074
0
                if(a_q < beta)
1075
0
                {
1076
0
                    /* q0', q1', q2' */
1077
0
                    pu1_src_temp[pos_q0] = (p1 + X2(p0) + X2(q0) + X2(q1) + q2
1078
0
                                    + 4) >> 3;
1079
0
                    pu1_src_temp[pos_q1] = (p0 + q0 + q1 + q2 + 2) >> 2;
1080
0
                    pu1_src_temp[pos_q2] = (X2(q3) + X3(q2) + q1 + q0 + p0 + 4)
1081
0
                                    >> 3;
1082
0
                }
1083
0
                else
1084
0
                {
1085
0
                    /* q0'*/
1086
0
                    pu1_src_temp[pos_q0] = (X2(q1) + q0 + p1 + 2) >> 2;
1087
0
                }
1088
0
            }
1089
0
            else
1090
0
            {
1091
0
                /* p0', q0'*/
1092
0
                pu1_src_temp[pos_p0] = ((X2(p1) + p0 + q1 + 2) >> 2);
1093
0
                pu1_src_temp[pos_q0] = (X2(q1) + q0 + p1 + 2) >> 2;
1094
0
            }
1095
0
        }
1096
0
    }
1097
0
}
1098
1099
/*****************************************************************************/
1100
/*                                                                           */
1101
/*  Function Name : ih264_deblk_chroma_vert_bs4_mbaff_bp()                   */
1102
/*                                                                           */
1103
/*  Description   : This function performs filtering of a chroma block       */
1104
/*                  vertical edge when boundary strength is set to 4.        */
1105
/*                                                                           */
1106
/*  Inputs        : pu1_src       - pointer to the src sample q0 of U        */
1107
/*                  src_strd      - source stride                            */
1108
/*                  alpha         - alpha value for the boundary             */
1109
/*                  beta          - beta value for the boundary              */
1110
/*                                                                           */
1111
/*  Globals       : None                                                     */
1112
/*                                                                           */
1113
/*  Processing    : When the function is called twice, this operation is as  */
1114
/*                  described in Sec. 8.7.2.3 under the title "Filtering     */
1115
/*                  process for edges for bS equal to 4" in ITU T Rec H.264. */
1116
/*                                                                           */
1117
/*  Outputs       : None                                                     */
1118
/*                                                                           */
1119
/*  Returns       : None                                                     */
1120
/*                                                                           */
1121
/*  Issues        : None                                                     */
1122
/*                                                                           */
1123
/*  Revision History:                                                        */
1124
/*                                                                           */
1125
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1126
/*         29 12 2014   Kaushik         Draft                                */
1127
/*                      Senthoor                                             */
1128
/*                                                                           */
1129
/*****************************************************************************/
1130
void ih264_deblk_chroma_vert_bs4_mbaff_bp(UWORD8 *pu1_src,
1131
                                          WORD32 src_strd,
1132
                                          WORD32 alpha,
1133
                                          WORD32 beta)
1134
0
{
1135
0
    UWORD8 *pu1_src_u = pu1_src; /* Pointer to the src sample q0 of U */
1136
0
    UWORD8 *pu1_src_v = pu1_src + 1; /* Pointer to the src sample q0 of V */
1137
0
    UWORD8 p1_u, p0_u, q0_u, q1_u, p1_v, p0_v, q0_v, q1_v;
1138
0
    WORD32 blk_strd = src_strd;
1139
0
    WORD32 pos_p1, pos_p0, pos_q0, pos_q1;
1140
0
    UWORD8 *pu1_src_temp_u, *pu1_src_temp_v;
1141
0
    WORD8 edge;
1142
0
1143
0
    pos_q0 = 0;
1144
0
    pos_q1 = 2;
1145
0
    pos_p0 = -2;
1146
0
    pos_p1 = -4;
1147
0
1148
0
    for(edge = 0; edge < 4;
1149
0
                    edge++, pu1_src_u += blk_strd, pu1_src_v += blk_strd)
1150
0
    {
1151
0
        pu1_src_temp_u = pu1_src_u;
1152
0
        pu1_src_temp_v = pu1_src_v;
1153
0
1154
0
        q0_u = pu1_src_temp_u[pos_q0];
1155
0
        q1_u = pu1_src_temp_u[pos_q1];
1156
0
        p0_u = pu1_src_temp_u[pos_p0];
1157
0
        p1_u = pu1_src_temp_u[pos_p1];
1158
0
        q0_v = pu1_src_temp_v[pos_q0];
1159
0
        q1_v = pu1_src_temp_v[pos_q1];
1160
0
        p0_v = pu1_src_temp_v[pos_p0];
1161
0
        p1_v = pu1_src_temp_v[pos_p1];
1162
0
1163
0
        /* Filter Decision */
1164
0
        if((ABS(p0_u - q0_u) < alpha) &&
1165
0
           (ABS(q1_u - q0_u) < beta) &&
1166
0
           (ABS(p1_u - p0_u) < beta))
1167
0
        {
1168
0
            /* p0' */
1169
0
            pu1_src_temp_u[pos_p0] = ((X2(p1_u) + p0_u + q1_u + 2) >> 2);
1170
0
            /* q0' */
1171
0
            pu1_src_temp_u[pos_q0] = (X2(q1_u) + q0_u + p1_u + 2) >> 2;
1172
0
        }
1173
0
1174
0
        /* Filter Decision */
1175
0
        if(ABS(p0_v - q0_v) < alpha && ABS(q1_v - q0_v) < beta
1176
0
                        && ABS(p1_v - p0_v) < beta)
1177
0
        {
1178
0
            /* p0' */
1179
0
            pu1_src_temp_v[pos_p0] = ((X2(p1_v) + p0_v + q1_v + 2) >> 2);
1180
0
            /* q0' */
1181
0
            pu1_src_temp_v[pos_q0] = (X2(q1_v) + q0_v + p1_v + 2) >> 2;
1182
0
        }
1183
0
    }
1184
0
}
1185
1186
/*****************************************************************************/
1187
/*                                                                           */
1188
/*  Function Name : ih264_deblk_luma_vert_bslt4_mbaff()                      */
1189
/*                                                                           */
1190
/*  Description   : This function performs filtering of a luma block         */
1191
/*                  vertical edge when boundary strength is less than 4.     */
1192
/*                                                                           */
1193
/*  Inputs        : pu1_src       - pointer to the src sample q0             */
1194
/*                  src_strd      - source stride                            */
1195
/*                  alpha         - alpha value for the boundary             */
1196
/*                  beta          - beta value for the boundary              */
1197
/*                  u4_bs         - packed Boundary strength array           */
1198
/*                  pu1_cliptab   - tc0_table                                */
1199
/*                                                                           */
1200
/*  Globals       : None                                                     */
1201
/*                                                                           */
1202
/*  Processing    : When the function is called twice, this operation is as  */
1203
/*                  described in Sec. 8.7.2.3 under the title "Filtering     */
1204
/*                  process for edges for bS less than 4" in ITU T Rec H.264.*/
1205
/*                                                                           */
1206
/*  Outputs       : None                                                     */
1207
/*                                                                           */
1208
/*  Returns       : None                                                     */
1209
/*                                                                           */
1210
/*  Issues        : None                                                     */
1211
/*                                                                           */
1212
/*  Revision History:                                                        */
1213
/*                                                                           */
1214
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1215
/*         29 12 2014   Kaushik         Draft                                */
1216
/*                      Senthoor                                             */
1217
/*                                                                           */
1218
/*****************************************************************************/
1219
void ih264_deblk_luma_vert_bslt4_mbaff(UWORD8 *pu1_src,
1220
                                       WORD32 src_strd,
1221
                                       WORD32 alpha,
1222
                                       WORD32 beta,
1223
                                       UWORD32 u4_bs,
1224
                                       const UWORD8 *pu1_cliptab)
1225
0
{
1226
0
    WORD8 i = 0, edge;
1227
0
    UWORD8 p2, p1, p0, q0, q1, q2;
1228
0
    WORD32 pos_p2, pos_p1, pos_p0, pos_q0, pos_q1, pos_q2;
1229
0
    UWORD8 a_p, a_q; /* Threshold variables */
1230
0
    WORD32 blk_strd = src_strd << 1; /* block_increment = src_strd * 2 */
1231
0
    UWORD8 *pu1_src_temp;
1232
0
    WORD8 delta;
1233
0
    WORD8 tc;
1234
0
    WORD16 val;
1235
0
    UWORD8 tc0, u1_bs;
1236
0
1237
0
    pos_q0 = 0;
1238
0
    pos_q1 = 1;
1239
0
    pos_q2 = 2;
1240
0
    pos_p0 = -1;
1241
0
    pos_p1 = -2;
1242
0
    pos_p2 = -3;
1243
0
1244
0
    for(edge = 0; edge < 4; edge++, pu1_src += blk_strd)
1245
0
    {
1246
0
        pu1_src_temp = pu1_src;
1247
0
        /* Filter Decision */
1248
0
        u1_bs = (UWORD8)((u4_bs >> ((3 - edge) << 3)) & 0x0ff);
1249
0
        if(!u1_bs)
1250
0
            continue;
1251
0
        /* tc0 */
1252
0
        tc0 = pu1_cliptab[u1_bs];
1253
0
        for(i = 0; i < 2; ++i, pu1_src_temp += src_strd)
1254
0
        {
1255
0
            q0 = pu1_src_temp[pos_q0];
1256
0
            q1 = pu1_src_temp[pos_q1];
1257
0
            p0 = pu1_src_temp[pos_p0];
1258
0
            p1 = pu1_src_temp[pos_p1];
1259
0
1260
0
            /* Filter Decision */
1261
0
            if((ABS(p0 - q0) >= alpha) ||
1262
0
               (ABS(q1 - q0) >= beta) ||
1263
0
               (ABS(p1 - p0) >= beta))
1264
0
                continue;
1265
0
1266
0
            q2 = pu1_src_temp[pos_q2];
1267
0
            p2 = pu1_src_temp[pos_p2];
1268
0
1269
0
            a_p = ABS(p2 - p0);
1270
0
            a_q = ABS(q2 - q0);
1271
0
1272
0
            /* tc */
1273
0
            tc = tc0 + (a_p < beta) + (a_q < beta);
1274
0
1275
0
            val = ((((q0 - p0) << 2) + (p1 - q1) + 4) >> 3);
1276
0
            delta = CLIP3(-tc, tc, val);
1277
0
            /* p0' */
1278
0
            val = p0 + delta;
1279
0
            pu1_src_temp[pos_p0] = CLIP_U8(val);
1280
0
            /* q0' */
1281
0
            val = q0 - delta;
1282
0
            pu1_src_temp[pos_q0] = CLIP_U8(val);
1283
0
1284
0
            /* Luma only */
1285
0
            if(a_p < beta)
1286
0
            {
1287
0
                /* p1' */
1288
0
                val = ((p2 + ((p0 + q0 + 1) >> 1) - (p1 << 1)) >> 1);
1289
0
                pu1_src_temp[pos_p1] += CLIP3(-tc0, tc0, val);
1290
0
            }
1291
0
1292
0
            if(a_q < beta)
1293
0
            {
1294
0
                /* q1' */
1295
0
                val = ((q2 + ((p0 + q0 + 1) >> 1) - (q1 << 1)) >> 1);
1296
0
                pu1_src_temp[pos_q1] += CLIP3(-tc0, tc0, val);
1297
0
            }
1298
0
        }
1299
0
    }
1300
0
}
1301
1302
/*****************************************************************************/
1303
/*                                                                           */
1304
/*  Function Name : ih264_deblk_chroma_vert_bslt4_mbaff_bp()                 */
1305
/*                                                                           */
1306
/*  Description   : This function performs filtering of a chroma block       */
1307
/*                  vertical edge when boundary strength is less than 4.     */
1308
/*                                                                           */
1309
/*  Inputs        : pu1_src       - pointer to the src sample q0 of U        */
1310
/*                  src_strd      - source stride                            */
1311
/*                  alpha         - alpha value for the boundary             */
1312
/*                  beta          - beta value for the boundary              */
1313
/*                  u4_bs         - packed Boundary strength array           */
1314
/*                  pu1_cliptab   - tc0_table                                */
1315
/*                                                                           */
1316
/*  Globals       : None                                                     */
1317
/*                                                                           */
1318
/*  Processing    : When the function is called twice, this operation is as  */
1319
/*                  described in Sec. 8.7.2.3 under the title "Filtering     */
1320
/*                  process for edges for bS less than 4" in ITU T Rec H.264.*/
1321
/*                                                                           */
1322
/*  Outputs       : None                                                     */
1323
/*                                                                           */
1324
/*  Returns       : None                                                     */
1325
/*                                                                           */
1326
/*  Issues        : None                                                     */
1327
/*                                                                           */
1328
/*  Revision History:                                                        */
1329
/*                                                                           */
1330
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1331
/*         29 12 2014   Kaushik         Draft                                */
1332
/*                      Senthoor                                             */
1333
/*                                                                           */
1334
/*****************************************************************************/
1335
void ih264_deblk_chroma_vert_bslt4_mbaff_bp(UWORD8 *pu1_src,
1336
                                            WORD32 src_strd,
1337
                                            WORD32 alpha,
1338
                                            WORD32 beta,
1339
                                            UWORD32 u4_bs,
1340
                                            const UWORD8 *pu1_cliptab)
1341
0
{
1342
0
    UWORD8 *pu1_src_u = pu1_src; /* Pointer to the src sample q0 of plane U*/
1343
0
    UWORD8 *pu1_src_v = pu1_src + 1; /* Pointer to the src sample q0 of plane V*/
1344
0
    UWORD8 p1_u, p0_u, q0_u, q1_u, p1_v, p0_v, q0_v, q1_v;
1345
0
    WORD32 blk_strd = src_strd;
1346
0
    WORD32 pos_p1, pos_p0, pos_q0, pos_q1;
1347
0
    UWORD8 *pu1_src_temp_u, *pu1_src_temp_v;
1348
0
    WORD8 edge;
1349
0
    WORD8 delta;
1350
0
    WORD8 tc;
1351
0
    WORD16 val;
1352
0
    UWORD8 tc0, u1_bs;
1353
0
1354
0
    pos_q0 = 0;
1355
0
    pos_q1 = 2;
1356
0
    pos_p0 = -2;
1357
0
    pos_p1 = -4;
1358
0
1359
0
    for(edge = 0; edge < 4;
1360
0
                    edge++, pu1_src_u += blk_strd, pu1_src_v += blk_strd)
1361
0
    {
1362
0
        pu1_src_temp_u = pu1_src_u;
1363
0
        pu1_src_temp_v = pu1_src_v;
1364
0
        /* Filter Decision */
1365
0
        u1_bs = (UWORD8)((u4_bs >> ((3 - edge) << 3)) & 0x0ff);
1366
0
        if(!u1_bs)
1367
0
            continue;
1368
0
        /* tc0 */
1369
0
        tc0 = pu1_cliptab[u1_bs];
1370
0
        tc = tc0 + 1;
1371
0
1372
0
        q0_u = pu1_src_temp_u[pos_q0];
1373
0
        q1_u = pu1_src_temp_u[pos_q1];
1374
0
        p0_u = pu1_src_temp_u[pos_p0];
1375
0
        p1_u = pu1_src_temp_u[pos_p1];
1376
0
1377
0
        q0_v = pu1_src_temp_v[pos_q0];
1378
0
        q1_v = pu1_src_temp_v[pos_q1];
1379
0
        p0_v = pu1_src_temp_v[pos_p0];
1380
0
        p1_v = pu1_src_temp_v[pos_p1];
1381
0
1382
0
        /* Filter Decision */
1383
0
        if((ABS(p0_u - q0_u) < alpha) &&
1384
0
           (ABS(q1_u - q0_u) < beta) &&
1385
0
           (ABS(p1_u - p0_u) < beta))
1386
0
        {
1387
0
            val = ((((q0_u - p0_u) << 2) + (p1_u - q1_u) + 4) >> 3);
1388
0
            delta = CLIP3(-tc, tc, val);
1389
0
            /* p0' */
1390
0
            val = p0_u + delta;
1391
0
            pu1_src_temp_u[pos_p0] = CLIP_U8(val);
1392
0
            /* q0' */
1393
0
            val = q0_u - delta;
1394
0
            pu1_src_temp_u[pos_q0] = CLIP_U8(val);
1395
0
        }
1396
0
1397
0
        /* Filter Decision */
1398
0
        if((ABS(p0_v - q0_v) < alpha) &&
1399
0
           (ABS(q1_v - q0_v) < beta) &&
1400
0
           (ABS(p1_v - p0_v) < beta))
1401
0
        {
1402
0
            val = ((((q0_v - p0_v) << 2) + (p1_v - q1_v) + 4) >> 3);
1403
0
            delta = CLIP3(-tc, tc, val);
1404
0
            /* p0' */
1405
0
            val = p0_v + delta;
1406
0
            pu1_src_temp_v[pos_p0] = CLIP_U8(val);
1407
0
            /* q0' */
1408
0
            val = q0_v - delta;
1409
0
            pu1_src_temp_v[pos_q0] = CLIP_U8(val);
1410
0
        }
1411
0
    }
1412
0
}
1413
1414
/*****************************************************************************/
1415
/* Function Definitions for chroma deblocking in high profile                */
1416
/*****************************************************************************/
1417
1418
/*****************************************************************************/
1419
/*                                                                           */
1420
/*  Function Name : ih264_deblk_chroma_vert_bs4()                            */
1421
/*                                                                           */
1422
/*  Description   : This function performs filtering of a chroma block       */
1423
/*                  vertical edge when the boundary strength is set to 4 in  */
1424
/*                  high profile.                                            */
1425
/*                                                                           */
1426
/*  Inputs        : pu1_src    - pointer to the src sample q0 of U           */
1427
/*                  src_strd   - source stride                               */
1428
/*                  alpha_cb   - alpha value for the boundary in U           */
1429
/*                  beta_cb    - beta value for the boundary in U            */
1430
/*                  alpha_cr   - alpha value for the boundary in V           */
1431
/*                  beta_cr    - beta value for the boundary in V            */
1432
/*                                                                           */
1433
/*  Globals       : None                                                     */
1434
/*                                                                           */
1435
/*  Processing    : This operation is described in Sec. 8.7.2.4 under the    */
1436
/*                  title "Filtering process for edges for bS equal to 4" in */
1437
/*                  ITU T Rec H.264 with alpha and beta values different in  */
1438
/*                  U and V.                                                 */
1439
/*                                                                           */
1440
/*  Outputs       : None                                                     */
1441
/*                                                                           */
1442
/*  Returns       : None                                                     */
1443
/*                                                                           */
1444
/*  Issues        : None                                                     */
1445
/*                                                                           */
1446
/*  Revision History:                                                        */
1447
/*                                                                           */
1448
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1449
/*         29 12 2014   Kaushik         Draft                                */
1450
/*                      Senthoor                                             */
1451
/*                                                                           */
1452
/*****************************************************************************/
1453
void ih264_deblk_chroma_vert_bs4(UWORD8 *pu1_src,
1454
                                 WORD32 src_strd,
1455
                                 WORD32 alpha_cb,
1456
                                 WORD32 beta_cb,
1457
                                 WORD32 alpha_cr,
1458
                                 WORD32 beta_cr)
1459
0
{
1460
0
    UWORD8 *pu1_src_u = pu1_src; /* Pointer to the src sample q0 of U */
1461
0
    UWORD8 *pu1_src_v = pu1_src + 1; /* Pointer to the src sample q0 of V */
1462
0
    UWORD8 p1_u, p0_u, q0_u, q1_u, p1_v, p0_v, q0_v, q1_v;
1463
0
    WORD32 blk_strd = src_strd << 1; /* block_increment = src_strd * 2*/
1464
0
    WORD32 pos_p1, pos_p0, pos_q0, pos_q1;
1465
0
    UWORD8 *pu1_src_temp_u, *pu1_src_temp_v;
1466
0
    WORD8 i = 0, edge;
1467
0
1468
0
    pos_q0 = 0;
1469
0
    pos_q1 = 2;
1470
0
    pos_p0 = -2;
1471
0
    pos_p1 = -4;
1472
0
1473
0
    for(edge = 0; edge < 4;
1474
0
                    edge++, pu1_src_u += blk_strd, pu1_src_v += blk_strd)
1475
0
    {
1476
0
        pu1_src_temp_u = pu1_src_u;
1477
0
        pu1_src_temp_v = pu1_src_v;
1478
0
        for(i = 0; i < 2; ++i, pu1_src_temp_u += src_strd, pu1_src_temp_v +=
1479
0
                        src_strd)
1480
0
        {
1481
0
            q0_u = pu1_src_temp_u[pos_q0];
1482
0
            q1_u = pu1_src_temp_u[pos_q1];
1483
0
            p0_u = pu1_src_temp_u[pos_p0];
1484
0
            p1_u = pu1_src_temp_u[pos_p1];
1485
0
            q0_v = pu1_src_temp_v[pos_q0];
1486
0
            q1_v = pu1_src_temp_v[pos_q1];
1487
0
            p0_v = pu1_src_temp_v[pos_p0];
1488
0
            p1_v = pu1_src_temp_v[pos_p1];
1489
0
1490
0
            /* Filter Decision */
1491
0
            if((ABS(p0_u - q0_u) < alpha_cb) &&
1492
0
               (ABS(q1_u - q0_u) < beta_cb) &&
1493
0
               (ABS(p1_u - p0_u) < beta_cb))
1494
0
            {
1495
0
                /* p0' */
1496
0
                pu1_src_temp_u[pos_p0] = ((X2(p1_u) + p0_u + q1_u + 2) >> 2);
1497
0
                /* q0' */
1498
0
                pu1_src_temp_u[pos_q0] = (X2(q1_u) + q0_u + p1_u + 2) >> 2;
1499
0
            }
1500
0
1501
0
            /* Filter Decision */
1502
0
            if((ABS(p0_v - q0_v) < alpha_cr) &&
1503
0
               (ABS(q1_v - q0_v) < beta_cr) &&
1504
0
               (ABS(p1_v - p0_v) < beta_cr))
1505
0
            {
1506
0
                /* p0' */
1507
0
                pu1_src_temp_v[pos_p0] = ((X2(p1_v) + p0_v + q1_v + 2) >> 2);
1508
0
                /* q0' */
1509
0
                pu1_src_temp_v[pos_q0] = (X2(q1_v) + q0_v + p1_v + 2) >> 2;
1510
0
            }
1511
0
        }
1512
0
    }
1513
0
}
1514
1515
/*****************************************************************************/
1516
/*                                                                           */
1517
/*  Function Name : ih264_deblk_chroma_horz_bs4()                            */
1518
/*                                                                           */
1519
/*  Description   : This function performs filtering of a chroma block       */
1520
/*                  horizontal edge when the boundary strength is set to 4   */
1521
/*                  in high profile.                                         */
1522
/*                                                                           */
1523
/*  Inputs        : pu1_src    - pointer to the src sample q0 of U           */
1524
/*                  src_strd   - source stride                               */
1525
/*                  alpha_cb   - alpha value for the boundary in U           */
1526
/*                  beta_cb    - beta value for the boundary in U            */
1527
/*                  alpha_cr   - alpha value for the boundary in V           */
1528
/*                  beta_cr    - beta value for the boundary in V            */
1529
/*                                                                           */
1530
/*  Globals       : None                                                     */
1531
/*                                                                           */
1532
/*  Processing    : This operation is described in Sec. 8.7.2.4 under the    */
1533
/*                  title "Filtering process for edges for bS equal to 4" in */
1534
/*                  ITU T Rec H.264 with alpha and beta values different in  */
1535
/*                  U and V.                                                 */
1536
/*                                                                           */
1537
/*  Outputs       : None                                                     */
1538
/*                                                                           */
1539
/*  Returns       : None                                                     */
1540
/*                                                                           */
1541
/*  Issues        : None                                                     */
1542
/*                                                                           */
1543
/*  Revision History:                                                        */
1544
/*                                                                           */
1545
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1546
/*         29 12 2014   Kaushik         Draft                                */
1547
/*                      Senthoor                                             */
1548
/*                                                                           */
1549
/*****************************************************************************/
1550
void ih264_deblk_chroma_horz_bs4(UWORD8 *pu1_src,
1551
                                 WORD32 src_strd,
1552
                                 WORD32 alpha_cb,
1553
                                 WORD32 beta_cb,
1554
                                 WORD32 alpha_cr,
1555
                                 WORD32 beta_cr)
1556
0
{
1557
0
    UWORD8 *pu1_src_u = pu1_src; /* Pointer to the src sample q0 of U */
1558
0
    UWORD8 *pu1_src_v = pu1_src + 1; /* Pointer to the src sample q0 of V */
1559
0
    UWORD8 p1_u, p0_u, q0_u, q1_u, p1_v, p0_v, q0_v, q1_v;
1560
0
    WORD32 pos_p1, pos_p0, pos_q0, pos_q1;
1561
0
    UWORD8 *pu1_src_temp_u, *pu1_src_temp_v;
1562
0
    UWORD8 *pu1_p1_u; /* Pointer to the src sample p1 of U */
1563
0
    UWORD8 *pu1_p1_v; /* Pointer to the src sample p1 of U */
1564
0
    UWORD8 *pu1_p1_temp_u, *pu1_p1_temp_v;
1565
0
    WORD8 i = 0, edge;
1566
0
1567
0
    pu1_p1_u = pu1_src_u - (src_strd << 1);
1568
0
    pu1_p1_v = pu1_src_v - (src_strd << 1);
1569
0
    pos_q0 = 0;
1570
0
    pos_q1 = src_strd;
1571
0
    pos_p0 = src_strd;
1572
0
    pos_p1 = 0;
1573
0
1574
0
    for(edge = 0; edge < 4; edge++, pu1_src_u += 4, pu1_p1_u += 4, pu1_src_v +=
1575
0
                    4, pu1_p1_v += 4)
1576
0
    {
1577
0
        pu1_src_temp_u = pu1_src_u;
1578
0
        pu1_p1_temp_u = pu1_p1_u;
1579
0
        pu1_src_temp_v = pu1_src_v;
1580
0
        pu1_p1_temp_v = pu1_p1_v;
1581
0
        for(i = 0; i < 2; ++i, pu1_src_temp_u += 2, pu1_p1_temp_u += 2,
1582
0
                       pu1_src_temp_v += 2, pu1_p1_temp_v += 2)
1583
0
        {
1584
0
            q0_u = pu1_src_temp_u[pos_q0];
1585
0
            q1_u = pu1_src_temp_u[pos_q1];
1586
0
            p0_u = pu1_p1_temp_u[pos_p0];
1587
0
            p1_u = pu1_p1_temp_u[pos_p1];
1588
0
1589
0
            q0_v = pu1_src_temp_v[pos_q0];
1590
0
            q1_v = pu1_src_temp_v[pos_q1];
1591
0
            p0_v = pu1_p1_temp_v[pos_p0];
1592
0
            p1_v = pu1_p1_temp_v[pos_p1];
1593
0
1594
0
            /* Filter Decision */
1595
0
            if(ABS(p0_u - q0_u) < alpha_cb && ABS(q1_u - q0_u) < beta_cb
1596
0
                            && ABS(p1_u - p0_u) < beta_cb)
1597
0
            {
1598
0
                /* p0' */
1599
0
                pu1_p1_temp_u[pos_p0] = (X2(p1_u) + p0_u + q1_u + 2) >> 2;
1600
0
                /* q0' */
1601
0
                pu1_src_temp_u[pos_q0] = (X2(q1_u) + q0_u + p1_u + 2) >> 2;
1602
0
            }
1603
0
1604
0
            /* Filter Decision */
1605
0
            if(ABS(p0_v - q0_v) < alpha_cr && ABS(q1_v - q0_v) < beta_cr
1606
0
                            && ABS(p1_v - p0_v) < beta_cr)
1607
0
            {
1608
0
                /* p0' */
1609
0
                pu1_p1_temp_v[pos_p0] = (X2(p1_v) + p0_v + q1_v + 2) >> 2;
1610
0
                /* q0' */
1611
0
                pu1_src_temp_v[pos_q0] = (X2(q1_v) + q0_v + p1_v + 2) >> 2;
1612
0
            }
1613
0
        }
1614
0
    }
1615
0
}
1616
1617
/*****************************************************************************/
1618
/*                                                                           */
1619
/*  Function Name : ih264_deblk_chroma_vert_bslt4()                          */
1620
/*                                                                           */
1621
/*  Description   : This function performs filtering of a chroma block       */
1622
/*                  vertical edge when the boundary strength is less than 4  */
1623
/*                  in high profile.                                         */
1624
/*                                                                           */
1625
/*  Inputs        : pu1_src          - pointer to the src sample q0 of U     */
1626
/*                  src_strd         - source stride                         */
1627
/*                  alpha_cb         - alpha value for the boundary in U     */
1628
/*                  beta_cb          - beta value for the boundary in U      */
1629
/*                  alpha_cr         - alpha value for the boundary in V     */
1630
/*                  beta_cr          - beta value for the boundary in V      */
1631
/*                  u4_bs            - packed Boundary strength array        */
1632
/*                  pu1_cliptab_cb   - tc0_table for U                       */
1633
/*                  pu1_cliptab_cr   - tc0_table for V                       */
1634
/*                                                                           */
1635
/*  Globals       : None                                                     */
1636
/*                                                                           */
1637
/*  Processing    : This operation is described in Sec. 8.7.2.3 under the    */
1638
/*                  title "Filtering process for edges for bS less than 4"   */
1639
/*                  in ITU T Rec H.264 with alpha and beta values different  */
1640
/*                  in U and V.                                              */
1641
/*                                                                           */
1642
/*  Outputs       : None                                                     */
1643
/*                                                                           */
1644
/*  Returns       : None                                                     */
1645
/*                                                                           */
1646
/*  Issues        : None                                                     */
1647
/*                                                                           */
1648
/*  Revision History:                                                        */
1649
/*                                                                           */
1650
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1651
/*         29 12 2014   Kaushik         Draft                                */
1652
/*                      Senthoor                                             */
1653
/*                                                                           */
1654
/*****************************************************************************/
1655
void ih264_deblk_chroma_vert_bslt4(UWORD8 *pu1_src,
1656
                                   WORD32 src_strd,
1657
                                   WORD32 alpha_cb,
1658
                                   WORD32 beta_cb,
1659
                                   WORD32 alpha_cr,
1660
                                   WORD32 beta_cr,
1661
                                   UWORD32 u4_bs,
1662
                                   const UWORD8 *pu1_cliptab_cb,
1663
                                   const UWORD8 *pu1_cliptab_cr)
1664
0
{
1665
0
    UWORD8 *pu1_src_u = pu1_src; /* Pointer to the src sample q0 of plane U*/
1666
0
    UWORD8 *pu1_src_v = pu1_src + 1; /* Pointer to the src sample q0 of plane V*/
1667
0
    UWORD8 p1_u, p0_u, q0_u, q1_u, p1_v, p0_v, q0_v, q1_v;
1668
0
    WORD32 blk_strd = src_strd << 1; /* block_increment = src_strd * 2 */
1669
0
    WORD32 pos_p1, pos_p0, pos_q0, pos_q1;
1670
0
    UWORD8 *pu1_src_temp_u, *pu1_src_temp_v;
1671
0
    WORD8 i = 0, edge;
1672
0
    WORD8 delta;
1673
0
    WORD8 tcb, tcr;
1674
0
    WORD16 val;
1675
0
    UWORD8 tcb0, tcr0, u1_bs;
1676
0
1677
0
    pos_q0 = 0;
1678
0
    pos_q1 = 2;
1679
0
    pos_p0 = -2;
1680
0
    pos_p1 = -4;
1681
0
1682
0
    for(edge = 0; edge < 4;
1683
0
                    edge++, pu1_src_u += blk_strd, pu1_src_v += blk_strd)
1684
0
    {
1685
0
        pu1_src_temp_u = pu1_src_u;
1686
0
        pu1_src_temp_v = pu1_src_v;
1687
0
        /* Filter Decision */
1688
0
        u1_bs = (UWORD8)((u4_bs >> ((3 - edge) << 3)) & 0x0ff);
1689
0
        if(!u1_bs)
1690
0
            continue;
1691
0
        /* tc0 */
1692
0
        tcb0 = pu1_cliptab_cb[u1_bs];
1693
0
        tcr0 = pu1_cliptab_cr[u1_bs];
1694
0
        tcb = tcb0 + 1;
1695
0
        tcr = tcr0 + 1;
1696
0
        for(i = 0; i < 2; ++i, pu1_src_temp_u += src_strd, pu1_src_temp_v +=
1697
0
                        src_strd)
1698
0
        {
1699
0
            q0_u = pu1_src_temp_u[pos_q0];
1700
0
            q1_u = pu1_src_temp_u[pos_q1];
1701
0
            p0_u = pu1_src_temp_u[pos_p0];
1702
0
            p1_u = pu1_src_temp_u[pos_p1];
1703
0
1704
0
            q0_v = pu1_src_temp_v[pos_q0];
1705
0
            q1_v = pu1_src_temp_v[pos_q1];
1706
0
            p0_v = pu1_src_temp_v[pos_p0];
1707
0
            p1_v = pu1_src_temp_v[pos_p1];
1708
0
1709
0
            /* Filter Decision */
1710
0
            if(ABS(p0_u - q0_u) < alpha_cb && ABS(q1_u - q0_u) < beta_cb
1711
0
                            && ABS(p1_u - p0_u) < beta_cb)
1712
0
            {
1713
0
                val = ((((q0_u - p0_u) << 2) + (p1_u - q1_u) + 4) >> 3);
1714
0
                delta = CLIP3(-tcb, tcb, val);
1715
0
                /* p0' */
1716
0
                val = p0_u + delta;
1717
0
                pu1_src_temp_u[pos_p0] = CLIP_U8(val);
1718
0
                /* q0' */
1719
0
                val = q0_u - delta;
1720
0
                pu1_src_temp_u[pos_q0] = CLIP_U8(val);
1721
0
            }
1722
0
1723
0
            /* Filter Decision */
1724
0
            if(ABS(p0_v - q0_v) < alpha_cr && ABS(q1_v - q0_v) < beta_cr
1725
0
                            && ABS(p1_v - p0_v) < beta_cr)
1726
0
            {
1727
0
                val = ((((q0_v - p0_v) << 2) + (p1_v - q1_v) + 4) >> 3);
1728
0
                delta = CLIP3(-tcr, tcr, val);
1729
0
                /* p0' */
1730
0
                val = p0_v + delta;
1731
0
                pu1_src_temp_v[pos_p0] = CLIP_U8(val);
1732
0
                /* q0' */
1733
0
                val = q0_v - delta;
1734
0
                pu1_src_temp_v[pos_q0] = CLIP_U8(val);
1735
0
            }
1736
0
        }
1737
0
    }
1738
0
}
1739
1740
/*****************************************************************************/
1741
/*                                                                           */
1742
/*  Function Name : ih264_deblk_chroma_horz_bslt4()                          */
1743
/*                                                                           */
1744
/*  Description   : This function performs filtering of a chroma block       */
1745
/*                  horizontal edge when the boundary strength is less than  */
1746
/*                  4 in high profile.                                       */
1747
/*                                                                           */
1748
/*  Inputs        : pu1_src          - pointer to the src sample q0 of U     */
1749
/*                  src_strd         - source stride                         */
1750
/*                  alpha_cb         - alpha value for the boundary in U     */
1751
/*                  beta_cb          - beta value for the boundary in U      */
1752
/*                  alpha_cr         - alpha value for the boundary in V     */
1753
/*                  beta_cr          - beta value for the boundary in V      */
1754
/*                  u4_bs            - packed Boundary strength array        */
1755
/*                  pu1_cliptab_cb   - tc0_table for U                       */
1756
/*                  pu1_cliptab_cr   - tc0_table for V                       */
1757
/*                                                                           */
1758
/*  Globals       : None                                                     */
1759
/*                                                                           */
1760
/*  Processing    : This operation is described in Sec. 8.7.2.3 under the    */
1761
/*                  title "Filtering process for edges for bS less than 4"   */
1762
/*                  in ITU T Rec H.264 with alpha and beta values different  */
1763
/*                  in U and V.                                              */
1764
/*                                                                           */
1765
/*  Outputs       : None                                                     */
1766
/*                                                                           */
1767
/*  Returns       : None                                                     */
1768
/*                                                                           */
1769
/*  Issues        : None                                                     */
1770
/*                                                                           */
1771
/*  Revision History:                                                        */
1772
/*                                                                           */
1773
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1774
/*         29 12 2014   Kaushik         Draft                                */
1775
/*                      Senthoor                                             */
1776
/*                                                                           */
1777
/*****************************************************************************/
1778
void ih264_deblk_chroma_horz_bslt4(UWORD8 *pu1_src,
1779
                                   WORD32 src_strd,
1780
                                   WORD32 alpha_cb,
1781
                                   WORD32 beta_cb,
1782
                                   WORD32 alpha_cr,
1783
                                   WORD32 beta_cr,
1784
                                   UWORD32 u4_bs,
1785
                                   const UWORD8 *pu1_cliptab_cb,
1786
                                   const UWORD8 *pu1_cliptab_cr)
1787
0
{
1788
0
    UWORD8 *pu1_src_u = pu1_src; /* Pointer to the src sample q0 of plane U*/
1789
0
    UWORD8 *pu1_src_v = pu1_src + 1; /* Pointer to the src sample q0 of plane V*/
1790
0
    UWORD8 p1_u, p0_u, q0_u, q1_u, p1_v, p0_v, q0_v, q1_v;
1791
0
    WORD32 pos_p1, pos_p0, pos_q0, pos_q1;
1792
0
    UWORD8 *pu1_src_temp_u, *pu1_src_temp_v;
1793
0
    UWORD8 *pu1_p1_u; /* Pointer to the src sample p1 of plane U*/
1794
0
    UWORD8 *pu1_p1_v; /* Pointer to the src sample p1 of plane V*/
1795
0
    UWORD8 *pu1_p1_temp_u, *pu1_p1_temp_v;
1796
0
    WORD8 i = 0, edge;
1797
0
    WORD8 delta;
1798
0
    WORD8 tcb, tcr;
1799
0
    WORD16 val;
1800
0
    UWORD8 u1_bs;
1801
0
    UWORD8 tcb0, tcr0;
1802
0
1803
0
    pu1_p1_u = pu1_src_u - (src_strd << 1);
1804
0
    pu1_p1_v = pu1_src_v - (src_strd << 1);
1805
0
    pos_q0 = 0;
1806
0
    pos_q1 = src_strd;
1807
0
    pos_p0 = src_strd;
1808
0
    pos_p1 = 0;
1809
0
1810
0
    for(edge = 0; edge < 4; edge++, pu1_src_u += 4, pu1_p1_u += 4,
1811
0
                    pu1_src_v += 4, pu1_p1_v += 4)
1812
0
    {
1813
0
        pu1_src_temp_u = pu1_src_u;
1814
0
        pu1_p1_temp_u = pu1_p1_u;
1815
0
        pu1_src_temp_v = pu1_src_v;
1816
0
        pu1_p1_temp_v = pu1_p1_v;
1817
0
1818
0
        /* Filter Decision */
1819
0
        u1_bs = (UWORD8)((u4_bs >> ((3 - edge) << 3)) & 0x0ff);
1820
0
        if(!u1_bs)
1821
0
            continue;
1822
0
        /* tc0 */
1823
0
        tcb0 = pu1_cliptab_cb[u1_bs];
1824
0
        tcr0 = pu1_cliptab_cr[u1_bs];
1825
0
1826
0
        for(i = 0; i < 2; ++i, pu1_src_temp_u += 2, pu1_p1_temp_u += 2,
1827
0
                       pu1_src_temp_v += 2, pu1_p1_temp_v += 2)
1828
0
        {
1829
0
            q0_u = pu1_src_temp_u[pos_q0];
1830
0
            q1_u = pu1_src_temp_u[pos_q1];
1831
0
            p0_u = pu1_p1_temp_u[pos_p0];
1832
0
            p1_u = pu1_p1_temp_u[pos_p1];
1833
0
1834
0
            q0_v = pu1_src_temp_v[pos_q0];
1835
0
            q1_v = pu1_src_temp_v[pos_q1];
1836
0
            p0_v = pu1_p1_temp_v[pos_p0];
1837
0
            p1_v = pu1_p1_temp_v[pos_p1];
1838
0
1839
0
            /* tc */
1840
0
            tcb = tcb0 + 1;
1841
0
            tcr = tcr0 + 1;
1842
0
            /* Filter Decision */
1843
0
            if(ABS(p0_u - q0_u) < alpha_cb && ABS(q1_u - q0_u) < beta_cb
1844
0
                            && ABS(p1_u - p0_u) < beta_cb)
1845
0
            {
1846
0
                val = ((((q0_u - p0_u) << 2) + (p1_u - q1_u) + 4) >> 3);
1847
0
                delta = CLIP3(-tcb, tcb, val);
1848
0
                /* p0' */
1849
0
                val = p0_u + delta;
1850
0
                pu1_p1_temp_u[pos_p0] = CLIP_U8(val);
1851
0
                /* q0' */
1852
0
                val = q0_u - delta;
1853
0
                pu1_src_temp_u[pos_q0] = CLIP_U8(val);
1854
0
            }
1855
0
            /* Filter Decision */
1856
0
            if(ABS(p0_v - q0_v) < alpha_cr && ABS(q1_v - q0_v) < beta_cr
1857
0
                            && ABS(p1_v - p0_v) < beta_cr)
1858
0
            {
1859
0
                val = ((((q0_v - p0_v) << 2) + (p1_v - q1_v) + 4) >> 3);
1860
0
                delta = CLIP3(-tcr, tcr, val);
1861
0
                /* p0' */
1862
0
                val = p0_v + delta;
1863
0
                pu1_p1_temp_v[pos_p0] = CLIP_U8(val);
1864
0
                /* q0' */
1865
0
                val = q0_v - delta;
1866
0
                pu1_src_temp_v[pos_q0] = CLIP_U8(val);
1867
0
            }
1868
0
        }
1869
0
    }
1870
0
}
1871
1872
/*****************************************************************************/
1873
/*                                                                           */
1874
/*  Function Name : ih264_deblk_chroma_vert_bs4_mbaff()                      */
1875
/*                                                                           */
1876
/*  Description   : This function performs filtering of a chroma block       */
1877
/*                  vertical edge when boundary strength is set to 4 in high */
1878
/*                  profile.                                                 */
1879
/*                                                                           */
1880
/*  Inputs        : pu1_src          - pointer to the src sample q0 of U     */
1881
/*                  src_strd         - source stride                         */
1882
/*                  alpha_cb         - alpha value for the boundary in U     */
1883
/*                  beta_cb          - beta value for the boundary in U      */
1884
/*                  alpha_cr         - alpha value for the boundary in V     */
1885
/*                  beta_cr          - beta value for the boundary in V      */
1886
/*                  u4_bs            - packed Boundary strength array        */
1887
/*                  pu1_cliptab_cb   - tc0_table for U                       */
1888
/*                  pu1_cliptab_cr   - tc0_table for V                       */
1889
/*                                                                           */
1890
/*  Globals       : None                                                     */
1891
/*                                                                           */
1892
/*  Processing    : When the function is called twice, this operation is as  */
1893
/*                  described in Sec. 8.7.2.4 under the title "Filtering     */
1894
/*                  process for edges for bS equal to 4" in ITU T Rec H.264  */
1895
/*                  with alpha and beta values different in U and V.         */
1896
/*                                                                           */
1897
/*  Outputs       : None                                                     */
1898
/*                                                                           */
1899
/*  Returns       : None                                                     */
1900
/*                                                                           */
1901
/*  Issues        : None                                                     */
1902
/*                                                                           */
1903
/*  Revision History:                                                        */
1904
/*                                                                           */
1905
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1906
/*         29 12 2014   Kaushik         Draft                                */
1907
/*                      Senthoor                                             */
1908
/*                                                                           */
1909
/*****************************************************************************/
1910
void ih264_deblk_chroma_vert_bs4_mbaff(UWORD8 *pu1_src,
1911
                                       WORD32 src_strd,
1912
                                       WORD32 alpha_cb,
1913
                                       WORD32 beta_cb,
1914
                                       WORD32 alpha_cr,
1915
                                       WORD32 beta_cr)
1916
0
{
1917
0
    UWORD8 *pu1_src_u = pu1_src; /* Pointer to the src sample q0 of U */
1918
0
    UWORD8 *pu1_src_v = pu1_src + 1; /* Pointer to the src sample q0 of V */
1919
0
    UWORD8 p1_u, p0_u, q0_u, q1_u, p1_v, p0_v, q0_v, q1_v;
1920
0
    WORD32 blk_strd = src_strd;
1921
0
    WORD32 pos_p1, pos_p0, pos_q0, pos_q1;
1922
0
    UWORD8 *pu1_src_temp_u, *pu1_src_temp_v;
1923
0
    WORD8 edge;
1924
0
1925
0
    pos_q0 = 0;
1926
0
    pos_q1 = 2;
1927
0
    pos_p0 = -2;
1928
0
    pos_p1 = -4;
1929
0
1930
0
    for(edge = 0; edge < 4;
1931
0
                    edge++, pu1_src_u += blk_strd, pu1_src_v += blk_strd)
1932
0
    {
1933
0
        pu1_src_temp_u = pu1_src_u;
1934
0
        pu1_src_temp_v = pu1_src_v;
1935
0
        q0_u = pu1_src_temp_u[pos_q0];
1936
0
        q1_u = pu1_src_temp_u[pos_q1];
1937
0
        p0_u = pu1_src_temp_u[pos_p0];
1938
0
        p1_u = pu1_src_temp_u[pos_p1];
1939
0
        q0_v = pu1_src_temp_v[pos_q0];
1940
0
        q1_v = pu1_src_temp_v[pos_q1];
1941
0
        p0_v = pu1_src_temp_v[pos_p0];
1942
0
        p1_v = pu1_src_temp_v[pos_p1];
1943
0
1944
0
        /* Filter Decision */
1945
0
        if((ABS(p0_u - q0_u) < alpha_cb) &&
1946
0
           (ABS(q1_u - q0_u) < beta_cb)  &&
1947
0
           (ABS(p1_u - p0_u) < beta_cb))
1948
0
        {
1949
0
            /* p0' */
1950
0
            pu1_src_temp_u[pos_p0] = ((X2(p1_u) + p0_u + q1_u + 2) >> 2);
1951
0
            /* q0' */
1952
0
            pu1_src_temp_u[pos_q0] = (X2(q1_u) + q0_u + p1_u + 2) >> 2;
1953
0
        }
1954
0
1955
0
        /* Filter Decision */
1956
0
        if((ABS(p0_v - q0_v) < alpha_cr) &&
1957
0
           (ABS(q1_v - q0_v) < beta_cr) &&
1958
0
           (ABS(p1_v - p0_v) < beta_cr))
1959
0
        {
1960
0
            /* p0' */
1961
0
            pu1_src_temp_v[pos_p0] = ((X2(p1_v) + p0_v + q1_v + 2) >> 2);
1962
0
            /* q0' */
1963
0
            pu1_src_temp_v[pos_q0] = (X2(q1_v) + q0_v + p1_v + 2) >> 2;
1964
0
        }
1965
0
    }
1966
0
}
1967
1968
/*****************************************************************************/
1969
/*                                                                           */
1970
/*  Function Name : ih264_deblk_chroma_vert_bslt4_mbaff()                    */
1971
/*                                                                           */
1972
/*  Description   : This function performs filtering of a chroma block       */
1973
/*                  vertical edge when boundary strength is less than 4 in   */
1974
/*                  high profile.                                            */
1975
/*                                                                           */
1976
/*  Inputs        : pu1_src          - pointer to the src sample q0 of U     */
1977
/*                  src_strd         - source stride                         */
1978
/*                  alpha_cb         - alpha value for the boundary in U     */
1979
/*                  beta_cb          - beta value for the boundary in U      */
1980
/*                  alpha_cr         - alpha value for the boundary in V     */
1981
/*                  beta_cr          - beta value for the boundary in V      */
1982
/*                  u4_bs            - packed Boundary strength array        */
1983
/*                  pu1_cliptab_cb   - tc0_table for U                       */
1984
/*                  pu1_cliptab_cr   - tc0_table for V                       */
1985
/*                                                                           */
1986
/*  Globals       : None                                                     */
1987
/*                                                                           */
1988
/*  Processing    : When the function is called twice, this operation is as  */
1989
/*                  described in Sec. 8.7.2.4 under the title "Filtering     */
1990
/*                  process for edges for bS less than 4" in ITU T Rec H.264 */
1991
/*                  with alpha and beta values different in U and V.         */
1992
/*                                                                           */
1993
/*  Outputs       : None                                                     */
1994
/*                                                                           */
1995
/*  Returns       : None                                                     */
1996
/*                                                                           */
1997
/*  Issues        : None                                                     */
1998
/*                                                                           */
1999
/*  Revision History:                                                        */
2000
/*                                                                           */
2001
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
2002
/*         29 12 2014   Kaushik         Draft                                */
2003
/*                      Senthoor                                             */
2004
/*                                                                           */
2005
/*****************************************************************************/
2006
void ih264_deblk_chroma_vert_bslt4_mbaff(UWORD8 *pu1_src,
2007
                                         WORD32 src_strd,
2008
                                         WORD32 alpha_cb,
2009
                                         WORD32 beta_cb,
2010
                                         WORD32 alpha_cr,
2011
                                         WORD32 beta_cr,
2012
                                         UWORD32 u4_bs,
2013
                                         const UWORD8 *pu1_cliptab_cb,
2014
                                         const UWORD8 *pu1_cliptab_cr)
2015
0
{
2016
0
    UWORD8 *pu1_src_u = pu1_src; /* Pointer to the src sample q0 of plane U*/
2017
0
    UWORD8 *pu1_src_v = pu1_src + 1; /* Pointer to the src sample q0 of plane V*/
2018
0
    UWORD8 p1_u, p0_u, q0_u, q1_u, p1_v, p0_v, q0_v, q1_v;
2019
0
    WORD32 blk_strd = src_strd;
2020
0
    WORD32 pos_p1, pos_p0, pos_q0, pos_q1;
2021
0
    UWORD8 *pu1_src_temp_u, *pu1_src_temp_v;
2022
0
    WORD8 edge;
2023
0
    WORD8 delta;
2024
0
    WORD8 tcb, tcr;
2025
0
    WORD16 val;
2026
0
    UWORD8 tcb0, tcr0, u1_bs;
2027
0
2028
0
    pos_q0 = 0;
2029
0
    pos_q1 = 2;
2030
0
    pos_p0 = -2;
2031
0
    pos_p1 = -4;
2032
0
2033
0
    for(edge = 0; edge < 4;
2034
0
                    edge++, pu1_src_u += blk_strd, pu1_src_v += blk_strd)
2035
0
    {
2036
0
        pu1_src_temp_u = pu1_src_u;
2037
0
        pu1_src_temp_v = pu1_src_v;
2038
0
        /* Filter Decision */
2039
0
        u1_bs = (UWORD8)((u4_bs >> ((3 - edge) << 3)) & 0x0ff);
2040
0
        if(!u1_bs)
2041
0
            continue;
2042
0
        /* tc0 */
2043
0
        tcb0 = pu1_cliptab_cb[u1_bs];
2044
0
        tcr0 = pu1_cliptab_cr[u1_bs];
2045
0
        tcb = tcb0 + 1;
2046
0
        tcr = tcr0 + 1;
2047
0
        q0_u = pu1_src_temp_u[pos_q0];
2048
0
        q1_u = pu1_src_temp_u[pos_q1];
2049
0
        p0_u = pu1_src_temp_u[pos_p0];
2050
0
        p1_u = pu1_src_temp_u[pos_p1];
2051
0
2052
0
        q0_v = pu1_src_temp_v[pos_q0];
2053
0
        q1_v = pu1_src_temp_v[pos_q1];
2054
0
        p0_v = pu1_src_temp_v[pos_p0];
2055
0
        p1_v = pu1_src_temp_v[pos_p1];
2056
0
2057
0
        /* Filter Decision */
2058
0
        if((ABS(p0_u - q0_u) < alpha_cb) &&
2059
0
           (ABS(q1_u - q0_u) < beta_cb) &&
2060
0
           (ABS(p1_u - p0_u) < beta_cb))
2061
0
        {
2062
0
            val = ((((q0_u - p0_u) << 2) + (p1_u - q1_u) + 4) >> 3);
2063
0
            delta = CLIP3(-tcb, tcb, val);
2064
0
            /* p0' */
2065
0
            val = p0_u + delta;
2066
0
            pu1_src_temp_u[pos_p0] = CLIP_U8(val);
2067
0
            /* q0' */
2068
0
            val = q0_u - delta;
2069
0
            pu1_src_temp_u[pos_q0] = CLIP_U8(val);
2070
0
        }
2071
0
2072
0
        /* Filter Decision */
2073
0
        if((ABS(p0_v - q0_v) < alpha_cr) &&
2074
0
           (ABS(q1_v - q0_v) < beta_cr) &&
2075
0
           (ABS(p1_v - p0_v) < beta_cr))
2076
0
        {
2077
0
            val = ((((q0_v - p0_v) << 2) + (p1_v - q1_v) + 4) >> 3);
2078
0
            delta = CLIP3(-tcr, tcr, val);
2079
0
            /* p0' */
2080
0
            val = p0_v + delta;
2081
0
            pu1_src_temp_v[pos_p0] = CLIP_U8(val);
2082
0
            /* q0' */
2083
0
            val = q0_v - delta;
2084
0
            pu1_src_temp_v[pos_q0] = CLIP_U8(val);
2085
0
        }
2086
0
    }
2087
0
}
/proc/self/cwd/external/libavc/common/ih264_debug.h
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/**
21
*******************************************************************************
22
* @file
23
*  ih264_debug.h
24
*
25
* @brief
26
*  Definitions for codec debugging
27
*
28
* @author
29
*  Ittiam
30
*
31
* @par List of Functions:
32
*
33
* @remarks
34
*  None
35
*
36
*******************************************************************************
37
*/
38
#ifndef _IH264_DEBUG_H_
39
#define _IH264_DEBUG_H_
40
41
42
#if DEBUG_PRINT
43
44
#define DEBUG(...)                                                          \
45
{                                                                           \
46
    printf("\n[H264 DBG] %s/%d:: ", __FUNCTION__, __LINE__);                \
47
    printf(__VA_ARGS__);                                                    \
48
}
49
50
#else
51
52
#define DEBUG(...) {}
53
54
#endif
55
56
57
44
#define ASSERT(x) assert((x))
58
59
60
#endif /* _IH264_DEBUG_H_ */
61
/proc/self/cwd/external/libavc/common/ih264_defs.h
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/**
21
*******************************************************************************
22
* @file
23
*  ih264_defs.h
24
*
25
* @brief
26
*  Definitions used in the codec
27
*
28
* @author
29
*  Ittiam
30
*
31
*
32
* @remarks
33
*  None
34
*
35
*******************************************************************************
36
*/
37
38
#ifndef IH264_DEFS_H_
39
#define IH264_DEFS_H_
40
41
/*****************************************************************************/
42
/* Enums                                                                     */
43
/*****************************************************************************/
44
45
46
/*****************************************************************************/
47
/* Profile and Levels                                                        */
48
/*****************************************************************************/
49
50
/**
51
******************************************************************************
52
 *  @enum  PROFILE_IDC
53
 *  @brief Defines the set of possible profiles
54
******************************************************************************
55
*/
56
enum
57
{
58
    IH264_PROFILE_BASELINE = 66,
59
    IH264_PROFILE_MAIN = 77,
60
    IH264_PROFILE_EXTENDED = 88,
61
    IH264_PROFILE_HIGH = 100,
62
    IH264_PROFILE_HIGH10 = 110,
63
    IH264_PROFILE_HIGH422 = 122,
64
    IH264_PROFILE_HIGH444 = 144,
65
};
66
67
/**
68
******************************************************************************
69
 *  @enum  LEVEL_IDC
70
 *  @brief Defines the set of possible levels
71
******************************************************************************
72
*/
73
typedef enum
74
{
75
    IH264_LEVEL_10         = 10,
76
    IH264_LEVEL_1B         = 9,
77
    IH264_LEVEL_11         = 11,
78
    IH264_LEVEL_12         = 12,
79
    IH264_LEVEL_13         = 13,
80
    IH264_LEVEL_20         = 20,
81
    IH264_LEVEL_21         = 21,
82
    IH264_LEVEL_22         = 22,
83
    IH264_LEVEL_30         = 30,
84
    IH264_LEVEL_31         = 31,
85
    IH264_LEVEL_32         = 32,
86
    IH264_LEVEL_40         = 40,
87
    IH264_LEVEL_41         = 41,
88
    IH264_LEVEL_42         = 42,
89
    IH264_LEVEL_50         = 50,
90
    IH264_LEVEL_51         = 51,
91
}IH264_LEVEL_T;
92
93
94
/**
95
******************************************************************************
96
 *  @enum  PIC TYPES
97
 *  @brief Defines the set of possible picture type - not signaled in bitstream
98
******************************************************************************
99
*/
100
typedef enum
101
{
102
    PIC_NA = 0x7FFFFFFF,
103
    PIC_IDR = 0,
104
    PIC_I = 1,
105
    PIC_P = 2,
106
    PIC_B = 3,
107
    PIC_P_NONREF = 4,
108
    PIC_B_NONREF = 5,
109
    PIC_MAX,
110
}PIC_TYPE_T;
111
112
/**
113
******************************************************************************
114
 *  @enum  FRAME-FIELD types
115
 *  @brief Defines the set of possible field types.
116
******************************************************************************
117
*/
118
enum
119
{
120
    TOP_FIELD,
121
    BOTTOM_FIELD,
122
    FRAME,
123
};
124
125
/**
126
******************************************************************************
127
 *  @enum  SLICE TYPES
128
 *  @brief Defines the set of possible SLICE TYPES
129
******************************************************************************
130
*/
131
enum
132
{
133
    PSLICE = 0,
134
    BSLICE = 1,
135
    ISLICE = 2,
136
    SPSLICE = 3,
137
    SISLICE = 4,
138
    MAXSLICE_TYPE,
139
};
140
141
/**
142
******************************************************************************
143
 *  @enum  NAL_UNIT_TYPE
144
 *  @brief Defines the set of possible nal unit types
145
******************************************************************************
146
*/
147
enum
148
{
149
    NAL_UNSPEC_0        = 0,
150
    NAL_SLICE_NON_IDR   = 1,
151
    NAL_SLICE_DPA       = 2,
152
    NAL_SLICE_DPB       = 3,
153
    NAL_SLICE_DPC       = 4,
154
    NAL_SLICE_IDR       = 5,
155
    NAL_SEI             = 6,
156
    NAL_SPS             = 7,
157
    NAL_PPS             = 8,
158
    NAL_AUD             = 9,
159
    NAL_EOSEQ           = 10,
160
    NAL_EOSTR           = 11,
161
    NAL_FILLER          = 12,
162
    NAL_SPSE            = 13,
163
    NAL_RES_18          = 14,
164
    NAL_AUX_PIC         = 19,
165
    NAL_RES_23          = 20,
166
    NAL_UNSPEC_31       = 24,
167
};
168
169
/**
170
******************************************************************************
171
 *  @enum  CHROMA_FORMAT_IDC
172
 *  @brief Defines the set of possible chroma formats
173
 *  Note Chorma format Do not change enum values
174
******************************************************************************
175
*/
176
enum
177
{
178
    CHROMA_FMT_IDC_MONOCHROME   = 0,
179
    CHROMA_FMT_IDC_YUV420       = 1,
180
    CHROMA_FMT_IDC_YUV422       = 2,
181
    CHROMA_FMT_IDC_YUV444       = 3,
182
    CHROMA_FMT_IDC_YUV444_PLANES = 4,
183
};
184
185
186
/**
187
******************************************************************************
188
 *  @enum  MBMODES_I16x16
189
 *  @brief Defines the set of possible intra 16x16 mb modes
190
******************************************************************************
191
*/
192
typedef enum
193
{
194
    VERT_I16x16     = 0,
195
    HORZ_I16x16     = 1,
196
    DC_I16x16       = 2,
197
    PLANE_I16x16    = 3,
198
    MAX_I16x16      = 4,
199
}MBMODES_I16x16;
200
201
/**
202
******************************************************************************
203
 *  @enum  MBMODES_I4x4
204
 *  @brief Defines the set of possible intra 4x4 mb modes
205
******************************************************************************
206
*/
207
typedef enum
208
{
209
    VERT_I4x4     = 0,
210
    HORZ_I4x4     = 1,
211
    DC_I4x4       = 2,
212
    DIAG_DL_I4x4  = 3,
213
    DIAG_DR_I4x4  = 4,
214
    VERT_R_I4x4   = 5,
215
    HORZ_D_I4x4   = 6,
216
    VERT_L_I4x4   = 7,
217
    HORZ_U_I4x4   = 8,
218
    MAX_I4x4      = 9,
219
}MBMODES_I4x4;
220
221
/**
222
******************************************************************************
223
 *  @enum  MBMODES_I8x8
224
 *  @brief Defines the set of possible intra 8x8 mb modes
225
******************************************************************************
226
*/
227
typedef enum
228
{
229
    VERT_I8x8     = 0,
230
    HORZ_I8x8     = 1,
231
    DC_I8x8       = 2,
232
    DIAG_DL_I8x8  = 3,
233
    DIAG_DR_I8x8  = 4,
234
    VERT_R_I8x8   = 5,
235
    HORZ_D_I8x8   = 6,
236
    VERT_L_I8x8   = 7,
237
    HORZ_U_I8x8   = 8,
238
    MAX_I8x8      = 9,
239
}MBMODES_I8x8;
240
241
/**
242
******************************************************************************
243
 *  @enum  MBMODES_CHROMA_I8x8 (Chroma)
244
 *  @brief Defines the set of possible intra 8x8 mb modes for chroma
245
******************************************************************************
246
*/
247
typedef enum
248
{
249
    DC_CH_I8x8     = 0,
250
    HORZ_CH_I8x8   = 1,
251
    VERT_CH_I8x8   = 2,
252
    PLANE_CH_I8x8  = 3,
253
    MAX_CH_I8x8    = 4,
254
}MBMODES_CHROMA_I8x8;
255
256
/**
257
******************************************************************************
258
 *  @enum  MBTYPES
259
 *  @brief Defines the set of possible macro block types
260
******************************************************************************
261
*/
262
typedef enum
263
{
264
    I16x16      = 0,
265
    I4x4        = 1,
266
    I8x8        = 2,
267
    P16x16      = 3,
268
    P16x8       = 4,
269
    P8x16       = 5,
270
    P8x8        = 6,
271
    PSKIP       = 7,
272
    IPCM        = 8,
273
    B16x16      = 9,
274
    BSKIP       = 10,
275
    BDIRECT     = 11,
276
    MAX_MBTYPES,
277
}MBTYPES_T;
278
279
/* Prediction list */
280
/* Do not change enum values */
281
enum
282
{
283
    PRED_L0 = 0,
284
    PRED_L1 = 1,
285
    PRED_BI = 2
286
};
287
288
289
/**
290
******************************************************************************
291
 *  @enum  ENTROPY_BLK_TYPE
292
 *  @brief Defines the nature of blocks employed in entropy coding
293
******************************************************************************
294
*/
295
typedef enum
296
{
297
    ENTROPY_BLK_INVALID = -1,
298
    CAVLC_LUMA_4x4_DC = 0,
299
    CAVLC_LUMA_4x4_AC = 1,
300
    CAVLC_LUMA_4x4 = 2,
301
    CAVLC_CHROMA_4x4_DC = 3,
302
    CAVLC_CHROMA_4x4_AC = 4,
303
} ENTROPY_BLK_TYPE;
304
305
/**
306
******************************************************************************
307
 *  @enum  ENTROPY_MODE
308
 *  @brief Entropy coding modes
309
******************************************************************************
310
*/
311
typedef enum
312
{
313
    CAVLC = 0,
314
    CABAC = 1,
315
} ENTROPY_MODE;
316
317
/**
318
******************************************************************************
319
 *  @enum  COMPONENT_TYPE
320
 *  @brief components Y, U & V
321
******************************************************************************
322
*/
323
typedef enum
324
{
325
    Y,
326
    U,
327
    V,
328
} COMPONENT_TYPE;
329
330
331
/**
332
******************************************************************************
333
 *  @enum  MBPART_PREDMODE_T
334
 *  @brief MbPartps_pred_mode_ctxt Table 7-11 to 7-14
335
******************************************************************************
336
*/
337
typedef enum
338
{
339
    MBPART_NA,
340
    MBPART_I4x4,
341
    MBPART_I8x8,
342
    MBPART_I16x16,
343
    MBPART_L0,
344
    MBPART_L1,
345
    MBPART_BI,
346
    MBPART_DIRECT,
347
    MBPART_IPCM,
348
}MBPART_PREDMODE_T;
349
350
351
typedef enum
352
{
353
    I_NxN,
354
    I_16x16_0_0_0,
355
    I_16x16_1_0_0,
356
    I_16x16_2_0_0,
357
    I_16x16_3_0_0,
358
    I_16x16_0_1_0,
359
    I_16x16_1_1_0,
360
    I_16x16_2_1_0,
361
    I_16x16_3_1_0,
362
    I_16x16_0_2_0,
363
    I_16x16_1_2_0,
364
    I_16x16_2_2_0,
365
    I_16x16_3_2_0,
366
    I_16x16_0_0_1,
367
    I_16x16_1_0_1,
368
    I_16x16_2_0_1,
369
    I_16x16_3_0_1,
370
    I_16x16_0_1_1,
371
    I_16x16_1_1_1,
372
    I_16x16_2_1_1,
373
    I_16x16_3_1_1,
374
    I_16x16_0_2_1,
375
    I_16x16_1_2_1,
376
    I_16x16_2_2_1,
377
    I_16x16_3_2_1,
378
    I_PCM,
379
}MBTYPE_ISLICE_T;
380
381
typedef enum
382
{
383
    P_L0_16x16,
384
    P_L0_L0_16x8,
385
    P_L0_L0_8x16,
386
    P_8x8,
387
    P_8x8REF0,
388
    P_SKIP
389
}MBTYPE_PSLICE_T;
390
391
typedef enum
392
{
393
    B_DIRECT_16x16,
394
    B_L0_16x16,
395
    B_L1_16x16,
396
    B_BI_16x16,
397
    B_L0_L0_16x8,
398
    B_L0_L0_8x16,
399
    B_L1_L1_16x8,
400
    B_L1_L1_8x16,
401
    B_L0_L1_16x8,
402
    B_L0_L1_8x16,
403
    B_L1_L0_16x8,
404
    B_L1_L0_8x16,
405
    B_L0_BI_16x8,
406
    B_L0_BI_8x16,
407
    B_L1_BI_16x8,
408
    B_L1_BI_8x16,
409
    B_BI_L0_16x8,
410
    B_BI_L0_8x16,
411
    B_BI_L1_16x8,
412
    B_BI_L1_8x16,
413
    B_BI_BI_16x8,
414
    B_BI_BI_8x16,
415
    B_8x8,
416
    B_SKIP,
417
}MBTYPE_BSLICE_T;
418
419
420
typedef enum
421
{
422
    P_L0_8x8,
423
    P_L0_8x4,
424
    P_L0_4x8,
425
    P_L0_4x4,
426
}SUBMBTYPE_PSLICE_T;
427
428
typedef enum
429
{
430
    B_DIRECT_8x8,
431
    B_L0_8x8,
432
    B_L1_8x8,
433
    B_BI_8x8,
434
    B_L0_8x4,
435
    B_L0_4x8,
436
    B_L1_8x4,
437
    B_L1_4x8,
438
    B_BI_8x4,
439
    B_BI_4x8,
440
    B_L0_4x4,
441
    B_L1_4x4,
442
    B_BI_4x4,
443
}SUBMBTYPE_BSLICE_T;
444
445
/**
446
 * DC Mode pattern for 4 4x4 sub blocks in an MB row
447
 */
448
#define DC_I16X16_MB_ROW (DC_I16x16 << 24) | (DC_I16x16 << 16) | \
449
                         (DC_I16x16 << 8)  | DC_I16x16
450
451
452
453
/*****************************************************************************/
454
/* Constant Macros                                                           */
455
/*****************************************************************************/
456
457
/*****************************************************************************/
458
/* Reference frame defs                                                      */
459
/*****************************************************************************/
460
/* Maximum DPB size */
461
#define MAX_DPB_SIZE 16
462
463
/* Maximum mmco commands in slice header */
464
#define MAX_MMCO_COMMANDS 32
465
466
/* Maximum reference reorder idc */
467
#define MAX_MODICATION_IDC 32
468
469
/*****************************************************************************/
470
/* SPS restrictions                                                          */
471
/*****************************************************************************/
472
473
/* Number of SPS allowed */
474
/* An extra buffer is allocated to write the parsed data
475
 * It is copied to the appropriate location later */
476
#define MAX_SPS_CNT         (32 + 1)
477
478
/* Maximum long term reference pics */
479
#define MAX_LTREF_PICS_SPS 16
480
481
/* Maximum short term reference pics */
482
#define MAX_STREF_PICS_SPS 64
483
484
485
/*****************************************************************************/
486
/* PPS restrictions                                                          */
487
/*****************************************************************************/
488
489
/* Number of PPS allowed  */
490
/* An extra buffer is allocated to write the parsed data
491
 * It is copied to the appropriate location later */
492
#define MAX_PPS_CNT         (256 + 1)
493
494
/*****************************************************************************/
495
/* Macro definitions for sizes of MB, PU, TU, CU                            */
496
/*****************************************************************************/
497
4.45k
#define MB_SIZE             16
498
7.41k
#define BLK8x8SIZE          8
499
49.6k
#define BLK_SIZE            4
500
501
502
/* TU Size Range */
503
#define MAX_TU_SIZE         8
504
#define MIN_TU_SIZE         4
505
506
/* Max Transform Size */
507
#define MAX_TRANS_SIZE      (MAX_TU_SIZE*MAX_TU_SIZE)
508
509
/* PU Size Range */
510
#define MAX_PU_SIZE         16
511
#define MIN_PU_SIZE         4
512
513
/* Number of max TU in a MB row */
514
#define MAX_TU_IN_MB_ROW   ((MB_SIZE / MIN_TU_SIZE))
515
516
/* Number of max PU in a CTb row */
517
#define MAX_PU_IN_MB_ROW   ((MB_SIZE / MIN_PU_SIZE))
518
519
520
/* Number of max PU in a MB */
521
/*****************************************************************************/
522
/* Note though for 64 x 64 MB, Max PU in MB is 128, in order to store      */
523
/*  intra pred info, 256 entries are needed                                  */
524
/*****************************************************************************/
525
#define MAX_PU_IN_MB       ((MB_SIZE / MIN_PU_SIZE) * \
526
                             (MB_SIZE / MIN_PU_SIZE))
527
528
/* Number of max TU in a MB */
529
#define MAX_TU_IN_MB       ((MB_SIZE / MIN_TU_SIZE) * \
530
                             (MB_SIZE / MIN_TU_SIZE))
531
532
533
534
/**
535
 * Maximum transform depths
536
 */
537
#define MAX_TRAFO_DEPTH 5
538
539
#define MAX_DC_4x4_SUBBLK_LUMA 1
540
#define MAX_AC_4x4_SUBBLK_LUMA 16
541
#define MAX_DC_4x4_SUBBLK_CHROMA 2
542
#define MAX_AC_4x4_SUBBLK_CHROMA 8
543
544
#define MAX_4x4_SUBBLKS (MAX_DC_4x4_SUBBLK_LUMA + MAX_DC_4x4_SUBBLK_CHROMA +\
545
                         MAX_AC_4x4_SUBBLK_LUMA + MAX_AC_4x4_SUBBLK_CHROMA)
546
547
/* Max number of deblocking edges */
548
#define MAX_VERT_DEBLK_EDGES ((MB_SIZE/8) * (MB_SIZE/4))
549
#define MAX_HORZ_DEBLK_EDGES ((MB_SIZE/4) * (MB_SIZE/8))
550
551
/* Qp can not change below 8x8 level */
552
#define MAX_DEBLK_QP_CNT     ((MB_SIZE/8) * (MB_SIZE/8))
553
554
/*****************************************************************************/
555
/* Parsing related macros                                                    */
556
/*****************************************************************************/
557
#define SUBBLK_COEFF_CNT    16
558
559
/* Quant and Trans defs */
560
561
/*****************************************************************************/
562
/* Sizes for Transform functions                                             */
563
/*****************************************************************************/
564
#define TRANS_SIZE_4   4
565
#define TRANS_SIZE_8   8
566
#define TRANS_SIZE_16 16
567
#define TRANS_SIZE_32 32
568
569
570
#define IT_SHIFT_STAGE_1 7
571
#define IT_SHIFT_STAGE_2 12
572
573
/**
574
 * @breif  Maximum transform dynamic range (excluding sign bit)
575
 */
576
#define MAX_TR_DYNAMIC_RANGE  15
577
578
/**
579
 * @brief  Q(QP%6) * IQ(QP%6) = 2^20
580
 */
581
#define QUANT_IQUANT_SHIFT    20
582
583
/**
584
 * @breif Q factor for Qp%6 multiplication
585
 */
586
#define QUANT_SHIFT           14
587
588
/**
589
 * @breif Q shift factor for flat rescale matrix weights
590
 */
591
#define FLAT_RESCALE_MAT_Q_SHIFT    11
592
593
/**
594
 * @breif  Scaling matrix is represented in Q15 format
595
 */
596
#define SCALING_Q_SHIFT       15
597
598
/**
599
 * @brief  rounding factor for quantization represented in Q9 format
600
 */
601
#define QUANT_ROUND_FACTOR_Q   9
602
603
/**
604
 * @brief  Minimum qp supported in H264 spec
605
 */
606
#define MIN_H264_QP 0
607
608
/**
609
 * @brief  Maximum qp supported in H264 spec
610
 */
611
#define MAX_H264_QP 51
612
613
/**
614
 * @breif  Total number of transform sizes
615
 * used for sizeID while getting scale matrix
616
 */
617
#define NUM_UNIQUE_TRANS_SIZE 4
618
619
/**
620
 * @breif  Maximum number of bits in frameNumber signaling
621
 */
622
#define MAX_BITS_IN_FRAME_NUM     16
623
624
/**
625
 * @breif  Maximum number of bits in POC LSB signaling
626
 */
627
#define MAX_BITS_IN_POC_LSB     16
628
629
630
/**
631
 * @breif  Maximum PIC Order Count type
632
 */
633
#define MAX_PIC_ORDER_COUNT_TYPE    2
634
635
636
/**
637
 * @breif  Maximum Weighted bipred idc
638
 */
639
#define MAX_WEIGHT_BIPRED_IDC 2
640
641
/*****************************************************************************/
642
/* Number of scaling matrices for each transform size                        */
643
/*****************************************************************************/
644
#define SCALE_MAT_CNT_TRANS_SIZE_4    6
645
#define SCALE_MAT_CNT_TRANS_SIZE_8    6
646
#define SCALE_MAT_CNT_TRANS_SIZE_16   6
647
#define SCALE_MAT_CNT_TRANS_SIZE_32   2
648
649
/* Maximum number of scale matrices for a given transform size */
650
#define SCALE_MAT_CNT_MAX_PER_TRANS_SIZE 6
651
652
/* Total number of scale matrices */
653
#define TOTAL_SCALE_MAT_COUNT   (SCALE_MAT_CNT_TRANS_SIZE_4     + \
654
                                 SCALE_MAT_CNT_TRANS_SIZE_8     + \
655
                                 SCALE_MAT_CNT_TRANS_SIZE_16    + \
656
                                 SCALE_MAT_CNT_TRANS_SIZE_32)
657
658
659
/*****************************************************************************/
660
/* Intra pred Macros                                                         */
661
/*****************************************************************************/
662
/** Planar Intra prediction mode */
663
#define INTRA_PLANAR             0
664
665
/** DC Intra prediction mode */
666
#define INTRA_DC                 1
667
668
/** Gives angular mode for intra prediction */
669
#define INTRA_ANGULAR(x) (x)
670
671
/** Following is used to signal no intra prediction in case of pcm blocks
672
 */
673
#define INTRA_PRED_NONE  63
674
675
676
/** Following is used to signal no intra prediction is needed for first three
677
 * 4x4 luma blocks in case of 4x4 TU sizes
678
 * Also used in pcm cases
679
 */
680
#define INTRA_PRED_CHROMA_IDX_NONE  7
681
682
683
/**
684
******************************************************************************
685
 *  @brief  neighbor availability masks
686
******************************************************************************
687
 */
688
#define LEFT_MB_AVAILABLE_MASK      0x01
689
#define TOP_LEFT_MB_AVAILABLE_MASK  0x02
690
#define TOP_MB_AVAILABLE_MASK       0x04
691
#define TOP_RIGHT_MB_AVAILABLE_MASK 0x08
692
693
#endif /* IH264_DEFS_H_ */
/proc/self/cwd/external/libavc/common/ih264_disp_mgr.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/**
21
*******************************************************************************
22
* @file
23
*  ih264_disp_mgr.c
24
*
25
* @brief
26
*  Contains function definitions for display management
27
*
28
* @author
29
*  Srinivas T
30
*
31
* @par List of Functions:
32
*   - ih264_disp_mgr_init()
33
*   - ih264_disp_mgr_add()
34
*   - ih264_disp_mgr_get()
35
*
36
* @remarks
37
*  None
38
*
39
*******************************************************************************
40
*/
41
#include <stdlib.h>
42
#include "ih264_typedefs.h"
43
#include "ih264_macros.h"
44
#include "ih264_disp_mgr.h"
45
46
47
/**
48
*******************************************************************************
49
*
50
* @brief
51
*    Initialization function for display buffer manager
52
*
53
* @par Description:
54
*    Initializes the display buffer management structure
55
*
56
* @param[in] ps_disp_mgr
57
*  Pointer to the display buffer management structure
58
*
59
* @returns none
60
*
61
* @remarks
62
*  None
63
*
64
*******************************************************************************
65
*/
66
void ih264_disp_mgr_init(disp_mgr_t *ps_disp_mgr)
67
1
{
68
1
    WORD32 id;
69
1
70
1
    ps_disp_mgr->u4_last_abs_poc = DEFAULT_POC;
71
1
72
65
    for(id = 0; id < DISP_MGR_MAX_CNT; id++)
73
64
    {
74
64
        ps_disp_mgr->ai4_abs_poc[id] = DEFAULT_POC;
75
64
        ps_disp_mgr->apv_ptr[id] = NULL;
76
64
    }
77
1
}
78
79
80
/**
81
*******************************************************************************
82
*
83
* @brief
84
*     Adds a buffer to the display manager
85
*
86
* @par Description:
87
*      Adds a buffer to the display buffer manager
88
*
89
* @param[in] ps_disp_mgr
90
*  Pointer to the display buffer management structure
91
*
92
* @param[in] buf_id
93
*  ID of the display buffer
94
*
95
* @param[in] abs_poc
96
*  Absolute POC of the display buffer
97
*
98
* @param[in] pv_ptr
99
*  Pointer to the display buffer
100
*
101
* @returns  0 if success, -1 otherwise
102
*
103
* @remarks
104
*  None
105
*
106
*******************************************************************************
107
*/
108
WORD32 ih264_disp_mgr_add(disp_mgr_t *ps_disp_mgr,
109
                          WORD32 buf_id,
110
                          WORD32 abs_poc,
111
                          void *pv_ptr)
112
10
{
113
10
    if(buf_id >= DISP_MGR_MAX_CNT)
114
10
    {
115
0
        return (-1);
116
0
    }
117
10
118
10
    if(ps_disp_mgr->apv_ptr[buf_id] != NULL)
119
10
    {
120
0
        return (-1);
121
0
    }
122
10
123
10
    ps_disp_mgr->apv_ptr[buf_id] = pv_ptr;
124
10
    ps_disp_mgr->ai4_abs_poc[buf_id] = abs_poc;
125
10
    return 0;
126
10
}
127
128
129
/**
130
*******************************************************************************
131
*
132
* @brief
133
*  Gets the next buffer
134
*
135
* @par Description:
136
*  Gets the next display buffer
137
*
138
* @param[in] ps_disp_mgr
139
*  Pointer to the display buffer structure
140
*
141
* @param[out]  pi4_buf_id
142
*  Pointer to hold buffer id of the display buffer being returned
143
*
144
* @returns  Pointer to the next display buffer
145
*
146
* @remarks
147
*  None
148
*
149
*******************************************************************************
150
*/
151
void* ih264_disp_mgr_get(disp_mgr_t *ps_disp_mgr, WORD32 *pi4_buf_id)
152
11
{
153
11
    WORD32 id;
154
11
    void *pv_ret_ptr;
155
11
    WORD32 i4_min_poc;
156
11
    WORD32 min_poc_id;
157
11
158
11
159
11
    pv_ret_ptr = NULL;
160
11
    i4_min_poc = 0x7FFFFFFF;
161
11
    min_poc_id = -1;
162
11
163
11
    /* Find minimum POC */
164
715
    for(id = 0; id < DISP_MGR_MAX_CNT; id++)
165
704
    {
166
704
        if((DEFAULT_POC != ps_disp_mgr->ai4_abs_poc[id]) &&
167
704
           (ps_disp_mgr->ai4_abs_poc[id] <= i4_min_poc))
168
9
        {
169
9
            i4_min_poc = ps_disp_mgr->ai4_abs_poc[id];
170
9
            min_poc_id = id;
171
9
        }
172
704
    }
173
11
    *pi4_buf_id = min_poc_id;
174
11
    /* If all pocs are still default_poc then return NULL */
175
11
    if(-1 == min_poc_id)
176
2
    {
177
2
        return NULL;
178
2
    }
179
9
180
9
    pv_ret_ptr = ps_disp_mgr->apv_ptr[min_poc_id];
181
9
182
9
    /* Set abs poc to default and apv_ptr to null so that the buffer is not returned again */
183
9
    ps_disp_mgr->apv_ptr[min_poc_id] = NULL;
184
9
    ps_disp_mgr->ai4_abs_poc[min_poc_id] = DEFAULT_POC;
185
9
    return pv_ret_ptr;
186
9
}
/proc/self/cwd/external/libavc/common/ih264_disp_mgr.h
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/**
21
*******************************************************************************
22
* @file
23
*  ih264_disp_mgr.h
24
*
25
* @brief
26
*  Function declarations used for display management
27
*
28
* @author
29
*  Srinivas T
30
*
31
*
32
* @remarks
33
*  None
34
*
35
*******************************************************************************
36
*/
37
#ifndef _DISP_MGR_H_
38
#define _DISP_MGR_H_
39
40
790
#define DISP_MGR_MAX_CNT 64
41
778
#define DEFAULT_POC 0x7FFFFFFF
42
43
typedef struct
44
{
45
    /**
46
     * last_abs_poc
47
     */
48
    UWORD32 u4_last_abs_poc;
49
50
    /**
51
     * au4_abs_poc[DISP_MGR_MAX_CNT]
52
     */
53
    WORD32 ai4_abs_poc[DISP_MGR_MAX_CNT];
54
55
    /**
56
     * apv_ptr[DISP_MGR_MAX_CNT]
57
     */
58
    void    *apv_ptr[DISP_MGR_MAX_CNT];
59
}disp_mgr_t;
60
61
void ih264_disp_mgr_init(disp_mgr_t *ps_disp_mgr);
62
63
WORD32 ih264_disp_mgr_add(disp_mgr_t *ps_disp_mgr,
64
                          WORD32 id,
65
                          WORD32 abs_poc,
66
                          void *pv_ptr);
67
68
void* ih264_disp_mgr_get(disp_mgr_t *ps_disp_mgr, WORD32 *pi4_buf_id);
69
70
#endif  //_DISP_MGR_H_
/proc/self/cwd/external/libavc/common/ih264_ihadamard_scaling.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/**
21
 *******************************************************************************
22
 * @file
23
 *  ih264_ihadamard_scaling.c
24
 *
25
 * @brief
26
 *  Contains definition of functions for h264 inverse hadamard 4x4 transform and scaling
27
 *
28
 * @author
29
 *  Mohit
30
 *
31
 *  @par List of Functions:
32
 *  - ih264_ihadamard_scaling_4x4()
33
 *
34
 * @remarks
35
 *
36
 *******************************************************************************
37
 */
38
39
/*****************************************************************************/
40
/* File Includes                                                             */
41
/*****************************************************************************/
42
43
/* User include files */
44
#include "ih264_typedefs.h"
45
#include "ih264_defs.h"
46
#include "ih264_trans_macros.h"
47
#include "ih264_macros.h"
48
#include "ih264_trans_data.h"
49
#include "ih264_size_defs.h"
50
#include "ih264_structs.h"
51
#include "ih264_trans_quant_itrans_iquant.h"
52
53
/*
54
 ********************************************************************************
55
 *
56
 * @brief This function performs a 4x4 inverse hadamard transform on the 4x4 DC coefficients
57
 * of a 16x16 intra prediction macroblock, and then performs scaling.
58
 * prediction buffer
59
 *
60
 * @par Description:
61
 *  The DC coefficients pass through a 2-stage inverse hadamard transform.
62
 *  This inverse transformed content is scaled to based on Qp value.
63
 *
64
 * @param[in] pi2_src
65
 *  input 4x4 block of DC coefficients
66
 *
67
 * @param[out] pi2_out
68
 *  output 4x4 block
69
 *
70
 * @param[in] pu2_iscal_mat
71
 *  pointer to scaling list
72
 *
73
 * @param[in] pu2_weigh_mat
74
 *  pointer to weight matrix
75
 *
76
 * @param[in] u4_qp_div_6
77
 *  Floor (qp/6)
78
 *
79
 * @param[in] pi4_tmp
80
 * temporary buffer of size 1*16
81
 *
82
 * @returns none
83
 *
84
 * @remarks none
85
 *
86
 *******************************************************************************
87
 */
88
void ih264_ihadamard_scaling_4x4(WORD16* pi2_src,
89
                                 WORD16* pi2_out,
90
                                 const UWORD16 *pu2_iscal_mat,
91
                                 const UWORD16 *pu2_weigh_mat,
92
                                 UWORD32 u4_qp_div_6,
93
                                 WORD32* pi4_tmp)
94
0
{
95
0
    WORD32 i;
96
0
    WORD32 x0, x1, x2, x3, x4, x5, x6, x7;
97
0
    WORD16* pi2_src_ptr, *pi2_out_ptr;
98
0
    WORD32* pi4_tmp_ptr;
99
0
    WORD32 rnd_fact = (u4_qp_div_6 < 6) ? (1 << (5 - u4_qp_div_6)) : 0;
100
0
    pi4_tmp_ptr = pi4_tmp;
101
0
    pi2_src_ptr = pi2_src;
102
0
    pi2_out_ptr = pi2_out;
103
0
    // Horizontal transform
104
0
    for(i = 0; i < SUB_BLK_WIDTH_4x4; i++)
105
0
    {
106
0
        x4 = pi2_src_ptr[0];
107
0
        x5 = pi2_src_ptr[1];
108
0
        x6 = pi2_src_ptr[2];
109
0
        x7 = pi2_src_ptr[3];
110
0
111
0
        x0 = x4 + x7;
112
0
        x1 = x5 + x6;
113
0
        x2 = x5 - x6;
114
0
        x3 = x4 - x7;
115
0
116
0
        pi4_tmp_ptr[0] = x0 + x1;
117
0
        pi4_tmp_ptr[1] = x2 + x3;
118
0
        pi4_tmp_ptr[2] = x0 - x1;
119
0
        pi4_tmp_ptr[3] = x3 - x2;
120
0
121
0
        pi4_tmp_ptr += SUB_BLK_WIDTH_4x4;
122
0
        pi2_src_ptr += SUB_BLK_WIDTH_4x4;
123
0
    }
124
0
    pi4_tmp_ptr = pi4_tmp;
125
0
    // Vertical Transform
126
0
    for(i = 0; i < SUB_BLK_WIDTH_4x4; i++)
127
0
    {
128
0
        x4 = pi4_tmp_ptr[0];
129
0
        x5 = pi4_tmp_ptr[4];
130
0
        x6 = pi4_tmp_ptr[8];
131
0
        x7 = pi4_tmp_ptr[12];
132
0
133
0
        x0 = x4 + x7;
134
0
        x1 = x5 + x6;
135
0
        x2 = x5 - x6;
136
0
        x3 = x4 - x7;
137
0
138
0
        pi4_tmp_ptr[0] = x0 + x1;
139
0
        pi4_tmp_ptr[4] = x2 + x3;
140
0
        pi4_tmp_ptr[8] = x0 - x1;
141
0
        pi4_tmp_ptr[12] = x3 - x2;
142
0
143
0
        pi4_tmp_ptr++;
144
0
    }
145
0
    pi4_tmp_ptr = pi4_tmp;
146
0
    //Scaling
147
0
    for(i = 0; i < (SUB_BLK_WIDTH_4x4 * SUB_BLK_WIDTH_4x4); i++)
148
0
    {
149
0
      INV_QUANT(pi4_tmp_ptr[i], pu2_iscal_mat[0], pu2_weigh_mat[0], u4_qp_div_6,
150
0
                rnd_fact, 6);
151
0
      pi2_out_ptr[i] = pi4_tmp_ptr[i];
152
0
    }
153
0
}
154
155
void ih264_ihadamard_scaling_2x2_uv(WORD16* pi2_src,
156
                                    WORD16* pi2_out,
157
                                    const UWORD16 *pu2_iscal_mat,
158
                                    const UWORD16 *pu2_weigh_mat,
159
                                    UWORD32 u4_qp_div_6,
160
                                    WORD32* pi4_tmp)
161
0
{
162
0
  WORD32 i4_x0,i4_x1,i4_x2,i4_x3,i4_x4,i4_x5,i4_x6,i4_x7;
163
0
  WORD32 i4_y0,i4_y1,i4_y2,i4_y3,i4_y4,i4_y5,i4_y6,i4_y7;
164
0
165
0
  UNUSED(pi4_tmp);
166
0
167
0
  i4_x4 = pi2_src[0];
168
0
  i4_x5 = pi2_src[1];
169
0
  i4_x6 = pi2_src[2];
170
0
  i4_x7 = pi2_src[3];
171
0
172
0
  i4_x0 = i4_x4 + i4_x5;
173
0
  i4_x1 = i4_x4 - i4_x5;
174
0
  i4_x2 = i4_x6 + i4_x7;
175
0
  i4_x3 = i4_x6 - i4_x7;
176
0
177
0
  i4_x4 = i4_x0+i4_x2;
178
0
  i4_x5 = i4_x1+i4_x3;
179
0
  i4_x6 = i4_x0-i4_x2;
180
0
  i4_x7 = i4_x1-i4_x3;
181
0
182
0
  INV_QUANT(i4_x4,pu2_iscal_mat[0],pu2_weigh_mat[0],u4_qp_div_6,0,5);
183
0
  INV_QUANT(i4_x5,pu2_iscal_mat[0],pu2_weigh_mat[0],u4_qp_div_6,0,5);
184
0
  INV_QUANT(i4_x6,pu2_iscal_mat[0],pu2_weigh_mat[0],u4_qp_div_6,0,5);
185
0
  INV_QUANT(i4_x7,pu2_iscal_mat[0],pu2_weigh_mat[0],u4_qp_div_6,0,5);
186
0
187
0
  pi2_out[0] = i4_x4;
188
0
  pi2_out[1] = i4_x5;
189
0
  pi2_out[2] = i4_x6;
190
0
  pi2_out[3] = i4_x7;
191
0
192
0
  i4_y4 = pi2_src[4];
193
0
  i4_y5 = pi2_src[5];
194
0
  i4_y6 = pi2_src[6];
195
0
  i4_y7 = pi2_src[7];
196
0
197
0
  i4_y0 = i4_y4 + i4_y5;
198
0
  i4_y1 = i4_y4 - i4_y5;
199
0
  i4_y2 = i4_y6 + i4_y7;
200
0
  i4_y3 = i4_y6 - i4_y7;
201
0
202
0
  i4_y4 = i4_y0+i4_y2;
203
0
  i4_y5 = i4_y1+i4_y3;
204
0
  i4_y6 = i4_y0-i4_y2;
205
0
  i4_y7 = i4_y1-i4_y3;
206
0
207
0
  INV_QUANT(i4_y4,pu2_iscal_mat[0],pu2_weigh_mat[0],u4_qp_div_6,0,5);
208
0
  INV_QUANT(i4_y5,pu2_iscal_mat[0],pu2_weigh_mat[0],u4_qp_div_6,0,5);
209
0
  INV_QUANT(i4_y6,pu2_iscal_mat[0],pu2_weigh_mat[0],u4_qp_div_6,0,5);
210
0
  INV_QUANT(i4_y7,pu2_iscal_mat[0],pu2_weigh_mat[0],u4_qp_div_6,0,5);
211
0
212
0
  pi2_out[4] = i4_y4;
213
0
  pi2_out[5] = i4_y5;
214
0
  pi2_out[6] = i4_y6;
215
0
  pi2_out[7] = i4_y7;
216
0
}
/proc/self/cwd/external/libavc/common/ih264_inter_pred_filters.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/**
21
 *******************************************************************************
22
 * @file
23
 *  ih264_inter_pred_filters.c
24
 *
25
 * @brief
26
 *  Contains function definitions for inter prediction interpolation filters
27
 *
28
 * @author
29
 *  Ittiam
30
 *
31
 * @par List of Functions:
32
 *  - ih264_inter_pred_luma_copy
33
 *  - ih264_interleave_copy
34
 *  - ih264_inter_pred_luma_horz
35
 *  - ih264_inter_pred_luma_vert
36
 *  - ih264_inter_pred_luma_horz_hpel_vert_hpel
37
 *  - ih264_inter_pred_luma_horz_qpel
38
 *  - ih264_inter_pred_luma_vert_qpel
39
 *  - ih264_inter_pred_luma_horz_qpel_vert_qpel
40
 *  - ih264_inter_pred_luma_horz_hpel_vert_qpel
41
 *  - ih264_inter_pred_luma_horz_qpel_vert_hpel
42
 *  - ih264_inter_pred_luma_bilinear
43
 *  - ih264_inter_pred_chroma
44
 *
45
 * @remarks
46
 *  None
47
 *
48
 *******************************************************************************
49
 */
50
51
/*****************************************************************************/
52
/* File Includes                                                             */
53
/*****************************************************************************/
54
55
/* User include files */
56
#include "ih264_typedefs.h"
57
#include "ih264_macros.h"
58
#include "ih264_platform_macros.h"
59
#include "ih264_inter_pred_filters.h"
60
61
62
/*****************************************************************************/
63
/* Constant Data variables                                                   */
64
/*****************************************************************************/
65
66
/* coefficients for 6 tap filtering*/
67
const WORD32 ih264_g_six_tap[3] ={1,-5,20};
68
69
70
/*****************************************************************************/
71
/*  Function definitions .                                                   */
72
/*****************************************************************************/
73
/**
74
 *******************************************************************************
75
 *
76
 * @brief
77
 * Interprediction luma function for copy
78
 *
79
 * @par Description:
80
 *    Copies the array of width 'wd' and height 'ht' from the  location pointed
81
 *    by 'src' to the location pointed by 'dst'
82
 *
83
 * @param[in] pu1_src
84
 *  UWORD8 pointer to the source
85
 *
86
 * @param[out] pu1_dst
87
 *  UWORD8 pointer to the destination
88
 *
89
 * @param[in] src_strd
90
 *  integer source stride
91
 *
92
 * @param[in] dst_strd
93
 *  integer destination stride
94
 *
95
 *
96
 * @param[in] ht
97
 *  integer height of the array
98
 *
99
 * @param[in] wd
100
 *  integer width of the array
101
 *
102
 * @returns
103
 *
104
 * @remarks
105
 *  None
106
 *
107
 *******************************************************************************
108
 */
109
110
void ih264_inter_pred_luma_copy(UWORD8 *pu1_src,
111
                                UWORD8 *pu1_dst,
112
                                WORD32 src_strd,
113
                                WORD32 dst_strd,
114
                                WORD32 ht,
115
                                WORD32 wd,
116
                                UWORD8* pu1_tmp,
117
                                WORD32 dydx)
118
0
{
119
0
    WORD32 row, col;
120
0
    UNUSED(pu1_tmp);
121
0
    UNUSED(dydx);
122
0
    for(row = 0; row < ht; row++)
123
0
    {
124
0
        for(col = 0; col < wd; col++)
125
0
        {
126
0
            pu1_dst[col] = pu1_src[col];
127
0
        }
128
0
129
0
        pu1_src += src_strd;
130
0
        pu1_dst += dst_strd;
131
0
    }
132
0
}
133
134
/**
135
 *******************************************************************************
136
 *
137
 * @brief
138
 * Fucntion for copying to an interleaved destination
139
 *
140
 * @par Description:
141
 *    Copies the array of width 'wd' and height 'ht' from the  location pointed
142
 *    by 'src' to the location pointed by 'dst'
143
 *
144
 * @param[in] pu1_src
145
 *  UWORD8 pointer to the source
146
 *
147
 * @param[out] pu1_dst
148
 *  UWORD8 pointer to the destination
149
 *
150
 * @param[in] src_strd
151
 *  integer source stride
152
 *
153
 * @param[in] dst_strd
154
 *  integer destination stride
155
 *
156
 * @param[in] ht
157
 *  integer height of the array
158
 *
159
 * @param[in] wd
160
 *  integer width of the array
161
 *
162
 * @returns
163
 *
164
 * @remarks
165
 *  The alternate elements of src will be copied to alternate locations in dsr
166
 *  Other locations are not touched
167
 *
168
 *******************************************************************************
169
 */
170
void ih264_interleave_copy(UWORD8 *pu1_src,
171
                           UWORD8 *pu1_dst,
172
                           WORD32 src_strd,
173
                           WORD32 dst_strd,
174
                           WORD32 ht,
175
                           WORD32 wd)
176
0
{
177
0
    WORD32 row, col;
178
0
    wd *= 2;
179
0
180
0
    for(row = 0; row < ht; row++)
181
0
    {
182
0
        for(col = 0; col < wd; col+=2)
183
0
        {
184
0
            pu1_dst[col] = pu1_src[col];
185
0
        }
186
0
187
0
        pu1_src += src_strd;
188
0
        pu1_dst += dst_strd;
189
0
    }
190
0
}
191
192
/**
193
 *******************************************************************************
194
 *
195
 * @brief
196
 *     Interprediction luma filter for horizontal input
197
 *
198
 * @par Description:
199
 *    Applies a 6 tap horizontal filter .The output is  clipped to 8 bits
200
 *    sec 8.4.2.2.1 titled "Luma sample interpolation process"
201
 *
202
 * @param[in] pu1_src
203
 *  UWORD8 pointer to the source
204
 *
205
 * @param[out] pu1_dst
206
 *  UWORD8 pointer to the destination
207
 *
208
 * @param[in] src_strd
209
 *  integer source stride
210
 *
211
 * @param[in] dst_strd
212
 *  integer destination stride
213
 *
214
 * @param[in] ht
215
 *  integer height of the array
216
 *
217
 * @param[in] wd
218
 *  integer width of the array
219
 *
220
 * @returns
221
 *
222
 * @remarks
223
 *  None
224
 *
225
 *******************************************************************************
226
 */
227
void ih264_inter_pred_luma_horz(UWORD8 *pu1_src,
228
                                UWORD8 *pu1_dst,
229
                                WORD32 src_strd,
230
                                WORD32 dst_strd,
231
                                WORD32 ht,
232
                                WORD32 wd,
233
                                UWORD8* pu1_tmp,
234
                                WORD32 dydx)
235
0
{
236
0
    WORD32 row, col;
237
0
    WORD16 i2_tmp;
238
0
    UNUSED(pu1_tmp);
239
0
    UNUSED(dydx);
240
0
241
0
    for(row = 0; row < ht; row++)
242
0
    {
243
0
        for(col = 0; col < wd; col++)
244
0
        {
245
0
            i2_tmp = 0;/*ih264_g_six_tap[] is the array containing the filter coeffs*/
246
0
            i2_tmp = ih264_g_six_tap[0] *
247
0
                            (pu1_src[col - 2] + pu1_src[col + 3])
248
0
                     + ih264_g_six_tap[1] *
249
0
                            (pu1_src[col - 1] + pu1_src[col + 2])
250
0
                     + ih264_g_six_tap[2] *
251
0
                            (pu1_src[col] + pu1_src[col + 1]);
252
0
            i2_tmp = (i2_tmp + 16) >> 5;
253
0
            pu1_dst[col] = CLIP_U8(i2_tmp);
254
0
        }
255
0
256
0
        pu1_src += src_strd;
257
0
        pu1_dst += dst_strd;
258
0
    }
259
0
260
0
}
261
262
/**
263
 *******************************************************************************
264
 *
265
 * @brief
266
 *    Interprediction luma filter for vertical input
267
 *
268
 * @par Description:
269
 *   Applies a 6 tap vertical filter.The output is  clipped to 8 bits
270
 *    sec 8.4.2.2.1 titled "Luma sample interpolation process"
271
 *
272
 * @param[in] pu1_src
273
 *  UWORD8 pointer to the source
274
 *
275
 * @param[out] pu1_dst
276
 *  UWORD8 pointer to the destination
277
 *
278
 * @param[in] src_strd
279
 *  integer source stride
280
 *
281
 * @param[in] dst_strd
282
 *  integer destination stride
283
 *
284
 * @param[in] ht
285
 *  integer height of the array
286
 *
287
 * @param[in] wd
288
 *  integer width of the array
289
 *
290
 * @returns
291
 *
292
 * @remarks
293
 *  None
294
 *
295
 *******************************************************************************
296
 */
297
void ih264_inter_pred_luma_vert(UWORD8 *pu1_src,
298
                                UWORD8 *pu1_dst,
299
                                WORD32 src_strd,
300
                                WORD32 dst_strd,
301
                                WORD32 ht,
302
                                WORD32 wd,
303
                                UWORD8* pu1_tmp,
304
                                WORD32 dydx)
305
0
{
306
0
    WORD32 row, col;
307
0
    WORD16 i2_tmp;
308
0
    UNUSED(pu1_tmp);
309
0
    UNUSED(dydx);
310
0
311
0
    for(row = 0; row < ht; row++)
312
0
    {
313
0
        for(col = 0; col < wd; col++)
314
0
        {
315
0
            i2_tmp = 0; /*ih264_g_six_tap[] is the array containing the filter coeffs*/
316
0
            i2_tmp = ih264_g_six_tap[0] *
317
0
                            (pu1_src[col - 2 * src_strd] + pu1_src[col + 3 * src_strd])
318
0
                     + ih264_g_six_tap[1] *
319
0
                            (pu1_src[col - 1 * src_strd] + pu1_src[col + 2 * src_strd])
320
0
                     + ih264_g_six_tap[2] *
321
0
                            (pu1_src[col] + pu1_src[col + 1 * src_strd]);
322
0
            i2_tmp = (i2_tmp + 16) >> 5;
323
0
            pu1_dst[col] = CLIP_U8(i2_tmp);
324
0
        }
325
0
        pu1_src += src_strd;
326
0
        pu1_dst += dst_strd;
327
0
    }
328
0
}
329
330
/*!
331
 **************************************************************************
332
 * \if Function name : ih264_inter_pred_luma_horz_hpel_vert_hpel \endif
333
 *
334
 * \brief
335
 *    This function implements a two stage cascaded six tap filter. It
336
 *    applies the six tap filter in the horizontal direction on the
337
 *    predictor values, followed by applying the same filter in the
338
 *    vertical direction on the output of the first stage. The six tap
339
 *    filtering operation is described in sec 8.4.2.2.1 titled "Luma sample
340
 *    interpolation process"
341
 *
342
 * \param pu1_src: Pointer to the buffer containing the predictor values.
343
 *     pu1_src could point to the frame buffer or the predictor buffer.
344
 * \param pu1_dst: Pointer to the destination buffer where the output of
345
 *     the six tap filter is stored.
346
 * \param ht: Height of the rectangular pixel grid to be interpolated
347
 * \param wd: Width of the rectangular pixel grid to be interpolated
348
 * \param src_strd: Width of the buffer pointed to by pu1_src.
349
 * \param dst_strd: Width of the destination buffer
350
 * \param pu1_tmp: temporary buffer.
351
 * \param dydx: x and y reference offset for qpel calculations: UNUSED in this function.
352
 *
353
 * \return
354
 *    None.
355
 *
356
 * \note
357
 *    This function takes the 8 bit predictor values, applies the six tap
358
 *    filter in the horizontal direction and outputs the result clipped to
359
 *    8 bit precision. The input is stored in the buffer pointed to by
360
 *    pu1_src while the output is stored in the buffer pointed by pu1_dst.
361
 *    Both pu1_src and pu1_dst could point to the same buffer i.e. the
362
 *    six tap filter could be done in place.
363
 *
364
 **************************************************************************
365
 */
366
void ih264_inter_pred_luma_horz_hpel_vert_hpel(UWORD8 *pu1_src,
367
                                               UWORD8 *pu1_dst,
368
                                               WORD32 src_strd,
369
                                               WORD32 dst_strd,
370
                                               WORD32 ht,
371
                                               WORD32 wd,
372
                                               UWORD8* pu1_tmp,
373
                                               WORD32 dydx)
374
0
{
375
0
    WORD32 row, col;
376
0
    WORD32 tmp;
377
0
    WORD16* pi2_pred1_temp;
378
0
    WORD16* pi2_pred1;
379
0
    UNUSED(dydx);
380
0
    pi2_pred1_temp = (WORD16*)pu1_tmp;
381
0
    pi2_pred1_temp += 2;
382
0
    pi2_pred1 = pi2_pred1_temp;
383
0
    for(row = 0; row < ht; row++)
384
0
    {
385
0
        for(col = -2; col < wd + 3; col++)
386
0
        {
387
0
            tmp = 0;/*ih264_g_six_tap[] is the array containing the filter coeffs*/
388
0
            tmp = ih264_g_six_tap[0] *
389
0
                            (pu1_src[col - 2 * src_strd] + pu1_src[col + 3 * src_strd])
390
0
                  + ih264_g_six_tap[1] *
391
0
                            (pu1_src[col - 1 * src_strd] + pu1_src[col + 2 * src_strd])
392
0
                  + ih264_g_six_tap[2] *
393
0
                            (pu1_src[col] + pu1_src[col + 1 * src_strd]);
394
0
            pi2_pred1_temp[col] = tmp;
395
0
        }
396
0
        pu1_src += src_strd;
397
0
        pi2_pred1_temp = pi2_pred1_temp + wd + 5;
398
0
    }
399
0
400
0
    for(row = 0; row < ht; row++)
401
0
    {
402
0
        for(col = 0; col < wd; col++)
403
0
        {
404
0
            tmp = 0;/*ih264_g_six_tap[] is the array containing the filter coeffs*/
405
0
            tmp = ih264_g_six_tap[0] *
406
0
                            (pi2_pred1[col - 2] + pi2_pred1[col + 3])
407
0
                  + ih264_g_six_tap[1] *
408
0
                            (pi2_pred1[col - 1] + pi2_pred1[col + 2])
409
0
                  + ih264_g_six_tap[2] * (pi2_pred1[col] + pi2_pred1[col + 1]);
410
0
            tmp = (tmp + 512) >> 10;
411
0
            pu1_dst[col] = CLIP_U8(tmp);
412
0
        }
413
0
        pi2_pred1 += (wd + 5);
414
0
        pu1_dst += dst_strd;
415
0
    }
416
0
}
417
418
/*!
419
 **************************************************************************
420
 * \if Function name : ih264_inter_pred_luma_horz_qpel \endif
421
 *
422
 * \brief
423
 *    This routine applies the six tap filter to the predictors in the
424
 *    horizontal direction. The six tap filtering operation is described in
425
 *    sec 8.4.2.2.1 titled "Luma sample interpolation process"
426
 *
427
 * \param pu1_src: Pointer to the buffer containing the predictor values.
428
 *     pu1_src could point to the frame buffer or the predictor buffer.
429
 * \param pu1_dst: Pointer to the destination buffer where the output of
430
 *     the six tap filter is stored.
431
 * \param ht: Height of the rectangular pixel grid to be interpolated
432
 * \param wd: Width of the rectangular pixel grid to be interpolated
433
 * \param src_strd: Width of the buffer pointed to by pu1_src.
434
 * \param dst_strd: Width of the destination buffer
435
 * \param pu1_tmp: temporary buffer: UNUSED in this function
436
 * \param dydx: x and y reference offset for qpel calculations.
437
 *
438
 * \return
439
 *    None.
440
 *
441
 * \note
442
 *    This function takes the 8 bit predictor values, applies the six tap
443
 *    filter in the horizontal direction and outputs the result clipped to
444
 *    8 bit precision. The input is stored in the buffer pointed to by
445
 *    pu1_src while the output is stored in the buffer pointed by pu1_dst.
446
 *    Both pu1_src and pu1_dst could point to the same buffer i.e. the
447
 *    six tap filter could be done in place.
448
 *
449
 **************************************************************************
450
 */
451
void ih264_inter_pred_luma_horz_qpel(UWORD8 *pu1_src,
452
                                     UWORD8 *pu1_dst,
453
                                     WORD32 src_strd,
454
                                     WORD32 dst_strd,
455
                                     WORD32 ht,
456
                                     WORD32 wd,
457
                                     UWORD8* pu1_tmp,
458
                                     WORD32 dydx)
459
0
{
460
0
    WORD32 row, col;
461
0
    UWORD8 *pu1_pred1;
462
0
    WORD32 x_offset = dydx & 0x3;
463
0
    UNUSED(pu1_tmp);
464
0
    pu1_pred1 = pu1_src + (x_offset >> 1);
465
0
466
0
    for(row = 0; row < ht; row++)
467
0
    {
468
0
        for(col = 0; col < wd; col++, pu1_src++, pu1_dst++)
469
0
        {
470
0
            WORD16 i2_temp;
471
0
            /* The logic below implements the following equation
472
0
             i2_temp = puc_pred[-2] - 5 * (puc_pred[-1] + puc_pred[2]) +
473
0
             20 * (puc_pred[0] + puc_pred[1]) + puc_pred[3]; */
474
0
            i2_temp = pu1_src[-2] + pu1_src[3]
475
0
                      - (pu1_src[-1] + pu1_src[2])
476
0
                      + ((pu1_src[0] + pu1_src[1] - pu1_src[-1] - pu1_src[2]) << 2)
477
0
                      + ((pu1_src[0] + pu1_src[1]) << 4);
478
0
            i2_temp = (i2_temp + 16) >> 5;
479
0
            i2_temp = CLIP_U8(i2_temp);
480
0
            *pu1_dst = (i2_temp + *pu1_pred1 + 1) >> 1;
481
0
482
0
            pu1_pred1++;
483
0
        }
484
0
        pu1_dst += dst_strd - wd;
485
0
        pu1_src += src_strd - wd;
486
0
        pu1_pred1 += src_strd - wd;
487
0
    }
488
0
}
489
490
/*!
491
 **************************************************************************
492
 * \if Function name : ih264_inter_pred_luma_vert_qpel \endif
493
 *
494
 * \brief
495
 *    This routine applies the six tap filter to the predictors in the
496
 *    vertical direction and interpolates them to obtain pixels at quarter vertical
497
 *    positions (0, 1/4) and (0, 3/4). The six tap filtering operation is
498
 *    described in sec 8.4.2.2.1 titled "Luma sample interpolation process"
499
 *
500
 * \param pu1_src: Pointer to the buffer containing the predictor values.
501
 *     pu1_src could point to the frame buffer or the predictor buffer.
502
 * \param pu1_dst: Pointer to the destination buffer where the output of
503
 *     the six tap filter is stored.
504
 * \param ht: Height of the rectangular pixel grid to be interpolated
505
 * \param wd: Width of the rectangular pixel grid to be interpolated
506
 * \param src_strd: Width of the buffer pointed to by puc_pred.
507
 * \param dst_strd: Width of the destination buffer
508
 * \param pu1_tmp: temporary buffer: UNUSED in this function
509
 * \param dydx: x and y reference offset for qpel calculations.
510
 *
511
 * \return
512
 *    void
513
 *
514
 * \note
515
 *    This function takes the 8 bit predictor values, applies the six tap
516
 *    filter in the vertical direction and outputs the result clipped to
517
 *    8 bit precision. The input is stored in the buffer pointed to by
518
 *    puc_pred while the output is stored in the buffer pointed by puc_dest.
519
 *    Both puc_pred and puc_dest could point to the same buffer i.e. the
520
 *    six tap filter could be done in place.
521
 *
522
 * \para <title>
523
 *    <paragraph>
524
 *  ...
525
 **************************************************************************
526
 */
527
void ih264_inter_pred_luma_vert_qpel(UWORD8 *pu1_src,
528
                                     UWORD8 *pu1_dst,
529
                                     WORD32 src_strd,
530
                                     WORD32 dst_strd,
531
                                     WORD32 ht,
532
                                     WORD32 wd,
533
                                     UWORD8* pu1_tmp,
534
                                     WORD32 dydx)
535
0
{
536
0
    WORD32 row, col;
537
0
    WORD32 y_offset = dydx >> 2;
538
0
    WORD32 off1, off2, off3;
539
0
    UWORD8 *pu1_pred1;
540
0
    UNUSED(pu1_tmp);
541
0
    y_offset = y_offset & 0x3;
542
0
543
0
    off1 = src_strd;
544
0
    off2 = src_strd << 1;
545
0
    off3 = off1 + off2;
546
0
547
0
    pu1_pred1 = pu1_src + (y_offset >> 1) * src_strd;
548
0
549
0
    for(row = 0; row < ht; row++)
550
0
    {
551
0
        for(col = 0; col < wd; col++, pu1_dst++, pu1_src++, pu1_pred1++)
552
0
        {
553
0
            WORD16 i2_temp;
554
0
            /* The logic below implements the following equation
555
0
             i16_temp = puc_pred[-2*src_strd] + puc_pred[3*src_strd] -
556
0
             5 * (puc_pred[-1*src_strd] + puc_pred[2*src_strd])  +
557
0
             20 * (puc_pred[0] + puc_pred[src_strd]); */
558
0
            i2_temp = pu1_src[-off2] + pu1_src[off3]
559
0
                       - (pu1_src[-off1] + pu1_src[off2])
560
0
                       + ((pu1_src[0] + pu1_src[off1] - pu1_src[-off1] - pu1_src[off2]) << 2)
561
0
                       + ((pu1_src[0] + pu1_src[off1]) << 4);
562
0
            i2_temp = (i2_temp + 16) >> 5;
563
0
            i2_temp = CLIP_U8(i2_temp);
564
0
565
0
            *pu1_dst = (i2_temp + *pu1_pred1 + 1) >> 1;
566
0
        }
567
0
        pu1_src += src_strd - wd;
568
0
        pu1_pred1 += src_strd - wd;
569
0
        pu1_dst += dst_strd - wd;
570
0
    }
571
0
}
572
573
/*!
574
 **************************************************************************
575
 * \if Function name : ih264_inter_pred_luma_horz_qpel_vert_qpel \endif
576
 *
577
 * \brief
578
 *    This routine applies the six tap filter to the predictors in the
579
 *    vertical and horizontal direction and averages them to get pixels at locations
580
 *    (1/4,1/4), (1/4, 3/4), (3/4, 1/4) & (3/4, 3/4). The six tap filtering operation
581
 *    is described in sec 8.4.2.2.1 titled "Luma sample interpolation process"
582
 *
583
 * \param pu1_src: Pointer to the buffer containing the predictor values.
584
 *     pu1_src could point to the frame buffer or the predictor buffer.
585
 * \param pu1_dst: Pointer to the destination buffer where the output of
586
 *     the six tap filter is stored.
587
 * \param wd: Width of the rectangular pixel grid to be interpolated
588
 * \param ht: Height of the rectangular pixel grid to be interpolated
589
 * \param src_strd: Width of the buffer pointed to by puc_pred.
590
 * \param dst_strd: Width of the destination buffer
591
 * \param pu1_tmp: temporary buffer, UNUSED in this function
592
 * \param dydx: x and y reference offset for qpel calculations.
593
 *
594
 * \return
595
 *    void
596
 *
597
 * \note
598
 *    This function takes the 8 bit predictor values, applies the six tap
599
 *    filter in the vertical direction and outputs the result clipped to
600
 *    8 bit precision. The input is stored in the buffer pointed to by
601
 *    puc_pred while the output is stored in the buffer pointed by puc_dest.
602
 *    Both puc_pred and puc_dest could point to the same buffer i.e. the
603
 *    six tap filter could be done in place.
604
 *
605
 * \para <title>
606
 *    <paragraph>
607
 *  ...
608
 **************************************************************************
609
 */
610
void ih264_inter_pred_luma_horz_qpel_vert_qpel(UWORD8 *pu1_src,
611
                                               UWORD8 *pu1_dst,
612
                                               WORD32 src_strd,
613
                                               WORD32 dst_strd,
614
                                               WORD32 ht,
615
                                               WORD32 wd,
616
                                               UWORD8* pu1_tmp,
617
                                               WORD32 dydx)
618
0
{
619
0
    WORD32 row, col;
620
0
    WORD32 x_offset = dydx & 0x3;
621
0
    WORD32 y_offset = dydx >> 2;
622
0
623
0
    WORD32 off1, off2, off3;
624
0
    UWORD8* pu1_pred_vert, *pu1_pred_horz;
625
0
    UNUSED(pu1_tmp);
626
0
    y_offset = y_offset & 0x3;
627
0
628
0
    off1 = src_strd;
629
0
    off2 = src_strd << 1;
630
0
    off3 = off1 + off2;
631
0
632
0
    pu1_pred_horz = pu1_src + (y_offset >> 1) * src_strd;
633
0
    pu1_pred_vert = pu1_src + (x_offset >> 1);
634
0
635
0
    for(row = 0; row < ht; row++)
636
0
    {
637
0
        for(col = 0; col < wd;
638
0
                        col++, pu1_dst++, pu1_pred_vert++, pu1_pred_horz++)
639
0
        {
640
0
            WORD16 i2_temp_vert, i2_temp_horz;
641
0
            /* The logic below implements the following equation
642
0
             i2_temp = puc_pred[-2*src_strd] + puc_pred[3*src_strd] -
643
0
             5 * (puc_pred[-1*src_strd] + puc_pred[2*src_strd])  +
644
0
             20 * (puc_pred[0] + puc_pred[src_strd]); */
645
0
            i2_temp_vert = pu1_pred_vert[-off2] + pu1_pred_vert[off3]
646
0
                            - (pu1_pred_vert[-off1] + pu1_pred_vert[off2])
647
0
                            + ((pu1_pred_vert[0] + pu1_pred_vert[off1]
648
0
                                            - pu1_pred_vert[-off1]
649
0
                                            - pu1_pred_vert[off2]) << 2)
650
0
                            + ((pu1_pred_vert[0] + pu1_pred_vert[off1]) << 4);
651
0
            i2_temp_vert = (i2_temp_vert + 16) >> 5;
652
0
            i2_temp_vert = CLIP_U8(i2_temp_vert);
653
0
654
0
            /* The logic below implements the following equation
655
0
             i16_temp = puc_pred[-2] - 5 * (puc_pred[-1] + puc_pred[2]) +
656
0
             20 * (puc_pred[0] + puc_pred[1]) + puc_pred[3]; */
657
0
            i2_temp_horz = pu1_pred_horz[-2] + pu1_pred_horz[3]
658
0
                            - (pu1_pred_horz[-1] + pu1_pred_horz[2])
659
0
                            + ((pu1_pred_horz[0] + pu1_pred_horz[1]
660
0
                                            - pu1_pred_horz[-1]
661
0
                                            - pu1_pred_horz[2]) << 2)
662
0
                            + ((pu1_pred_horz[0] + pu1_pred_horz[1]) << 4);
663
0
            i2_temp_horz = (i2_temp_horz + 16) >> 5;
664
0
            i2_temp_horz = CLIP_U8(i2_temp_horz);
665
0
            *pu1_dst = (i2_temp_vert + i2_temp_horz + 1) >> 1;
666
0
        }
667
0
        pu1_pred_vert += (src_strd - wd);
668
0
        pu1_pred_horz += (src_strd - wd);
669
0
        pu1_dst += (dst_strd - wd);
670
0
    }
671
0
}
672
673
/*!
674
 **************************************************************************
675
 * \if Function name : ih264_inter_pred_luma_horz_qpel_vert_hpel \endif
676
 *
677
 * \brief
678
 *    This routine applies the six tap filter to the predictors in the vertical
679
 *    and horizontal direction to obtain the pixel at (1/2,1/2). It then interpolates
680
 *    pixel at (0,1/2) and (1/2,1/2) to obtain pixel at (1/4,1/2). Similarly for (3/4,1/2).
681
 *    The six tap filtering operation is described in sec 8.4.2.2.1 titled
682
 *    "Luma sample interpolation process"
683
 *
684
 * \param pu1_src: Pointer to the buffer containing the predictor values.
685
 *     pu1_src could point to the frame buffer or the predictor buffer.
686
 * \param pu1_dst: Pointer to the destination buffer where the output of
687
 *     the six tap filter followed by interpolation is stored.
688
 * \param wd: Width of the rectangular pixel grid to be interpolated
689
 * \param ht: Height of the rectangular pixel grid to be interpolated
690
 * \param src_strd: Width of the buffer pointed to by puc_pred.
691
 * \param dst_strd: Width of the destination buffer
692
 * \param pu1_tmp: buffer to store temporary output after 1st 6-tap filter.
693
 * \param dydx: x and y reference offset for qpel calculations.
694
 *
695
 * \return
696
 *    void
697
 *
698
 * \note
699
 *    This function takes the 8 bit predictor values, applies the six tap
700
 *    filter in the vertical direction and outputs the result clipped to
701
 *    8 bit precision. The input is stored in the buffer pointed to by
702
 *    puc_pred while the output is stored in the buffer pointed by puc_dest.
703
 *    Both puc_pred and puc_dest could point to the same buffer i.e. the
704
 *    six tap filter could be done in place.
705
 *
706
 * \para <title>
707
 *    <paragraph>
708
 *  ...
709
 **************************************************************************
710
 */
711
void ih264_inter_pred_luma_horz_qpel_vert_hpel(UWORD8 *pu1_src,
712
                                               UWORD8 *pu1_dst,
713
                                               WORD32 src_strd,
714
                                               WORD32 dst_strd,
715
                                               WORD32 ht,
716
                                               WORD32 wd,
717
                                               UWORD8* pu1_tmp,
718
                                               WORD32 dydx)
719
0
{
720
0
    WORD32 row, col;
721
0
    WORD32 tmp;
722
0
    WORD16* pi2_pred1_temp, *pi2_pred1;
723
0
    UWORD8* pu1_dst_tmp;
724
0
    WORD32 x_offset = dydx & 0x3;
725
0
    WORD16 i2_macro;
726
0
727
0
    pi2_pred1_temp = (WORD16*)pu1_tmp;
728
0
    pi2_pred1_temp += 2;
729
0
    pi2_pred1 = pi2_pred1_temp;
730
0
    pu1_dst_tmp = pu1_dst;
731
0
732
0
    for(row = 0; row < ht; row++)
733
0
    {
734
0
        for(col = -2; col < wd + 3; col++)
735
0
        {
736
0
            tmp = 0;/*ih264_g_six_tap[] is the array containing the filter coeffs*/
737
0
            tmp = ih264_g_six_tap[0] *
738
0
                            (pu1_src[col - 2 * src_strd] + pu1_src[col + 3 * src_strd])
739
0
                  + ih264_g_six_tap[1] *
740
0
                            (pu1_src[col - 1 * src_strd] + pu1_src[col + 2 * src_strd])
741
0
                  + ih264_g_six_tap[2] *
742
0
                            (pu1_src[col] + pu1_src[col + 1 * src_strd]);
743
0
            pi2_pred1_temp[col] = tmp;
744
0
        }
745
0
746
0
        pu1_src += src_strd;
747
0
        pi2_pred1_temp = pi2_pred1_temp + wd + 5;
748
0
    }
749
0
750
0
    pi2_pred1_temp = pi2_pred1;
751
0
    for(row = 0; row < ht; row++)
752
0
    {
753
0
        for(col = 0; col < wd; col++)
754
0
        {
755
0
            tmp = 0;/*ih264_g_six_tap[] is the array containing the filter coeffs*/
756
0
            tmp = ih264_g_six_tap[0] *
757
0
                            (pi2_pred1[col - 2] + pi2_pred1[col + 3])
758
0
                  + ih264_g_six_tap[1] *
759
0
                            (pi2_pred1[col - 1] + pi2_pred1[col + 2])
760
0
                  + ih264_g_six_tap[2] *
761
0
                            (pi2_pred1[col] + pi2_pred1[col + 1]);
762
0
            tmp = (tmp + 512) >> 10;
763
0
            pu1_dst[col] = CLIP_U8(tmp);
764
0
        }
765
0
        pi2_pred1 += (wd + 5);
766
0
        pu1_dst += dst_strd;
767
0
    }
768
0
769
0
    pu1_dst = pu1_dst_tmp;
770
0
    pi2_pred1_temp += (x_offset >> 1);
771
0
    for(row = ht; row != 0; row--)
772
0
    {
773
0
        for(col = wd; col != 0; col--, pu1_dst++, pi2_pred1_temp++)
774
0
        {
775
0
            UWORD8 uc_temp;
776
0
            /* Clipping the output of the six tap filter obtained from the
777
0
             first stage of the 2d filter stage */
778
0
            *pi2_pred1_temp = (*pi2_pred1_temp + 16) >> 5;
779
0
            i2_macro = (*pi2_pred1_temp);
780
0
            uc_temp = CLIP_U8(i2_macro);
781
0
            *pu1_dst = (*pu1_dst + uc_temp + 1) >> 1;
782
0
        }
783
0
        pi2_pred1_temp += 5;
784
0
        pu1_dst += dst_strd - wd;
785
0
    }
786
0
}
787
788
/*!
789
 **************************************************************************
790
 * \if Function name : ih264_inter_pred_luma_horz_hpel_vert_qpel \endif
791
 *
792
 * \brief
793
 *    This routine applies the six tap filter to the predictors in the horizontal
794
 *    and vertical direction to obtain the pixel at (1/2,1/2). It then interpolates
795
 *    pixel at (1/2,0) and (1/2,1/2) to obtain pixel at (1/2,1/4). Similarly for (1/2,3/4).
796
 *    The six tap filtering operation is described in sec 8.4.2.2.1 titled
797
 *    "Luma sample interpolation process"
798
 *
799
 * \param pu1_src: Pointer to the buffer containing the predictor values.
800
 *     pu1_src could point to the frame buffer or the predictor buffer.
801
 * \param pu1_dst: Pointer to the destination buffer where the output of
802
 *     the six tap filter followed by interpolation is stored.
803
 * \param wd: Width of the rectangular pixel grid to be interpolated
804
 * \param ht: Height of the rectangular pixel grid to be interpolated
805
 * \param src_strd: Width of the buffer pointed to by puc_pred.
806
 * \param dst_strd: Width of the destination buffer
807
 * \param pu1_tmp: buffer to store temporary output after 1st 6-tap filter.
808
 * \param dydx: x and y reference offset for qpel calculations.
809
 *
810
 * \return
811
 *    void
812
 *
813
 * \note
814
 *    This function takes the 8 bit predictor values, applies the six tap
815
 *    filter in the vertical direction and outputs the result clipped to
816
 *    8 bit precision. The input is stored in the buffer pointed to by
817
 *    puc_pred while the output is stored in the buffer pointed by puc_dest.
818
 *    Both puc_pred and puc_dest could point to the same buffer i.e. the
819
 *    six tap filter could be done in place.
820
 *
821
 * \para <title>
822
 *    <paragraph>
823
 *  ...
824
 **************************************************************************
825
 */
826
void ih264_inter_pred_luma_horz_hpel_vert_qpel(UWORD8 *pu1_src,
827
                                               UWORD8 *pu1_dst,
828
                                               WORD32 src_strd,
829
                                               WORD32 dst_strd,
830
                                               WORD32 ht,
831
                                               WORD32 wd,
832
                                               UWORD8* pu1_tmp,
833
                                               WORD32 dydx)
834
0
{
835
0
836
0
    WORD32 row, col;
837
0
    WORD32 tmp;
838
0
    WORD32 y_offset = dydx >> 2;
839
0
    WORD16* pi2_pred1_temp, *pi2_pred1;
840
0
    UWORD8* pu1_dst_tmp;
841
0
    //WORD32 x_offset = dydx & 0x3;
842
0
    WORD16 i2_macro;
843
0
844
0
    y_offset = y_offset & 0x3;
845
0
846
0
    pi2_pred1_temp = (WORD16*)pu1_tmp;
847
0
    pi2_pred1_temp += 2 * wd;
848
0
    pi2_pred1 = pi2_pred1_temp;
849
0
    pu1_dst_tmp = pu1_dst;
850
0
    pu1_src -= 2 * src_strd;
851
0
    for(row = -2; row < ht + 3; row++)
852
0
    {
853
0
        for(col = 0; col < wd; col++)
854
0
        {
855
0
            tmp = 0;/*ih264_g_six_tap[] is the array containing the filter coeffs*/
856
0
            tmp = ih264_g_six_tap[0] * (pu1_src[col - 2] + pu1_src[col + 3])
857
0
                  + ih264_g_six_tap[1] * (pu1_src[col - 1] + pu1_src[col + 2])
858
0
                  + ih264_g_six_tap[2] * (pu1_src[col] + pu1_src[col + 1]);
859
0
            pi2_pred1_temp[col - 2 * wd] = tmp;
860
0
        }
861
0
862
0
        pu1_src += src_strd;
863
0
        pi2_pred1_temp += wd;
864
0
    }
865
0
    pi2_pred1_temp = pi2_pred1;
866
0
    for(row = 0; row < ht; row++)
867
0
    {
868
0
        for(col = 0; col < wd; col++)
869
0
        {
870
0
            tmp = 0;/*ih264_g_six_tap[] is the array containing the filter coeffs*/
871
0
            tmp = ih264_g_six_tap[0] * (pi2_pred1[col - 2 * wd] + pi2_pred1[col + 3 * wd])
872
0
                  + ih264_g_six_tap[1] * (pi2_pred1[col - 1 * wd] + pi2_pred1[col + 2 * wd])
873
0
                  + ih264_g_six_tap[2] * (pi2_pred1[col] + pi2_pred1[col + 1 * wd]);
874
0
            tmp = (tmp + 512) >> 10;
875
0
            pu1_dst[col] = CLIP_U8(tmp);
876
0
        }
877
0
        pi2_pred1 += wd;
878
0
        pu1_dst += dst_strd;
879
0
    }
880
0
    pu1_dst = pu1_dst_tmp;
881
0
    pi2_pred1_temp += (y_offset >> 1) * wd;
882
0
    for(row = ht; row != 0; row--)
883
0
884
0
    {
885
0
        for(col = wd; col != 0; col--, pu1_dst++, pi2_pred1_temp++)
886
0
        {
887
0
            UWORD8 u1_temp;
888
0
            /* Clipping the output of the six tap filter obtained from the
889
0
             first stage of the 2d filter stage */
890
0
            *pi2_pred1_temp = (*pi2_pred1_temp + 16) >> 5;
891
0
            i2_macro = (*pi2_pred1_temp);
892
0
            u1_temp = CLIP_U8(i2_macro);
893
0
            *pu1_dst = (*pu1_dst + u1_temp + 1) >> 1;
894
0
        }
895
0
        //pi16_pred1_temp += wd;
896
0
        pu1_dst += dst_strd - wd;
897
0
    }
898
0
}
899
900
/**
901
 *******************************************************************************
902
 *  function:ih264_inter_pred_luma_bilinear
903
 *
904
 * @brief
905
 *    This routine applies the bilinear filter to the predictors .
906
 *    The  filtering operation is described in
907
 *    sec 8.4.2.2.1 titled "Luma sample interpolation process"
908
 *
909
 * @par Description:
910
\note
911
 *     This function is called to obtain pixels lying at the following
912
 *    locations (1/4,1), (3/4,1),(1,1/4), (1,3/4) ,(1/4,1/2), (3/4,1/2),(1/2,1/4), (1/2,3/4),(3/4,1/4),(1/4,3/4),(3/4,3/4)&& (1/4,1/4) .
913
 *    The function averages the two adjacent values from the two input arrays in horizontal direction.
914
 *
915
 *
916
 * @param[in] pu1_src1:
917
 *  UWORD8 Pointer to the buffer containing the first input array.
918
 *
919
 * @param[in] pu1_src2:
920
 *  UWORD8 Pointer to the buffer containing the second input array.
921
 *
922
 * @param[out] pu1_dst
923
 *  UWORD8 pointer to the destination where the output of bilinear filter is stored.
924
 *
925
 * @param[in] src_strd1
926
 *  Stride of the first input buffer
927
 *
928
 * @param[in] src_strd2
929
 *  Stride of the second input buffer
930
 *
931
 * @param[in] dst_strd
932
 *  integer destination stride of pu1_dst
933
 *
934
 * @param[in] ht
935
 *  integer height of the array
936
 *
937
 * @param[in] wd
938
 *  integer width of the array
939
 *
940
 * @returns
941
 *
942
 * @remarks
943
 *  None
944
 *
945
 *******************************************************************************
946
 */
947
void ih264_inter_pred_luma_bilinear(UWORD8 *pu1_src1,
948
                                    UWORD8 *pu1_src2,
949
                                    UWORD8 *pu1_dst,
950
                                    WORD32 src_strd1,
951
                                    WORD32 src_strd2,
952
                                    WORD32 dst_strd,
953
                                    WORD32 ht,
954
                                    WORD32 wd)
955
0
{
956
0
    WORD32 row, col;
957
0
    WORD16 i2_tmp;
958
0
959
0
    for(row = 0; row < ht; row++)
960
0
    {
961
0
        for(col = 0; col < wd; col++)
962
0
        {
963
0
            i2_tmp = pu1_src1[col] + pu1_src2[col];
964
0
            i2_tmp = (i2_tmp + 1) >> 1;
965
0
            pu1_dst[col] = CLIP_U8(i2_tmp);
966
0
        }
967
0
        pu1_src1 += src_strd1;
968
0
        pu1_src2 += src_strd2;
969
0
        pu1_dst += dst_strd;
970
0
    }
971
0
972
0
}
973
974
/**
975
 *******************************************************************************
976
 *
977
 * @brief
978
 *    Interprediction chroma filter
979
 *
980
 * @par Description:
981
 *   Applies filtering to chroma samples as mentioned in
982
 *    sec 8.4.2.2.2 titled "chroma sample interpolation process"
983
 *
984
 * @param[in] pu1_src
985
 *  UWORD8 pointer to the source containing alternate U and V samples
986
 *
987
 * @param[out] pu1_dst
988
 *  UWORD8 pointer to the destination
989
 *
990
 * @param[in] src_strd
991
 *  integer source stride
992
 *
993
 * @param[in] dst_strd
994
 *  integer destination stride
995
 *
996
 * @param[in] u1_dx
997
 *  dx value where the sample is to be produced(refer sec 8.4.2.2.2 )
998
 *
999
 * @param[in] u1_dy
1000
 *  dy value where the sample is to be produced(refer sec 8.4.2.2.2 )
1001
 *
1002
 * @param[in] ht
1003
 *  integer height of the array
1004
 *
1005
 * @param[in] wd
1006
 *  integer width of the array
1007
 *
1008
 * @returns
1009
 *
1010
 * @remarks
1011
 *  None
1012
 *
1013
 *******************************************************************************
1014
 */
1015
void ih264_inter_pred_chroma(UWORD8 *pu1_src,
1016
                             UWORD8 *pu1_dst,
1017
                             WORD32 src_strd,
1018
                             WORD32 dst_strd,
1019
                             WORD32 dx,
1020
                             WORD32 dy,
1021
                             WORD32 ht,
1022
                             WORD32 wd)
1023
0
{
1024
0
    WORD32 row, col;
1025
0
    WORD16 i2_tmp;
1026
0
1027
0
    for(row = 0; row < ht; row++)
1028
0
    {
1029
0
        for(col = 0; col < 2 * wd; col++)
1030
0
        {
1031
0
            i2_tmp = 0; /* applies equation (8-266) in section 8.4.2.2.2 */
1032
0
            i2_tmp = (8 - dx) * (8 - dy) * pu1_src[col]
1033
0
                     + (dx) * (8 - dy) * pu1_src[col + 2]
1034
0
                     + (8 - dx) * (dy) * (pu1_src + src_strd)[col]
1035
0
                     + (dx) * (dy) * (pu1_src + src_strd)[col + 2];
1036
0
            i2_tmp = (i2_tmp + 32) >> 6;
1037
0
            pu1_dst[col] = CLIP_U8(i2_tmp);
1038
0
        }
1039
0
        pu1_src += src_strd;
1040
0
        pu1_dst += dst_strd;
1041
0
    }
1042
0
}
/proc/self/cwd/external/libavc/common/ih264_intra_pred_filters.h
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/**
21
 *******************************************************************************
22
 * @file
23
 *  ih264_intra_pred_filters.h
24
 *
25
 * @brief
26
 *  Declarations of functions used for intra prediction
27
 *
28
 * @author
29
 *  Ittiam
30
 *
31
 * @remarks
32
 *  None
33
 *
34
 *******************************************************************************
35
 */
36
37
#ifndef IH264_INTRA_PRED_FILTERS_H_
38
39
#define IH264_INTRA_PRED_FILTERS_H_
40
41
/*****************************************************************************/
42
/*  Macro Expansion                                                          */
43
/*****************************************************************************/
44
45
/*! Filter (1,2,1) i.e (a + 2b + c) / 4 */
46
0
#define FILT121(a,b,c) ((a + (b<<1) + c + 2)>>2)
47
/*! Filter (1,1) i.e (a + b) / 2 */
48
0
#define FILT11(a,b) ((a + b + 1)>>1)
49
/*****************************************************************************/
50
/*  Global Variables                                                        */
51
/*****************************************************************************/
52
53
/* Global variables used only in assembly files*/
54
extern const WORD8  ih264_gai1_intrapred_luma_plane_coeffs[];
55
extern const WORD8  ih264_gai1_intrapred_chroma_plane_coeffs1[];
56
extern const WORD8  ih264_gai1_intrapred_chroma_plane_coeffs2[];
57
extern const WORD8  ih264_gai1_intrapred_luma_8x8_horz_u[];
58
59
/*****************************************************************************/
60
/* Extern Function Declarations                                              */
61
/*****************************************************************************/
62
63
64
typedef void ih264_intra_pred_ref_filtering_ft(UWORD8 *pu1_left,
65
                                               UWORD8 *pu1_topleft,
66
                                               UWORD8 *pu1_top,
67
                                               UWORD8 *pu1_dst,
68
                                               WORD32 left_strd,
69
                                               WORD32 ngbr_avail);
70
71
typedef void ih264_intra_pred_luma_ft(UWORD8 *pu1_src,
72
                                      UWORD8 *pu1_dst,
73
                                      WORD32 src_strd,
74
                                      WORD32 dst_strd,
75
                                      WORD32 ngbr_avail);
76
77
/* No Neon Definitions */
78
79
/* Luma 4x4 Intra pred filters */
80
81
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_vert;
82
83
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_horz;
84
85
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_dc;
86
87
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_diag_dl;
88
89
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_diag_dr;
90
91
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_vert_r;
92
93
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_horz_d;
94
95
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_vert_l;
96
97
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_horz_u;
98
99
/* Luma 8x8 Intra pred filters */
100
101
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_vert;
102
103
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_horz;
104
105
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_dc;
106
107
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_diag_dl;
108
109
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_diag_dr;
110
111
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_vert_r;
112
113
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_horz_d;
114
115
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_vert_l;
116
117
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_horz_u;
118
119
/* Luma 16x16 Intra pred filters */
120
121
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_16x16_mode_vert;
122
123
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_16x16_mode_horz;
124
125
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_16x16_mode_dc;
126
127
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_16x16_mode_plane;
128
129
/* Chroma 8x8 Intra pred filters */
130
131
typedef ih264_intra_pred_luma_ft ih264_intra_pred_chroma_ft;
132
133
ih264_intra_pred_chroma_ft ih264_intra_pred_chroma_8x8_mode_dc;
134
135
ih264_intra_pred_chroma_ft ih264_intra_pred_chroma_8x8_mode_horz;
136
137
ih264_intra_pred_chroma_ft ih264_intra_pred_chroma_8x8_mode_vert;
138
139
ih264_intra_pred_chroma_ft ih264_intra_pred_chroma_8x8_mode_plane;
140
141
142
ih264_intra_pred_ref_filtering_ft  ih264_intra_pred_luma_8x8_mode_ref_filtering;
143
144
/* A9 Definition */
145
146
/* Luma 4x4 Intra pred filters */
147
148
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_vert_a9q;
149
150
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_horz_a9q;
151
152
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_dc_a9q;
153
154
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_diag_dl_a9q;
155
156
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_diag_dr_a9q;
157
158
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_vert_r_a9q;
159
160
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_horz_d_a9q;
161
162
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_vert_l_a9q;
163
164
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_horz_u_a9q;
165
166
/* Luma 8x8 Intra pred filters */
167
168
ih264_intra_pred_ref_filtering_ft  ih264_intra_pred_luma_8x8_mode_ref_filtering_a9q;
169
170
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_vert_a9q;
171
172
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_horz_a9q;
173
174
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_dc_a9q;
175
176
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_diag_dl_a9q;
177
178
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_diag_dr_a9q;
179
180
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_vert_r_a9q;
181
182
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_horz_d_a9q;
183
184
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_vert_l_a9q;
185
186
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_horz_u_a9q;
187
188
/* Luma 16x16 Intra pred filters */
189
190
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_16x16_mode_vert_a9q;
191
192
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_16x16_mode_horz_a9q;
193
194
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_16x16_mode_dc_a9q;
195
196
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_16x16_mode_plane_a9q;
197
198
/* Chroma 8x8 Intra pred filters */
199
200
ih264_intra_pred_chroma_ft ih264_intra_pred_chroma_8x8_mode_dc_a9q;
201
202
ih264_intra_pred_chroma_ft ih264_intra_pred_chroma_8x8_mode_horz_a9q;
203
204
ih264_intra_pred_chroma_ft ih264_intra_pred_chroma_8x8_mode_vert_a9q;
205
206
ih264_intra_pred_chroma_ft ih264_intra_pred_chroma_8x8_mode_plane_a9q;
207
208
/* X86 Intrinsic Definitions */
209
210
/* Luma 4x4 Intra pred filters */
211
212
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_vert_ssse3;
213
214
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_horz_ssse3;
215
216
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_dc_ssse3;
217
218
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_diag_dl_ssse3;
219
220
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_diag_dr_ssse3;
221
222
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_vert_r_ssse3;
223
224
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_horz_d_ssse3;
225
226
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_vert_l_ssse3;
227
228
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_horz_u_ssse3;
229
230
/* Luma 8x8 Intra pred filters */
231
232
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_vert_ssse3;
233
234
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_horz_ssse3;
235
236
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_dc_ssse3;
237
238
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_diag_dl_ssse3;
239
240
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_diag_dr_ssse3;
241
242
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_vert_r_ssse3;
243
244
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_horz_d_ssse3;
245
246
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_vert_l_ssse3;
247
248
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_horz_u_ssse3;
249
250
/* Luma 16x16 Intra pred filters */
251
252
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_16x16_mode_vert_ssse3;
253
254
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_16x16_mode_horz_ssse3;
255
256
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_16x16_mode_dc_ssse3;
257
258
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_16x16_mode_plane_ssse3;
259
260
/* Chroma 8x8 Intra pred filters */
261
262
ih264_intra_pred_chroma_ft ih264_intra_pred_chroma_8x8_mode_dc_ssse3;
263
264
ih264_intra_pred_chroma_ft ih264_intra_pred_chroma_8x8_mode_horz_ssse3;
265
266
ih264_intra_pred_chroma_ft ih264_intra_pred_chroma_8x8_mode_vert_ssse3;
267
268
ih264_intra_pred_chroma_ft ih264_intra_pred_chroma_8x8_mode_plane_ssse3;
269
270
/* AV8 Definition */
271
272
/* Luma 4x4 Intra pred filters */
273
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_vert_av8;
274
275
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_horz_av8;
276
277
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_dc_av8;
278
279
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_diag_dl_av8;
280
281
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_diag_dr_av8;
282
283
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_vert_r_av8;
284
285
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_horz_d_av8;
286
287
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_vert_l_av8;
288
289
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_4x4_mode_horz_u_av8;
290
291
/* Luma 8x8 Intra pred filters */
292
293
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_vert_av8;
294
295
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_horz_av8;
296
297
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_dc_av8;
298
299
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_diag_dl_av8;
300
301
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_diag_dr_av8;
302
303
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_vert_r_av8;
304
305
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_horz_d_av8;
306
307
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_vert_l_av8;
308
309
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_8x8_mode_horz_u_av8;
310
311
/* Luma 16x16 Intra pred filters */
312
313
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_16x16_mode_vert_av8;
314
315
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_16x16_mode_horz_av8;
316
317
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_16x16_mode_dc_av8;
318
319
ih264_intra_pred_luma_ft  ih264_intra_pred_luma_16x16_mode_plane_av8;
320
321
/* Chroma 8x8 Intra pred filters */
322
323
ih264_intra_pred_chroma_ft ih264_intra_pred_chroma_8x8_mode_dc_av8;
324
325
ih264_intra_pred_chroma_ft ih264_intra_pred_chroma_8x8_mode_horz_av8;
326
327
ih264_intra_pred_chroma_ft ih264_intra_pred_chroma_8x8_mode_vert_av8;
328
329
ih264_intra_pred_chroma_ft ih264_intra_pred_chroma_8x8_mode_plane_av8;
330
331
#endif /* IH264_INTRA_PRED_FILTERS_H_ */
/proc/self/cwd/external/libavc/common/ih264_iquant_itrans_recon.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/**
21
 *******************************************************************************
22
 * @file
23
 *  ih264_iquant_itrans_recon.c
24
 *
25
 * @brief
26
 *  Contains definition of functions for h264 inverse quantization inverse transformation and recon
27
 *
28
 * @author
29
 *  Ittiam
30
 *
31
 *  @par List of Functions:
32
 *  - ih264_iquant_itrans_recon_4x4()
33
 *  - ih264_iquant_itrans_recon_8x8()
34
 *  - ih264_iquant_itrans_recon_4x4_dc()
35
 *  - ih264_iquant_itrans_recon_8x8_dc()
36
 *  - ih264_iquant_itrans_recon_chroma_4x4()
37
 *  -ih264_iquant_itrans_recon_chroma_4x4_dc()
38
 *
39
 * @remarks
40
 *
41
 *******************************************************************************
42
 */
43
44
/*****************************************************************************/
45
/* File Includes                                                             */
46
/*****************************************************************************/
47
48
/* User include files */
49
#include "ih264_typedefs.h"
50
#include "ih264_defs.h"
51
#include "ih264_trans_macros.h"
52
#include "ih264_macros.h"
53
#include "ih264_platform_macros.h"
54
#include "ih264_trans_data.h"
55
#include "ih264_size_defs.h"
56
#include "ih264_structs.h"
57
#include "ih264_trans_quant_itrans_iquant.h"
58
59
/*
60
 ********************************************************************************
61
 *
62
 * @brief This function reconstructs a 4x4 sub block from quantized resiude and
63
 * prediction buffer
64
 *
65
 * @par Description:
66
 *  The quantized residue is first inverse quantized, then inverse transformed.
67
 *  This inverse transformed content is added to the prediction buffer to recon-
68
 *  struct the end output
69
 *
70
 * @param[in] pi2_src
71
 *  quantized 4x4 block
72
 *
73
 * @param[in] pu1_pred
74
 *  prediction 4x4 block
75
 *
76
 * @param[out] pu1_out
77
 *  reconstructed 4x4 block
78
 *
79
 * @param[in] src_strd
80
 *  quantization buffer stride
81
 *
82
 * @param[in] pred_strd,
83
 *  Prediction buffer stride
84
 *
85
 * @param[in] out_strd
86
 *  recon buffer Stride
87
 *
88
 * @param[in] pu2_scaling_list
89
 *  pointer to scaling list
90
 *
91
 * @param[in] pu2_norm_adjust
92
 *  pointer to inverse scale matrix
93
 *
94
 * @param[in] u4_qp_div_6
95
 *  Floor (qp/6)
96
 *
97
 * @param[in] pi4_tmp
98
 * temporary buffer of size 1*16
99
 *
100
 * @returns none
101
 *
102
 * @remarks none
103
 *
104
 *******************************************************************************
105
 */
106
void ih264_iquant_itrans_recon_4x4(WORD16 *pi2_src,
107
                                   UWORD8 *pu1_pred,
108
                                   UWORD8 *pu1_out,
109
                                   WORD32 pred_strd,
110
                                   WORD32 out_strd,
111
                                   const UWORD16 *pu2_iscal_mat,
112
                                   const UWORD16 *pu2_weigh_mat,
113
                                   UWORD32 u4_qp_div_6,
114
                                   WORD16 *pi2_tmp,
115
                                   WORD32 iq_start_idx,
116
                                   WORD16 *pi2_dc_ld_addr
117
)
118
0
{
119
0
    WORD16 *pi2_src_ptr = pi2_src;
120
0
    WORD16 *pi2_tmp_ptr = pi2_tmp;
121
0
    UWORD8 *pu1_pred_ptr = pu1_pred;
122
0
    UWORD8 *pu1_out_ptr = pu1_out;
123
0
    WORD16 x0, x1, x2, x3, i;
124
0
    WORD32 q0, q1, q2, q3;
125
0
    WORD16 i_macro;
126
0
    WORD16 rnd_fact = (u4_qp_div_6 < 4) ? 1 << (3 - u4_qp_div_6) : 0;
127
0
128
0
    /* inverse quant */
129
0
    /*horizontal inverse transform */
130
0
    for(i = 0; i < SUB_BLK_WIDTH_4x4; i++)
131
0
    {
132
0
        q0 = pi2_src_ptr[0];
133
0
        INV_QUANT(q0, pu2_iscal_mat[0], pu2_weigh_mat[0], u4_qp_div_6, rnd_fact,
134
0
                  4);
135
0
        if (i==0 && iq_start_idx == 1)
136
0
            q0 = pi2_dc_ld_addr[0];     // Restoring dc value for intra case
137
0
138
0
        q2 = pi2_src_ptr[2];
139
0
        INV_QUANT(q2, pu2_iscal_mat[2], pu2_weigh_mat[2], u4_qp_div_6, rnd_fact,
140
0
                  4);
141
0
142
0
        x0 = q0 + q2;
143
0
        x1 = q0 - q2;
144
0
145
0
        q1 = pi2_src_ptr[1];
146
0
        INV_QUANT(q1, pu2_iscal_mat[1], pu2_weigh_mat[1], u4_qp_div_6, rnd_fact,
147
0
                  4);
148
0
149
0
        q3 = pi2_src_ptr[3];
150
0
        INV_QUANT(q3, pu2_iscal_mat[3], pu2_weigh_mat[3], u4_qp_div_6, rnd_fact,
151
0
                  4);
152
0
153
0
        x2 = (q1 >> 1) - q3;
154
0
        x3 = q1 + (q3 >> 1);
155
0
156
0
        pi2_tmp_ptr[0] = x0 + x3;
157
0
        pi2_tmp_ptr[1] = x1 + x2;
158
0
        pi2_tmp_ptr[2] = x1 - x2;
159
0
        pi2_tmp_ptr[3] = x0 - x3;
160
0
161
0
        pi2_src_ptr += SUB_BLK_WIDTH_4x4;
162
0
        pi2_tmp_ptr += SUB_BLK_WIDTH_4x4;
163
0
        pu2_iscal_mat += SUB_BLK_WIDTH_4x4;
164
0
        pu2_weigh_mat += SUB_BLK_WIDTH_4x4;
165
0
    }
166
0
167
0
    /* vertical inverse transform */
168
0
    pi2_tmp_ptr = pi2_tmp;
169
0
    for(i = 0; i < SUB_BLK_WIDTH_4x4; i++)
170
0
    {
171
0
        pu1_pred_ptr = pu1_pred;
172
0
        pu1_out = pu1_out_ptr;
173
0
174
0
        x0 = (pi2_tmp_ptr[0] + pi2_tmp_ptr[8]);
175
0
        x1 = (pi2_tmp_ptr[0] - pi2_tmp_ptr[8]);
176
0
        x2 = (pi2_tmp_ptr[4] >> 1) - pi2_tmp_ptr[12];
177
0
        x3 = pi2_tmp_ptr[4] + (pi2_tmp_ptr[12] >> 1);
178
0
179
0
        /* inverse prediction */
180
0
        i_macro = x0 + x3;
181
0
        i_macro = ((i_macro + 32) >> 6);
182
0
        i_macro += *pu1_pred_ptr;
183
0
        *pu1_out = CLIP_U8(i_macro);
184
0
        pu1_pred_ptr += pred_strd;
185
0
        pu1_out += out_strd;
186
0
187
0
        i_macro = x1 + x2;
188
0
        i_macro = ((i_macro + 32) >> 6);
189
0
        i_macro += *pu1_pred_ptr;
190
0
        *pu1_out = CLIP_U8(i_macro);
191
0
        pu1_pred_ptr += pred_strd;
192
0
        pu1_out += out_strd;
193
0
194
0
        i_macro = x1 - x2;
195
0
        i_macro = ((i_macro + 32) >> 6);
196
0
        i_macro += *pu1_pred_ptr;
197
0
        *pu1_out = CLIP_U8(i_macro);
198
0
        pu1_pred_ptr += pred_strd;
199
0
        pu1_out += out_strd;
200
0
201
0
        i_macro = x0 - x3;
202
0
        i_macro = ((i_macro + 32) >> 6);
203
0
        i_macro += *pu1_pred_ptr;
204
0
        *pu1_out = CLIP_U8(i_macro);
205
0
206
0
        pi2_tmp_ptr++;
207
0
        pu1_out_ptr++;
208
0
        pu1_pred++;
209
0
    }
210
0
211
0
}
212
213
void ih264_iquant_itrans_recon_4x4_dc(WORD16 *pi2_src,
214
                                      UWORD8 *pu1_pred,
215
                                      UWORD8 *pu1_out,
216
                                      WORD32 pred_strd,
217
                                      WORD32 out_strd,
218
                                      const UWORD16 *pu2_iscal_mat,
219
                                      const UWORD16 *pu2_weigh_mat,
220
                                      UWORD32 u4_qp_div_6,
221
                                      WORD16 *pi2_tmp,
222
                                      WORD32 iq_start_idx,
223
                                      WORD16 *pi2_dc_ld_addr)
224
0
{
225
0
    UWORD8 *pu1_pred_ptr = pu1_pred;
226
0
    UWORD8 *pu1_out_ptr = pu1_out;
227
0
    WORD32 q0;
228
0
    WORD16 x, i_macro, i;
229
0
    WORD16 rnd_fact = (u4_qp_div_6 < 4) ? 1 << (3 - u4_qp_div_6) : 0;
230
0
    UNUSED(pi2_tmp);
231
0
232
0
    if (iq_start_idx == 0)
233
0
    {
234
0
      q0 = pi2_src[0];
235
0
      INV_QUANT(q0, pu2_iscal_mat[0], pu2_weigh_mat[0], u4_qp_div_6, rnd_fact, 4);
236
0
    }
237
0
    else
238
0
    {
239
0
      q0 = pi2_dc_ld_addr[0];    // Restoring dc value for intra case3
240
0
    }
241
0
    i_macro = ((q0 + 32) >> 6);
242
0
    for(i = 0; i < SUB_BLK_WIDTH_4x4; i++)
243
0
    {
244
0
        pu1_pred_ptr = pu1_pred;
245
0
        pu1_out = pu1_out_ptr;
246
0
247
0
        /* inverse prediction */
248
0
249
0
        x = i_macro + *pu1_pred_ptr;
250
0
        *pu1_out = CLIP_U8(x);
251
0
        pu1_pred_ptr += pred_strd;
252
0
        pu1_out += out_strd;
253
0
254
0
        x = i_macro + *pu1_pred_ptr;
255
0
        *pu1_out = CLIP_U8(x);
256
0
        pu1_pred_ptr += pred_strd;
257
0
        pu1_out += out_strd;
258
0
259
0
        x = i_macro + *pu1_pred_ptr;
260
0
        *pu1_out = CLIP_U8(x);
261
0
        pu1_pred_ptr += pred_strd;
262
0
        pu1_out += out_strd;
263
0
264
0
        x = i_macro + *pu1_pred_ptr;
265
0
        *pu1_out = CLIP_U8(x);
266
0
267
0
        pu1_out_ptr++;
268
0
        pu1_pred++;
269
0
    }
270
0
}
271
272
/**
273
 *******************************************************************************
274
 *
275
 * @brief
276
 *  This function performs inverse quant and Inverse transform type Ci4 for 8x8 block
277
 *
278
 * @par Description:
279
 *  Performs inverse transform Ci8 and adds the residue to get the
280
 *  reconstructed block
281
 *
282
 * @param[in] pi2_src
283
 *  Input 8x8coefficients
284
 *
285
 * @param[in] pu1_pred
286
 *  Prediction 8x8 block
287
 *
288
 * @param[out] pu1_recon
289
 *  Output 8x8 block
290
 *
291
 * @param[in] q_div
292
 *  QP/6
293
 *
294
 * @param[in] q_rem
295
 *  QP%6
296
 *
297
 * @param[in] q_lev
298
 *  Quantizer level
299
 *
300
 * @param[in] src_strd
301
 *  Input stride
302
 *
303
 * @param[in] pred_strd,
304
 *  Prediction stride
305
 *
306
 * @param[in] out_strd
307
 *  Output Stride
308
 *
309
 * @param[in] pi4_tmp
310
 *  temporary buffer of size 1*16 we dont need a bigger blcok since we reuse
311
 *  the tmp for each block
312
 *
313
 * @param[in] pu4_iquant_mat
314
 *  Pointer to the inverse quantization matrix
315
 *
316
 * @returns  Void
317
 *
318
 * @remarks
319
 *  None
320
 *
321
 *******************************************************************************
322
 */
323
void ih264_iquant_itrans_recon_8x8(WORD16 *pi2_src,
324
                                   UWORD8 *pu1_pred,
325
                                   UWORD8 *pu1_out,
326
                                   WORD32 pred_strd,
327
                                   WORD32 out_strd,
328
                                   const UWORD16 *pu2_iscale_mat,
329
                                   const UWORD16 *pu2_weigh_mat,
330
                                   UWORD32 qp_div,
331
                                   WORD16 *pi2_tmp,
332
                                   WORD32 iq_start_idx,
333
                                   WORD16 *pi2_dc_ld_addr
334
)
335
0
{
336
0
    WORD32 i;
337
0
    WORD16 *pi2_tmp_ptr = pi2_tmp;
338
0
    UWORD8 *pu1_pred_ptr = pu1_pred;
339
0
    UWORD8 *pu1_out_ptr = pu1_out;
340
0
    WORD16 i_z0, i_z1, i_z2, i_z3, i_z4, i_z5, i_z6, i_z7;
341
0
    WORD16 i_y0, i_y1, i_y2, i_y3, i_y4, i_y5, i_y6, i_y7;
342
0
    WORD16 i_macro;
343
0
    WORD32 q;
344
0
    WORD32 rnd_fact = (qp_div < 6) ? (1 << (5 - qp_div)) : 0;
345
0
    UNUSED(iq_start_idx);
346
0
    UNUSED(pi2_dc_ld_addr);
347
0
    /*************************************************************/
348
0
    /* De quantization of coefficients. Will be replaced by SIMD */
349
0
    /* operations on platform. Note : DC coeff is not scaled     */
350
0
    /*************************************************************/
351
0
    for(i = 0; i < (SUB_BLK_WIDTH_8x8 * SUB_BLK_WIDTH_8x8); i++)
352
0
    {
353
0
        q = pi2_src[i];
354
0
        INV_QUANT(q, pu2_iscale_mat[i], pu2_weigh_mat[i], qp_div, rnd_fact, 6);
355
0
        pi2_tmp_ptr[i] = q;
356
0
    }
357
0
    /* Perform Inverse transform */
358
0
    /*--------------------------------------------------------------------*/
359
0
    /* IDCT [ Horizontal transformation ]                                 */
360
0
    /*--------------------------------------------------------------------*/
361
0
    for(i = 0; i < SUB_BLK_WIDTH_8x8; i++)
362
0
    {
363
0
        /*------------------------------------------------------------------*/
364
0
        /* y0 = w0 + w4                                                     */
365
0
        /* y1 = -w3 + w5 - w7 - (w7 >> 1)                                   */
366
0
        /* y2 = w0 - w4                                                     */
367
0
        /* y3 = w1 + w7 - w3 - (w3 >> 1)                                    */
368
0
        /* y4 = (w2 >> 1) - w6                                              */
369
0
        /* y5 = -w1 + w7 + w5 + (w5 >> 1)                                   */
370
0
        /* y6 = w2 + (w6 >> 1)                                              */
371
0
        /* y7 = w3 + w5 + w1 + (w1 >> 1)                                    */
372
0
        /*------------------------------------------------------------------*/
373
0
        i_y0 = (pi2_tmp_ptr[0] + pi2_tmp_ptr[4] );
374
0
375
0
        i_y1 = ((WORD32)(-pi2_tmp_ptr[3]) + pi2_tmp_ptr[5] - pi2_tmp_ptr[7]
376
0
                        - (pi2_tmp_ptr[7] >> 1));
377
0
378
0
        i_y2 = (pi2_tmp_ptr[0] - pi2_tmp_ptr[4] );
379
0
380
0
        i_y3 = ((WORD32)pi2_tmp_ptr[1] + pi2_tmp_ptr[7] - pi2_tmp_ptr[3]
381
0
                        - (pi2_tmp_ptr[3] >> 1));
382
0
383
0
        i_y4 = ((pi2_tmp_ptr[2] >> 1) - pi2_tmp_ptr[6] );
384
0
385
0
        i_y5 = ((WORD32)(-pi2_tmp_ptr[1]) + pi2_tmp_ptr[7] + pi2_tmp_ptr[5]
386
0
                        + (pi2_tmp_ptr[5] >> 1));
387
0
388
0
        i_y6 = (pi2_tmp_ptr[2] + (pi2_tmp_ptr[6] >> 1));
389
0
390
0
        i_y7 = ((WORD32)pi2_tmp_ptr[3] + pi2_tmp_ptr[5] + pi2_tmp_ptr[1]
391
0
                        + (pi2_tmp_ptr[1] >> 1));
392
0
393
0
        /*------------------------------------------------------------------*/
394
0
        /* z0 = y0 + y6                                                     */
395
0
        /* z1 = y1 + (y7 >> 2)                                              */
396
0
        /* z2 = y2 + y4                                                     */
397
0
        /* z3 = y3 + (y5 >> 2)                                              */
398
0
        /* z4 = y2 - y4                                                     */
399
0
        /* z5 = (y3 >> 2) - y5                                              */
400
0
        /* z6 = y0 - y6                                                     */
401
0
        /* z7 = y7 - (y1 >> 2)                                              */
402
0
        /*------------------------------------------------------------------*/
403
0
        i_z0 = i_y0 + i_y6;
404
0
        i_z1 = i_y1 + (i_y7 >> 2);
405
0
        i_z2 = i_y2 + i_y4;
406
0
        i_z3 = i_y3 + (i_y5 >> 2);
407
0
        i_z4 = i_y2 - i_y4;
408
0
        i_z5 = (i_y3 >> 2) - i_y5;
409
0
        i_z6 = i_y0 - i_y6;
410
0
        i_z7 = i_y7 - (i_y1 >> 2);
411
0
412
0
        /*------------------------------------------------------------------*/
413
0
        /* x0 = z0 + z7                                                     */
414
0
        /* x1 = z2 + z5                                                     */
415
0
        /* x2 = z4 + z3                                                     */
416
0
        /* x3 = z6 + z1                                                     */
417
0
        /* x4 = z6 - z1                                                     */
418
0
        /* x5 = z4 - z3                                                     */
419
0
        /* x6 = z2 - z5                                                     */
420
0
        /* x7 = z0 - z7                                                     */
421
0
        /*------------------------------------------------------------------*/
422
0
        pi2_tmp_ptr[0] = i_z0 + i_z7;
423
0
        pi2_tmp_ptr[1] = i_z2 + i_z5;
424
0
        pi2_tmp_ptr[2] = i_z4 + i_z3;
425
0
        pi2_tmp_ptr[3] = i_z6 + i_z1;
426
0
        pi2_tmp_ptr[4] = i_z6 - i_z1;
427
0
        pi2_tmp_ptr[5] = i_z4 - i_z3;
428
0
        pi2_tmp_ptr[6] = i_z2 - i_z5;
429
0
        pi2_tmp_ptr[7] = i_z0 - i_z7;
430
0
431
0
        /* move to the next row */
432
0
        //pi2_src_ptr += SUB_BLK_WIDTH_8x8;
433
0
        pi2_tmp_ptr += SUB_BLK_WIDTH_8x8;
434
0
    }
435
0
    /*--------------------------------------------------------------------*/
436
0
    /* IDCT [ Vertical transformation] and Xij = (xij + 32)>>6            */
437
0
    /*                                                                    */
438
0
    /* Add the prediction and store it back to reconstructed frame buffer */
439
0
    /* [Prediction buffer itself in this case]                            */
440
0
    /*--------------------------------------------------------------------*/
441
0
442
0
    pi2_tmp_ptr = pi2_tmp;
443
0
    for(i = 0; i < SUB_BLK_WIDTH_8x8; i++)
444
0
    {
445
0
        pu1_pred_ptr = pu1_pred;
446
0
        pu1_out = pu1_out_ptr;
447
0
        /*------------------------------------------------------------------*/
448
0
        /* y0j = w0j + w4j                                                  */
449
0
        /* y1j = -w3j + w5j -w7j -(w7j >> 1)                                */
450
0
        /* y2j = w0j -w4j                                                   */
451
0
        /* y3j = w1j + w7j -w3j -(w3j >> 1)                                 */
452
0
        /* y4j = ( w2j >> 1 ) -w6j                                          */
453
0
        /* y5j = -w1j + w7j + w5j + (w5j >> 1)                              */
454
0
        /* y6j = w2j + ( w6j >> 1 )                                         */
455
0
        /* y7j = w3j + w5j + w1j + (w1j >> 1)                               */
456
0
        /*------------------------------------------------------------------*/
457
0
        i_y0 = pi2_tmp_ptr[0] + pi2_tmp_ptr[32];
458
0
459
0
        i_y1 = (WORD32)(-pi2_tmp_ptr[24]) + pi2_tmp_ptr[40] - pi2_tmp_ptr[56]
460
0
                        - (pi2_tmp_ptr[56] >> 1);
461
0
462
0
        i_y2 = pi2_tmp_ptr[0] - pi2_tmp_ptr[32];
463
0
464
0
        i_y3 = (WORD32)pi2_tmp_ptr[8] + pi2_tmp_ptr[56] - pi2_tmp_ptr[24]
465
0
                        - (pi2_tmp_ptr[24] >> 1);
466
0
467
0
        i_y4 = (pi2_tmp_ptr[16] >> 1) - pi2_tmp_ptr[48];
468
0
469
0
        i_y5 = (WORD32)(-pi2_tmp_ptr[8]) + pi2_tmp_ptr[56] + pi2_tmp_ptr[40]
470
0
                        + (pi2_tmp_ptr[40] >> 1);
471
0
472
0
        i_y6 = pi2_tmp_ptr[16] + (pi2_tmp_ptr[48] >> 1);
473
0
474
0
        i_y7 = (WORD32)pi2_tmp_ptr[24] + pi2_tmp_ptr[40] + pi2_tmp_ptr[8]
475
0
                        + (pi2_tmp_ptr[8] >> 1);
476
0
477
0
        /*------------------------------------------------------------------*/
478
0
        /* z0j = y0j + y6j                                                  */
479
0
        /* z1j = y1j + (y7j >> 2)                                           */
480
0
        /* z2j = y2j + y4j                                                  */
481
0
        /* z3j = y3j + (y5j >> 2)                                           */
482
0
        /* z4j = y2j -y4j                                                   */
483
0
        /* z5j = (y3j >> 2) -y5j                                            */
484
0
        /* z6j = y0j -y6j                                                   */
485
0
        /* z7j = y7j -(y1j >> 2)                                            */
486
0
        /*------------------------------------------------------------------*/
487
0
        i_z0 = i_y0 + i_y6;
488
0
        i_z1 = i_y1 + (i_y7 >> 2);
489
0
        i_z2 = i_y2 + i_y4;
490
0
        i_z3 = i_y3 + (i_y5 >> 2);
491
0
        i_z4 = i_y2 - i_y4;
492
0
        i_z5 = (i_y3 >> 2) - i_y5;
493
0
        i_z6 = i_y0 - i_y6;
494
0
        i_z7 = i_y7 - (i_y1 >> 2);
495
0
496
0
        /*------------------------------------------------------------------*/
497
0
        /* x0j = z0j + z7j                                                  */
498
0
        /* x1j = z2j + z5j                                                  */
499
0
        /* x2j = z4j + z3j                                                  */
500
0
        /* x3j = z6j + z1j                                                  */
501
0
        /* x4j = z6j -z1j                                                   */
502
0
        /* x5j = z4j -z3j                                                   */
503
0
        /* x6j = z2j -z5j                                                   */
504
0
        /* x7j = z0j -z7j                                                   */
505
0
        /*------------------------------------------------------------------*/
506
0
        i_macro = ((i_z0 + i_z7 + 32) >> 6) + *pu1_pred_ptr;
507
0
        *pu1_out = CLIP_U8(i_macro);
508
0
        /* Change uc_recBuffer to Point to next element in the same column*/
509
0
        pu1_pred_ptr += pred_strd;
510
0
        pu1_out += out_strd;
511
0
512
0
        i_macro = ((i_z2 + i_z5 + 32) >> 6) + *pu1_pred_ptr;
513
0
        *pu1_out = CLIP_U8(i_macro);
514
0
        pu1_pred_ptr += pred_strd;
515
0
        pu1_out += out_strd;
516
0
517
0
        i_macro = ((i_z4 + i_z3 + 32) >> 6) + *pu1_pred_ptr;
518
0
        *pu1_out = CLIP_U8(i_macro);
519
0
        pu1_pred_ptr += pred_strd;
520
0
        pu1_out += out_strd;
521
0
522
0
        i_macro = ((i_z6 + i_z1 + 32) >> 6) + *pu1_pred_ptr;
523
0
        *pu1_out = CLIP_U8(i_macro);
524
0
        pu1_pred_ptr += pred_strd;
525
0
        pu1_out += out_strd;
526
0
527
0
        i_macro = ((i_z6 - i_z1 + 32) >> 6) + *pu1_pred_ptr;
528
0
        *pu1_out = CLIP_U8(i_macro);
529
0
        pu1_pred_ptr += pred_strd;
530
0
        pu1_out += out_strd;
531
0
532
0
        i_macro = ((i_z4 - i_z3 + 32) >> 6) + *pu1_pred_ptr;
533
0
        *pu1_out = CLIP_U8(i_macro);
534
0
        pu1_pred_ptr += pred_strd;
535
0
        pu1_out += out_strd;
536
0
537
0
        i_macro = ((i_z2 - i_z5 + 32) >> 6) + *pu1_pred_ptr;
538
0
        *pu1_out = CLIP_U8(i_macro);
539
0
        pu1_pred_ptr += pred_strd;
540
0
        pu1_out += out_strd;
541
0
542
0
        i_macro = ((i_z0 - i_z7 + 32) >> 6) + *pu1_pred_ptr;
543
0
        *pu1_out = CLIP_U8(i_macro);
544
0
545
0
        pi2_tmp_ptr++;
546
0
        pu1_out_ptr++;
547
0
        pu1_pred++;
548
0
    }
549
0
}
550
551
void ih264_iquant_itrans_recon_8x8_dc(WORD16 *pi2_src,
552
                                      UWORD8 *pu1_pred,
553
                                      UWORD8 *pu1_out,
554
                                      WORD32 pred_strd,
555
                                      WORD32 out_strd,
556
                                      const UWORD16 *pu2_iscale_mat,
557
                                      const UWORD16 *pu2_weigh_mat,
558
                                      UWORD32 qp_div,
559
                                      WORD16 *pi2_tmp,
560
                                      WORD32 iq_start_idx,
561
                                      WORD16 *pi2_dc_ld_addr)
562
0
{
563
0
    UWORD8 *pu1_pred_ptr = pu1_pred;
564
0
    UWORD8 *pu1_out_ptr = pu1_out;
565
0
    WORD16 x, i, i_macro;
566
0
    WORD32 q;
567
0
    WORD32 rnd_fact = (qp_div < 6) ? (1 << (5 - qp_div)) : 0;
568
0
    UNUSED(pi2_tmp);
569
0
    UNUSED(iq_start_idx);
570
0
    UNUSED(pi2_dc_ld_addr);
571
0
    /*************************************************************/
572
0
    /* Dequantization of coefficients. Will be replaced by SIMD  */
573
0
    /* operations on platform. Note : DC coeff is not scaled     */
574
0
    /*************************************************************/
575
0
    q = pi2_src[0];
576
0
    INV_QUANT(q, pu2_iscale_mat[0], pu2_weigh_mat[0], qp_div, rnd_fact, 6);
577
0
    i_macro = (q + 32) >> 6;
578
0
    /* Perform Inverse transform */
579
0
    /*--------------------------------------------------------------------*/
580
0
    /* IDCT [ Horizontal transformation ]                                 */
581
0
    /*--------------------------------------------------------------------*/
582
0
    /*--------------------------------------------------------------------*/
583
0
    /* IDCT [ Vertical transformation] and Xij = (xij + 32)>>6            */
584
0
    /*                                                                    */
585
0
    /* Add the prediction and store it back to reconstructed frame buffer */
586
0
    /* [Prediction buffer itself in this case]                            */
587
0
    /*--------------------------------------------------------------------*/
588
0
    for(i = 0; i < SUB_BLK_WIDTH_8x8; i++)
589
0
    {
590
0
        pu1_pred_ptr = pu1_pred;
591
0
        pu1_out = pu1_out_ptr;
592
0
593
0
        x = i_macro + *pu1_pred_ptr;
594
0
        *pu1_out = CLIP_U8(x);
595
0
        /* Change uc_recBuffer to Point to next element in the same column*/
596
0
        pu1_pred_ptr += pred_strd;
597
0
        pu1_out += out_strd;
598
0
599
0
        x = i_macro + *pu1_pred_ptr;
600
0
        *pu1_out = CLIP_U8(x);
601
0
        pu1_pred_ptr += pred_strd;
602
0
        pu1_out += out_strd;
603
0
604
0
        x = i_macro + *pu1_pred_ptr;
605
0
        *pu1_out = CLIP_U8(x);
606
0
        pu1_pred_ptr += pred_strd;
607
0
        pu1_out += out_strd;
608
0
609
0
        x = i_macro + *pu1_pred_ptr;
610
0
        *pu1_out = CLIP_U8(x);
611
0
        pu1_pred_ptr += pred_strd;
612
0
        pu1_out += out_strd;
613
0
614
0
        x = i_macro + *pu1_pred_ptr;
615
0
        *pu1_out = CLIP_U8(x);
616
0
        pu1_pred_ptr += pred_strd;
617
0
        pu1_out += out_strd;
618
0
619
0
        x = i_macro + *pu1_pred_ptr;
620
0
        *pu1_out = CLIP_U8(x);
621
0
        pu1_pred_ptr += pred_strd;
622
0
        pu1_out += out_strd;
623
0
624
0
        x = i_macro + *pu1_pred_ptr;
625
0
        *pu1_out = CLIP_U8(x);
626
0
        pu1_pred_ptr += pred_strd;
627
0
        pu1_out += out_strd;
628
0
629
0
        x = i_macro + *pu1_pred_ptr;
630
0
        *pu1_out = CLIP_U8(x);
631
0
632
0
        pu1_out_ptr++;
633
0
        pu1_pred++;
634
0
    }
635
0
}
636
637
/*
638
 ********************************************************************************
639
 *
640
 * @brief This function reconstructs a 4x4 sub block from quantized resiude and
641
 * prediction buffer
642
 *
643
 * @par Description:
644
 *  The quantized residue is first inverse quantized, then inverse transformed.
645
 *  This inverse transformed content is added to the prediction buffer to recon-
646
 *  struct the end output
647
 *
648
 * @param[in] pi2_src
649
 *  quantized 4x4 block
650
 *
651
 * @param[in] pu1_pred
652
 *  prediction 4x4 block
653
 *
654
 * @param[out] pu1_out
655
 *  reconstructed 4x4 block
656
 *
657
 * @param[in] src_strd
658
 *  quantization buffer stride
659
 *
660
 * @param[in] pred_strd,
661
 *  Prediction buffer stride
662
 *
663
 * @param[in] out_strd
664
 *  recon buffer Stride
665
 *
666
 * @param[in] pu2_scaling_list
667
 *  pointer to scaling list
668
 *
669
 * @param[in] pu2_norm_adjust
670
 *  pointer to inverse scale matrix
671
 *
672
 * @param[in] u4_qp_div_6
673
 *  Floor (qp/6)
674
 *
675
 * @param[in] pi4_tmp
676
 * temporary buffer of size 1*16
677
 *
678
 * @returns none
679
 *
680
 * @remarks none
681
 *
682
 *******************************************************************************
683
 */
684
void ih264_iquant_itrans_recon_chroma_4x4(WORD16 *pi2_src,
685
                                          UWORD8 *pu1_pred,
686
                                          UWORD8 *pu1_out,
687
                                          WORD32 pred_strd,
688
                                          WORD32 out_strd,
689
                                          const UWORD16 *pu2_iscal_mat,
690
                                          const UWORD16 *pu2_weigh_mat,
691
                                          UWORD32 u4_qp_div_6,
692
                                          WORD16 *pi2_tmp,
693
                                          WORD16 *pi2_dc_src)
694
0
{
695
0
    WORD16 *pi2_src_ptr = pi2_src;
696
0
    WORD16 *pi2_tmp_ptr = pi2_tmp;
697
0
    UWORD8 *pu1_pred_ptr = pu1_pred;
698
0
    UWORD8 *pu1_out_ptr = pu1_out;
699
0
    WORD16 x0, x1, x2, x3, i;
700
0
    WORD32 q0, q1, q2, q3;
701
0
    WORD16 i_macro;
702
0
    WORD16 rnd_fact = (u4_qp_div_6 < 4) ? 1 << (3 - u4_qp_div_6) : 0;
703
0
704
0
    /* inverse quant */
705
0
    /*horizontal inverse transform */
706
0
    for(i = 0; i < SUB_BLK_WIDTH_4x4; i++)
707
0
    {
708
0
      if(i==0)
709
0
      {
710
0
        q0 = pi2_dc_src[0];
711
0
      }
712
0
      else
713
0
      {
714
0
        q0 = pi2_src_ptr[0];
715
0
        INV_QUANT(q0, pu2_iscal_mat[0], pu2_weigh_mat[0], u4_qp_div_6, rnd_fact, 4);
716
0
      }
717
0
718
0
      q2 = pi2_src_ptr[2];
719
0
      INV_QUANT(q2, pu2_iscal_mat[2], pu2_weigh_mat[2], u4_qp_div_6, rnd_fact,
720
0
                4);
721
0
722
0
      x0 = q0 + q2;
723
0
      x1 = q0 - q2;
724
0
725
0
      q1 = pi2_src_ptr[1];
726
0
      INV_QUANT(q1, pu2_iscal_mat[1], pu2_weigh_mat[1], u4_qp_div_6, rnd_fact,
727
0
                4);
728
0
729
0
      q3 = pi2_src_ptr[3];
730
0
      INV_QUANT(q3, pu2_iscal_mat[3], pu2_weigh_mat[3], u4_qp_div_6, rnd_fact,
731
0
                4);
732
0
733
0
      x2 = (q1 >> 1) - q3;
734
0
      x3 = q1 + (q3 >> 1);
735
0
736
0
      pi2_tmp_ptr[0] = x0 + x3;
737
0
      pi2_tmp_ptr[1] = x1 + x2;
738
0
      pi2_tmp_ptr[2] = x1 - x2;
739
0
      pi2_tmp_ptr[3] = x0 - x3;
740
0
741
0
      pi2_src_ptr += SUB_BLK_WIDTH_4x4;
742
0
      pi2_tmp_ptr += SUB_BLK_WIDTH_4x4;
743
0
      pu2_iscal_mat += SUB_BLK_WIDTH_4x4;
744
0
      pu2_weigh_mat += SUB_BLK_WIDTH_4x4;
745
0
    }
746
0
747
0
    /* vertical inverse transform */
748
0
    pi2_tmp_ptr = pi2_tmp;
749
0
    for(i = 0; i < SUB_BLK_WIDTH_4x4; i++)
750
0
    {
751
0
        pu1_pred_ptr = pu1_pred;
752
0
        pu1_out = pu1_out_ptr;
753
0
754
0
        x0 = (pi2_tmp_ptr[0] + pi2_tmp_ptr[8]);
755
0
        x1 = (pi2_tmp_ptr[0] - pi2_tmp_ptr[8]);
756
0
        x2 = (pi2_tmp_ptr[4] >> 1) - pi2_tmp_ptr[12];
757
0
        x3 =  pi2_tmp_ptr[4] + (pi2_tmp_ptr[12] >> 1);
758
0
759
0
        /* inverse prediction */
760
0
        i_macro = x0 + x3;
761
0
        i_macro = ((i_macro + 32) >> 6);
762
0
        i_macro += *pu1_pred_ptr;
763
0
        *pu1_out = CLIP_U8(i_macro);
764
0
        pu1_pred_ptr += pred_strd;
765
0
        pu1_out += out_strd;
766
0
767
0
        i_macro = x1 + x2;
768
0
        i_macro = ((i_macro + 32) >> 6);
769
0
        i_macro += *pu1_pred_ptr;
770
0
        *pu1_out = CLIP_U8(i_macro);
771
0
        pu1_pred_ptr += pred_strd;
772
0
        pu1_out += out_strd;
773
0
774
0
        i_macro = x1 - x2;
775
0
        i_macro = ((i_macro + 32) >> 6);
776
0
        i_macro += *pu1_pred_ptr;
777
0
        *pu1_out = CLIP_U8(i_macro);
778
0
        pu1_pred_ptr += pred_strd;
779
0
        pu1_out += out_strd;
780
0
781
0
        i_macro = x0 - x3;
782
0
        i_macro = ((i_macro + 32) >> 6);
783
0
        i_macro += *pu1_pred_ptr;
784
0
        *pu1_out = CLIP_U8(i_macro);
785
0
786
0
        pi2_tmp_ptr++;
787
0
        pu1_out_ptr+= 2;    //Interleaved store for output
788
0
        pu1_pred+= 2;       //Interleaved load for pred buffer
789
0
    }
790
0
}
791
792
/*
793
 ********************************************************************************
794
 *
795
 * @brief This function reconstructs a 4x4 sub block from quantized resiude and
796
 * prediction buffer if only dc value is present for residue
797
 *
798
 * @par Description:
799
 *  The quantized residue is first inverse quantized,
800
 *  This inverse quantized content is added to the prediction buffer to recon-
801
 *  struct the end output
802
 *
803
 * @param[in] pi2_src
804
 *  quantized dc coefficient
805
 *
806
 * @param[in] pu1_pred
807
 *  prediction 4x4 block in interleaved format
808
 *
809
 * @param[in] pred_strd,
810
 *  Prediction buffer stride in interleaved format
811
 *
812
 * @param[in] out_strd
813
 *  recon buffer Stride
814
 *
815
 * @returns none
816
 *
817
 * @remarks none
818
 *
819
 *******************************************************************************
820
 */
821
822
void ih264_iquant_itrans_recon_chroma_4x4_dc(WORD16 *pi2_src,
823
                                             UWORD8 *pu1_pred,
824
                                             UWORD8 *pu1_out,
825
                                             WORD32 pred_strd,
826
                                             WORD32 out_strd,
827
                                             const UWORD16 *pu2_iscal_mat,
828
                                             const UWORD16 *pu2_weigh_mat,
829
                                             UWORD32 u4_qp_div_6,
830
                                             WORD16 *pi2_tmp,
831
                                             WORD16 *pi2_dc_src)
832
0
{
833
0
    UWORD8 *pu1_pred_ptr = pu1_pred;
834
0
    UWORD8 *pu1_out_ptr = pu1_out;
835
0
    WORD32 q0;
836
0
    WORD16 x, i_macro, i;
837
0
    UNUSED(pi2_src);
838
0
    UNUSED(pu2_iscal_mat);
839
0
    UNUSED(pu2_weigh_mat);
840
0
    UNUSED(u4_qp_div_6);
841
0
    UNUSED(pi2_tmp);
842
0
843
0
    q0 = pi2_dc_src[0];    // Restoring dc value for intra case3
844
0
    i_macro = ((q0 + 32) >> 6);
845
0
846
0
    for(i = 0; i < SUB_BLK_WIDTH_4x4; i++)
847
0
    {
848
0
        pu1_pred_ptr = pu1_pred;
849
0
        pu1_out = pu1_out_ptr;
850
0
851
0
        /* inverse prediction */
852
0
        x = i_macro + *pu1_pred_ptr;
853
0
        *pu1_out =  CLIP_U8(x);
854
0
        pu1_pred_ptr += pred_strd;
855
0
        pu1_out += out_strd;
856
0
857
0
        x = i_macro + *pu1_pred_ptr;
858
0
        *pu1_out = CLIP_U8(x);
859
0
        pu1_pred_ptr += pred_strd;
860
0
        pu1_out += out_strd;
861
0
862
0
        x = i_macro + *pu1_pred_ptr;
863
0
        *pu1_out = CLIP_U8(x);
864
0
        pu1_pred_ptr += pred_strd;
865
0
        pu1_out += out_strd;
866
0
867
0
        x = i_macro + *pu1_pred_ptr;
868
0
        *pu1_out = CLIP_U8(x);
869
0
870
0
        pu1_out_ptr+=2;
871
0
        pu1_pred+=2;
872
0
    }
873
0
}
/proc/self/cwd/external/libavc/common/ih264_luma_intra_pred_filters.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/**
21
 *******************************************************************************
22
 * @file
23
 *  ih264_luma_intra_pred_filters.c
24
 *
25
 * @brief
26
 *  Contains function definitions for intra prediction  filters
27
 *
28
 * @author
29
 *  Ittiam
30
 *
31
 * @par List of Functions:
32
 *  - ih264_intra_pred_luma_4x4_mode_vert
33
 *  - ih264_intra_pred_luma_4x4_mode_horz
34
 *  - ih264_intra_pred_luma_4x4_mode_dc
35
 *  - ih264_intra_pred_luma_4x4_mode_diag_dl
36
 *  - ih264_intra_pred_luma_4x4_mode_diag_dr
37
 *  - ih264_intra_pred_luma_4x4_mode_vert_r
38
 *  - ih264_intra_pred_luma_4x4_mode_horz_d
39
 *  - ih264_intra_pred_luma_4x4_mode_vert_l
40
 *  - ih264_intra_pred_luma_4x4_mode_horz_u
41
 *  - ih264_intra_pred_luma_8x8_mode_ref_filtering
42
 *  - ih264_intra_pred_luma_8x8_mode_vert
43
 *  - ih264_intra_pred_luma_8x8_mode_horz
44
 *  - ih264_intra_pred_luma_8x8_mode_dc
45
 *  - ih264_intra_pred_luma_8x8_mode_diag_dl
46
 *  - ih264_intra_pred_luma_8x8_mode_diag_dr
47
 *  - ih264_intra_pred_luma_8x8_mode_vert_r
48
 *  - ih264_intra_pred_luma_8x8_mode_horz_d
49
 *  - ih264_intra_pred_luma_8x8_mode_vert_l
50
 *  - ih264_intra_pred_luma_8x8_mode_horz_u
51
 *  - ih264_intra_pred_luma_16x16_mode_vert
52
 *  - ih264_intra_pred_luma_16x16_mode_horz
53
 *  - ih264_intra_pred_luma_16x16_mode_dc
54
 *  - ih264_intra_pred_luma_16x16_mode_plane
55
 *
56
 *
57
 * @remarks
58
 *  None
59
 *
60
 ******************************************************************************
61
 */
62
63
/*****************************************************************************/
64
/* File Includes                                                             */
65
/*****************************************************************************/
66
/* System include files */
67
#include <stdio.h>
68
#include <stddef.h>
69
#include <string.h>
70
71
/* User include files */
72
#include "ih264_defs.h"
73
#include "ih264_typedefs.h"
74
#include "ih264_macros.h"
75
#include "ih264_platform_macros.h"
76
#include "ih264_intra_pred_filters.h"
77
78
/* Global variables used only in assembly files*/
79
const WORD8 ih264_gai1_intrapred_luma_plane_coeffs[] =
80
{ 0x01, 0x02, 0x03, 0x04,
81
  0x05, 0x06, 0x07, 0x08,
82
  0x09, 0x0A, 0x0B, 0x0C,
83
  0x0D, 0x0E, 0x0F, 0x10, };
84
85
const WORD8  ih264_gai1_intrapred_luma_8x8_horz_u[] =
86
{ 0x06,0x15,0x05,0x14,
87
  0x04,0x13,0x03,0x12,
88
  0x02,0x11,0x01,0x10,
89
  0x00,0x1F,0x0F,0x0F
90
};
91
92
/*******************    LUMA INTRAPREDICTION    *******************/
93
94
/*******************    4x4 Modes    *******************/
95
96
/**
97
 *******************************************************************************
98
 *
99
 *ih264_intra_pred_luma_4x4_mode_vert
100
 *
101
 * @brief
102
 *  Perform Intra prediction for  luma_4x4 mode:vertical
103
 *
104
 * @par Description:
105
 * Perform Intra prediction for  luma_4x4 mode:vertical ,described in sec 8.3.1.2.1
106
 *
107
 * @param[in] pu1_src
108
 *  UWORD8 pointer to the source
109
 *
110
 * @param[out] pu1_dst
111
 *  UWORD8 pointer to the destination
112
 *
113
 * @param[in] src_strd
114
 *  integer source stride
115
 *
116
 * @param[in] dst_strd
117
 *  integer destination stride
118
 *
119
 * @param[in] ngbr_avail
120
 * availability of neighbouring pixels(Not used in this function)
121
 *
122
 * @returns
123
 *
124
 * @remarks
125
 *  None
126
 *
127
 *******************************************************************************
128
 */
129
void ih264_intra_pred_luma_4x4_mode_vert(UWORD8 *pu1_src,
130
                                         UWORD8 *pu1_dst,
131
                                         WORD32 src_strd,
132
                                         WORD32 dst_strd,
133
                                         WORD32 ngbr_avail)
134
0
{
135
0
    UWORD8 *pu1_top = NULL; /* Pointer to start of top predictors */
136
0
    UNUSED(src_strd);
137
0
    UNUSED(ngbr_avail);
138
0
    pu1_top = pu1_src + BLK_SIZE + 1;
139
0
140
0
    memcpy(pu1_dst, pu1_top, 4);
141
0
    memcpy(pu1_dst + dst_strd, pu1_top, 4);
142
0
    memcpy(pu1_dst + 2 * dst_strd, pu1_top, 4);
143
0
    memcpy(pu1_dst + 3 * dst_strd, pu1_top, 4);
144
0
}
145
146
/**
147
 *******************************************************************************
148
 *
149
 *ih264_intra_pred_luma_4x4_mode_horz
150
 *
151
 * @brief
152
 *  Perform Intra prediction for  luma_4x4 mode:horizontal
153
 *
154
 * @par Description:
155
 *  Perform Intra prediction for  luma_4x4 mode:horizontal ,described in sec 8.3.1.2.2
156
 *
157
 * @param[in] pu1_src
158
 *  UWORD8 pointer to the source
159
 *
160
 * @param[out] pu1_dst
161
 *  UWORD8 pointer to the destination
162
 *
163
 * @param[in] src_strd
164
 *  integer source stride
165
 *
166
 * @param[in] dst_strd
167
 *  integer destination stride
168
 *
169
 * @param[in] ngbr_avail
170
 * availability of neighbouring pixels(Not used in this function)
171
 *
172
 * @returns
173
 *
174
 * @remarks
175
 *  None
176
 *
177
 *******************************************************************************
178
 */
179
void ih264_intra_pred_luma_4x4_mode_horz(UWORD8 *pu1_src,
180
                                         UWORD8 *pu1_dst,
181
                                         WORD32 src_strd,
182
                                         WORD32 dst_strd,
183
                                         WORD32 ngbr_avail)
184
0
{
185
0
    UWORD8 *pu1_left = NULL; /* Pointer to start of left predictors */
186
0
187
0
    UNUSED(src_strd);
188
0
    UNUSED(ngbr_avail);
189
0
    pu1_left = pu1_src + BLK_SIZE - 1;
190
0
191
0
    memset(pu1_dst, *pu1_left, 4);
192
0
    memset(pu1_dst + dst_strd, *(pu1_left - 1), 4);
193
0
    memset(pu1_dst + 2 * dst_strd, *(pu1_left - 2), 4);
194
0
    memset(pu1_dst + 3 * dst_strd, *(pu1_left - 3), 4);
195
0
}
196
197
/**
198
 *******************************************************************************
199
 *
200
 *ih264_intra_pred_luma_4x4_mode_dc
201
 *
202
 * @brief
203
 *  Perform Intra prediction for  luma_4x4 mode:DC
204
 *
205
 * @par Description:
206
 *  Perform Intra prediction for  luma_4x4 mode:DC ,described in sec 8.3.1.2.3
207
 *
208
 * @param[in] pu1_src
209
 *  UWORD8 pointer to the source
210
 *
211
 * @param[out] pu1_dst
212
 *  UWORD8 pointer to the destination
213
 *
214
 * @param[in] src_strd
215
 *  integer source stride
216
 *
217
 * @param[in] dst_strd
218
 *  integer destination stride
219
 *
220
 * @param[in] ngbr_avail
221
 *  availability of neighbouring pixels
222
 *
223
 * @returns
224
 *
225
 * @remarks
226
 *  None
227
 *
228
 *******************************************************************************/
229
void ih264_intra_pred_luma_4x4_mode_dc(UWORD8 *pu1_src,
230
                                       UWORD8 *pu1_dst,
231
                                       WORD32 src_strd,
232
                                       WORD32 dst_strd,
233
                                       WORD32 ngbr_avail)
234
0
{
235
0
    UWORD8 u1_useleft; /* availability of left predictors (only for DC) */
236
0
    UWORD8 u1_usetop; /* availability of top predictors (only for DC) */
237
0
    UWORD8 *pu1_left = NULL; /* Pointer to start of left predictors */
238
0
    UWORD8 *pu1_top = NULL; /* Pointer to start of top predictors */
239
0
    WORD32 val = 0;
240
0
    UNUSED(src_strd);
241
0
    UNUSED(ngbr_avail);
242
0
    u1_useleft = BOOLEAN(ngbr_avail & LEFT_MB_AVAILABLE_MASK);
243
0
    u1_usetop = BOOLEAN(ngbr_avail & TOP_MB_AVAILABLE_MASK);
244
0
    pu1_top = pu1_src + BLK_SIZE + 1;
245
0
    pu1_left = pu1_src + BLK_SIZE - 1;
246
0
247
0
    if(u1_useleft)
248
0
    {
249
0
        val += *pu1_left--;
250
0
        val += *pu1_left--;
251
0
        val += *pu1_left--;
252
0
        val += *pu1_left + 2;
253
0
    }
254
0
    if(u1_usetop)
255
0
    {
256
0
        val += *pu1_top + *(pu1_top + 1) + *(pu1_top + 2) + *(pu1_top + 3)
257
0
                        + 2;
258
0
    }
259
0
    /* Since 2 is added if either left/top pred is there,
260
0
     val still being zero implies both preds are not there */
261
0
    val = (val) ? (val >> (1 + u1_useleft + u1_usetop)) : 128;
262
0
263
0
    /* 4 bytes are copied from src to dst */
264
0
    memset(pu1_dst, val, 4);
265
0
    memset(pu1_dst + dst_strd, val, 4);
266
0
    memset(pu1_dst + 2 * dst_strd, val, 4);
267
0
    memset(pu1_dst + 3 * dst_strd, val, 4);
268
0
}
269
270
/**
271
 *******************************************************************************
272
 *
273
 *ih264_intra_pred_luma_4x4_mode_diag_dl
274
 *
275
 * @brief
276
 *     Perform Intra prediction for  luma_4x4 mode:Diagonal_Down_Left
277
 *
278
 * @par Description:
279
 *    Perform Intra prediction for  luma_4x4 mode:Diagonal_Down_Left ,described in sec 8.3.1.2.4
280
 *
281
 * @param[in] pu1_src
282
 *  UWORD8 pointer to the source
283
 *
284
 * @param[out] pu1_dst
285
 *  UWORD8 pointer to the destination
286
 *
287
 * @param[in] src_strd
288
 *  integer source stride
289
 *
290
 * @param[in] dst_strd
291
 *  integer destination stride
292
 *
293
 * @param[in] ngbr_avail
294
 * availability of neighbouring pixels(Not used in this function)
295
 *
296
 * @returns
297
 *
298
 * @remarks
299
 *  None
300
 *
301
 *******************************************************************************/
302
void ih264_intra_pred_luma_4x4_mode_diag_dl(UWORD8 *pu1_src,
303
                                            UWORD8 *pu1_dst,
304
                                            WORD32 src_strd,
305
                                            WORD32 dst_strd,
306
                                            WORD32 ngbr_avail)
307
0
{
308
0
    UWORD8 *pu1_top = NULL; /* Pointer to start of top predictors */
309
0
    UWORD32 ui4_a, ui4_b, ui4_c, ui4_d, ui4_e, ui4_f, ui4_g, ui4_h;
310
0
    UWORD8 predicted_pixels[7];
311
0
    UNUSED(src_strd);
312
0
    UNUSED(ngbr_avail);
313
0
    pu1_top = pu1_src +BLK_SIZE + 1;
314
0
315
0
    ui4_a = *pu1_top++;
316
0
    ui4_b = *pu1_top++;
317
0
    ui4_c = *pu1_top++;
318
0
    ui4_d = *pu1_top++;
319
0
    ui4_e = *pu1_top++;
320
0
    ui4_f = *pu1_top++;
321
0
    ui4_g = *pu1_top++;
322
0
    ui4_h = *pu1_top;
323
0
324
0
    predicted_pixels[0] = FILT121(ui4_a, ui4_b, ui4_c);
325
0
    predicted_pixels[1] = FILT121(ui4_b, ui4_c, ui4_d);
326
0
    predicted_pixels[2] = FILT121(ui4_c, ui4_d, ui4_e);
327
0
    predicted_pixels[3] = FILT121(ui4_d, ui4_e, ui4_f);
328
0
    predicted_pixels[4] = FILT121(ui4_e, ui4_f, ui4_g);
329
0
    predicted_pixels[5] = FILT121(ui4_f, ui4_g, ui4_h);
330
0
    predicted_pixels[6] = FILT121(ui4_g, ui4_h, ui4_h);
331
0
332
0
    memcpy(pu1_dst, predicted_pixels, 4);
333
0
    memcpy(pu1_dst + dst_strd, predicted_pixels + 1, 4);
334
0
    memcpy(pu1_dst + 2 * dst_strd, predicted_pixels + 2, 4);
335
0
    memcpy(pu1_dst + 3 * dst_strd, predicted_pixels + 3, 4);
336
0
}
337
338
/**
339
 *******************************************************************************
340
 *
341
 *ih264_intra_pred_luma_4x4_mode_diag_dr
342
 *
343
 * @brief
344
 *     Perform Intra prediction for  luma_4x4 mode:Diagonal_Down_Right
345
 *
346
 * @par Description:
347
 *    Perform Intra prediction for  luma_4x4 mode:Diagonal_Down_Right ,described in sec 8.3.1.2.5
348
 *
349
 * @param[in] pu1_src
350
 *  UWORD8 pointer to the source
351
 *
352
 * @param[out] pu1_dst
353
 *  UWORD8 pointer to the destination
354
 *
355
 * @param[in] src_strd
356
 *  integer source stride
357
 *
358
 * @param[in] dst_strd
359
 *  integer destination stride
360
 *
361
 * @param[in] ngbr_avail
362
 * availability of neighbouring pixels(Not used in this function)
363
 *
364
 * @returns
365
 *
366
 * @remarks
367
 *  None
368
 *
369
 *******************************************************************************/
370
void ih264_intra_pred_luma_4x4_mode_diag_dr(UWORD8 *pu1_src,
371
                                            UWORD8 *pu1_dst,
372
                                            WORD32 src_strd,
373
                                            WORD32 dst_strd,
374
                                            WORD32 ngbr_avail)
375
0
{
376
0
    UWORD8 *pu1_top = NULL; /* Pointer to start of top predictors */
377
0
    UWORD8 *pu1_left = NULL; /* Pointer to start of left predictors */
378
0
    UWORD8 *pu1_topleft = NULL;/* Pointer to top left predictor */
379
0
    UWORD32 ui4_a, ui4_b, ui4_c, ui4_d, ui4_i, ui4_j, ui4_k, ui4_l, ui4_m;
380
0
    UWORD8 predicted_pixels[7];
381
0
    UNUSED(src_strd);
382
0
    UNUSED(ngbr_avail);
383
0
    pu1_top = pu1_src + BLK_SIZE + 1;
384
0
    pu1_left = pu1_src + BLK_SIZE - 1;
385
0
    pu1_topleft = pu1_src +BLK_SIZE;
386
0
387
0
    ui4_a = *pu1_top++;
388
0
    ui4_b = *pu1_top++;
389
0
    ui4_c = *pu1_top++;
390
0
    ui4_d = *pu1_top++;
391
0
    ui4_i = *pu1_left--;
392
0
    ui4_j = *pu1_left--;
393
0
    ui4_k = *pu1_left--;
394
0
    ui4_l = *pu1_left;
395
0
    ui4_m = *pu1_topleft;
396
0
397
0
    predicted_pixels[2] = FILT121(ui4_j, ui4_i, ui4_m);
398
0
    predicted_pixels[1] = FILT121(ui4_k, ui4_j, ui4_i);
399
0
    predicted_pixels[0] = FILT121(ui4_l, ui4_k, ui4_j);
400
0
    predicted_pixels[3] = FILT121(ui4_i, ui4_m, ui4_a);
401
0
    predicted_pixels[4] = FILT121(ui4_m, ui4_a, ui4_b);
402
0
    predicted_pixels[5] = FILT121(ui4_a, ui4_b, ui4_c);
403
0
    predicted_pixels[6] = FILT121(ui4_b, ui4_c, ui4_d);
404
0
405
0
    memcpy(pu1_dst, predicted_pixels + 3, 4);
406
0
    memcpy(pu1_dst + dst_strd, predicted_pixels + 2, 4);
407
0
    memcpy(pu1_dst + 2 * dst_strd, predicted_pixels + 1, 4);
408
0
    memcpy(pu1_dst + 3 * dst_strd, predicted_pixels, 4);
409
0
}
410
411
/**
412
 *******************************************************************************
413
 *
414
 *ih264_intra_pred_luma_4x4_mode_vert_r
415
 *
416
 * @brief
417
 *     Perform Intra prediction for  luma_4x4 mode:Vertical_Right
418
 *
419
 * @par Description:
420
 *    Perform Intra prediction for  luma_4x4 mode:Vertical_Right ,described in sec 8.3.1.2.6
421
 *
422
 * @param[in] pu1_src
423
 *  UWORD8 pointer to the source
424
 *
425
 * @param[out] pu1_dst
426
 *  UWORD8 pointer to the destination
427
 *
428
 * @param[in] src_strd
429
 *  integer source stride
430
 *
431
 * @param[in] dst_strd
432
 *  integer destination stride
433
 *
434
 * @param[in] ngbr_avail
435
 * availability of neighbouring pixels(Not used in this function)
436
 *
437
 * @returns
438
 *
439
 * @remarks
440
 *  None
441
 *
442
 *******************************************************************************/
443
void ih264_intra_pred_luma_4x4_mode_vert_r(UWORD8 *pu1_src,
444
                                           UWORD8 *pu1_dst,
445
                                           WORD32 src_strd,
446
                                           WORD32 dst_strd,
447
                                           WORD32 ngbr_avail)
448
0
{
449
0
450
0
    UWORD32 ui4_a, ui4_b, ui4_c, ui4_d, ui4_i, ui4_j, ui4_k, ui4_m;
451
0
    UWORD8 *pu1_top = NULL; /* Pointer to start of top predictors */
452
0
    UWORD8 *pu1_left = NULL; /* Pointer to start of left predictors */
453
0
    UWORD8 *pu1_topleft = NULL;/* Pointer to top left predictor */
454
0
    UWORD8 predicted_pixels[10];
455
0
    UNUSED(src_strd);
456
0
    UNUSED(ngbr_avail);
457
0
    pu1_top = pu1_src +BLK_SIZE + 1;
458
0
    pu1_left = pu1_src + BLK_SIZE - 1;
459
0
    pu1_topleft = pu1_src + BLK_SIZE;
460
0
461
0
    ui4_a = *pu1_top++;
462
0
    ui4_b = *pu1_top++;
463
0
    ui4_c = *pu1_top++;
464
0
    ui4_d = *pu1_top++;
465
0
    ui4_i = *pu1_left--;
466
0
    ui4_j = *pu1_left--;
467
0
    ui4_k = *pu1_left;
468
0
    ui4_m = *pu1_topleft;
469
0
470
0
    predicted_pixels[6] = FILT11(ui4_m, ui4_a);
471
0
    predicted_pixels[7] = FILT11(ui4_a, ui4_b);
472
0
    predicted_pixels[8] = FILT11(ui4_b, ui4_c);
473
0
    predicted_pixels[9] = FILT11(ui4_c, ui4_d);
474
0
    predicted_pixels[1] = FILT121(ui4_i, ui4_m, ui4_a);
475
0
    predicted_pixels[2] = FILT121(ui4_m, ui4_a, ui4_b);
476
0
    predicted_pixels[3] = FILT121(ui4_a, ui4_b, ui4_c);
477
0
    predicted_pixels[4] = FILT121(ui4_b, ui4_c, ui4_d);
478
0
    predicted_pixels[5] = FILT121(ui4_j, ui4_i, ui4_m);
479
0
    predicted_pixels[0] = FILT121(ui4_k, ui4_j, ui4_i);
480
0
481
0
    memcpy(pu1_dst, predicted_pixels + 6, 4);
482
0
    memcpy(pu1_dst + dst_strd, predicted_pixels + 1, 4);
483
0
    memcpy(pu1_dst + 2 * dst_strd, predicted_pixels + 5, 4);
484
0
    memcpy(pu1_dst + 3 * dst_strd, predicted_pixels, 4);
485
0
}
486
487
/*
488
 *******************************************************************************
489
 *
490
 *ih264_intra_pred_luma_4x4_mode_horz_d
491
 *
492
 * @brief
493
 *     Perform Intra prediction for  luma_4x4 mode:Horizontal_Down
494
 *
495
 * @par Description:
496
 *    Perform Intra prediction for  luma_4x4 mode:Horizontal_Down ,described in sec 8.3.1.2.7
497
 *
498
 * @param[in] pu1_src
499
 *  UWORD8 pointer to the source
500
 *
501
 * @param[out] pu1_dst
502
 *  UWORD8 pointer to the destination
503
 *
504
 * @param[in] src_strd
505
 *  integer source stride
506
 *
507
 * @param[in] dst_strd
508
 *  integer destination stride
509
 *
510
 * @param[in] ngbr_avail
511
 * availability of neighbouring pixels(Not used in this function)
512
 *
513
 * @returns
514
 *
515
 * @remarks
516
 *  None
517
 *
518
 *******************************************************************************/
519
void ih264_intra_pred_luma_4x4_mode_horz_d(UWORD8 *pu1_src,
520
                                           UWORD8 *pu1_dst,
521
                                           WORD32 src_strd,
522
                                           WORD32 dst_strd,
523
                                           WORD32 ngbr_avail)
524
0
{
525
0
    UWORD8 *pu1_top = NULL; /* Pointer to start of top predictors */
526
0
    UWORD8 *pu1_left = NULL; /* Pointer to start of left predictors */
527
0
    UWORD8 *pu1_topleft = NULL;/* Pointer to top left predictor */
528
0
    UWORD32 ui4_a, ui4_b, ui4_c, ui4_i, ui4_j, ui4_k, ui4_l, ui4_m;
529
0
    UWORD8 predicted_pixels[10];
530
0
    UNUSED(src_strd);
531
0
    UNUSED(ngbr_avail);
532
0
    pu1_top = pu1_src + BLK_SIZE + 1;
533
0
    pu1_left = pu1_src + BLK_SIZE - 1;
534
0
    pu1_topleft = pu1_src + BLK_SIZE;
535
0
536
0
    ui4_a = *pu1_top++;
537
0
    ui4_b = *pu1_top++;
538
0
    ui4_c = *pu1_top++;
539
0
    ui4_i = *pu1_left--;
540
0
    ui4_j = *pu1_left--;
541
0
    ui4_k = *pu1_left--;
542
0
    ui4_l = *pu1_left--;
543
0
    ui4_m = *pu1_topleft;
544
0
545
0
    predicted_pixels[6] = FILT11(ui4_i, ui4_m);
546
0
    predicted_pixels[7] = FILT121(ui4_i, ui4_m, ui4_a);
547
0
    predicted_pixels[8] = FILT121(ui4_m, ui4_a, ui4_b);
548
0
    predicted_pixels[9] = FILT121(ui4_a, ui4_b, ui4_c);
549
0
    predicted_pixels[1] = FILT121(ui4_l, ui4_k, ui4_j);
550
0
    predicted_pixels[2] = FILT11(ui4_k, ui4_j);
551
0
    predicted_pixels[3] = FILT121(ui4_k, ui4_j, ui4_i);
552
0
    predicted_pixels[4] = FILT11(ui4_j, ui4_i);
553
0
    predicted_pixels[5] = FILT121(ui4_j, ui4_i, ui4_m);
554
0
    predicted_pixels[0] = FILT11(ui4_l, ui4_k);
555
0
556
0
    memcpy(pu1_dst, predicted_pixels + 6, 4);
557
0
    memcpy(pu1_dst + dst_strd, predicted_pixels + 4, 4);
558
0
    memcpy(pu1_dst + 2 * dst_strd, predicted_pixels + 2, 4);
559
0
    memcpy(pu1_dst + 3 * dst_strd, predicted_pixels, 4);
560
0
}
561
562
/**
563
 *******************************************************************************
564
 *
565
 *ih264_intra_pred_luma_4x4_mode_vert_l
566
 *
567
 * @brief
568
 *     Perform Intra prediction for  luma_4x4 mode:Vertical_Left
569
 *
570
 * @par Description:
571
 *    Perform Intra prediction for  luma_4x4 mode:Vertical_Left ,described in sec 8.3.1.2.8
572
 *
573
 * @param[in] pu1_src
574
 *  UWORD8 pointer to the source
575
 *
576
 * @param[out] pu1_dst
577
 *  UWORD8 pointer to the destination
578
 *
579
 * @param[in] src_strd
580
 *  integer source stride
581
 *
582
 * @param[in] dst_strd
583
 *  integer destination stride
584
 *
585
 * @param[in] ngbr_avail
586
 * availability of neighbouring pixels(Not used in this function)
587
 *
588
 * @returns
589
 *
590
 * @remarks
591
 *  None
592
 *
593
 *******************************************************************************/
594
void ih264_intra_pred_luma_4x4_mode_vert_l(UWORD8 *pu1_src,
595
                                           UWORD8 *pu1_dst,
596
                                           WORD32 src_strd,
597
                                           WORD32 dst_strd,
598
                                           WORD32 ngbr_avail)
599
0
{
600
0
    UWORD8 *pu1_top = NULL; /* Pointer to start of top predictors */
601
0
    UWORD32 ui4_a, ui4_b, ui4_c, ui4_d, ui4_e, ui4_f, ui4_g;
602
0
    UWORD8 predicted_pixels[10];
603
0
    UNUSED(src_strd);
604
0
    UNUSED(ngbr_avail);
605
0
    pu1_top = pu1_src + BLK_SIZE + 1;
606
0
607
0
    ui4_a = *pu1_top++;
608
0
    ui4_b = *pu1_top++;
609
0
    ui4_c = *pu1_top++;
610
0
    ui4_d = *pu1_top++;
611
0
    ui4_e = *pu1_top++;
612
0
    ui4_f = *pu1_top++;
613
0
    ui4_g = *pu1_top;
614
0
615
0
    predicted_pixels[5] = FILT11(ui4_a, ui4_b);
616
0
    predicted_pixels[6] = FILT11(ui4_b, ui4_c);
617
0
    predicted_pixels[7] = FILT11(ui4_c, ui4_d);
618
0
    predicted_pixels[8] = FILT11(ui4_d, ui4_e);
619
0
    predicted_pixels[0] = FILT121(ui4_a, ui4_b, ui4_c);
620
0
    predicted_pixels[1] = FILT121(ui4_b, ui4_c, ui4_d);
621
0
    predicted_pixels[2] = FILT121(ui4_c, ui4_d, ui4_e);
622
0
    predicted_pixels[3] = FILT121(ui4_d, ui4_e, ui4_f);
623
0
    predicted_pixels[9] = FILT11(ui4_e, ui4_f);
624
0
    predicted_pixels[4] = FILT121(ui4_e, ui4_f, ui4_g);
625
0
626
0
    memcpy(pu1_dst, predicted_pixels + 5, 4);
627
0
    memcpy(pu1_dst + dst_strd, predicted_pixels, 4);
628
0
    memcpy(pu1_dst + 2 * dst_strd, predicted_pixels + 6, 4);
629
0
    memcpy(pu1_dst + 3 * dst_strd, predicted_pixels + 1, 4);
630
0
}
631
632
/**
633
 *******************************************************************************
634
 *
635
 *ih264_intra_pred_luma_4x4_mode_horz_u
636
 *
637
 * @brief
638
 *     Perform Intra prediction for  luma_4x4 mode:Horizontal_Up
639
 *
640
 * @par Description:
641
 *    Perform Intra prediction for  luma_4x4 mode:Horizontal_Up ,described in sec 8.3.1.2.9
642
 *
643
 * @param[in] pu1_src
644
 *  UWORD8 pointer to the source
645
 *
646
 * @param[out] pu1_dst
647
 *  UWORD8 pointer to the destination
648
 *
649
 * @param[in] src_strd
650
 *  integer source stride
651
 *
652
 * @param[in] dst_strd
653
 *  integer destination stride
654
 *
655
 * @param[in] ngbr_avail
656
 * availability of neighbouring pixels(Not used in this function)
657
 *
658
 * @returns
659
 *
660
 * @remarks
661
 *  None
662
 *
663
 *******************************************************************************/
664
void ih264_intra_pred_luma_4x4_mode_horz_u(UWORD8 *pu1_src,
665
                                           UWORD8 *pu1_dst,
666
                                           WORD32 src_strd,
667
                                           WORD32 dst_strd,
668
                                           WORD32 ngbr_avail)
669
0
{
670
0
    UWORD8 *pu1_left = NULL; /* Pointer to start of left predictors */
671
0
    UWORD32 ui4_i, ui4_j, ui4_k, ui4_l;
672
0
    UWORD8 predicted_pixels[10];
673
0
    UNUSED(src_strd);
674
0
    UNUSED(ngbr_avail);
675
0
    pu1_left = pu1_src + BLK_SIZE - 1;
676
0
677
0
    ui4_i = *pu1_left--;
678
0
    ui4_j = *pu1_left--;
679
0
    ui4_k = *pu1_left--;
680
0
    ui4_l = *pu1_left--;
681
0
682
0
    predicted_pixels[0] = FILT11(ui4_j, ui4_i);
683
0
    predicted_pixels[1] = FILT121(ui4_k, ui4_j, ui4_i);
684
0
    predicted_pixels[2] = FILT11(ui4_k, ui4_j);
685
0
    predicted_pixels[3] = FILT121(ui4_l, ui4_k, ui4_j);
686
0
    predicted_pixels[4] = FILT11(ui4_l, ui4_k);
687
0
    predicted_pixels[5] = FILT121(ui4_l, ui4_l, ui4_k);
688
0
    predicted_pixels[6] = ui4_l;
689
0
    predicted_pixels[7] = ui4_l;
690
0
    predicted_pixels[8] = ui4_l;
691
0
    predicted_pixels[9] = ui4_l;
692
0
693
0
    memcpy(pu1_dst, predicted_pixels, 4);
694
0
    memcpy(pu1_dst + dst_strd, predicted_pixels + 2, 4);
695
0
    memcpy(pu1_dst + 2 * dst_strd, predicted_pixels + 4, 4);
696
0
    memcpy(pu1_dst + 3 * dst_strd, predicted_pixels + 6, 4);
697
0
}
698
699
/*******************    8x8 Modes    *******************/
700
701
/**
702
 *******************************************************************************
703
 *
704
 *ih264_intra_pred_luma_8x8_mode_ref_filtering
705
 *
706
 * @brief
707
 *     Reference sample filtering process for Intra_8x8 sample prediction
708
 *
709
 * @par Description:
710
 *    Perform Reference sample filtering process for Intra_8x8 sample prediction ,described in sec 8.3.2.2.1
711
 *
712
 * @param[in] pu1_src
713
 *  UWORD8 pointer to the source
714
 *
715
 * @param[out] pu1_dst
716
 *  UWORD8 pointer to the destination
717
 *
718
 * @param[in] src_strd
719
 *  integer source stride[Not Used]
720
 *
721
 * @param[in] dst_strd
722
 *  integer destination stride[Not Used]
723
 *
724
 * @param[in] ngbr_avail
725
 * availability of neighbouring pixels(Not used in this function)
726
 *
727
 * @returns
728
 *
729
 * @remarks
730
 *  None
731
 *
732
 *
733
 *******************************************************************************/
734
void ih264_intra_pred_luma_8x8_mode_ref_filtering(UWORD8 *pu1_left,
735
                                                  UWORD8 *pu1_topleft,
736
                                                  UWORD8 *pu1_top,
737
                                                  UWORD8 *pu1_dst,
738
                                                  WORD32 left_strd,
739
                                                  WORD32 ngbr_avail)
740
0
{
741
0
    WORD32 top_avail, left_avail, top_left_avail, top_right_avail;
742
0
743
0
    left_avail = BOOLEAN(ngbr_avail & LEFT_MB_AVAILABLE_MASK);
744
0
    top_avail = BOOLEAN(ngbr_avail & TOP_MB_AVAILABLE_MASK);
745
0
    top_left_avail = BOOLEAN(ngbr_avail & TOP_LEFT_MB_AVAILABLE_MASK);
746
0
    top_right_avail = BOOLEAN(ngbr_avail & TOP_RIGHT_MB_AVAILABLE_MASK);
747
0
748
0
    if(top_avail)
749
0
    {
750
0
        WORD32 i;
751
0
        UWORD32 u4_xm1;
752
0
753
0
        if(!top_right_avail)
754
0
        {
755
0
            memset(pu1_dst + 8 + 1 + 8, pu1_top[7], 8);
756
0
            top_right_avail = 1;
757
0
        }
758
0
        else
759
0
        {
760
0
            memcpy(pu1_dst + 8 + 1 + 8, pu1_top + 8, 8);
761
0
        }
762
0
763
0
        if(top_left_avail)
764
0
        {
765
0
            pu1_dst[8 + 1 + 0] = FILT121((*pu1_topleft), pu1_top[0],
766
0
                                         pu1_top[1]);
767
0
768
0
        }
769
0
        else
770
0
        {
771
0
            pu1_dst[8 + 1] = ((3 * pu1_top[0]) + pu1_top[1] + 2) >> 2;
772
0
        }
773
0
774
0
        for(i = 1; i <= 6; i++)
775
0
        {
776
0
            pu1_dst[8 + 1 + i] = FILT121(pu1_top[i - 1], pu1_top[i],
777
0
                                         pu1_top[i + 1]);
778
0
779
0
        }
780
0
        /* First byte of Top Right input is in pu1_dst[8 + 1 + 8]*/
781
0
        pu1_dst[8 + 1 + 7] = FILT121(pu1_top[6], pu1_top[7],
782
0
                                     pu1_dst[8 + 1 + 8]);
783
0
784
0
        /* filtered output and source in same buf, to prevent output(x - 1)
785
0
         being over written in process */
786
0
        u4_xm1 = pu1_top[7];
787
0
788
0
        for(i = 8; i <= 14; i++)
789
0
        {
790
0
            UWORD32 u4_x;
791
0
            u4_x = (u4_xm1 + (pu1_dst[8 + 1 + i] << 1) + pu1_dst[8 + 1 + i + 1]
792
0
                            + 2) >> 2;
793
0
            /* assigning u4_xm1 from the un-filtered values for the next iteration */
794
0
            u4_xm1 = pu1_dst[8 + 1 + i];
795
0
            pu1_dst[8 + 1 + i] = u4_x;
796
0
        }
797
0
798
0
        pu1_dst[8 + 1 + 15] = (u4_xm1 + (3 * pu1_dst[8 + 1 + 15]) + 2) >> 2;
799
0
800
0
    }
801
0
802
0
    /* pu1_topleft is overloaded. It is both: */
803
0
    /* a. A pointer for the top left pixel */
804
0
    /* b. An indicator of availability of top left. */
805
0
    /*    If it is null then top left not available */
806
0
    if(top_left_avail)
807
0
    {
808
0
        if((!top_avail) || (!left_avail))
809
0
        {
810
0
            if(top_avail)
811
0
                pu1_dst[8] = (3 * pu1_topleft[0] + pu1_top[0] + 2) >> 2;
812
0
            else if(left_avail)
813
0
                pu1_dst[8] = (3 * pu1_topleft[0] + pu1_left[0] + 2) >> 2;
814
0
        }
815
0
        else
816
0
        {
817
0
            pu1_dst[8] = FILT121(pu1_top[0], (*pu1_topleft), pu1_left[0]);
818
0
        }
819
0
    }
820
0
821
0
    if(left_avail)
822
0
    {
823
0
        UWORD32 idx;
824
0
        if(0 != pu1_topleft)
825
0
        {
826
0
            pu1_dst[7] = FILT121((*pu1_topleft), pu1_left[0],
827
0
                                 pu1_left[left_strd]);
828
0
        }
829
0
        else
830
0
        {
831
0
            pu1_dst[7] = ((3 * pu1_left[0]) + pu1_left[left_strd] + 2) >> 2;
832
0
        }
833
0
834
0
        for(idx = 1; idx <= 6; idx++)
835
0
        {
836
0
            pu1_dst[7 - idx] = FILT121(pu1_left[(idx - 1) * left_strd],
837
0
                                       pu1_left[idx * left_strd],
838
0
                                       pu1_left[(idx + 1) * left_strd]);
839
0
840
0
        }
841
0
        pu1_dst[0] = (pu1_left[6 * left_strd] + 3 * pu1_left[7 * left_strd] + 2)
842
0
                        >> 2;
843
0
844
0
    }
845
0
}
846
847
/**
848
 *******************************************************************************
849
 *
850
 *ih264_intra_pred_luma_8x8_mode_vert
851
 *
852
 * @brief
853
 *  Perform Intra prediction for  luma_8x8 mode:vertical
854
 *
855
 * @par Description:
856
 *  Perform Intra prediction for  luma_8x8 mode:vertical ,described in sec 8.3.2.2.2
857
 *
858
 * @param[in] pu1_src
859
 *  UWORD8 pointer to the source
860
 *
861
 * @param[out] pu1_dst
862
 *  UWORD8 pointer to the destination
863
 *
864
 * @param[in] src_strd
865
 *  integer source stride
866
 *
867
 * @param[in] dst_strd
868
 *  integer destination stride
869
 *
870
 * @param[in] ngbr_avail
871
 * availability of neighbouring pixels(Not used in this function)
872
 *
873
 * @returns
874
 *
875
 * @remarks
876
 *  None
877
 *
878
 *******************************************************************************
879
 */
880
void ih264_intra_pred_luma_8x8_mode_vert(UWORD8 *pu1_src,
881
                                         UWORD8 *pu1_dst,
882
                                         WORD32 src_strd,
883
                                         WORD32 dst_strd,
884
                                         WORD32 ngbr_avail)
885
0
{
886
0
    UWORD8 *pu1_top = NULL;
887
0
    UNUSED(src_strd);
888
0
    UNUSED(ngbr_avail);
889
0
    pu1_top = pu1_src + BLK8x8SIZE + 1;
890
0
891
0
    memcpy(pu1_dst, pu1_top, 8);
892
0
    memcpy(pu1_dst + dst_strd, pu1_top, 8);
893
0
    memcpy(pu1_dst + 2 * dst_strd, pu1_top, 8);
894
0
    memcpy(pu1_dst + 3 * dst_strd, pu1_top, 8);
895
0
    memcpy(pu1_dst + 4 * dst_strd, pu1_top, 8);
896
0
    memcpy(pu1_dst + 5 * dst_strd, pu1_top, 8);
897
0
    memcpy(pu1_dst + 6 * dst_strd, pu1_top, 8);
898
0
    memcpy(pu1_dst + 7 * dst_strd, pu1_top, 8);
899
0
}
900
901
/**
902
 *******************************************************************************
903
 *
904
 *ih264_intra_pred_luma_8x8_mode_horz
905
 *
906
 * @brief
907
 *  Perform Intra prediction for  luma_8x8 mode:horizontal
908
 *
909
 * @par Description:
910
 *  Perform Intra prediction for  luma_8x8 mode:horizontal ,described in sec 8.3.2.2.2
911
 *
912
 * @param[in] pu1_src
913
 *  UWORD8 pointer to the source
914
 *
915
 * @param[out] pu1_dst
916
 *  UWORD8 pointer to the destination
917
 *
918
 * @param[in] src_strd
919
 *  integer source stride
920
 *
921
 * @param[in] dst_strd
922
 *  integer destination stride
923
 *
924
 * @param[in] ngbr_avail
925
 * availability of neighbouring pixels(Not used in this function)
926
 *
927
 * @returns
928
 *
929
 * @remarks
930
 *  None
931
 *
932
 *******************************************************************************
933
 */
934
935
void ih264_intra_pred_luma_8x8_mode_horz(UWORD8 *pu1_src,
936
                                         UWORD8 *pu1_dst,
937
                                         WORD32 src_strd,
938
                                         WORD32 dst_strd,
939
                                         WORD32 ngbr_avail)
940
0
{
941
0
    UWORD8 *pu1_left = pu1_src + BLK8x8SIZE - 1;
942
0
    UNUSED(src_strd);
943
0
    UNUSED(ngbr_avail);
944
0
    memset(pu1_dst, *pu1_left, 8);
945
0
    memset(pu1_dst + dst_strd, *(pu1_left - 1), 8);
946
0
    memset(pu1_dst + 2 * dst_strd, *(pu1_left - 2), 8);
947
0
    memset(pu1_dst + 3 * dst_strd, *(pu1_left - 3), 8);
948
0
    memset(pu1_dst + 4 * dst_strd, *(pu1_left - 4), 8);
949
0
    memset(pu1_dst + 5 * dst_strd, *(pu1_left - 5), 8);
950
0
    memset(pu1_dst + 6 * dst_strd, *(pu1_left - 6), 8);
951
0
    memset(pu1_dst + 7 * dst_strd, *(pu1_left - 7), 8);
952
0
}
953
954
/**
955
 *******************************************************************************
956
 *
957
 *ih264_intra_pred_luma_8x8_mode_dc
958
 *
959
 * @brief
960
 *     Perform Intra prediction for  luma_8x8 mode:DC
961
 *
962
 * @par Description:
963
 *    Perform Intra prediction for  luma_8x8 mode:DC ,described in sec 8.3.2.2.4
964
 *
965
 * @param[in] pu1_src
966
 *  UWORD8 pointer to the source
967
 *
968
 * @param[out] pu1_dst
969
 *  UWORD8 pointer to the destination
970
 *
971
 * @param[in] src_strd
972
 *  integer source stride
973
 *
974
 * @param[in] dst_strd
975
 *  integer destination stride
976
 *
977
 * @param[in] ngbr_avail
978
 *  availability of neighbouring pixels
979
 *
980
 * @returns
981
 *
982
 * @remarks
983
 *  None
984
 *
985
 *******************************************************************************/
986
void ih264_intra_pred_luma_8x8_mode_dc(UWORD8 *pu1_src,
987
                                       UWORD8 *pu1_dst,
988
                                       WORD32 src_strd,
989
                                       WORD32 dst_strd,
990
                                       WORD32 ngbr_avail)
991
0
{
992
0
    UWORD8 u1_useleft; /* availability of left predictors (only for DC) */
993
0
    UWORD8 u1_usetop; /* availability of top predictors (only for DC) */
994
0
    UWORD8 *pu1_left = NULL; /* Pointer to start of left predictors */
995
0
    UWORD8 *pu1_top = NULL; /* Pointer to start of top predictors */
996
0
    WORD32 row;
997
0
    WORD32 val = 0;
998
0
    UNUSED(src_strd);
999
0
1000
0
    u1_useleft = BOOLEAN(ngbr_avail & LEFT_MB_AVAILABLE_MASK);
1001
0
    u1_usetop = BOOLEAN(ngbr_avail & TOP_MB_AVAILABLE_MASK);
1002
0
    pu1_top = pu1_src + BLK8x8SIZE + 1;
1003
0
    pu1_left = pu1_src + BLK8x8SIZE - 1;
1004
0
1005
0
    if(u1_useleft)
1006
0
    {
1007
0
        for(row = 0; row < BLK8x8SIZE; row++)
1008
0
            val += *(pu1_left - row);
1009
0
        val += 4;
1010
0
    }
1011
0
    if(u1_usetop)
1012
0
    {
1013
0
        for(row = 0; row < BLK8x8SIZE; row++)
1014
0
            val += *(pu1_top + row);
1015
0
        val += 4;
1016
0
    }
1017
0
1018
0
    /* Since 4 is added if either left/top pred is there,
1019
0
     val still being zero implies both preds are not there */
1020
0
    val = (val) ? (val >> (2 + u1_useleft + u1_usetop)) : 128;
1021
0
1022
0
    memset(pu1_dst, val, 8);
1023
0
    memset(pu1_dst + dst_strd, val, 8);
1024
0
    memset(pu1_dst + 2 * dst_strd, val, 8);
1025
0
    memset(pu1_dst + 3 * dst_strd, val, 8);
1026
0
    memset(pu1_dst + 4 * dst_strd, val, 8);
1027
0
    memset(pu1_dst + 5 * dst_strd, val, 8);
1028
0
    memset(pu1_dst + 6 * dst_strd, val, 8);
1029
0
    memset(pu1_dst + 7 * dst_strd, val, 8);
1030
0
}
1031
1032
/**
1033
 *******************************************************************************
1034
 *
1035
 *ih264_intra_pred_luma_8x8_mode_diag_dl
1036
 *
1037
 * @brief
1038
 *     Perform Intra prediction for  luma_8x8 mode:Diagonal_Down_Left
1039
 *
1040
 * @par Description:
1041
 *    Perform Intra prediction for  luma_8x8 mode:Diagonal_Down_Left ,described in sec 8.3.2.2.5
1042
 *
1043
 * @param[in] pu1_src
1044
 *  UWORD8 pointer to the source
1045
 *
1046
 * @param[out] pu1_dst
1047
 *  UWORD8 pointer to the destination
1048
 *
1049
 * @param[in] src_strd
1050
 *  integer source stride
1051
 *
1052
 * @param[in] dst_strd
1053
 *  integer destination stride
1054
 *
1055
 * @param[in] ngbr_avail
1056
 * availability of neighbouring pixels(Not used in this function)
1057
 *
1058
 * @returns
1059
 *
1060
 * @remarks
1061
 *  None
1062
 *
1063
 *******************************************************************************/
1064
void ih264_intra_pred_luma_8x8_mode_diag_dl(UWORD8 *pu1_src,
1065
                                            UWORD8 *pu1_dst,
1066
                                            WORD32 src_strd,
1067
                                            WORD32 dst_strd,
1068
                                            WORD32 ngbr_avail)
1069
0
{
1070
0
    UWORD8 *pu1_top = NULL; /* Pointer to start of top predictors */
1071
0
    UWORD32 ui4_a, ui4_b, ui4_c, ui4_d, ui4_e, ui4_f, ui4_g, ui4_h;
1072
0
    UWORD32 ui4_i, ui4_j, ui4_k, ui4_l, ui4_m, ui4_n, ui4_o, ui4_p;
1073
0
    UWORD8 predicted_pixels[15];
1074
0
    UNUSED(src_strd);
1075
0
    UNUSED(ngbr_avail);
1076
0
    pu1_top = pu1_src + BLK8x8SIZE + 1;
1077
0
1078
0
    ui4_a = *pu1_top++;
1079
0
    ui4_b = *pu1_top++;
1080
0
    ui4_c = *pu1_top++;
1081
0
    ui4_d = *pu1_top++;
1082
0
    ui4_e = *pu1_top++;
1083
0
    ui4_f = *pu1_top++;
1084
0
    ui4_g = *pu1_top++;
1085
0
    ui4_h = *pu1_top++;
1086
0
    ui4_i = *pu1_top++;
1087
0
    ui4_j = *pu1_top++;
1088
0
    ui4_k = *pu1_top++;
1089
0
    ui4_l = *pu1_top++;
1090
0
    ui4_m = *pu1_top++;
1091
0
    ui4_n = *pu1_top++;
1092
0
    ui4_o = *pu1_top++;
1093
0
    ui4_p = *pu1_top;
1094
0
1095
0
    predicted_pixels[0] = FILT121(ui4_a, ui4_b, ui4_c);
1096
0
    predicted_pixels[1] = FILT121(ui4_b, ui4_c, ui4_d);
1097
0
    predicted_pixels[2] = FILT121(ui4_c, ui4_d, ui4_e);
1098
0
    predicted_pixels[3] = FILT121(ui4_d, ui4_e, ui4_f);
1099
0
    predicted_pixels[4] = FILT121(ui4_e, ui4_f, ui4_g);
1100
0
    predicted_pixels[5] = FILT121(ui4_f, ui4_g, ui4_h);
1101
0
    predicted_pixels[6] = FILT121(ui4_g, ui4_h, ui4_i);
1102
0
    predicted_pixels[7] = FILT121(ui4_h, ui4_i, ui4_j);
1103
0
    predicted_pixels[8] = FILT121(ui4_i, ui4_j, ui4_k);
1104
0
    predicted_pixels[9] = FILT121(ui4_j, ui4_k, ui4_l);
1105
0
    predicted_pixels[10] = FILT121(ui4_k, ui4_l, ui4_m);
1106
0
    predicted_pixels[11] = FILT121(ui4_l, ui4_m, ui4_n);
1107
0
    predicted_pixels[12] = FILT121(ui4_m, ui4_n, ui4_o);
1108
0
    predicted_pixels[13] = FILT121(ui4_n, ui4_o, ui4_p);
1109
0
    predicted_pixels[14] = FILT121(ui4_o, ui4_p, ui4_p);
1110
0
1111
0
    memcpy(pu1_dst, predicted_pixels, 8);
1112
0
    memcpy(pu1_dst + dst_strd, predicted_pixels + 1, 8);
1113
0
    memcpy(pu1_dst + 2 * dst_strd, predicted_pixels + 2, 8);
1114
0
    memcpy(pu1_dst + 3 * dst_strd, predicted_pixels + 3, 8);
1115
0
    memcpy(pu1_dst + 4 * dst_strd, predicted_pixels + 4, 8);
1116
0
    memcpy(pu1_dst + 5 * dst_strd, predicted_pixels + 5, 8);
1117
0
    memcpy(pu1_dst + 6 * dst_strd, predicted_pixels + 6, 8);
1118
0
    memcpy(pu1_dst + 7 * dst_strd, predicted_pixels + 7, 8);
1119
0
}
1120
1121
/**
1122
 *******************************************************************************
1123
 *
1124
 *ih264_intra_pred_luma_8x8_mode_diag_dr
1125
 *
1126
 * @brief
1127
 *     Perform Intra prediction for  luma_8x8 mode:Diagonal_Down_Right
1128
 *
1129
 * @par Description:
1130
 *    Perform Intra prediction for  luma_8x8 mode:Diagonal_Down_Right ,described in sec 8.3.2.2.6
1131
 *
1132
 * @param[in] pu1_src
1133
 *  UWORD8 pointer to the source
1134
 *
1135
 * @param[out] pu1_dst
1136
 *  UWORD8 pointer to the destination
1137
 *
1138
 * @param[in] src_strd
1139
 *  integer source stride
1140
 *
1141
 * @param[in] dst_strd
1142
 *  integer destination stride
1143
 *
1144
 * @param[in] ngbr_avail
1145
 * availability of neighbouring pixels(Not used in this function)
1146
 *
1147
 * @returns
1148
 *
1149
 * @remarks
1150
 *  None
1151
 *
1152
 *******************************************************************************/
1153
void ih264_intra_pred_luma_8x8_mode_diag_dr(UWORD8 *pu1_src,
1154
                                            UWORD8 *pu1_dst,
1155
                                            WORD32 src_strd,
1156
                                            WORD32 dst_strd,
1157
                                            WORD32 ngbr_avail)
1158
0
{
1159
0
    UWORD8 *pu1_left = NULL; /* Pointer to start of left predictors */
1160
0
    UWORD8 *pu1_top = NULL; /* Pointer to start of top predictors */
1161
0
    UWORD8 *pu1_topleft = NULL; /* Pointer to start of top left predictors */
1162
0
    UWORD32 ui4_a;
1163
0
    UWORD32 ui4_b, ui4_c, ui4_d, ui4_e, ui4_f, ui4_g, ui4_h, ui4_i;
1164
0
    UWORD32 ui4_j, ui4_k, ui4_l, ui4_m, ui4_n, ui4_o, ui4_p, ui4_q;
1165
0
    UWORD8 predicted_pixels[15];
1166
0
    UNUSED(src_strd);
1167
0
    UNUSED(ngbr_avail);
1168
0
    pu1_top = pu1_src + BLK8x8SIZE + 1;
1169
0
    pu1_left = pu1_src + BLK8x8SIZE - 1;
1170
0
    pu1_topleft = pu1_src + BLK8x8SIZE;
1171
0
1172
0
    ui4_a = *pu1_topleft;
1173
0
    ui4_b = *pu1_top++;
1174
0
    ui4_c = *pu1_top++;
1175
0
    ui4_d = *pu1_top++;
1176
0
    ui4_e = *pu1_top++;
1177
0
    ui4_f = *pu1_top++;
1178
0
    ui4_g = *pu1_top++;
1179
0
    ui4_h = *pu1_top++;
1180
0
    ui4_i = *pu1_top;
1181
0
    ui4_j = *pu1_left--;
1182
0
    ui4_k = *pu1_left--;
1183
0
    ui4_l = *pu1_left--;
1184
0
    ui4_m = *pu1_left--;
1185
0
    ui4_n = *pu1_left--;
1186
0
    ui4_o = *pu1_left--;
1187
0
    ui4_p = *pu1_left--;
1188
0
    ui4_q = *pu1_left;
1189
0
1190
0
    predicted_pixels[6] = FILT121(ui4_a, ui4_j, ui4_k);
1191
0
    predicted_pixels[5] = FILT121(ui4_j, ui4_k, ui4_l);
1192
0
    predicted_pixels[4] = FILT121(ui4_k, ui4_l, ui4_m);
1193
0
    predicted_pixels[3] = FILT121(ui4_l, ui4_m, ui4_n);
1194
0
    predicted_pixels[2] = FILT121(ui4_m, ui4_n, ui4_o);
1195
0
    predicted_pixels[1] = FILT121(ui4_n, ui4_o, ui4_p);
1196
0
    predicted_pixels[0] = FILT121(ui4_o, ui4_p, ui4_q);
1197
0
    predicted_pixels[7] = FILT121(ui4_b, ui4_a, ui4_j);
1198
0
    predicted_pixels[8] = FILT121(ui4_a, ui4_b, ui4_c);
1199
0
    predicted_pixels[9] = FILT121(ui4_b, ui4_c, ui4_d);
1200
0
    predicted_pixels[10] = FILT121(ui4_c, ui4_d, ui4_e);
1201
0
    predicted_pixels[11] = FILT121(ui4_d, ui4_e, ui4_f);
1202
0
    predicted_pixels[12] = FILT121(ui4_e, ui4_f, ui4_g);
1203
0
    predicted_pixels[13] = FILT121(ui4_f, ui4_g, ui4_h);
1204
0
    predicted_pixels[14] = FILT121(ui4_g, ui4_h, ui4_i);
1205
0
1206
0
    memcpy(pu1_dst, predicted_pixels + 7, 8);
1207
0
    memcpy(pu1_dst + dst_strd, predicted_pixels + 6, 8);
1208
0
    memcpy(pu1_dst + 2 * dst_strd, predicted_pixels + 5, 8);
1209
0
    memcpy(pu1_dst + 3 * dst_strd, predicted_pixels + 4, 8);
1210
0
    memcpy(pu1_dst + 4 * dst_strd, predicted_pixels + 3, 8);
1211
0
    memcpy(pu1_dst + 5 * dst_strd, predicted_pixels + 2, 8);
1212
0
    memcpy(pu1_dst + 6 * dst_strd, predicted_pixels + 1, 8);
1213
0
    memcpy(pu1_dst + 7 * dst_strd, predicted_pixels, 8);
1214
0
}
1215
1216
/**
1217
 *******************************************************************************
1218
 *
1219
 *ih264_intra_pred_luma_8x8_mode_vert_r
1220
 *
1221
 * @brief
1222
 *     Perform Intra prediction for  luma_8x8 mode:Vertical_Right
1223
 *
1224
 * @par Description:
1225
 *    Perform Intra prediction for  luma_8x8 mode:Vertical_Right ,described in sec 8.3.2.2.7
1226
 *
1227
 * @param[in] pu1_src
1228
 *  UWORD8 pointer to the source
1229
 *
1230
 * @param[out] pu1_dst
1231
 *  UWORD8 pointer to the destination
1232
 *
1233
 * @param[in] src_strd
1234
 *  integer source stride
1235
 *
1236
 * @param[in] dst_strd
1237
 *  integer destination stride
1238
 *
1239
 * @param[in] ngbr_avail
1240
 * availability of neighbouring pixels(Not used in this function)
1241
 *
1242
 * @returns
1243
 *
1244
 * @remarks
1245
 *  None
1246
 *
1247
 *******************************************************************************/
1248
void ih264_intra_pred_luma_8x8_mode_vert_r(UWORD8 *pu1_src,
1249
                                           UWORD8 *pu1_dst,
1250
                                           WORD32 src_strd,
1251
                                           WORD32 dst_strd,
1252
                                           WORD32 ngbr_avail)
1253
0
{
1254
0
    UWORD8 *pu1_left = NULL; /* Pointer to start of left predictors */
1255
0
    UWORD8 *pu1_top = NULL; /* Pointer to start of top predictors */
1256
0
    UWORD8 *pu1_topleft = NULL; /* Pointer to start of top left predictors */
1257
0
    UWORD32 ui4_a;
1258
0
    UWORD32 ui4_b, ui4_c, ui4_d, ui4_e, ui4_f, ui4_g, ui4_h, ui4_i;
1259
0
    UWORD32 ui4_j, ui4_k, ui4_l, ui4_m, ui4_n, ui4_o, ui4_p;
1260
0
    UWORD8 predicted_pixels[22];
1261
0
1262
0
    UNUSED(src_strd);
1263
0
    UNUSED(ngbr_avail);
1264
0
    pu1_top = pu1_src + BLK8x8SIZE + 1;
1265
0
    pu1_left = pu1_src + BLK8x8SIZE - 1;
1266
0
    pu1_topleft = pu1_src + BLK8x8SIZE;
1267
0
1268
0
    ui4_a = *pu1_topleft;
1269
0
1270
0
    ui4_b = *pu1_top++;
1271
0
    ui4_c = *pu1_top++;
1272
0
    ui4_d = *pu1_top++;
1273
0
    ui4_e = *pu1_top++;
1274
0
    ui4_f = *pu1_top++;
1275
0
    ui4_g = *pu1_top++;
1276
0
    ui4_h = *pu1_top++;
1277
0
    ui4_i = *pu1_top;
1278
0
    ui4_j = *pu1_left--;
1279
0
    ui4_k = *pu1_left--;
1280
0
    ui4_l = *pu1_left--;
1281
0
    ui4_m = *pu1_left--;
1282
0
    ui4_n = *pu1_left--;
1283
0
    ui4_o = *pu1_left--;
1284
0
    ui4_p = *pu1_left--;
1285
0
1286
0
    predicted_pixels[0] = FILT121(ui4_o, ui4_n, ui4_m);
1287
0
    predicted_pixels[1] = FILT121(ui4_m, ui4_l, ui4_k);
1288
0
    predicted_pixels[2] = FILT121(ui4_k, ui4_j, ui4_a);
1289
0
    predicted_pixels[3] = FILT11(ui4_a, ui4_b);
1290
0
    predicted_pixels[4] = FILT11(ui4_b, ui4_c);
1291
0
    predicted_pixels[5] = FILT11(ui4_c, ui4_d);
1292
0
    predicted_pixels[6] = FILT11(ui4_d, ui4_e);
1293
0
    predicted_pixels[7] = FILT11(ui4_e, ui4_f);
1294
0
    predicted_pixels[8] = FILT11(ui4_f, ui4_g);
1295
0
    predicted_pixels[9] = FILT11(ui4_g, ui4_h);
1296
0
    predicted_pixels[10] = FILT11(ui4_h, ui4_i);
1297
0
    predicted_pixels[11] = FILT121(ui4_p, ui4_o, ui4_n);
1298
0
    predicted_pixels[12] = FILT121(ui4_n, ui4_m, ui4_l);
1299
0
    predicted_pixels[13] = FILT121(ui4_l, ui4_k, ui4_j);
1300
0
    predicted_pixels[14] = FILT121(ui4_b, ui4_a, ui4_j);
1301
0
    predicted_pixels[15] = FILT121(ui4_a, ui4_b, ui4_c);
1302
0
    predicted_pixels[16] = FILT121(ui4_b, ui4_c, ui4_d);
1303
0
    predicted_pixels[17] = FILT121(ui4_c, ui4_d, ui4_e);
1304
0
    predicted_pixels[18] = FILT121(ui4_d, ui4_e, ui4_f);
1305
0
    predicted_pixels[19] = FILT121(ui4_e, ui4_f, ui4_g);
1306
0
    predicted_pixels[20] = FILT121(ui4_f, ui4_g, ui4_h);
1307
0
    predicted_pixels[21] = FILT121(ui4_g, ui4_h, ui4_i);
1308
0
1309
0
    memcpy(pu1_dst, predicted_pixels + 3, 8);
1310
0
    memcpy(pu1_dst + 1 * dst_strd, predicted_pixels + 14, 8);
1311
0
    memcpy(pu1_dst + 2 * dst_strd, predicted_pixels + 2, 8);
1312
0
    memcpy(pu1_dst + 3 * dst_strd, predicted_pixels + 13, 8);
1313
0
    memcpy(pu1_dst + 4 * dst_strd, predicted_pixels + 1, 8);
1314
0
    memcpy(pu1_dst + 5 * dst_strd, predicted_pixels + 12, 8);
1315
0
    memcpy(pu1_dst + 6 * dst_strd, predicted_pixels, 8);
1316
0
    memcpy(pu1_dst + 7 * dst_strd, predicted_pixels + 11, 8);
1317
0
1318
0
}
1319
1320
/*
1321
 *******************************************************************************
1322
 *
1323
 *ih264_intra_pred_luma_8x8_mode_horz_d
1324
 *
1325
 * @brief
1326
 *     Perform Intra prediction for  luma_8x8 mode:Horizontal_Down
1327
 *
1328
 * @par Description:
1329
 *    Perform Intra prediction for  luma_8x8 mode:Horizontal_Down ,described in sec 8.3.2.2.8
1330
 *
1331
 * @param[in] pu1_src
1332
 *  UWORD8 pointer to the source
1333
 *
1334
 * @param[out] pu1_dst
1335
 *  UWORD8 pointer to the destination
1336
 *
1337
 * @param[in] src_strd
1338
 *  integer source stride
1339
 *
1340
 * @param[in] dst_strd
1341
 *  integer destination stride
1342
 *
1343
 * @param[in] ngbr_avail
1344
 * availability of neighbouring pixels(Not used in this function)
1345
 *
1346
 * @returns
1347
 *
1348
 * @remarks
1349
 *  None
1350
 *
1351
 *******************************************************************************/
1352
1353
void ih264_intra_pred_luma_8x8_mode_horz_d(UWORD8 *pu1_src,
1354
                                           UWORD8 *pu1_dst,
1355
                                           WORD32 src_strd,
1356
                                           WORD32 dst_strd,
1357
                                           WORD32 ngbr_avail)
1358
0
{
1359
0
    UWORD8 *pu1_left = NULL; /* Pointer to start of left predictors */
1360
0
    UWORD8 *pu1_top = NULL; /* Pointer to start of top predictors */
1361
0
    UWORD8 *pu1_topleft = NULL; /* Pointer to start of top left predictors */
1362
0
    UWORD32 ui4_a;
1363
0
    UWORD32 ui4_b, ui4_c, ui4_d, ui4_e, ui4_f, ui4_g, ui4_h, ui4_i;
1364
0
    UWORD32 ui4_j, ui4_k, ui4_l, ui4_m, ui4_n, ui4_o, ui4_p;
1365
0
    UWORD8 predicted_pixels[22];
1366
0
    UNUSED(src_strd);
1367
0
    UNUSED(ngbr_avail);
1368
0
    pu1_top = pu1_src + BLK8x8SIZE + 1;
1369
0
    pu1_left = pu1_src + BLK8x8SIZE - 1;
1370
0
    pu1_topleft = pu1_src + BLK8x8SIZE;
1371
0
1372
0
    ui4_a = *pu1_topleft;
1373
0
    ui4_j = *pu1_top++;
1374
0
    ui4_k = *pu1_top++;
1375
0
    ui4_l = *pu1_top++;
1376
0
    ui4_m = *pu1_top++;
1377
0
    ui4_n = *pu1_top++;
1378
0
    ui4_o = *pu1_top++;
1379
0
    ui4_p = *pu1_top++;
1380
0
    ui4_b = *pu1_left--;
1381
0
    ui4_c = *pu1_left--;
1382
0
    ui4_d = *pu1_left--;
1383
0
    ui4_e = *pu1_left--;
1384
0
    ui4_f = *pu1_left--;
1385
0
    ui4_g = *pu1_left--;
1386
0
    ui4_h = *pu1_left--;
1387
0
    ui4_i = *pu1_left;
1388
0
1389
0
    predicted_pixels[0] = FILT11(ui4_h, ui4_i);
1390
0
    predicted_pixels[1] = FILT121(ui4_g, ui4_h, ui4_i);
1391
0
    predicted_pixels[2] = FILT11(ui4_g, ui4_h);
1392
0
    predicted_pixels[3] = FILT121(ui4_f, ui4_g, ui4_h);
1393
0
    predicted_pixels[4] = FILT11(ui4_f, ui4_g);
1394
0
    predicted_pixels[5] = FILT121(ui4_e, ui4_f, ui4_g);
1395
0
    predicted_pixels[6] = FILT11(ui4_e, ui4_f);
1396
0
    predicted_pixels[7] = FILT121(ui4_d, ui4_e, ui4_f);
1397
0
    predicted_pixels[8] = FILT11(ui4_d, ui4_e);
1398
0
    predicted_pixels[9] = FILT121(ui4_c, ui4_d, ui4_e);
1399
0
    predicted_pixels[10] = FILT11(ui4_c, ui4_d);
1400
0
    predicted_pixels[11] = FILT121(ui4_b, ui4_c, ui4_d);
1401
0
    predicted_pixels[12] = FILT11(ui4_b, ui4_c);
1402
0
    predicted_pixels[13] = FILT121(ui4_a, ui4_b, ui4_c);
1403
0
    predicted_pixels[14] = FILT11(ui4_a, ui4_b);
1404
0
    predicted_pixels[15] = FILT121(ui4_j, ui4_a, ui4_b);
1405
0
    predicted_pixels[16] = FILT121(ui4_k, ui4_j, ui4_a);
1406
0
    predicted_pixels[17] = FILT121(ui4_l, ui4_k, ui4_j);
1407
0
    predicted_pixels[18] = FILT121(ui4_m, ui4_l, ui4_k);
1408
0
    predicted_pixels[19] = FILT121(ui4_n, ui4_m, ui4_l);
1409
0
    predicted_pixels[20] = FILT121(ui4_o, ui4_n, ui4_m);
1410
0
    predicted_pixels[21] = FILT121(ui4_p, ui4_o, ui4_n);
1411
0
1412
0
    memcpy(pu1_dst, predicted_pixels + 14, 8);
1413
0
    memcpy(pu1_dst + dst_strd, predicted_pixels + 12, 8);
1414
0
    memcpy(pu1_dst + 2 * dst_strd, predicted_pixels + 10, 8);
1415
0
    memcpy(pu1_dst + 3 * dst_strd, predicted_pixels + 8, 8);
1416
0
    memcpy(pu1_dst + 4 * dst_strd, predicted_pixels + 6, 8);
1417
0
    memcpy(pu1_dst + 5 * dst_strd, predicted_pixels + 4, 8);
1418
0
    memcpy(pu1_dst + 6 * dst_strd, predicted_pixels + 2, 8);
1419
0
    memcpy(pu1_dst + 7 * dst_strd, predicted_pixels, 8);
1420
0
}
1421
1422
/**
1423
 *******************************************************************************
1424
 *
1425
 *ih264_intra_pred_luma_8x8_mode_vert_l
1426
 *
1427
 * @brief
1428
 *     Perform Intra prediction for  luma_8x8 mode:Vertical_Left
1429
 *
1430
 * @par Description:
1431
 *    Perform Intra prediction for  luma_8x8 mode:Vertical_Left ,described in sec 8.3.2.2.9
1432
 *
1433
 * @param[in] pu1_src
1434
 *  UWORD8 pointer to the source
1435
 *
1436
 * @param[out] pu1_dst
1437
 *  UWORD8 pointer to the destination
1438
 *
1439
 * @param[in] src_strd
1440
 *  integer source stride
1441
 *
1442
 * @param[in] dst_strd
1443
 *  integer destination stride
1444
 *
1445
 * @param[in] ngbr_avail
1446
 * availability of neighbouring pixels(Not used in this function)
1447
 *
1448
 * @returns
1449
 *
1450
 * @remarks
1451
 *  None
1452
 *
1453
 *******************************************************************************/
1454
1455
void ih264_intra_pred_luma_8x8_mode_vert_l(UWORD8 *pu1_src,
1456
                                           UWORD8 *pu1_dst,
1457
                                           WORD32 src_strd,
1458
                                           WORD32 dst_strd,
1459
                                           WORD32 ngbr_avail)
1460
0
{
1461
0
    UWORD8 *pu1_top = NULL; /* Pointer to start of top predictors */
1462
0
    UWORD32 ui4_a, ui4_b, ui4_c, ui4_d, ui4_e, ui4_f, ui4_g, ui4_h;
1463
0
    UWORD32 ui4_i, ui4_j, ui4_k, ui4_l, ui4_m;
1464
0
    UWORD8 predicted_pixels[22];
1465
0
    UNUSED(src_strd);
1466
0
    UNUSED(ngbr_avail);
1467
0
    pu1_top = pu1_src + BLK8x8SIZE + 1;
1468
0
1469
0
    ui4_a = *pu1_top++;
1470
0
    ui4_b = *pu1_top++;
1471
0
    ui4_c = *pu1_top++;
1472
0
    ui4_d = *pu1_top++;
1473
0
    ui4_e = *pu1_top++;
1474
0
    ui4_f = *pu1_top++;
1475
0
    ui4_g = *pu1_top++;
1476
0
    ui4_h = *pu1_top++;
1477
0
    ui4_i = *pu1_top++;
1478
0
    ui4_j = *pu1_top++;
1479
0
    ui4_k = *pu1_top++;
1480
0
    ui4_l = *pu1_top++;
1481
0
    ui4_m = *pu1_top++;
1482
0
1483
0
    predicted_pixels[0] = FILT11(ui4_a, ui4_b);
1484
0
    predicted_pixels[1] = FILT11(ui4_b, ui4_c);
1485
0
    predicted_pixels[2] = FILT11(ui4_c, ui4_d);
1486
0
    predicted_pixels[3] = FILT11(ui4_d, ui4_e);
1487
0
    predicted_pixels[4] = FILT11(ui4_e, ui4_f);
1488
0
    predicted_pixels[5] = FILT11(ui4_f, ui4_g);
1489
0
    predicted_pixels[6] = FILT11(ui4_g, ui4_h);
1490
0
    predicted_pixels[7] = FILT11(ui4_h, ui4_i);
1491
0
    predicted_pixels[8] = FILT11(ui4_i, ui4_j);
1492
0
    predicted_pixels[9] = FILT11(ui4_j, ui4_k);
1493
0
    predicted_pixels[10] = FILT11(ui4_k, ui4_l);
1494
0
    predicted_pixels[11] = FILT121(ui4_a, ui4_b, ui4_c);
1495
0
    predicted_pixels[12] = FILT121(ui4_b, ui4_c, ui4_d);
1496
0
    predicted_pixels[13] = FILT121(ui4_c, ui4_d, ui4_e);
1497
0
    predicted_pixels[14] = FILT121(ui4_d, ui4_e, ui4_f);
1498
0
    predicted_pixels[15] = FILT121(ui4_e, ui4_f, ui4_g);
1499
0
    predicted_pixels[16] = FILT121(ui4_f, ui4_g, ui4_h);
1500
0
    predicted_pixels[17] = FILT121(ui4_g, ui4_h, ui4_i);
1501
0
    predicted_pixels[18] = FILT121(ui4_h, ui4_i, ui4_j);
1502
0
    predicted_pixels[19] = FILT121(ui4_i, ui4_j, ui4_k);
1503
0
    predicted_pixels[20] = FILT121(ui4_j, ui4_k, ui4_l);
1504
0
    predicted_pixels[21] = FILT121(ui4_k, ui4_l, ui4_m);
1505
0
1506
0
    memcpy(pu1_dst, predicted_pixels, 8);
1507
0
    memcpy(pu1_dst + 2 * dst_strd, predicted_pixels + 1, 8);
1508
0
    memcpy(pu1_dst + 4 * dst_strd, predicted_pixels + 2, 8);
1509
0
    memcpy(pu1_dst + 6 * dst_strd, predicted_pixels + 3, 8);
1510
0
    memcpy(pu1_dst + 1 * dst_strd, predicted_pixels + 11, 8);
1511
0
    memcpy(pu1_dst + 3 * dst_strd, predicted_pixels + 12, 8);
1512
0
    memcpy(pu1_dst + 5 * dst_strd, predicted_pixels + 13, 8);
1513
0
    memcpy(pu1_dst + 7 * dst_strd, predicted_pixels + 14, 8);
1514
0
}
1515
1516
/**
1517
 *******************************************************************************
1518
 *
1519
 *ih264_intra_pred_luma_8x8_mode_horz_u
1520
 *
1521
 * @brief
1522
 *     Perform Intra prediction for  luma_8x8 mode:Horizontal_Up
1523
 *
1524
 * @par Description:
1525
 *    Perform Intra prediction for  luma_8x8 mode:Horizontal_Up ,described in sec 8.3.2.2.10
1526
 *
1527
 * @param[in] pu1_src
1528
 *  UWORD8 pointer to the source
1529
 *
1530
 * @param[out] pu1_dst
1531
 *  UWORD8 pointer to the destination
1532
 *
1533
 * @param[in] src_strd
1534
 *  integer source stride
1535
 *
1536
 * @param[in] dst_strd
1537
 *  integer destination stride
1538
 *
1539
 * @param[in] ngbr_avail
1540
 * availability of neighbouring pixels(Not used in this function)
1541
 *
1542
 * @returns
1543
 *
1544
 * @remarks
1545
 *  None
1546
 *
1547
 *******************************************************************************/
1548
1549
void ih264_intra_pred_luma_8x8_mode_horz_u(UWORD8 *pu1_src,
1550
                                           UWORD8 *pu1_dst,
1551
                                           WORD32 src_strd,
1552
                                           WORD32 dst_strd,
1553
                                           WORD32 ngbr_avail)
1554
1555
0
{
1556
0
    UWORD8 *pu1_left = NULL; /* Pointer to start of left predictors */
1557
0
    UWORD32 ui4_j, ui4_k, ui4_l, ui4_m, ui4_n, ui4_o, ui4_p, ui4_q;
1558
0
    UWORD8 predicted_pixels[22];
1559
0
    UNUSED(src_strd);
1560
0
    UNUSED(ngbr_avail);
1561
0
    pu1_left = pu1_src + BLK8x8SIZE - 1;
1562
0
1563
0
    ui4_j = *pu1_left--;
1564
0
    ui4_k = *pu1_left--;
1565
0
    ui4_l = *pu1_left--;
1566
0
    ui4_m = *pu1_left--;
1567
0
    ui4_n = *pu1_left--;
1568
0
    ui4_o = *pu1_left--;
1569
0
    ui4_p = *pu1_left--;
1570
0
    ui4_q = *pu1_left;
1571
0
1572
0
    pu1_left = pu1_src + BLK8x8SIZE - 1;
1573
0
1574
0
    predicted_pixels[0] = FILT11(ui4_j, ui4_k);
1575
0
    predicted_pixels[1] = FILT121(ui4_j, ui4_k, ui4_l);
1576
0
    predicted_pixels[2] = FILT11(ui4_k, ui4_l);
1577
0
    predicted_pixels[3] = FILT121(ui4_k, ui4_l, ui4_m);
1578
0
    predicted_pixels[4] = FILT11(ui4_l, ui4_m);
1579
0
    predicted_pixels[5] = FILT121(ui4_l, ui4_m, ui4_n);
1580
0
    predicted_pixels[6] = FILT11(ui4_m, ui4_n);
1581
0
    predicted_pixels[7] = FILT121(ui4_m, ui4_n, ui4_o);
1582
0
    predicted_pixels[8] = FILT11(ui4_n, ui4_o);
1583
0
    predicted_pixels[9] = FILT121(ui4_n, ui4_o, ui4_p);
1584
0
    predicted_pixels[10] = FILT11(ui4_o, ui4_p);
1585
0
    predicted_pixels[11] = FILT121(ui4_o, ui4_p, ui4_q);
1586
0
    predicted_pixels[12] = FILT11(ui4_p, ui4_q);
1587
0
    predicted_pixels[13] = FILT121(ui4_p, ui4_q, ui4_q);
1588
0
    memset(predicted_pixels+14,ui4_q,8);
1589
0
1590
0
    memcpy(pu1_dst, predicted_pixels, 8);
1591
0
    memcpy(pu1_dst + 1 * dst_strd, predicted_pixels + 2, 8);
1592
0
    memcpy(pu1_dst + 2 * dst_strd, predicted_pixels + 4, 8);
1593
0
    memcpy(pu1_dst + 3 * dst_strd, predicted_pixels + 6, 8);
1594
0
    memcpy(pu1_dst + 4 * dst_strd, predicted_pixels + 8, 8);
1595
0
    memcpy(pu1_dst + 5 * dst_strd, predicted_pixels + 10, 8);
1596
0
    memcpy(pu1_dst + 6 * dst_strd, predicted_pixels + 12, 8);
1597
0
    memcpy(pu1_dst + 7 * dst_strd, predicted_pixels + 14, 8);
1598
0
}
1599
1600
1601
/*******************    16x16 Modes    *******************/
1602
1603
/**
1604
 *******************************************************************************
1605
 *
1606
 *ih264_intra_pred_luma_16x16_mode_vert
1607
 *
1608
 * @brief
1609
 *  Perform Intra prediction for  luma_16x16 mode:Vertical
1610
 *
1611
 * @par Description:
1612
 *  Perform Intra prediction for  luma_16x16 mode:Vertical, described in sec 8.3.3.1
1613
 *
1614
 * @param[in] pu1_src
1615
 *  UWORD8 pointer to the source
1616
 *
1617
 * @param[out] pu1_dst
1618
 *  UWORD8 pointer to the destination
1619
 *
1620
 * @param[in] src_strd
1621
 *  integer source stride
1622
 *
1623
 * @param[in] dst_strd
1624
 *  integer destination stride
1625
 *
1626
 * @param[in] ngbr_avail
1627
 *  availability of neighbouring pixels (Not used in this function)
1628
 *
1629
 * @returns
1630
 *
1631
 * @remarks
1632
 *  None
1633
 *
1634
 *******************************************************************************/
1635
1636
void ih264_intra_pred_luma_16x16_mode_vert(UWORD8 *pu1_src,
1637
                                           UWORD8 *pu1_dst,
1638
                                           WORD32 src_strd,
1639
                                           WORD32 dst_strd,
1640
                                           WORD32 ngbr_avail)
1641
0
{
1642
0
    UWORD8 *pu1_top = NULL; /* Pointer to start of top predictors */
1643
0
    WORD32 rows; /* loop variables*/
1644
0
    UNUSED(src_strd);
1645
0
    UNUSED(ngbr_avail);
1646
0
    pu1_top = pu1_src + MB_SIZE + 1;
1647
0
1648
0
    for(rows = 0; rows < 16; rows += 4, pu1_dst += dst_strd)
1649
0
    {
1650
0
        memcpy(pu1_dst, pu1_top, 16);
1651
0
        pu1_dst += dst_strd;
1652
0
        memcpy(pu1_dst, pu1_top, 16);
1653
0
        pu1_dst += dst_strd;
1654
0
        memcpy(pu1_dst, pu1_top, 16);
1655
0
        pu1_dst += dst_strd;
1656
0
        memcpy(pu1_dst, pu1_top, 16);
1657
0
    }
1658
0
}
1659
1660
/**
1661
 *******************************************************************************
1662
 *
1663
 *ih264_intra_pred_luma_16x16_mode_horz
1664
 *
1665
 * @brief
1666
 *  Perform Intra prediction for  luma_16x16 mode:Horizontal
1667
 *
1668
 * @par Description:
1669
 *  Perform Intra prediction for  luma_16x16 mode:Horizontal, described in sec 8.3.3.2
1670
 *
1671
 * @param[in] pu1_src
1672
 *  UWORD8 pointer to the source
1673
 *
1674
 * @param[out] pu1_dst
1675
 *  UWORD8 pointer to the destination
1676
 *
1677
 * @param[in] src_strd
1678
 *  integer source stride
1679
 *
1680
 * @param[in] dst_strd
1681
 *  integer destination stride
1682
 *
1683
 * @param[in] ngbr_avail
1684
 * availability of neighbouring pixels(Not used in this function)
1685
 *
1686
 * @returns
1687
 *
1688
 * @remarks
1689
 *  None
1690
 *
1691
 *******************************************************************************/
1692
1693
void ih264_intra_pred_luma_16x16_mode_horz(UWORD8 *pu1_src,
1694
                                           UWORD8 *pu1_dst,
1695
                                           WORD32 src_strd,
1696
                                           WORD32 dst_strd,
1697
                                           WORD32 ngbr_avail)
1698
0
{
1699
0
    UWORD8 *pu1_left = NULL; /* Pointer to start of top predictors */
1700
0
    WORD32 rows;
1701
0
    UNUSED(src_strd);
1702
0
    UNUSED(ngbr_avail);
1703
0
    pu1_left = pu1_src + MB_SIZE - 1;
1704
0
1705
0
    for(rows = 0; rows < 16; rows += 4, pu1_dst += dst_strd, pu1_left --)
1706
0
    {
1707
0
        memset(pu1_dst, *pu1_left, 16); /* copy the left value to the entire row*/
1708
0
        pu1_left --;
1709
0
        pu1_dst += dst_strd;
1710
0
        memset(pu1_dst, *pu1_left, 16);
1711
0
        pu1_left --;
1712
0
        pu1_dst += dst_strd;
1713
0
        memset(pu1_dst, *pu1_left, 16);
1714
0
        pu1_left --;
1715
0
        pu1_dst += dst_strd;
1716
0
        memset(pu1_dst, *pu1_left, 16);
1717
0
    }
1718
0
}
1719
1720
/**
1721
 *******************************************************************************
1722
 *
1723
 *ih264_intra_pred_luma_16x16_mode_dc
1724
 *
1725
 * @brief
1726
 *  Perform Intra prediction for  luma_16x16 mode:DC
1727
 *
1728
 * @par Description:
1729
 *  Perform Intra prediction for  luma_16x16 mode:DC, described in sec 8.3.3.3
1730
 *
1731
 * @param[in] pu1_src
1732
 *  UWORD8 pointer to the source
1733
 *
1734
 * @param[out] pu1_dst
1735
 *  UWORD8 pointer to the destination
1736
 *
1737
 * @param[in] src_strd
1738
 *  integer source stride
1739
 *
1740
 * @param[in] dst_strd
1741
 *  integer destination stride
1742
 *
1743
 ** @param[in] ngbr_avail
1744
 *  availability of neighbouring pixels
1745
 *
1746
 * @returns
1747
 *
1748
 * @remarks
1749
 *  None
1750
 *
1751
 *******************************************************************************/
1752
1753
void ih264_intra_pred_luma_16x16_mode_dc(UWORD8 *pu1_src,
1754
                                         UWORD8 *pu1_dst,
1755
                                         WORD32 src_strd,
1756
                                         WORD32 dst_strd,
1757
                                         WORD32 ngbr_avail)
1758
0
{
1759
0
    WORD8 u1_useleft; /* availability of left predictors (only for DC) */
1760
0
    UWORD8 u1_usetop; /* availability of top predictors (only for DC) */
1761
0
    UWORD8 *pu1_left = NULL; /* Pointer to start of left predictors */
1762
0
    UWORD8 *pu1_top = NULL; /* Pointer to start of top predictors */
1763
0
    WORD32 rows; /* loop variables*/
1764
0
    WORD32 val = 0;
1765
0
    UNUSED(src_strd);
1766
0
1767
0
    u1_useleft = BOOLEAN(ngbr_avail & LEFT_MB_AVAILABLE_MASK);
1768
0
    u1_usetop = BOOLEAN(ngbr_avail & TOP_MB_AVAILABLE_MASK);
1769
0
    pu1_top = pu1_src + MB_SIZE + 1;
1770
0
    pu1_left = pu1_src + MB_SIZE - 1;
1771
0
    if(u1_useleft)
1772
0
    {
1773
0
        for(rows = 0; rows < 16; rows++)
1774
0
            val += *(pu1_left - rows);
1775
0
        val += 8;
1776
0
    }
1777
0
    if(u1_usetop)
1778
0
    {
1779
0
        for(rows = 0; rows < 16; rows++)
1780
0
            val += *(pu1_top + rows);
1781
0
        val += 8;
1782
0
    }
1783
0
    /* Since 8 is added if either left/top pred is there,
1784
0
     val still being zero implies both preds are not there */
1785
0
    val = (val) ? (val >> (3 + u1_useleft + u1_usetop)) : 128;
1786
0
1787
0
    for(rows = 0; rows < 16; rows += 4, pu1_dst += dst_strd)
1788
0
    {
1789
0
        memset(pu1_dst, val, 16);
1790
0
        pu1_dst += dst_strd;
1791
0
        memset(pu1_dst, val, 16);
1792
0
        pu1_dst += dst_strd;
1793
0
        memset(pu1_dst, val, 16);
1794
0
        pu1_dst += dst_strd;
1795
0
        memset(pu1_dst, val, 16);
1796
0
    }
1797
0
}
1798
1799
/**
1800
 *******************************************************************************
1801
 *
1802
 *ih264_intra_pred_luma_16x16_mode_plane
1803
 *
1804
 * @brief
1805
 *  Perform Intra prediction for  luma_16x16 mode:PLANE
1806
 *
1807
 * @par Description:
1808
 *  Perform Intra prediction for  luma_16x16 mode:PLANE, described in sec 8.3.3.4
1809
 *
1810
 * @param[in] pu1_src
1811
 *  UWORD8 pointer to the source
1812
 *
1813
 * @param[out] pu1_dst
1814
 *  UWORD8 pointer to the destination
1815
 *
1816
 * @param[in] src_strd
1817
 *  integer source stride
1818
 *
1819
 * @param[in] dst_strd
1820
 *  integer destination stride
1821
 *
1822
 * @param[in] ngbr_avail
1823
 * availability of neighbouring pixels(Not used in this function)
1824
 *
1825
 * @returns
1826
 *
1827
 * @remarks
1828
 *  None
1829
 *
1830
 *******************************************************************************/
1831
1832
void ih264_intra_pred_luma_16x16_mode_plane(UWORD8 *pu1_src,
1833
                                            UWORD8 *pu1_dst,
1834
                                            WORD32 src_strd,
1835
                                            WORD32 dst_strd,
1836
                                            WORD32 ngbr_avail)
1837
0
{
1838
0
    /*! Written with no multiplications */
1839
0
    UWORD8 *pu1_left = NULL; /* Pointer to start of left predictors */
1840
0
    UWORD8 *pu1_top = NULL; /* Pointer to start of top predictors */
1841
0
    UWORD8 *pu1_topleft = NULL;
1842
0
    WORD32 a, b, c, tmp;
1843
0
    UWORD8 *pu1_tmp1, *pu1_tmp2;
1844
0
    WORD32 shift;
1845
0
    UNUSED(src_strd);
1846
0
    UNUSED(ngbr_avail);
1847
0
    pu1_top = pu1_src + MB_SIZE + 1;
1848
0
    pu1_left = pu1_src + MB_SIZE - 1;
1849
0
    pu1_topleft = pu1_src + MB_SIZE;
1850
0
1851
0
    {
1852
0
        a = (*(pu1_top + 15) + *(pu1_left - 15)) << 4;
1853
0
1854
0
        /*! Implement Sum(x*(P((x+7),-1) - P((x-7),-1))) x=1...8 */
1855
0
        pu1_tmp1 = pu1_top + 8;
1856
0
        pu1_tmp2 = pu1_tmp1 - 2;
1857
0
1858
0
        /* Pixel diffs are only 9 bits;
1859
0
         so sign extension allows shifts to be used even for signed */
1860
0
        b = ((*pu1_tmp1++) - (*pu1_tmp2--)); /* x=1 */
1861
0
        b += ((*pu1_tmp1++) - (*pu1_tmp2--)) << 1; /* x=2 */
1862
0
        tmp = ((*pu1_tmp1++) - (*pu1_tmp2--));
1863
0
        b += (tmp << 1) + tmp; /* x=3 */
1864
0
        b += ((*pu1_tmp1++) - (*pu1_tmp2--)) << 2; /* x=4 */
1865
0
1866
0
        tmp = ((*pu1_tmp1++) - (*pu1_tmp2--));
1867
0
        b += (tmp << 2) + tmp; /* x=5 */
1868
0
        tmp = ((*pu1_tmp1++) - (*pu1_tmp2--));
1869
0
        b += (tmp << 2) + (tmp << 1); /* x=6 */
1870
0
        tmp = ((*pu1_tmp1++) - (*pu1_tmp2--));
1871
0
        b += (tmp << 3) - tmp; /* x=7 */
1872
0
        b += ((*pu1_tmp1) - (*pu1_topleft)) << 3; /* x=8 */
1873
0
1874
0
        b = ((b << 2) + b + 32) >> 6; /*! (5*H + 32)>>6 */
1875
0
1876
0
        /*! Implement Sum(y*(P(-1,(y+7)) - P(-1,(y-7)))) y=1...8 */
1877
0
        pu1_tmp1 = pu1_left - 8;
1878
0
        pu1_tmp2 = pu1_tmp1 + 2;
1879
0
1880
0
        c = ((*pu1_tmp1) - (*pu1_tmp2)); /* y=1 */
1881
0
        pu1_tmp1--;
1882
0
        pu1_tmp2++;
1883
0
        c += ((*pu1_tmp1) - (*pu1_tmp2)) << 1; /* y=2 */
1884
0
        pu1_tmp1--;
1885
0
        pu1_tmp2++;
1886
0
        tmp = ((*pu1_tmp1) - (*pu1_tmp2));
1887
0
        c += (tmp << 1) + tmp; /* y=3 */
1888
0
        pu1_tmp1--;
1889
0
        pu1_tmp2++;
1890
0
        c += ((*pu1_tmp1) - (*pu1_tmp2)) << 2; /* y=4 */
1891
0
        pu1_tmp1--;
1892
0
        pu1_tmp2++;
1893
0
1894
0
        tmp = ((*pu1_tmp1) - (*pu1_tmp2));
1895
0
        c += (tmp << 2) + tmp; /* y=5 */
1896
0
        pu1_tmp1--;
1897
0
        pu1_tmp2++;
1898
0
        tmp = ((*pu1_tmp1) - (*pu1_tmp2));
1899
0
        c += (tmp << 2) + (tmp << 1); /* y=6 */
1900
0
        pu1_tmp1--;
1901
0
        pu1_tmp2++;
1902
0
        tmp = ((*pu1_tmp1) - (*pu1_tmp2));
1903
0
        c += (tmp << 3) - tmp; /* y=7 */
1904
0
        pu1_tmp1--; //pu1_tmp2 ++;
1905
0
        /* Modified to get (-1,-1) location as *(pu1_top - 1) instead of (pu1_left - ui4_stride) */
1906
0
        //c += ((*pu1_tmp1) - (*(pu1_top - 1)))<<3;      /* y=8 */
1907
0
        c += ((*pu1_tmp1) - (*pu1_topleft)) << 3; /* y=8 */
1908
0
1909
0
        c = ((c << 2) + c + 32) >> 6; /*! (5*V + 32)>>32 */
1910
0
        shift = 3;
1911
0
    }
1912
0
1913
0
    /*! Now from the plane parameters a, b, and c,
1914
0
     compute the fitted plane values over the block */
1915
0
    {
1916
0
        WORD32 tmp1, tmpx, tmpx_init, j, i;
1917
0
1918
0
        tmpx_init = -(b << shift); /* -8b */
1919
0
        tmp = a - (c << shift) + 16; /* a-((4or8)*c)+16 */
1920
0
        for(i = 0; i < 16; i++)
1921
0
        {
1922
0
            tmp += c; /*increment every time by c to get c*(y-7or3)*/
1923
0
            tmpx = tmpx_init; /* Init to -8b */
1924
0
            for(j = 0; j < 16; j++)
1925
0
            {
1926
0
                tmpx += b; /* increment every time by b to get b*(x-7or3) */
1927
0
                tmp1 = (tmp + tmpx) >> 5;
1928
0
                *pu1_dst++ = CLIP_U8(tmp1);
1929
0
            }
1930
0
            pu1_dst += (dst_strd - 16);
1931
0
        }
1932
0
    }
1933
0
}
/proc/self/cwd/external/libavc/common/ih264_macros.h
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
21
/*********************************************************************************
22
* @file
23
*  ih264_macros.h
24
*
25
* @brief
26
*  Macro definitions used in the codec
27
*
28
* @author
29
*  Ittiam
30
*
31
* @remarks
32
*  None
33
*
34
*******************************************************************************
35
*/
36
#ifndef _IH264_MACROS_H_
37
#define _IH264_MACROS_H_
38
39
/*****************************************************************************/
40
/* Function Macros                                                           */
41
/*****************************************************************************/
42
237
#define RETURN_IF(cond, retval) if(cond) {return (retval);}
43
200k
#define UNUSED(x) ((void)(x))
44
45
#define ALIGN128(x) ((((x) + 127) >> 7) << 7)
46
18
#define ALIGN64(x)  ((((x) + 63) >> 6) << 6)
47
#define ALIGN32(x)  ((((x) + 31) >> 5) << 5)
48
0
#define ALIGN16(x)  ((((x) + 15) >> 4) << 4)
49
#define ALIGN8(x)   ((((x) + 7) >> 3) << 3)
50
51.3k
#define ALIGN4(x)   ((((x) + 3) >> 2) << 2)
51
#define ALIGN2(x)   ((((x) + 1) >> 1) << 1)
52
53
/**
54
******************************************************************************
55
 *  @brief      Min, Max
56
******************************************************************************
57
 */
58
28
#define MAX(a,b) ((a > b)?(a):(b))
59
334k
#define MIN(a,b) ((a < b)?(a):(b))
60
#define MIN3(a,b,c) ((a) < (b)) ? (((a) < (c)) ? (a) : (c)) : (((b) < (c)) ? (b) : (c))
61
#define MAX3(a,b,c) ((a) > (b)) ? (((a) > (c)) ? (a) : (c)) : (((b) > (c)) ? (b) : (c))
62
/**
63
******************************************************************************
64
 *  @brief      Div, Mod
65
******************************************************************************
66
 */
67
#define MOD(x,y) ((x)%(y))
68
#define DIV(x,y) ((x)/(y))
69
70
/**
71
******************************************************************************
72
 *  @brief      Clip
73
******************************************************************************
74
 */
75
40.6k
#define CLIP3(miny, maxy, y) (((y) < (miny))?(miny):(((y) > (maxy))?(maxy):(y)))
76
77
/**
78
******************************************************************************
79
 *  @brief      True, False
80
******************************************************************************
81
 */
82
21.7k
#define BOOLEAN(x) (!!(x))
83
84
/**
85
******************************************************************************
86
 *  @brief      Frequently used multiplications x2. x3, and x4
87
******************************************************************************
88
 */
89
39.9k
#define X2(a)   ((a) << 1)
90
24.7k
#define X3(a)   (((a) << 1) + (a))
91
#define X4(a)   ((a) << 2)
92
93
/**
94
******************************************************************************
95
 *  @brief      Misc
96
******************************************************************************
97
 */
98
0
#define ABS(x)          ((x) < 0 ? (-(x)) : (x))
99
#define SIGNXY(x,y)     (((y) < 0) ? (-1 * (x)) : (x))
100
101
#define SIGN(x)     (((x) >= 0) ? (((x) > 0) ? 1 : 0) : -1)
102
103
280k
#define RESET_BIT(x, pos) (x) = (x) & ~(1 << pos);
104
226k
#define SET_BIT(x, pos) (x) = (x) | (1 << pos);
105
#define GET_BIT(x, pos) ((x) >> (pos)) & 0x1
106
107
58.3k
#define INSERT_BIT(x, pos, bit) { RESET_BIT(x, pos); (x) = (x) | (bit << pos); }
108
#endif /*_IH264_MACROS_H_*/
109
110
/proc/self/cwd/external/libavc/common/ih264_padding.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
21
/**
22
*******************************************************************************
23
* @file
24
*  ih264_padding.c
25
*
26
* @brief
27
*  Contains function definitions for Padding
28
*
29
* @author
30
*  Ittiam
31
*
32
* @par List of Functions:
33
*   - ih264_pad_top()
34
*   - ih264_pad_bottom()
35
*   - ih264_pad_left_luma()
36
*   - ih264_pad_left_chroma()
37
*   - ih264_pad_right_luma()
38
*   - ih264_pad_right_chroma()
39
*
40
* @remarks
41
*  None
42
*
43
*******************************************************************************
44
*/
45
46
/*****************************************************************************/
47
/* File Includes                                                             */
48
/*****************************************************************************/
49
50
/* System include files */
51
#include <stddef.h>
52
#include <string.h>
53
54
/* User include files */
55
#include "ih264_typedefs.h"
56
#include "ih264_macros.h"
57
#include "ih264_padding.h"
58
59
60
/*****************************************************************************/
61
/* Function Definitions                                                      */
62
/*****************************************************************************/
63
64
/**
65
*******************************************************************************
66
*
67
* @brief pad at the top of a 2d array
68
*
69
* @par Description:
70
*  The top row of a 2d array is replicated for pad_size times at the top
71
*
72
* @param[in] pu1_src
73
*  UWORD8 pointer to the source
74
*
75
* @param[in] src_strd
76
*  integer source stride
77
*
78
* @param[in] wd
79
*  integer width of the array
80
*
81
* @param[in] pad_size
82
*  integer -padding size of the array
83
*
84
* @returns none
85
*
86
* @remarks none
87
*
88
*******************************************************************************
89
*/
90
void ih264_pad_top(UWORD8 *pu1_src,
91
                   WORD32 src_strd,
92
                   WORD32 wd,
93
                   WORD32 pad_size)
94
22
{
95
22
    WORD32 row;
96
22
97
330
    for(row = 1; row <= pad_size; row++)
98
308
    {
99
308
        memcpy(pu1_src - row * src_strd, pu1_src, wd);
100
308
    }
101
22
}
102
103
104
105
/**
106
*******************************************************************************
107
*
108
* @brief pad at the bottom of a 2d array
109
*
110
* @par Description:
111
*  The bottom row of a 2d array is replicated for pad_size times at the bottom
112
*
113
* @param[in] pu1_src
114
*  UWORD8 pointer to the source
115
*
116
* @param[in] src_strd
117
*  integer source stride
118
*
119
* @param[in] wd
120
*  integer width of the array
121
*
122
* @param[in] pad_size
123
*  integer -padding size of the array
124
*
125
* @returns none
126
*
127
* @remarks none
128
*
129
*******************************************************************************
130
*/
131
void ih264_pad_bottom(UWORD8 *pu1_src,
132
                      WORD32 src_strd,
133
                      WORD32 wd,
134
                      WORD32 pad_size)
135
22
{
136
22
    WORD32 row;
137
22
138
330
    for(row = 1; row <= pad_size; row++)
139
308
    {
140
308
        memcpy(pu1_src + (row - 1) * src_strd, pu1_src - 1 * src_strd, wd);
141
308
    }
142
22
}
143
144
/**
145
*******************************************************************************
146
*
147
* @brief pad (luma block) at the left of a 2d array
148
*
149
* @par Description:
150
*   The left column of a 2d array is replicated for pad_size times to the left
151
*
152
* @param[in] pu1_src
153
*  UWORD8 pointer to the source
154
*
155
* @param[in] src_strd
156
*  integer source stride
157
*
158
* @param[in] ht
159
*  integer height of the array
160
*
161
* @param[in] pad_size
162
*  integer -padding size of the array
163
*
164
* @returns none
165
*
166
* @remarks none
167
*
168
*******************************************************************************
169
 */
170
void ih264_pad_left_luma(UWORD8 *pu1_src,
171
                         WORD32 src_strd,
172
                         WORD32 ht,
173
                         WORD32 pad_size)
174
0
{
175
0
    WORD32 row;
176
0
177
0
    for(row = 0; row < ht; row++)
178
0
    {
179
0
180
0
        memset(pu1_src - pad_size, *pu1_src, pad_size);
181
0
182
0
        pu1_src += src_strd;
183
0
    }
184
0
}
185
186
/**
187
*******************************************************************************
188
*
189
* @brief pad (chroma block) at the left of a 2d array
190
*
191
* @par Description:
192
*   The left column of a 2d array is replicated for pad_size times to the left
193
*
194
* @param[in] pu1_src
195
*  UWORD8 pointer to the source
196
*
197
* @param[in] src_strd
198
*  integer source stride
199
*
200
* @param[in] ht
201
*  integer height of the array
202
*
203
* @param[in] pad_size
204
*  integer -padding size of the array
205
*
206
* @returns none
207
*
208
* @remarks none
209
*
210
*******************************************************************************
211
*/
212
void ih264_pad_left_chroma(UWORD8 *pu1_src,
213
                           WORD32 src_strd,
214
                           WORD32 ht,
215
                           WORD32 pad_size)
216
0
{
217
0
    /* temp var */
218
0
    WORD32 row, col;
219
0
    UWORD16 u2_uv_val;
220
0
221
0
    /* pointer to src */
222
0
    UWORD16 *pu2_src = (UWORD16 *)pu1_src;
223
0
224
0
    src_strd >>= 1;
225
0
    pad_size >>= 1;
226
0
227
0
    for(row = 0; row < ht; row++)
228
0
    {
229
0
        u2_uv_val = pu2_src[0];
230
0
231
0
        for (col = -pad_size; col < 0; col++)
232
0
        {
233
0
            pu2_src[col] = u2_uv_val;
234
0
        }
235
0
236
0
        pu2_src += src_strd;
237
0
    }
238
0
}
239
240
/**
241
*******************************************************************************
242
*
243
* @brief pad (luma block) at the right of a 2d array
244
*
245
* @par Description:
246
*  The right column of a 2d array is replicated for pad_size times at the right
247
*
248
* @param[in] pu1_src
249
*  UWORD8 pointer to the source
250
*
251
* @param[in] src_strd
252
*  integer source stride
253
*
254
* @param[in] ht
255
*  integer height of the array
256
*
257
* @param[in] pad_size
258
*  integer -padding size of the array
259
*
260
* @returns none
261
*
262
* @remarks none
263
*
264
*******************************************************************************
265
*/
266
void ih264_pad_right_luma(UWORD8 *pu1_src,
267
                          WORD32 src_strd,
268
                          WORD32 ht,
269
                          WORD32 pad_size)
270
0
{
271
0
    WORD32 row;
272
0
273
0
    for(row = 0; row < ht; row++)
274
0
    {
275
0
        memset(pu1_src, *(pu1_src -1), pad_size);
276
0
277
0
        pu1_src += src_strd;
278
0
    }
279
0
}
280
281
/**
282
*******************************************************************************
283
*
284
* @brief pad (chroma block) at the right of a 2d array
285
*
286
* @par Description:
287
*  The right column of a 2d array is replicated for pad_size times at the right
288
*
289
* @param[in] pu1_src
290
*  UWORD8 pointer to the source
291
*
292
* @param[in] src_strd
293
*  integer source stride
294
*
295
* @param[in] ht
296
*  integer height of the array
297
*
298
* @param[in] pad_size
299
*  integer -padding size of the array
300
*
301
* @returns none
302
*
303
* @remarks none
304
*
305
*******************************************************************************
306
*/
307
void ih264_pad_right_chroma(UWORD8 *pu1_src,
308
                            WORD32 src_strd,
309
                            WORD32 ht,
310
                            WORD32 pad_size)
311
0
{
312
0
    WORD32 row, col;
313
0
    UWORD16 u2_uv_val;
314
0
    UWORD16 *pu2_src = (UWORD16 *)pu1_src;
315
0
316
0
    src_strd >>= 1;
317
0
    pad_size >>= 1;
318
0
319
0
    for(row = 0; row < ht; row++)
320
0
    {
321
0
        u2_uv_val = pu2_src[-1];
322
0
323
0
        for (col = 0; col < pad_size; col++)
324
0
        {
325
0
            pu2_src[col] = u2_uv_val;
326
0
        }
327
0
328
0
        pu2_src += src_strd;
329
0
    }
330
0
}
331
/proc/self/cwd/external/libavc/common/ih264_size_defs.h
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/**
21
 *******************************************************************************
22
 * @file
23
 *  ih264_size_defs.h
24
 *
25
 * @brief
26
 *  Contains declaration of global variables for H264 transform , quant and inverse quant
27
 *
28
 * @author
29
 *  Ittiam
30
 *
31
 * @remarks
32
 *
33
 ********************************************************************************/
34
35
#ifndef IH264_SIZE_DEFS_H_
36
#define IH264_SIZE_DEFS_H_
37
38
/*****************************************************************************/
39
/* Constant Macros                                                           */
40
/*****************************************************************************/
41
42
/*-----------------------Primary defs--------------------------*/
43
44
/*Width of a 4x4 block*/
45
0
#define SUB_BLK_WIDTH_4x4                   4
46
47
/*Width of an 8x8 block*/
48
0
#define SUB_BLK_WIDTH_8x8                   8
49
50
/*Number of chroma blocks in a row of coffs*/
51
#define SUB_BLK_COUNT_CHROMA_4x4_420        2
52
53
/*Number of luma blocks in a row of coffs*/
54
#define SUB_BLK_COUNT_LUMA_4x4              4
55
56
/*Numbr of chroma planes*/
57
#define NUM_CHROMA_PLANES                   2
58
59
/*Constant bit shifts*/
60
#define QP_BITS_h264_4x4                    15
61
#define QP_BITS_h264_8x8                    16
62
63
64
/*---------------------------Derived defs------------------------*/
65
66
/*Number of coefficients ina 4x4 block*/
67
#define COFF_CNT_SUB_BLK_4x4                SUB_BLK_WIDTH_4x4*SUB_BLK_WIDTH_4x4;
68
69
/*Number of luma blocks in a row of coffs*/
70
#define SUB_BLK_LUMA_4X4_CNT_MB             SUB_BLK_COUNT_LUMA_4x4 * SUB_BLK_COUNT_LUMA_4x4
71
72
/*Number of chroma coffs in an MB*/
73
#define SUB_BLK_CHROMA_4X4_CNT_MB           SUB_BLK_COUNT_CHROMA_4x4_420 * SUB_BLK_COUNT_CHROMA_4x4_420
74
#define SUB_BLK_CHROMA_4X4_CNT_MB_BIPLANE   SUB_BLK_CHROMA_4X4_CNT_MB*NUM_CHROMA_PLANES
75
76
/*Size of trans buff = 4x4 for DC block +  4x4 * coffs for 4x4 ac blocks*/
77
#define SIZE_TRANS_BUFF                     (SUB_BLK_WIDTH_4x4*SUB_BLK_WIDTH_4x4*+ \
78
                                            SUB_BLK_WIDTH_4x4*SUB_BLK_WIDTH_4x4*   \
79
                                            SUB_BLK_COUNT_LUMA_4x4*SUB_BLK_COUNT_LUMA_4x4)
80
81
/*memory size = memory size of 4x4 block of resi coff + 4x4 for DC coff block                          */
82
#define SIZE_TMP_BUFF_ITRANS                ((SUB_BLK_WIDTH_4x4*SUB_BLK_WIDTH_4x4) +\
83
                                             (SUB_BLK_WIDTH_4x4*SUB_BLK_WIDTH_4x4))
84
85
#endif /* IH264_DEFS_H_ */
/proc/self/cwd/external/libavc/common/ih264_trans_macros.h
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/**
21
*******************************************************************************
22
* @file
23
*  ih264_trans_macros.h
24
*
25
* @brief
26
*  The file contains definitions of macros that perform forward and inverse
27
*  quantization
28
*
29
* @author
30
*  Ittiam
31
*
32
* @remark
33
*  None
34
*
35
*******************************************************************************
36
*/
37
38
#ifndef IH264_TRANS_MACROS_H_
39
#define IH264_TRANS_MACROS_H_
40
41
/*****************************************************************************/
42
/* Function Macros                                                           */
43
/*****************************************************************************/
44
45
/**
46
******************************************************************************
47
 *  @brief   Macro to perform forward quantization.
48
 *  @description The value to be quantized is first compared with a threshold.
49
 *  If the value is less than the threshold, the quantization value is returned
50
 *  as zero else the value is quantized traditionally as per the rules of
51
 *  h264 specification
52
******************************************************************************
53
 */
54
#define FWD_QUANT(i4_value, u4_abs_value, i4_sign, threshold, scale, rndfactor, qbits, u4_nnz)      \
55
                {\
56
                        if (i4_value < 0)\
57
                        {\
58
                            u4_abs_value = -i4_value;\
59
                            i4_sign = -1;\
60
                        }\
61
                        else\
62
                        {\
63
                            u4_abs_value = i4_value;\
64
                            i4_sign = 1;\
65
                        }\
66
                        if (u4_abs_value < threshold)\
67
                        {\
68
                            i4_value = 0;\
69
                        }\
70
                        else\
71
                        {\
72
                            u4_abs_value *= scale;\
73
                            u4_abs_value += rndfactor;\
74
                            u4_abs_value >>= qbits;\
75
                            i4_value = u4_abs_value * i4_sign;\
76
                            if (i4_value)\
77
                            {\
78
                                u4_nnz++;\
79
                            }\
80
                        }\
81
                }
82
83
/**
84
******************************************************************************
85
 *  @brief   Macro to perform inverse quantization.
86
 *  @remarks The value can also be de-quantized as
87
 *  if (u4_qp_div_6 < 4)
88
 *  {
89
 *      i4_value = (quant_scale * weight_scale * i4_value + (1 << (3-u4_qp_div_6)))
90
 *      i4_value >>= (4 - u4_qp_div_6)
91
 *  }
92
 *  else
93
 *  {
94
 *      i4_value = (quant_scale * weight_scale * i4_value) << (u4_qp_div_6 -4)
95
 *  }
96
******************************************************************************
97
 */
98
#define INV_QUANT(i4_value, quant_scale, weight_scale, u4_qp_div_6, rndfactor, qbits)\
99
66
                {\
100
66
                    i4_value *= quant_scale;\
101
66
                    i4_value *= weight_scale;\
102
66
                    i4_value += rndfactor;\
103
66
                    i4_value <<= u4_qp_div_6;\
104
66
                    i4_value >>= qbits;\
105
66
                }
106
107
#define QUANT_H264(x,y,w,z,shft) (shft = ABS(x),\
108
                shft *= y,\
109
                shft += z,\
110
                shft = shft>>w,\
111
                shft = SIGNXY(shft,x))
112
113
#define IQUANT_H264(x,y,wscal,w,shft) (shft = x, \
114
                shft *=y, \
115
                shft *=wscal, \
116
                shft = shft<<w)
117
118
#define IQUANT_lev_H264(x,y,wscal,add_f,w,shft) (shft = x, \
119
                shft *=y, \
120
                shft *=wscal, \
121
                shft+= add_f, \
122
                shft = shft>>w)
123
124
#endif /* IH264_TRANS_MACROS_H_ */
/proc/self/cwd/external/libavc/common/ih264_weighted_pred.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/*****************************************************************************/
21
/*                                                                           */
22
/*  File Name         : ih264_weighted_pred.c                                */
23
/*                                                                           */
24
/*  Description       : Contains function definitions for weighted           */
25
/*                      prediction functions                                 */
26
/*                                                                           */
27
/*  List of Functions : ih264_default_weighted_pred_luma()                   */
28
/*                      ih264_default_weighted_pred_chroma()                 */
29
/*                      ih264_weighted_pred_luma()                           */
30
/*                      ih264_weighted_pred_chroma()                         */
31
/*                      ih264_weighted_bipred_luma()                         */
32
/*                      ih264_weighted_bipred_chroma()                       */
33
/*                                                                           */
34
/*  Issues / Problems : None                                                 */
35
/*                                                                           */
36
/*  Revision History  :                                                      */
37
/*                                                                           */
38
/*         DD MM YYYY   Author(s)       Changes                              */
39
/*         07 01 2015   Kaushik         Initial version                      */
40
/*                      Senthoor                                             */
41
/*                                                                           */
42
/*****************************************************************************/
43
/*****************************************************************************/
44
/* File Includes                                                             */
45
/*****************************************************************************/
46
47
/* User include files */
48
#include "ih264_typedefs.h"
49
#include "ih264_macros.h"
50
#include "ih264_platform_macros.h"
51
#include "ih264_weighted_pred.h"
52
53
/*****************************************************************************/
54
/*  Function definitions .                                                   */
55
/*****************************************************************************/
56
/*****************************************************************************/
57
/*                                                                           */
58
/*  Function Name : ih264_default_weighted_pred_luma                         */
59
/*                                                                           */
60
/*  Description   : This function performs the default weighted prediction   */
61
/*                  as described in sec 8.4.2.3.1 titled "Default weighted   */
62
/*                  sample prediction process" for luma. The function gets   */
63
/*                  two ht x wd blocks, calculates their rounded-average and */
64
/*                  stores it in the destination block. (ht,wd) can be       */
65
/*                  (4,4), (8,4), (4,8), (8,8), (16,8), (8,16) or (16,16).   */
66
/*                                                                           */
67
/*  Inputs        : puc_src1  - Pointer to source 1                          */
68
/*                  puc_src2  - Pointer to source 2                          */
69
/*                  puc_dst   - Pointer to destination                       */
70
/*                  src_strd1 - stride for source 1                          */
71
/*                  src_strd1 - stride for source 2                          */
72
/*                  dst_strd  - stride for destination                       */
73
/*                  ht        - height of the block                          */
74
/*                  wd        - width of the block                           */
75
/*                                                                           */
76
/*  Issues        : None                                                     */
77
/*                                                                           */
78
/*  Revision History:                                                        */
79
/*                                                                           */
80
/*         DD MM YYYY   Author(s)       Changes                              */
81
/*         07 01 2015   Kaushik         Initial Version                      */
82
/*                      Senthoor                                             */
83
/*                                                                           */
84
/*****************************************************************************/
85
void ih264_default_weighted_pred_luma(UWORD8 *pu1_src1,
86
                                      UWORD8 *pu1_src2,
87
                                      UWORD8 *pu1_dst,
88
                                      WORD32 src_strd1,
89
                                      WORD32 src_strd2,
90
                                      WORD32 dst_strd,
91
                                      WORD32 ht,
92
                                      WORD32 wd)
93
0
{
94
0
    WORD32 i, j;
95
0
96
0
    src_strd1 -= wd;
97
0
    src_strd2 -= wd;
98
0
    dst_strd -= wd;
99
0
100
0
    for(i = 0; i < ht; i++)
101
0
    {
102
0
        for(j = 0; j < wd; j++, pu1_src1++, pu1_src2++, pu1_dst++)
103
0
            *pu1_dst = (*pu1_src1 + *pu1_src2 + 1) >> 1;
104
0
105
0
        pu1_src1 += src_strd1;
106
0
        pu1_src2 += src_strd2;
107
0
        pu1_dst += dst_strd;
108
0
    }
109
0
}
110
111
/*****************************************************************************/
112
/*                                                                           */
113
/*  Function Name : ih264_default_weighted_pred_chroma                       */
114
/*                                                                           */
115
/*  Description   : This function performs the default weighted prediction   */
116
/*                  as described in sec 8.4.2.3.1 titled "Default weighted   */
117
/*                  sample prediction process" for chroma. The function gets */
118
/*                  two ht x wd blocks, calculates their rounded-average and */
119
/*                  stores it in the destination block. (ht,wd) can be       */
120
/*                  (2,2), (4,2) , (2,4), (4,4), (8,4), (4,8) or (8,8).      */
121
/*                                                                           */
122
/*  Inputs        : puc_src1  - Pointer to source 1                          */
123
/*                  puc_src2  - Pointer to source 2                          */
124
/*                  puc_dst   - Pointer to destination                       */
125
/*                  src_strd1 - stride for source 1                          */
126
/*                  src_strd1 - stride for source 2                          */
127
/*                  dst_strd  - stride for destination                       */
128
/*                  ht        - height of the block                          */
129
/*                  wd        - width of the block                           */
130
/*                                                                           */
131
/*  Issues        : None                                                     */
132
/*                                                                           */
133
/*  Revision History:                                                        */
134
/*                                                                           */
135
/*         DD MM YYYY   Author(s)       Changes                              */
136
/*         07 01 2015   Kaushik         Initial Version                      */
137
/*                      Senthoor                                             */
138
/*                                                                           */
139
/*****************************************************************************/
140
void ih264_default_weighted_pred_chroma(UWORD8 *pu1_src1,
141
                                        UWORD8 *pu1_src2,
142
                                        UWORD8 *pu1_dst,
143
                                        WORD32 src_strd1,
144
                                        WORD32 src_strd2,
145
                                        WORD32 dst_strd,
146
                                        WORD32 ht,
147
                                        WORD32 wd)
148
0
{
149
0
    WORD32 i, j;
150
0
151
0
    wd = wd << 1;
152
0
153
0
    src_strd1 -= wd;
154
0
    src_strd2 -= wd;
155
0
    dst_strd -= wd;
156
0
157
0
    for(i = 0; i < ht; i++)
158
0
    {
159
0
        for(j = 0; j < wd; j++, pu1_src1++, pu1_src2++, pu1_dst++)
160
0
            *pu1_dst = (*pu1_src1 + *pu1_src2 + 1) >> 1;
161
0
162
0
        pu1_src1 += src_strd1;
163
0
        pu1_src2 += src_strd2;
164
0
        pu1_dst += dst_strd;
165
0
    }
166
0
}
167
168
/*****************************************************************************/
169
/*                                                                           */
170
/*  Function Name : ih264_weighted_pred_luma                                 */
171
/*                                                                           */
172
/*  Description   : This function performs the weighted prediction as        */
173
/*                  described in sec 8.4.2.3.2 titled "Weighted sample       */
174
/*                  prediction process" for luma. The function gets one      */
175
/*                  ht x wd block, weights it, rounds it off, offsets it,    */
176
/*                  saturates it to unsigned 8-bit and stores it in the      */
177
/*                  destination block. (ht,wd) can be (4,4), (8,4), (4,8),   */
178
/*                  (8,8), (16,8), (8,16) or (16,16).                        */
179
/*                                                                           */
180
/*  Inputs        : puc_src  - Pointer to source                             */
181
/*                  puc_dst  - Pointer to destination                        */
182
/*                  src_strd - stride for source                             */
183
/*                  dst_strd - stride for destination                        */
184
/*                  log_wd   - number of bits to be rounded off              */
185
/*                  wt       - weight value                                  */
186
/*                  ofst     - offset value                                  */
187
/*                  ht       - height of the block                           */
188
/*                  wd       - width of the block                            */
189
/*                                                                           */
190
/*  Issues        : None                                                     */
191
/*                                                                           */
192
/*  Revision History:                                                        */
193
/*                                                                           */
194
/*         DD MM YYYY   Author(s)       Changes                              */
195
/*         07 01 2015   Kaushik         Initial Version                      */
196
/*                      Senthoor                                             */
197
/*                                                                           */
198
/*****************************************************************************/
199
void ih264_weighted_pred_luma(UWORD8 *pu1_src,
200
                              UWORD8 *pu1_dst,
201
                              WORD32 src_strd,
202
                              WORD32 dst_strd,
203
                              WORD32 log_wd,
204
                              WORD32 wt,
205
                              WORD32 ofst,
206
                              WORD32 ht,
207
                              WORD32 wd)
208
0
{
209
0
    WORD32 i, j;
210
0
211
0
    wt = (WORD16)(wt & 0xffff);
212
0
    ofst = (WORD8)(ofst & 0xff);
213
0
214
0
    src_strd -= wd;
215
0
    dst_strd -= wd;
216
0
217
0
    if(log_wd >= 1)
218
0
    {
219
0
        WORD32 i_ofst = (1 << (log_wd - 1)) + (ofst << log_wd);
220
0
        for(i = 0; i < ht; i++)
221
0
        {
222
0
            for(j = 0; j < wd; j++, pu1_src++, pu1_dst++)
223
0
                *pu1_dst = CLIP_U8((wt * (*pu1_src) + i_ofst) >> log_wd);
224
0
225
0
            pu1_src += src_strd;
226
0
            pu1_dst += dst_strd;
227
0
        }
228
0
    }
229
0
    else
230
0
    {
231
0
        for(i = 0; i < ht; i++)
232
0
        {
233
0
            for(j = 0; j < wd; j++, pu1_src++, pu1_dst++)
234
0
                *pu1_dst = CLIP_U8(wt * (*pu1_src) + ofst);
235
0
236
0
            pu1_src += src_strd;
237
0
            pu1_dst += dst_strd;
238
0
        }
239
0
    }
240
0
}
241
242
/*****************************************************************************/
243
/*                                                                           */
244
/*  Function Name : ih264_weighted_pred_chroma                               */
245
/*                                                                           */
246
/*  Description   : This function performs the weighted prediction as        */
247
/*                  described in sec 8.4.2.3.2 titled "Weighted sample       */
248
/*                  prediction process" for chroma. The function gets one    */
249
/*                  ht x wd block, weights it, rounds it off, offsets it,    */
250
/*                  saturates it to unsigned 8-bit and stores it in the      */
251
/*                  destination block. (ht,wd) can be (2,2), (4,2), (2,4),   */
252
/*                  (4,4), (8,4), (4,8) or (8,8).                            */
253
/*                                                                           */
254
/*  Inputs        : puc_src  - Pointer to source                             */
255
/*                  puc_dst  - Pointer to destination                        */
256
/*                  src_strd - stride for source                             */
257
/*                  dst_strd - stride for destination                        */
258
/*                  log_wd   - number of bits to be rounded off              */
259
/*                  wt       - weight values for u and v                     */
260
/*                  ofst     - offset values for u and v                     */
261
/*                  ht       - height of the block                           */
262
/*                  wd       - width of the block                            */
263
/*                                                                           */
264
/*  Issues        : None                                                     */
265
/*                                                                           */
266
/*  Revision History:                                                        */
267
/*                                                                           */
268
/*         DD MM YYYY   Author(s)       Changes                              */
269
/*         07 01 2015   Kaushik         Initial Version                      */
270
/*                      Senthoor                                             */
271
/*                                                                           */
272
/*****************************************************************************/
273
void ih264_weighted_pred_chroma(UWORD8 *pu1_src,
274
                                UWORD8 *pu1_dst,
275
                                WORD32 src_strd,
276
                                WORD32 dst_strd,
277
                                WORD32 log_wd,
278
                                WORD32 wt,
279
                                WORD32 ofst,
280
                                WORD32 ht,
281
                                WORD32 wd)
282
0
{
283
0
    WORD32 i, j;
284
0
    WORD32 wt_u, wt_v;
285
0
    WORD32 ofst_u, ofst_v;
286
0
287
0
    wt_u = (WORD16)(wt & 0xffff);
288
0
    wt_v = (WORD16)(wt >> 16);
289
0
290
0
    ofst_u = (WORD8)(ofst & 0xff);
291
0
    ofst_v = (WORD8)(ofst >> 8);
292
0
293
0
    src_strd -= wd << 1;
294
0
    dst_strd -= wd << 1;
295
0
296
0
    if(log_wd >= 1)
297
0
    {
298
0
        ofst_u = (1 << (log_wd - 1)) + (ofst_u << log_wd);
299
0
        ofst_v = (1 << (log_wd - 1)) + (ofst_v << log_wd);
300
0
301
0
        for(i = 0; i < ht; i++)
302
0
        {
303
0
            for(j = 0; j < wd; j++, pu1_src++, pu1_dst++)
304
0
            {
305
0
                *pu1_dst = CLIP_U8((wt_u * (*pu1_src) + ofst_u) >> log_wd);
306
0
                pu1_src++;
307
0
                pu1_dst++;
308
0
                *pu1_dst = CLIP_U8((wt_v * (*pu1_src) + ofst_v) >> log_wd);
309
0
            }
310
0
            pu1_src += src_strd;
311
0
            pu1_dst += dst_strd;
312
0
        }
313
0
    }
314
0
    else
315
0
    {
316
0
        for(i = 0; i < ht; i++)
317
0
        {
318
0
            for(j = 0; j < wd; j++, pu1_src++, pu1_dst++)
319
0
            {
320
0
                *pu1_dst = CLIP_U8(wt_u * (*pu1_src) + ofst_u);
321
0
                pu1_src++;
322
0
                pu1_dst++;
323
0
                *pu1_dst = CLIP_U8(wt_v * (*pu1_src) + ofst_v);
324
0
            }
325
0
            pu1_src += src_strd;
326
0
            pu1_dst += dst_strd;
327
0
        }
328
0
    }
329
0
}
330
331
/*****************************************************************************/
332
/*                                                                           */
333
/*  Function Name : ih264_weighted_bi_pred_luma                              */
334
/*                                                                           */
335
/*  Description   : This function performs the weighted biprediction as      */
336
/*                  described in sec 8.4.2.3.2 titled "Weighted sample       */
337
/*                  prediction process" for luma. The function gets two      */
338
/*                  ht x wd blocks, weights them, adds them, rounds off the  */
339
/*                  sum, offsets it, saturates it to unsigned 8-bit and      */
340
/*                  stores it in the destination block. (ht,wd) can be       */
341
/*                  (4,4), (8,4), (4,8), (8,8), (16,8), (8,16) or (16,16).   */
342
/*                                                                           */
343
/*  Inputs        : puc_src1  - Pointer to source 1                          */
344
/*                  puc_src2  - Pointer to source 2                          */
345
/*                  puc_dst   - Pointer to destination                       */
346
/*                  src_strd1 - stride for source 1                          */
347
/*                  src_strd2 - stride for source 2                          */
348
/*                  dst_strd2 - stride for destination                       */
349
/*                  log_wd    - number of bits to be rounded off             */
350
/*                  wt1       - weight value for source 1                    */
351
/*                  wt2       - weight value for source 2                    */
352
/*                  ofst1     - offset value for source 1                    */
353
/*                  ofst2     - offset value for source 2                    */
354
/*                  ht        - height of the block                          */
355
/*                  wd        - width of the block                           */
356
/*                                                                           */
357
/*  Issues        : None                                                     */
358
/*                                                                           */
359
/*  Revision History:                                                        */
360
/*                                                                           */
361
/*         DD MM YYYY   Author(s)       Changes                              */
362
/*         07 01 2015   Kaushik         Initial Version                      */
363
/*                      Senthoor                                             */
364
/*                                                                           */
365
/*****************************************************************************/
366
void ih264_weighted_bi_pred_luma(UWORD8 *pu1_src1,
367
                                 UWORD8 *pu1_src2,
368
                                 UWORD8 *pu1_dst,
369
                                 WORD32 src_strd1,
370
                                 WORD32 src_strd2,
371
                                 WORD32 dst_strd,
372
                                 WORD32 log_wd,
373
                                 WORD32 wt1,
374
                                 WORD32 wt2,
375
                                 WORD32 ofst1,
376
                                 WORD32 ofst2,
377
                                 WORD32 ht,
378
                                 WORD32 wd)
379
0
{
380
0
    WORD32 i, j;
381
0
    WORD32 shft, ofst;
382
0
383
0
    ofst1 = (WORD8)(ofst1 & 0xff);
384
0
    ofst2 = (WORD8)(ofst2 & 0xff);
385
0
    wt1 = (WORD16)(wt1 & 0xffff);
386
0
    wt2 = (WORD16)(wt2 & 0xffff);
387
0
    ofst = (ofst1 + ofst2 + 1) >> 1;
388
0
389
0
    shft = log_wd + 1;
390
0
    ofst = (1 << log_wd) + (ofst << shft);
391
0
392
0
    src_strd1 -= wd;
393
0
    src_strd2 -= wd;
394
0
    dst_strd -= wd;
395
0
396
0
    for(i = 0; i < ht; i++)
397
0
    {
398
0
        for(j = 0; j < wd; j++, pu1_src1++, pu1_src2++, pu1_dst++)
399
0
            *pu1_dst = CLIP_U8((wt1 * (*pu1_src1) + wt2 * (*pu1_src2) + ofst) >> shft);
400
0
401
0
        pu1_src1 += src_strd1;
402
0
        pu1_src2 += src_strd2;
403
0
        pu1_dst += dst_strd;
404
0
    }
405
0
}
406
407
/*****************************************************************************/
408
/*                                                                           */
409
/*  Function Name : ih264_weighted_bi_pred_chroma                            */
410
/*                                                                           */
411
/*  Description   : This function performs the weighted biprediction as      */
412
/*                  described in sec 8.4.2.3.2 titled "Weighted sample       */
413
/*                  prediction process" for chroma. The function gets two    */
414
/*                  ht x wd blocks, weights them, adds them, rounds off the  */
415
/*                  sum, offsets it, saturates it to unsigned 8-bit and      */
416
/*                  stores it in the destination block. (ht,wd) can be       */
417
/*                  (2,2), (4,2), (2,4), (4,4), (8,4), (4,8) or (8,8).       */
418
/*                                                                           */
419
/*  Inputs        : puc_src1  - Pointer to source 1                          */
420
/*                  puc_src2  - Pointer to source 2                          */
421
/*                  puc_dst   - Pointer to destination                       */
422
/*                  src_strd1 - stride for source 1                          */
423
/*                  src_strd2 - stride for source 2                          */
424
/*                  dst_strd2 - stride for destination                       */
425
/*                  log_wd    - number of bits to be rounded off             */
426
/*                  wt1       - weight values for u and v in source 1        */
427
/*                  wt2       - weight values for u and v in source 2        */
428
/*                  ofst1     - offset value for u and v in source 1         */
429
/*                  ofst2     - offset value for u and v in source 2         */
430
/*                  ht        - height of the block                          */
431
/*                  wd        - width of the block                           */
432
/*                                                                           */
433
/*  Issues        : None                                                     */
434
/*                                                                           */
435
/*  Revision History:                                                        */
436
/*                                                                           */
437
/*         DD MM YYYY   Author(s)       Changes                              */
438
/*         07 01 2015   Kaushik         Initial Version                      */
439
/*                      Senthoor                                             */
440
/*                                                                           */
441
/*****************************************************************************/
442
void ih264_weighted_bi_pred_chroma(UWORD8 *pu1_src1,
443
                                   UWORD8 *pu1_src2,
444
                                   UWORD8 *pu1_dst,
445
                                   WORD32 src_strd1,
446
                                   WORD32 src_strd2,
447
                                   WORD32 dst_strd,
448
                                   WORD32 log_wd,
449
                                   WORD32 wt1,
450
                                   WORD32 wt2,
451
                                   WORD32 ofst1,
452
                                   WORD32 ofst2,
453
                                   WORD32 ht,
454
                                   WORD32 wd)
455
0
{
456
0
    WORD32 i, j;
457
0
    WORD32 wt1_u, wt1_v, wt2_u, wt2_v;
458
0
    WORD32 ofst1_u, ofst1_v, ofst2_u, ofst2_v;
459
0
    WORD32 ofst_u, ofst_v;
460
0
    WORD32 shft;
461
0
462
0
    ofst1_u = (WORD8)(ofst1 & 0xff);
463
0
    ofst1_v = (WORD8)(ofst1 >> 8);
464
0
    ofst2_u = (WORD8)(ofst2 & 0xff);
465
0
    ofst2_v = (WORD8)(ofst2 >> 8);
466
0
    wt1_u = (WORD16)(wt1 & 0xffff);
467
0
    wt1_v = (WORD16)(wt1 >> 16);
468
0
    wt2_u = (WORD16)(wt2 & 0xffff);
469
0
    wt2_v = (WORD16)(wt2 >> 16);
470
0
    ofst_u = (ofst1_u + ofst2_u + 1) >> 1;
471
0
    ofst_v = (ofst1_v + ofst2_v + 1) >> 1;
472
0
473
0
    src_strd1 -= wd << 1;
474
0
    src_strd2 -= wd << 1;
475
0
    dst_strd -= wd << 1;
476
0
477
0
    shft = log_wd + 1;
478
0
    ofst_u = (1 << log_wd) + (ofst_u << shft);
479
0
    ofst_v = (1 << log_wd) + (ofst_v << shft);
480
0
481
0
    for(i = 0; i < ht; i++)
482
0
    {
483
0
        for(j = 0; j < wd; j++, pu1_src1++, pu1_src2++, pu1_dst++)
484
0
        {
485
0
            *pu1_dst = CLIP_U8((wt1_u * (*pu1_src1) + wt2_u * (*pu1_src2) + ofst_u) >> shft);
486
0
            pu1_src1++;
487
0
            pu1_src2++;
488
0
            pu1_dst++;
489
0
            *pu1_dst = CLIP_U8((wt1_v * (*pu1_src1) + wt2_v * (*pu1_src2) + ofst_v) >> shft);
490
0
        }
491
0
        pu1_src1 += src_strd1;
492
0
        pu1_src2 += src_strd2;
493
0
        pu1_dst += dst_strd;
494
0
    }
495
0
}
/proc/self/cwd/external/libavc/common/ithread.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/*****************************************************************************/
21
/*                                                                           */
22
/*  File Name         : ithread.c                                            */
23
/*                                                                           */
24
/*  Description       : Contains abstraction for threads, mutex and semaphores*/
25
/*                                                                           */
26
/*  List of Functions :                                                      */
27
/*                                                                           */
28
/*  Issues / Problems : None                                                 */
29
/*                                                                           */
30
/*  Revision History  :                                                      */
31
/*                                                                           */
32
/*         DD MM YYYY   Author(s)       Changes                              */
33
/*         07 09 2012   Harish          Initial Version                      */
34
/*****************************************************************************/
35
/*****************************************************************************/
36
/* File Includes                                                             */
37
/*****************************************************************************/
38
#include <string.h>
39
#include "ih264_typedefs.h"
40
41
42
43
#include "ithread.h"
44
#include <sys/types.h>
45
46
47
79
#define UNUSED(x) ((void)(x))
48
49
//#define PTHREAD_AFFINITY
50
//#define SYSCALL_AFFINITY
51
52
#ifdef PTHREAD_AFFINITY
53
#define _GNU_SOURCE
54
#define __USE_GNU
55
#endif
56
57
#include <pthread.h>
58
#include <sched.h>
59
#include <semaphore.h>
60
#include <unistd.h>
61
#ifdef PTHREAD_AFFINITY
62
#include <sys/prctl.h>
63
#endif
64
65
66
UWORD32 ithread_get_handle_size(void)
67
2
{
68
2
    return sizeof(pthread_t);
69
2
}
70
71
UWORD32 ithread_get_mutex_lock_size(void)
72
8
{
73
8
    return sizeof(pthread_mutex_t);
74
8
}
75
76
77
WORD32 ithread_create(void *thread_handle, void *attribute, void *strt, void *argument)
78
22
{
79
22
    UNUSED(attribute);
80
22
    return pthread_create((pthread_t *)thread_handle, NULL,(void *(*)(void *)) strt, argument);
81
22
}
82
83
WORD32 ithread_join(void *thread_handle, void ** val_ptr)
84
22
{
85
22
    UNUSED(val_ptr);
86
22
    pthread_t *pthread_handle   = (pthread_t *)thread_handle;
87
22
    return pthread_join(*pthread_handle, NULL);
88
22
}
89
90
WORD32 ithread_get_mutex_struct_size(void)
91
0
{
92
0
    return(sizeof(pthread_mutex_t));
93
0
}
94
WORD32 ithread_mutex_init(void *mutex)
95
2
{
96
2
    return pthread_mutex_init((pthread_mutex_t *) mutex, NULL);
97
2
}
98
99
WORD32 ithread_mutex_destroy(void *mutex)
100
0
{
101
0
    return pthread_mutex_destroy((pthread_mutex_t *) mutex);
102
0
}
103
104
WORD32 ithread_mutex_lock(void *mutex)
105
91
{
106
91
    return pthread_mutex_lock((pthread_mutex_t *)mutex);
107
91
}
108
109
WORD32 ithread_mutex_unlock(void *mutex)
110
91
{
111
91
    return pthread_mutex_unlock((pthread_mutex_t *)mutex);
112
91
}
113
114
void ithread_yield(void)
115
3.56k
{
116
3.56k
    sched_yield();
117
3.56k
}
118
119
void ithread_sleep(UWORD32 u4_time)
120
0
{
121
0
    usleep(u4_time * 1000 * 1000);
122
0
}
123
124
void ithread_msleep(UWORD32 u4_time_ms)
125
0
{
126
0
    usleep(u4_time_ms * 1000);
127
0
}
128
129
void ithread_usleep(UWORD32 u4_time_us)
130
0
{
131
0
    usleep(u4_time_us);
132
0
}
133
134
UWORD32 ithread_get_sem_struct_size(void)
135
0
{
136
0
    return(sizeof(sem_t));
137
0
}
138
139
140
WORD32 ithread_sem_init(void *sem,WORD32 pshared,UWORD32 value)
141
0
{
142
0
    return sem_init((sem_t *)sem,pshared,value);
143
0
}
144
145
WORD32 ithread_sem_post(void *sem)
146
0
{
147
0
    return sem_post((sem_t *)sem);
148
0
}
149
150
151
WORD32 ithread_sem_wait(void *sem)
152
0
{
153
0
    return sem_wait((sem_t *)sem);
154
0
}
155
156
157
WORD32 ithread_sem_destroy(void *sem)
158
0
{
159
0
    return sem_destroy((sem_t *)sem);
160
0
}
161
162
void ithread_set_name(CHAR *pc_thread_name)
163
35
{
164
35
165
35
#ifndef WIN32
166
35
#ifndef QNX
167
35
#ifndef IOS
168
35
    UNUSED(pc_thread_name);
169
35
//prctl(PR_SET_NAME, (unsigned long)pu1_thread_name, 0, 0, 0);
170
35
#endif
171
35
#endif
172
35
#endif
173
35
174
35
}
175
WORD32 ithread_set_affinity(WORD32 core_id)
176
0
{
177
#ifdef PTHREAD_AFFINITY
178
    cpu_set_t cpuset;
179
    int num_cores = sysconf(_SC_NPROCESSORS_ONLN);
180
    pthread_t cur_thread = pthread_self();
181
182
    if (core_id >= num_cores)
183
        return -1;
184
185
    CPU_ZERO(&cpuset);
186
    CPU_SET(core_id, &cpuset);
187
188
    return pthread_setaffinity_np(cur_thread, sizeof(cpu_set_t), &cpuset);
189
190
#elif SYSCALL_AFFINITY
191
    WORD32 i4_sys_res;
192
    UNUSED(core_id);
193
194
    pid_t pid = gettid();
195
196
197
    i4_sys_res = syscall(__NR_sched_setaffinity, pid, sizeof(i4_mask), &i4_mask);
198
    if (i4_sys_res)
199
    {
200
        //WORD32 err;
201
        //err = errno;
202
        //perror("Error in setaffinity syscall PERROR : ");
203
        //LOG_ERROR("Error in the syscall setaffinity: mask=0x%x err=0x%x", i4_mask, i4_sys_res);
204
        return -1;
205
    }
206
#else
207
0
    UNUSED(core_id);
208
0
#endif
209
0
    return 1;
210
0
211
0
}
/proc/self/cwd/external/libavc/common/x86/ih264_chroma_intra_pred_filters_ssse3.c
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/**
21
*******************************************************************************
22
* @file
23
*  ih264_chroma_intra_pred_filters_ssse3.c
24
*
25
* @brief
26
*  Contains function definitions for chroma intra prediction filters in x86
27
*  intrinsics
28
*
29
* @author
30
*  Ittiam
31
*
32
* @par List of Functions:
33
*  -ih264_intra_pred_chroma_8x8_mode_horz_ssse3
34
*  -ih264_intra_pred_chroma_8x8_mode_vert_ssse3
35
*  -ih264_intra_pred_chroma_8x8_mode_plane_ssse3
36
*
37
* @remarks
38
*  None
39
*
40
*******************************************************************************
41
*/
42
43
/*****************************************************************************/
44
/* File Includes                                                             */
45
/*****************************************************************************/
46
47
/* System include files */
48
#include <stdio.h>
49
#include <stddef.h>
50
#include <string.h>
51
52
/* User include files */
53
#include "ih264_defs.h"
54
#include "ih264_typedefs.h"
55
#include "ih264_macros.h"
56
#include "ih264_platform_macros.h"
57
#include "ih264_intra_pred_filters.h"
58
59
60
/*****************************************************************************/
61
/* Chroma Intra prediction 8x8 filters                                       */
62
/*****************************************************************************/
63
/**
64
*******************************************************************************
65
*
66
* ih264_intra_pred_chroma_8x8_mode_horz_ssse3
67
*
68
* @brief
69
*  Perform Intra prediction for chroma_8x8 mode:Horizontal
70
*
71
* @par Description:
72
*  Perform Intra prediction for chroma_8x8 mode:Horizontal ,described in sec 8.3.4.2
73
*
74
* @param[in] pu1_src
75
*  UWORD8 pointer to the source containing alternate U and V samples
76
*
77
* @param[out] pu1_dst
78
*  UWORD8 pointer to the destination with alternate U and V samples
79
*
80
* @param[in] src_strd
81
*  integer source stride
82
*
83
* @param[in] dst_strd
84
*  integer destination stride
85
*
86
* @param[in] ngbr_avail
87
* availability of neighbouring pixels(Not used in this function)
88
*
89
* @returns
90
*
91
* @remarks
92
*  None
93
*
94
******************************************************************************
95
*/
96
void ih264_intra_pred_chroma_8x8_mode_horz_ssse3(UWORD8 *pu1_src,
97
                                                 UWORD8 *pu1_dst,
98
                                                 WORD32 src_strd,
99
                                                 WORD32 dst_strd,
100
                                                 WORD32 ngbr_avail)
101
1.01k
{
102
1.01k
103
1.01k
    UWORD8 *pu1_left; /* Pointer to start of top predictors */
104
1.01k
    WORD32 dst_strd2;
105
1.01k
106
1.01k
    __m128i row1_16x8b, row2_16x8b;
107
1.01k
108
1.01k
    UNUSED(src_strd);
109
1.01k
    UNUSED(ngbr_avail);
110
1.01k
111
1.01k
    pu1_left = pu1_src + 2 * BLK8x8SIZE - 2;
112
1.01k
113
1.01k
114
1.01k
    dst_strd2 = dst_strd << 1;
115
1.01k
    row1_16x8b = _mm_set1_epi16(*((WORD16 *)(pu1_left)));
116
1.01k
    row2_16x8b = _mm_set1_epi16(*((WORD16 *)(pu1_left - 2)));
117
1.01k
    _mm_storeu_si128((__m128i *)pu1_dst, row1_16x8b);
118
1.01k
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), row2_16x8b);
119
1.01k
120
1.01k
    pu1_dst += dst_strd2;
121
1.01k
    row1_16x8b = _mm_set1_epi16(*((WORD16 *)(pu1_left - 4)));
122
1.01k
    row2_16x8b = _mm_set1_epi16(*((WORD16 *)(pu1_left - 6)));
123
1.01k
    _mm_storeu_si128((__m128i *)pu1_dst, row1_16x8b);
124
1.01k
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), row2_16x8b);
125
1.01k
126
1.01k
    pu1_dst += dst_strd2;
127
1.01k
    row1_16x8b = _mm_set1_epi16(*((WORD16 *)(pu1_left - 8)));
128
1.01k
    row2_16x8b = _mm_set1_epi16(*((WORD16 *)(pu1_left - 10)));
129
1.01k
    _mm_storeu_si128((__m128i *)pu1_dst, row1_16x8b);
130
1.01k
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), row2_16x8b);
131
1.01k
132
1.01k
    pu1_dst += dst_strd2;
133
1.01k
    row1_16x8b = _mm_set1_epi16(*((WORD16 *)(pu1_left - 12)));
134
1.01k
    row2_16x8b = _mm_set1_epi16(*((WORD16 *)(pu1_left - 14)));
135
1.01k
    _mm_storeu_si128((__m128i *)pu1_dst, row1_16x8b);
136
1.01k
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), row2_16x8b);
137
1.01k
}
138
139
/**
140
*******************************************************************************
141
*
142
* ih264_intra_pred_chroma_8x8_mode_vert_ssse3
143
*
144
* @brief
145
*  Perform Intra prediction for  chroma_8x8 mode:vertical
146
*
147
* @par Description:
148
*  Perform Intra prediction for  chroma_8x8 mode:vertical ,described in sec 8.3.4.3
149
*
150
* @param[in] pu1_src
151
*  UWORD8 pointer to the source containing alternate U and V samples
152
*
153
* @param[out] pu1_dst
154
*  UWORD8 pointer to the destination with alternate U and V samples
155
*
156
* @param[in] src_strd
157
*  integer source stride
158
*
159
* @param[in] dst_strd
160
*  integer destination stride
161
*
162
* @param[in] ngbr_avail
163
* availability of neighbouring pixels(Not used in this function)
164
*
165
* @returns
166
*
167
* @remarks
168
*  None
169
*
170
*******************************************************************************
171
*/
172
void ih264_intra_pred_chroma_8x8_mode_vert_ssse3(UWORD8 *pu1_src,
173
                                                 UWORD8 *pu1_dst,
174
                                                 WORD32 src_strd,
175
                                                 WORD32 dst_strd,
176
                                                 WORD32 ngbr_avail)
177
1.49k
{
178
1.49k
    UWORD8 *pu1_top; /* Pointer to start of top predictors */
179
1.49k
    WORD32 dst_strd2;
180
1.49k
181
1.49k
    __m128i top_16x8b;
182
1.49k
183
1.49k
    UNUSED(src_strd);
184
1.49k
    UNUSED(ngbr_avail);
185
1.49k
186
1.49k
    pu1_top = pu1_src + 2 * BLK8x8SIZE + 2;
187
1.49k
188
1.49k
    top_16x8b = _mm_loadu_si128((__m128i *)pu1_top);
189
1.49k
190
1.49k
    dst_strd2 = dst_strd << 1;
191
1.49k
    _mm_storeu_si128((__m128i *)pu1_dst, top_16x8b);
192
1.49k
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), top_16x8b);
193
1.49k
194
1.49k
    pu1_dst += dst_strd2;
195
1.49k
    _mm_storeu_si128((__m128i *)pu1_dst, top_16x8b);
196
1.49k
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), top_16x8b);
197
1.49k
198
1.49k
    pu1_dst += dst_strd2;
199
1.49k
    _mm_storeu_si128((__m128i *)pu1_dst, top_16x8b);
200
1.49k
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), top_16x8b);
201
1.49k
202
1.49k
    pu1_dst += dst_strd2;
203
1.49k
    _mm_storeu_si128((__m128i *)pu1_dst, top_16x8b);
204
1.49k
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), top_16x8b);
205
1.49k
}
206
207
/**
208
*******************************************************************************
209
*
210
* ih264_intra_pred_chroma_8x8_mode_plane_ssse3
211
*
212
* @brief
213
*  Perform Intra prediction for chroma_8x8 mode:PLANE
214
*
215
* @par Description:
216
*  Perform Intra prediction for chroma_8x8 mode:PLANE ,described in sec 8.3.4.4
217
*
218
* @param[in] pu1_src
219
*  UWORD8 pointer to the source containing alternate U and V samples
220
*
221
* @param[out] pu1_dst
222
*  UWORD8 pointer to the destination with alternate U and V samples
223
*
224
* @param[in] src_strd
225
*  integer source stride
226
*
227
* @param[in] dst_strd
228
*  integer destination stride
229
*
230
* @param[in] ngbr_avail
231
* availability of neighbouring pixels(Not used in this function)
232
*
233
* @returns
234
*
235
* @remarks
236
*  None
237
*
238
******************************************************************************
239
*/
240
void ih264_intra_pred_chroma_8x8_mode_plane_ssse3(UWORD8 *pu1_src,
241
                                                  UWORD8 *pu1_dst,
242
                                                  WORD32 src_strd,
243
                                                  WORD32 dst_strd,
244
                                                  WORD32 ngbr_avail)
245
99
{
246
99
    UWORD8 *pu1_left, *pu1_top;
247
99
    WORD32 a_u, a_v, b_u, b_v, c_u, c_v;
248
99
249
99
    __m128i mul_8x16b, shuffle_8x16b;
250
99
251
99
    UNUSED(src_strd);
252
99
    UNUSED(ngbr_avail);
253
99
254
99
    pu1_top = pu1_src + MB_SIZE + 2;
255
99
    pu1_left = pu1_src + MB_SIZE - 2;
256
99
257
99
    mul_8x16b = _mm_setr_epi16(1, 2, 3, 4, 1, 2, 3, 4);
258
99
    shuffle_8x16b = _mm_setr_epi16(0xff00, 0xff02, 0xff04, 0xff06,
259
99
                                   0xff01, 0xff03, 0xff05, 0xff07);
260
99
261
99
    //calculating a, b and c
262
99
    {
263
99
        WORD32 h_u, h_v, v_u, v_v;
264
99
265
99
        __m128i h_val1_16x8b, h_val2_16x8b;
266
99
        __m128i h_val1_8x16b, h_val2_8x16b, h_val_4x32b;
267
99
        __m128i v_val1_16x8b, v_val2_16x8b;
268
99
        __m128i v_val1_8x16b, v_val2_8x16b, v_val_4x32b;
269
99
        __m128i hv_val_4x32b;
270
99
271
99
        h_val1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_top + 8));
272
99
        h_val2_16x8b = _mm_loadl_epi64((__m128i *)(pu1_top - 2));
273
99
        v_val1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_left - 14));
274
99
        v_val2_16x8b = _mm_loadl_epi64((__m128i *)(pu1_left - 4));
275
99
276
99
        // reversing the order
277
99
        h_val2_16x8b = _mm_shufflelo_epi16(h_val2_16x8b, 0x1b);
278
99
        v_val1_16x8b = _mm_shufflelo_epi16(v_val1_16x8b, 0x1b);
279
99
280
99
        // separating u and v and 8-bit to 16-bit conversion
281
99
        h_val1_8x16b = _mm_shuffle_epi8(h_val1_16x8b, shuffle_8x16b);
282
99
        h_val2_8x16b = _mm_shuffle_epi8(h_val2_16x8b, shuffle_8x16b);
283
99
        v_val1_8x16b = _mm_shuffle_epi8(v_val1_16x8b, shuffle_8x16b);
284
99
        v_val2_8x16b = _mm_shuffle_epi8(v_val2_16x8b, shuffle_8x16b);
285
99
286
99
        h_val1_8x16b = _mm_sub_epi16(h_val1_8x16b, h_val2_8x16b);
287
99
        v_val1_8x16b = _mm_sub_epi16(v_val1_8x16b, v_val2_8x16b);
288
99
289
99
        h_val_4x32b = _mm_madd_epi16(mul_8x16b, h_val1_8x16b);
290
99
        v_val_4x32b = _mm_madd_epi16(mul_8x16b, v_val1_8x16b);
291
99
292
99
        hv_val_4x32b = _mm_hadd_epi32(h_val_4x32b, v_val_4x32b);
293
99
294
99
        a_u = (pu1_left[7 * (-2)] + pu1_top[14]) << 4;
295
99
        a_v = (pu1_left[7 * (-2) + 1] + pu1_top[15]) << 4;
296
99
297
99
        h_u = _mm_extract_epi16(hv_val_4x32b, 0);
298
99
        h_v = _mm_extract_epi16(hv_val_4x32b, 2);
299
99
        v_u = _mm_extract_epi16(hv_val_4x32b, 4);
300
99
        v_v = _mm_extract_epi16(hv_val_4x32b, 6);
301
99
302
99
        h_u = (h_u << 16) >> 15; // sign-extension and multiplication by 2
303
99
        h_v = (h_v << 16) >> 15;
304
99
        v_u = (v_u << 16) >> 15;
305
99
        v_v = (v_v << 16) >> 15;
306
99
307
99
        b_u = ((h_u << 4) + h_u + 32) >> 6;
308
99
        b_v = ((h_v << 4) + h_v + 32) >> 6;
309
99
        c_u = ((v_u << 4) + v_u + 32) >> 6;
310
99
        c_v = ((v_v << 4) + v_v + 32) >> 6;
311
99
    }
312
99
    //using a, b and c to compute the fitted plane values
313
99
    {
314
99
        __m128i const_8x16b, c2_8x16b;
315
99
        __m128i res1_l_8x16b, res1_h_8x16b;
316
99
        __m128i res2_l_8x16b, res2_h_8x16b;
317
99
        __m128i res1_sh_l_8x16b, res1_sh_h_8x16b, res1_16x8b;
318
99
        __m128i res2_sh_l_8x16b, res2_sh_h_8x16b, res2_16x8b;
319
99
320
99
        WORD32 b_u2, b_v2, b_u3, b_v3;
321
99
        WORD32 const_u, const_v;
322
99
        WORD32 dst_strd2;
323
99
324
99
        const_u = a_u - (c_u << 1) - c_u + 16;
325
99
        const_v = a_v - (c_v << 1) - c_v + 16;
326
99
327
99
        b_u2 = b_u << 1;
328
99
        b_v2 = b_v << 1;
329
99
        b_u3 = b_u + b_u2;
330
99
        b_v3 = b_v + b_v2;
331
99
332
99
        const_8x16b = _mm_setr_epi16(const_u, const_v, const_u, const_v, const_u, const_v, const_u, const_v);
333
99
        res1_l_8x16b = _mm_setr_epi16(-b_u3, -b_v3, -b_u2, -b_v2, -b_u, -b_v, 0, 0);
334
99
        //contains {-b*3, -b*2, -b*1, b*0}
335
99
        res1_h_8x16b = _mm_setr_epi16(b_u, b_v, b_u2, b_v2, b_u3, b_v3, b_u << 2, b_v << 2);
336
99
        //contains {b*1, b*2, b*3, b*4}
337
99
        c2_8x16b = _mm_setr_epi16(c_u, c_v, c_u, c_v, c_u, c_v, c_u, c_v);
338
99
339
99
        // rows 1, 2
340
99
        res1_l_8x16b = _mm_add_epi16(res1_l_8x16b, const_8x16b);
341
99
        res1_h_8x16b = _mm_add_epi16(res1_h_8x16b, const_8x16b);
342
99
        res2_l_8x16b = _mm_add_epi16(res1_l_8x16b, c2_8x16b);
343
99
        res2_h_8x16b = _mm_add_epi16(res1_h_8x16b, c2_8x16b);
344
99
345
99
        res1_sh_l_8x16b = _mm_srai_epi16(res1_l_8x16b, 5);
346
99
        res1_sh_h_8x16b = _mm_srai_epi16(res1_h_8x16b, 5);
347
99
        res2_sh_l_8x16b = _mm_srai_epi16(res2_l_8x16b, 5);
348
99
        res2_sh_h_8x16b = _mm_srai_epi16(res2_h_8x16b, 5);
349
99
350
99
        dst_strd2 = dst_strd << 1;
351
99
        c2_8x16b = _mm_slli_epi16(c2_8x16b, 1);
352
99
353
99
        res1_16x8b = _mm_packus_epi16(res1_sh_l_8x16b, res1_sh_h_8x16b);
354
99
        res2_16x8b = _mm_packus_epi16(res2_sh_l_8x16b, res2_sh_h_8x16b);
355
99
356
99
        _mm_storeu_si128((__m128i *)pu1_dst, res1_16x8b);
357
99
        _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), res2_16x8b);
358
99
359
99
        // rows 3, 4
360
99
        res1_l_8x16b = _mm_add_epi16(res1_l_8x16b, c2_8x16b);
361
99
        res1_h_8x16b = _mm_add_epi16(res1_h_8x16b, c2_8x16b);
362
99
        res2_l_8x16b = _mm_add_epi16(res2_l_8x16b, c2_8x16b);
363
99
        res2_h_8x16b = _mm_add_epi16(res2_h_8x16b, c2_8x16b);
364
99
365
99
        res1_sh_l_8x16b = _mm_srai_epi16(res1_l_8x16b, 5);
366
99
        res1_sh_h_8x16b = _mm_srai_epi16(res1_h_8x16b, 5);
367
99
        res2_sh_l_8x16b = _mm_srai_epi16(res2_l_8x16b, 5);
368
99
        res2_sh_h_8x16b = _mm_srai_epi16(res2_h_8x16b, 5);
369
99
370
99
        pu1_dst += dst_strd2;
371
99
372
99
        res1_16x8b = _mm_packus_epi16(res1_sh_l_8x16b, res1_sh_h_8x16b);
373
99
        res2_16x8b = _mm_packus_epi16(res2_sh_l_8x16b, res2_sh_h_8x16b);
374
99
375
99
        _mm_storeu_si128((__m128i *)pu1_dst, res1_16x8b);
376
99
        _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), res2_16x8b);
377
99
378
99
        // rows 5, 6
379
99
        res1_l_8x16b = _mm_add_epi16(res1_l_8x16b, c2_8x16b);
380
99
        res1_h_8x16b = _mm_add_epi16(res1_h_8x16b, c2_8x16b);
381
99
        res2_l_8x16b = _mm_add_epi16(res2_l_8x16b, c2_8x16b);
382
99
        res2_h_8x16b = _mm_add_epi16(res2_h_8x16b, c2_8x16b);
383
99
384
99
        res1_sh_l_8x16b = _mm_srai_epi16(res1_l_8x16b, 5);
385
99
        res1_sh_h_8x16b = _mm_srai_epi16(res1_h_8x16b, 5);
386
99
        res2_sh_l_8x16b = _mm_srai_epi16(res2_l_8x16b, 5);
387
99
        res2_sh_h_8x16b = _mm_srai_epi16(res2_h_8x16b, 5);
388
99
389
99
        pu1_dst += dst_strd2;
390
99
391
99
        res1_16x8b = _mm_packus_epi16(res1_sh_l_8x16b, res1_sh_h_8x16b);
392
99
        res2_16x8b = _mm_packus_epi16(res2_sh_l_8x16b, res2_sh_h_8x16b);
393
99
394
99
        _mm_storeu_si128((__m128i *)pu1_dst, res1_16x8b);
395
99
        _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), res2_16x8b);
396
99
397
99
        // rows 7, 8
398
99
        res1_l_8x16b = _mm_add_epi16(res1_l_8x16b, c2_8x16b);
399
99
        res1_h_8x16b = _mm_add_epi16(res1_h_8x16b, c2_8x16b);
400
99
        res2_l_8x16b = _mm_add_epi16(res2_l_8x16b, c2_8x16b);
401
99
        res2_h_8x16b = _mm_add_epi16(res2_h_8x16b, c2_8x16b);
402
99
403
99
        res1_sh_l_8x16b = _mm_srai_epi16(res1_l_8x16b, 5);
404
99
        res1_sh_h_8x16b = _mm_srai_epi16(res1_h_8x16b, 5);
405
99
        res2_sh_l_8x16b = _mm_srai_epi16(res2_l_8x16b, 5);
406
99
        res2_sh_h_8x16b = _mm_srai_epi16(res2_h_8x16b, 5);
407
99
408
99
        pu1_dst += dst_strd2;
409
99
410
99
        res1_16x8b = _mm_packus_epi16(res1_sh_l_8x16b, res1_sh_h_8x16b);
411
99
        res2_16x8b = _mm_packus_epi16(res2_sh_l_8x16b, res2_sh_h_8x16b);
412
99
413
99
        _mm_storeu_si128((__m128i *)pu1_dst, res1_16x8b);
414
99
        _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), res2_16x8b);
415
99
416
99
    }
417
99
}
/proc/self/cwd/external/libavc/common/x86/ih264_deblk_chroma_ssse3.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/*****************************************************************************/
21
/*                                                                           */
22
/*  File Name         : ih264_deblk_chroma_ssse3.c                           */
23
/*                                                                           */
24
/*  Description       : Contains function definitions for deblocking         */
25
/*                                                                           */
26
/*  List of Functions : ih264_deblk_chroma_vert_bs4_ssse3()                  */
27
/*                      ih264_deblk_chroma_horz_bs4_ssse3()                  */
28
/*                      ih264_deblk_chroma_vert_bslt4_ssse3()                */
29
/*                      ih264_deblk_chroma_horz_bslt4_ssse3()                */
30
/*                      ih264_deblk_chroma_vert_bs4_mbaff_ssse3()            */
31
/*                      ih264_deblk_chroma_vert_bslt4_mbaff_ssse3()          */
32
/*                                                                           */
33
/*  Issues / Problems : None                                                 */
34
/*                                                                           */
35
/*  Revision History  :                                                      */
36
/*                                                                           */
37
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
38
/*         12 02 2015   Naveen Kumar P  Added chrom deblocking ssse3         */
39
/*                                      intrinsics                           */
40
/*                                                                           */
41
/*****************************************************************************/
42
43
/*****************************************************************************/
44
/* File Includes                                                             */
45
/*****************************************************************************/
46
47
/* System include files */
48
#include <stdio.h>
49
50
/* User include files */
51
#include "ih264_typedefs.h"
52
#include "ih264_platform_macros.h"
53
#include "ih264_deblk_edge_filters.h"
54
#include "ih264_macros.h"
55
56
/*****************************************************************************/
57
/* Function Definitions                                                      */
58
/*****************************************************************************/
59
60
/*****************************************************************************/
61
/*                                                                           */
62
/*  Function Name : ih264_deblk_chroma_vert_bs4_ssse3()                      */
63
/*                                                                           */
64
/*  Description   : This function performs filtering of a chroma block       */
65
/*                  vertical edge when the boundary strength is set to 4 in  */
66
/*                  high profile.                                            */
67
/*                                                                           */
68
/*  Inputs        : pu1_src    - pointer to the src sample q0 of U           */
69
/*                  src_strd   - source stride                               */
70
/*                  alpha_cb   - alpha value for the boundary in U           */
71
/*                  beta_cb    - beta value for the boundary in U            */
72
/*                  alpha_cr   - alpha value for the boundary in V           */
73
/*                  beta_cr    - beta value for the boundary in V            */
74
/*                                                                           */
75
/*  Globals       : None                                                     */
76
/*                                                                           */
77
/*  Processing    : This operation is described in Sec. 8.7.2.4 under the    */
78
/*                  title "Filtering process for edges for bS equal to 4" in */
79
/*                  ITU T Rec H.264 with alpha and beta values different in  */
80
/*                  U and V.                                                 */
81
/*                                                                           */
82
/*  Outputs       : None                                                     */
83
/*                                                                           */
84
/*  Returns       : None                                                     */
85
/*                                                                           */
86
/*  Issues        : None                                                     */
87
/*                                                                           */
88
/*  Revision History:                                                        */
89
/*                                                                           */
90
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
91
/*         12 02 2015   Naveen Kumar P  Initial version                      */
92
/*                                                                           */
93
/*****************************************************************************/
94
void ih264_deblk_chroma_vert_bs4_ssse3(UWORD8 *pu1_src,
95
                                       WORD32 src_strd,
96
                                       WORD32 alpha_cb,
97
                                       WORD32 beta_cb,
98
                                       WORD32 alpha_cr,
99
                                       WORD32 beta_cr)
100
4.84k
{
101
4.84k
    UWORD8 *pu1_src_uv = pu1_src; /* Pointer to the src sample q0 of plane U*/
102
4.84k
    WORD32 alpha_cbcr = (alpha_cr << 16) + alpha_cb;
103
4.84k
    WORD32 beta_cbcr = (beta_cr << 16) + beta_cb;
104
4.84k
    __m128i linea, lineb, linec, lined, linee, linef, lineg, lineh;
105
4.84k
    __m128i temp1, temp2, temp3, temp4;
106
4.84k
107
4.84k
    __m128i q0_uv_16x8, p0_uv_16x8, q1_uv_16x8, p1_uv_16x8;
108
4.84k
    __m128i q0_uv_8x16, p0_uv_8x16, q1_uv_8x16, p1_uv_8x16;
109
4.84k
    __m128i flag1, flag2;
110
4.84k
    __m128i diff, alpha_cbcr_16x8, beta_cbcr_16x8;
111
4.84k
    __m128i zero = _mm_setzero_si128();
112
4.84k
    __m128i p0_uv_8x16_1, p0_uv_8x16_2, q0_uv_8x16_1, q0_uv_8x16_2;
113
4.84k
114
4.84k
    /* Load and transpose the pixel values */
115
4.84k
    linea = _mm_loadl_epi64((__m128i *)(pu1_src_uv - 4));
116
4.84k
    lineb = _mm_loadl_epi64((__m128i *)(pu1_src_uv - 4 + src_strd));
117
4.84k
    linec = _mm_loadl_epi64((__m128i *)(pu1_src_uv - 4 + 2 * src_strd));
118
4.84k
    lined = _mm_loadl_epi64((__m128i *)(pu1_src_uv - 4 + 3 * src_strd));
119
4.84k
    linee = _mm_loadl_epi64((__m128i *)(pu1_src_uv - 4 + 4 * src_strd));
120
4.84k
    linef = _mm_loadl_epi64((__m128i *)(pu1_src_uv - 4 + 5 * src_strd));
121
4.84k
    lineg = _mm_loadl_epi64((__m128i *)(pu1_src_uv - 4 + 6 * src_strd));
122
4.84k
    lineh = _mm_loadl_epi64((__m128i *)(pu1_src_uv - 4 + 7 * src_strd));
123
4.84k
124
4.84k
    temp1 = _mm_unpacklo_epi16(linea, lineb);
125
4.84k
    temp2 = _mm_unpacklo_epi16(linec, lined);
126
4.84k
    temp3 = _mm_unpacklo_epi16(linee, linef);
127
4.84k
    temp4 = _mm_unpacklo_epi16(lineg, lineh);
128
4.84k
129
4.84k
    p1_uv_8x16 = _mm_unpacklo_epi32(temp1, temp2);
130
4.84k
    p0_uv_8x16 = _mm_unpacklo_epi32(temp3, temp4);
131
4.84k
    q0_uv_8x16 = _mm_unpackhi_epi32(temp1, temp2);
132
4.84k
    q1_uv_8x16 = _mm_unpackhi_epi32(temp3, temp4);
133
4.84k
134
4.84k
    p1_uv_16x8 = _mm_unpacklo_epi64(p1_uv_8x16, p0_uv_8x16);
135
4.84k
    p0_uv_16x8 = _mm_unpackhi_epi64(p1_uv_8x16, p0_uv_8x16);
136
4.84k
    q0_uv_16x8 = _mm_unpacklo_epi64(q0_uv_8x16, q1_uv_8x16);
137
4.84k
    q1_uv_16x8 = _mm_unpackhi_epi64(q0_uv_8x16, q1_uv_8x16);
138
4.84k
    /* End of transpose */
139
4.84k
140
4.84k
    q0_uv_8x16 = _mm_unpacklo_epi8(q0_uv_16x8, zero);
141
4.84k
    q1_uv_8x16 = _mm_unpacklo_epi8(q1_uv_16x8, zero);
142
4.84k
    p1_uv_8x16 = _mm_unpacklo_epi8(p1_uv_16x8, zero);
143
4.84k
    p0_uv_8x16 = _mm_unpacklo_epi8(p0_uv_16x8, zero);
144
4.84k
145
4.84k
    diff = _mm_subs_epi16(p0_uv_8x16, q0_uv_8x16); //Condn 1
146
4.84k
    diff = _mm_abs_epi16(diff);
147
4.84k
    alpha_cbcr_16x8 = _mm_set1_epi32(alpha_cbcr);
148
4.84k
    flag1 = _mm_cmpgt_epi16(alpha_cbcr_16x8, diff);
149
4.84k
150
4.84k
    diff = _mm_subs_epi16(q1_uv_8x16, q0_uv_8x16); //Condtn 2
151
4.84k
    diff = _mm_abs_epi16(diff);
152
4.84k
    beta_cbcr_16x8 = _mm_set1_epi32(beta_cbcr);
153
4.84k
    flag1 = _mm_and_si128(flag1, _mm_cmpgt_epi16(beta_cbcr_16x8, diff));
154
4.84k
155
4.84k
    diff = _mm_subs_epi16(p1_uv_8x16, p0_uv_8x16); //Condtn 3
156
4.84k
    diff = _mm_abs_epi16(diff);
157
4.84k
    flag1 = _mm_and_si128(flag1, _mm_cmpgt_epi16(beta_cbcr_16x8, diff));
158
4.84k
159
4.84k
    temp1 = _mm_slli_epi16(p1_uv_8x16, 1);
160
4.84k
    temp2 = _mm_add_epi16(p0_uv_8x16, q1_uv_8x16);
161
4.84k
    temp1 = _mm_add_epi16(temp1, _mm_set1_epi16(2));
162
4.84k
    temp1 = _mm_add_epi16(temp1, temp2);
163
4.84k
    p0_uv_8x16_1 = _mm_srai_epi16(temp1, 2);
164
4.84k
165
4.84k
    temp1 = _mm_slli_epi16(q1_uv_8x16, 1);
166
4.84k
    temp2 = _mm_add_epi16(p1_uv_8x16, q0_uv_8x16);
167
4.84k
    temp1 = _mm_add_epi16(temp1, _mm_set1_epi16(2));
168
4.84k
    temp1 = _mm_add_epi16(temp1, temp2);
169
4.84k
    q0_uv_8x16_1 = _mm_srai_epi16(temp1, 2);
170
4.84k
171
4.84k
    q0_uv_8x16 = _mm_unpackhi_epi8(q0_uv_16x8, zero);
172
4.84k
    q1_uv_8x16 = _mm_unpackhi_epi8(q1_uv_16x8, zero);
173
4.84k
    p1_uv_8x16 = _mm_unpackhi_epi8(p1_uv_16x8, zero);
174
4.84k
    p0_uv_8x16 = _mm_unpackhi_epi8(p0_uv_16x8, zero);
175
4.84k
176
4.84k
    diff = _mm_subs_epi16(p0_uv_8x16, q0_uv_8x16); //Condn 1
177
4.84k
    diff = _mm_abs_epi16(diff);
178
4.84k
    alpha_cbcr_16x8 = _mm_set1_epi32(alpha_cbcr);
179
4.84k
    flag2 = _mm_cmpgt_epi16(alpha_cbcr_16x8, diff);
180
4.84k
181
4.84k
    diff = _mm_subs_epi16(q1_uv_8x16, q0_uv_8x16); //Condtn 2
182
4.84k
    diff = _mm_abs_epi16(diff);
183
4.84k
    beta_cbcr_16x8 = _mm_set1_epi32(beta_cbcr);
184
4.84k
    flag2 = _mm_and_si128(flag2, _mm_cmpgt_epi16(beta_cbcr_16x8, diff));
185
4.84k
186
4.84k
    diff = _mm_subs_epi16(p1_uv_8x16, p0_uv_8x16); //Condtn 3
187
4.84k
    diff = _mm_abs_epi16(diff);
188
4.84k
    flag2 = _mm_and_si128(flag2, _mm_cmpgt_epi16(beta_cbcr_16x8, diff));
189
4.84k
190
4.84k
    temp1 = _mm_slli_epi16(p1_uv_8x16, 1);
191
4.84k
    temp2 = _mm_add_epi16(p0_uv_8x16, q1_uv_8x16);
192
4.84k
    temp1 = _mm_add_epi16(temp1, _mm_set1_epi16(2));
193
4.84k
    temp1 = _mm_add_epi16(temp1, temp2);
194
4.84k
    p0_uv_8x16_2 = _mm_srai_epi16(temp1, 2);
195
4.84k
196
4.84k
    temp1 = _mm_slli_epi16(q1_uv_8x16, 1);
197
4.84k
    temp2 = _mm_add_epi16(p1_uv_8x16, q0_uv_8x16);
198
4.84k
    temp1 = _mm_add_epi16(temp1, _mm_set1_epi16(2));
199
4.84k
    temp1 = _mm_add_epi16(temp1, temp2);
200
4.84k
    q0_uv_8x16_2 = _mm_srai_epi16(temp1, 2);
201
4.84k
202
4.84k
    p0_uv_8x16_2 = _mm_packus_epi16(p0_uv_8x16_1, p0_uv_8x16_2);
203
4.84k
    q0_uv_8x16_2 = _mm_packus_epi16(q0_uv_8x16_1, q0_uv_8x16_2);
204
4.84k
205
4.84k
    flag1 = _mm_packs_epi16(flag1, flag2);
206
4.84k
207
4.84k
    p0_uv_8x16_1 = _mm_and_si128(p0_uv_16x8,
208
4.84k
                                 _mm_xor_si128(flag1, _mm_set1_epi8(0xFF)));
209
4.84k
    p0_uv_8x16_2 = _mm_and_si128(p0_uv_8x16_2, flag1);
210
4.84k
    p0_uv_16x8 = _mm_add_epi8(p0_uv_8x16_1, p0_uv_8x16_2);
211
4.84k
212
4.84k
    q0_uv_8x16_1 = _mm_and_si128(q0_uv_16x8,
213
4.84k
                                 _mm_xor_si128(flag1, _mm_set1_epi8(0xFF)));
214
4.84k
    q0_uv_8x16_2 = _mm_and_si128(q0_uv_8x16_2, flag1);
215
4.84k
    q0_uv_16x8 = _mm_add_epi8(q0_uv_8x16_1, q0_uv_8x16_2);
216
4.84k
217
4.84k
    /* Inverse-transpose and store back */
218
4.84k
    temp1 = _mm_unpacklo_epi16(p1_uv_16x8, p0_uv_16x8);
219
4.84k
    temp2 = _mm_unpackhi_epi16(p1_uv_16x8, p0_uv_16x8);
220
4.84k
    temp3 = _mm_unpacklo_epi16(q0_uv_16x8, q1_uv_16x8);
221
4.84k
    temp4 = _mm_unpackhi_epi16(q0_uv_16x8, q1_uv_16x8);
222
4.84k
223
4.84k
    linea = _mm_unpacklo_epi32(temp1, temp3);
224
4.84k
    lineb = _mm_srli_si128(linea, 8);
225
4.84k
    linec = _mm_unpackhi_epi32(temp1, temp3);
226
4.84k
    lined = _mm_srli_si128(linec, 8);
227
4.84k
    linee = _mm_unpacklo_epi32(temp2, temp4);
228
4.84k
    linef = _mm_srli_si128(linee, 8);
229
4.84k
    lineg = _mm_unpackhi_epi32(temp2, temp4);
230
4.84k
    lineh = _mm_srli_si128(lineg, 8);
231
4.84k
232
4.84k
    _mm_storel_epi64((__m128i *)(pu1_src_uv - 4), linea);
233
4.84k
    _mm_storel_epi64((__m128i *)(pu1_src_uv - 4 + src_strd), lineb);
234
4.84k
    _mm_storel_epi64((__m128i *)(pu1_src_uv - 4 + 2 * src_strd), linec);
235
4.84k
    _mm_storel_epi64((__m128i *)(pu1_src_uv - 4 + 3 * src_strd), lined);
236
4.84k
    _mm_storel_epi64((__m128i *)(pu1_src_uv - 4 + 4 * src_strd), linee);
237
4.84k
    _mm_storel_epi64((__m128i *)(pu1_src_uv - 4 + 5 * src_strd), linef);
238
4.84k
    _mm_storel_epi64((__m128i *)(pu1_src_uv - 4 + 6 * src_strd), lineg);
239
4.84k
    _mm_storel_epi64((__m128i *)(pu1_src_uv - 4 + 7 * src_strd), lineh);
240
4.84k
241
4.84k
}
242
243
/*****************************************************************************/
244
/*                                                                           */
245
/*  Function Name : ih264_deblk_chroma_horz_bs4_ssse3()                      */
246
/*                                                                           */
247
/*  Description   : This function performs filtering of a chroma block       */
248
/*                  horizontal edge when the boundary strength is set to 4   */
249
/*                  in high profile.                                         */
250
/*                                                                           */
251
/*  Inputs        : pu1_src    - pointer to the src sample q0 of U           */
252
/*                  src_strd   - source stride                               */
253
/*                  alpha_cb   - alpha value for the boundary in U           */
254
/*                  beta_cb    - beta value for the boundary in U            */
255
/*                  alpha_cr   - alpha value for the boundary in V           */
256
/*                  beta_cr    - beta value for the boundary in V            */
257
/*                                                                           */
258
/*  Globals       : None                                                     */
259
/*                                                                           */
260
/*  Processing    : This operation is described in Sec. 8.7.2.4 under the    */
261
/*                  title "Filtering process for edges for bS equal to 4" in */
262
/*                  ITU T Rec H.264 with alpha and beta values different in  */
263
/*                  U and V.                                                 */
264
/*                                                                           */
265
/*  Outputs       : None                                                     */
266
/*                                                                           */
267
/*  Returns       : None                                                     */
268
/*                                                                           */
269
/*  Issues        : None                                                     */
270
/*                                                                           */
271
/*  Revision History:                                                        */
272
/*                                                                           */
273
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
274
/*         12 02 2015   Naveen Kumar P  Initial version                      */
275
/*                                                                           */
276
/*****************************************************************************/
277
void ih264_deblk_chroma_horz_bs4_ssse3(UWORD8 *pu1_src,
278
                                       WORD32 src_strd,
279
                                       WORD32 alpha_cb,
280
                                       WORD32 beta_cb,
281
                                       WORD32 alpha_cr,
282
                                       WORD32 beta_cr)
283
4.80k
{
284
4.80k
    UWORD8 *pu1_src_uv = pu1_src; /* Pointer to the src sample q0 of plane U*/
285
4.80k
    WORD16 i16_posP1, i16_posP0, i16_posQ1;
286
4.80k
287
4.80k
    UWORD8 *pu1_HorzPixelUV; /*! < Pointer to the first pixel of the boundary */
288
4.80k
    WORD32 alpha_cbcr = (alpha_cr << 16) + alpha_cb;
289
4.80k
    WORD32 beta_cbcr = (beta_cr << 16) + beta_cb;
290
4.80k
    __m128i q0_uv_16x8, p0_uv_16x8, q1_uv_16x8, p1_uv_16x8;
291
4.80k
    __m128i q0_uv_8x16, p0_uv_8x16, q1_uv_8x16, p1_uv_8x16;
292
4.80k
    __m128i flag1, flag2;
293
4.80k
    __m128i diff, alpha_cbcr_16x8, beta_cbcr_16x8;
294
4.80k
    __m128i zero = _mm_setzero_si128();
295
4.80k
    __m128i p0_uv_8x16_1, p0_uv_8x16_2, q0_uv_8x16_1, q0_uv_8x16_2;
296
4.80k
    __m128i temp1, temp2;
297
4.80k
298
4.80k
    pu1_HorzPixelUV = pu1_src_uv - (src_strd << 1);
299
4.80k
300
4.80k
    i16_posQ1 = src_strd;
301
4.80k
    i16_posP0 = src_strd;
302
4.80k
    i16_posP1 = 0;
303
4.80k
304
4.80k
    q0_uv_16x8 = _mm_loadu_si128((__m128i *)(pu1_src_uv));
305
4.80k
    q1_uv_16x8 = _mm_loadu_si128((__m128i *)(pu1_src_uv + i16_posQ1));
306
4.80k
    p1_uv_16x8 = _mm_loadu_si128((__m128i *)(pu1_HorzPixelUV + i16_posP1));
307
4.80k
    p0_uv_16x8 = _mm_loadu_si128((__m128i *)(pu1_HorzPixelUV + i16_posP0));
308
4.80k
309
4.80k
    q0_uv_8x16 = _mm_unpacklo_epi8(q0_uv_16x8, zero);
310
4.80k
    q1_uv_8x16 = _mm_unpacklo_epi8(q1_uv_16x8, zero);
311
4.80k
    p1_uv_8x16 = _mm_unpacklo_epi8(p1_uv_16x8, zero);
312
4.80k
    p0_uv_8x16 = _mm_unpacklo_epi8(p0_uv_16x8, zero);
313
4.80k
314
4.80k
    diff = _mm_subs_epi16(p0_uv_8x16, q0_uv_8x16); //Condn 1
315
4.80k
    diff = _mm_abs_epi16(diff);
316
4.80k
    alpha_cbcr_16x8 = _mm_set1_epi32(alpha_cbcr);
317
4.80k
    flag1 = _mm_cmpgt_epi16(alpha_cbcr_16x8, diff);
318
4.80k
319
4.80k
    diff = _mm_subs_epi16(q1_uv_8x16, q0_uv_8x16); //Condtn 2
320
4.80k
    diff = _mm_abs_epi16(diff);
321
4.80k
    beta_cbcr_16x8 = _mm_set1_epi32(beta_cbcr);
322
4.80k
    flag1 = _mm_and_si128(flag1, _mm_cmpgt_epi16(beta_cbcr_16x8, diff));
323
4.80k
324
4.80k
    diff = _mm_subs_epi16(p1_uv_8x16, p0_uv_8x16); //Condtn 3
325
4.80k
    diff = _mm_abs_epi16(diff);
326
4.80k
    flag1 = _mm_and_si128(flag1, _mm_cmpgt_epi16(beta_cbcr_16x8, diff));
327
4.80k
328
4.80k
    temp1 = _mm_slli_epi16(p1_uv_8x16, 1);
329
4.80k
    temp2 = _mm_add_epi16(p0_uv_8x16, q1_uv_8x16);
330
4.80k
    temp1 = _mm_add_epi16(temp1, _mm_set1_epi16(2));
331
4.80k
    temp1 = _mm_add_epi16(temp1, temp2);
332
4.80k
    p0_uv_8x16_1 = _mm_srai_epi16(temp1, 2);
333
4.80k
334
4.80k
    temp1 = _mm_slli_epi16(q1_uv_8x16, 1);
335
4.80k
    temp2 = _mm_add_epi16(p1_uv_8x16, q0_uv_8x16);
336
4.80k
    temp1 = _mm_add_epi16(temp1, _mm_set1_epi16(2));
337
4.80k
    temp1 = _mm_add_epi16(temp1, temp2);
338
4.80k
    q0_uv_8x16_1 = _mm_srai_epi16(temp1, 2);
339
4.80k
340
4.80k
    q0_uv_8x16 = _mm_unpackhi_epi8(q0_uv_16x8, zero);
341
4.80k
    q1_uv_8x16 = _mm_unpackhi_epi8(q1_uv_16x8, zero);
342
4.80k
    p1_uv_8x16 = _mm_unpackhi_epi8(p1_uv_16x8, zero);
343
4.80k
    p0_uv_8x16 = _mm_unpackhi_epi8(p0_uv_16x8, zero);
344
4.80k
345
4.80k
    diff = _mm_subs_epi16(p0_uv_8x16, q0_uv_8x16); //Condn 1
346
4.80k
    diff = _mm_abs_epi16(diff);
347
4.80k
    alpha_cbcr_16x8 = _mm_set1_epi32(alpha_cbcr);
348
4.80k
    flag2 = _mm_cmpgt_epi16(alpha_cbcr_16x8, diff);
349
4.80k
350
4.80k
    diff = _mm_subs_epi16(q1_uv_8x16, q0_uv_8x16); //Condtn 2
351
4.80k
    diff = _mm_abs_epi16(diff);
352
4.80k
    beta_cbcr_16x8 = _mm_set1_epi32(beta_cbcr);
353
4.80k
    flag2 = _mm_and_si128(flag2, _mm_cmpgt_epi16(beta_cbcr_16x8, diff));
354
4.80k
355
4.80k
    diff = _mm_subs_epi16(p1_uv_8x16, p0_uv_8x16); //Condtn 3
356
4.80k
    diff = _mm_abs_epi16(diff);
357
4.80k
    flag2 = _mm_and_si128(flag2, _mm_cmpgt_epi16(beta_cbcr_16x8, diff));
358
4.80k
359
4.80k
    temp1 = _mm_slli_epi16(p1_uv_8x16, 1);
360
4.80k
    temp2 = _mm_add_epi16(p0_uv_8x16, q1_uv_8x16);
361
4.80k
    temp1 = _mm_add_epi16(temp1, _mm_set1_epi16(2));
362
4.80k
    temp1 = _mm_add_epi16(temp1, temp2);
363
4.80k
    p0_uv_8x16_2 = _mm_srai_epi16(temp1, 2);
364
4.80k
365
4.80k
    temp1 = _mm_slli_epi16(q1_uv_8x16, 1);
366
4.80k
    temp2 = _mm_add_epi16(p1_uv_8x16, q0_uv_8x16);
367
4.80k
    temp1 = _mm_add_epi16(temp1, _mm_set1_epi16(2));
368
4.80k
    temp1 = _mm_add_epi16(temp1, temp2);
369
4.80k
    q0_uv_8x16_2 = _mm_srai_epi16(temp1, 2);
370
4.80k
371
4.80k
    p0_uv_8x16_2 = _mm_packus_epi16(p0_uv_8x16_1, p0_uv_8x16_2);
372
4.80k
    q0_uv_8x16_2 = _mm_packus_epi16(q0_uv_8x16_1, q0_uv_8x16_2);
373
4.80k
374
4.80k
    flag1 = _mm_packs_epi16(flag1, flag2);
375
4.80k
376
4.80k
    p0_uv_8x16_1 = _mm_and_si128(p0_uv_16x8,
377
4.80k
                                 _mm_xor_si128(flag1, _mm_set1_epi8(0xFF)));
378
4.80k
    p0_uv_8x16_2 = _mm_and_si128(p0_uv_8x16_2, flag1);
379
4.80k
    p0_uv_8x16_1 = _mm_add_epi8(p0_uv_8x16_1, p0_uv_8x16_2);
380
4.80k
    _mm_storeu_si128((__m128i *)(pu1_HorzPixelUV + i16_posP0), p0_uv_8x16_1);
381
4.80k
382
4.80k
    q0_uv_8x16_1 = _mm_and_si128(q0_uv_16x8,
383
4.80k
                                 _mm_xor_si128(flag1, _mm_set1_epi8(0xFF)));
384
4.80k
    q0_uv_8x16_2 = _mm_and_si128(q0_uv_8x16_2, flag1);
385
4.80k
    q0_uv_8x16_1 = _mm_add_epi8(q0_uv_8x16_1, q0_uv_8x16_2);
386
4.80k
    _mm_storeu_si128((__m128i *)(pu1_src_uv), q0_uv_8x16_1);
387
4.80k
388
4.80k
}
389
390
/*****************************************************************************/
391
/*                                                                           */
392
/*  Function Name : ih264_deblk_chroma_vert_bslt4_ssse3()                    */
393
/*                                                                           */
394
/*  Description   : This function performs filtering of a chroma block       */
395
/*                  vertical edge when the boundary strength is less than 4  */
396
/*                  in high profile.                                         */
397
/*                                                                           */
398
/*  Inputs        : pu1_src          - pointer to the src sample q0 of U     */
399
/*                  src_strd         - source stride                         */
400
/*                  alpha_cb         - alpha value for the boundary in U     */
401
/*                  beta_cb          - beta value for the boundary in U      */
402
/*                  alpha_cr         - alpha value for the boundary in V     */
403
/*                  beta_cr          - beta value for the boundary in V      */
404
/*                  u4_bs            - packed Boundary strength array        */
405
/*                  pu1_cliptab_cb   - tc0_table for U                       */
406
/*                  pu1_cliptab_cr   - tc0_table for V                       */
407
/*                                                                           */
408
/*  Globals       : None                                                     */
409
/*                                                                           */
410
/*  Processing    : This operation is described in Sec. 8.7.2.3 under the    */
411
/*                  title "Filtering process for edges for bS less than 4"   */
412
/*                  in ITU T Rec H.264 with alpha and beta values different  */
413
/*                  in U and V.                                              */
414
/*                                                                           */
415
/*  Outputs       : None                                                     */
416
/*                                                                           */
417
/*  Returns       : None                                                     */
418
/*                                                                           */
419
/*  Issues        : None                                                     */
420
/*                                                                           */
421
/*  Revision History:                                                        */
422
/*                                                                           */
423
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
424
/*         12 02 2015   Naveen Kumar P  Initial version                      */
425
/*                                                                           */
426
/*****************************************************************************/
427
void ih264_deblk_chroma_vert_bslt4_ssse3(UWORD8 *pu1_src,
428
                                         WORD32 src_strd,
429
                                         WORD32 alpha_cb,
430
                                         WORD32 beta_cb,
431
                                         WORD32 alpha_cr,
432
                                         WORD32 beta_cr,
433
                                         UWORD32 u4_bs,
434
                                         const UWORD8 *pu1_cliptab_cb,
435
                                         const UWORD8 *pu1_cliptab_cr)
436
5.06k
{
437
5.06k
    UWORD8 *pu1_src_uv = pu1_src; /* Pointer to the src sample q0 of plane U*/
438
5.06k
    UWORD8 u1_Bs0, u1_Bs1, u1_Bs2, u1_Bs3;
439
5.06k
    WORD32 alpha_cbcr = (alpha_cr << 16) + alpha_cb;
440
5.06k
    WORD32 beta_cbcr = (beta_cr << 16) + beta_cb;
441
5.06k
    __m128i linea, lineb, linec, lined, linee, linef, lineg, lineh;
442
5.06k
    __m128i temp1, temp2, temp3, temp4;
443
5.06k
444
5.06k
    __m128i q0_uv_16x8, p0_uv_16x8, q1_uv_16x8, p1_uv_16x8;
445
5.06k
    __m128i q0_uv_8x16, p0_uv_8x16, q1_uv_8x16, p1_uv_8x16;
446
5.06k
    __m128i flag_bs, flag1, flag2;
447
5.06k
    __m128i diff, diff1, alpha_cbcr_16x8, beta_cbcr_16x8, in_macro;
448
5.06k
    __m128i zero = _mm_setzero_si128();
449
5.06k
    __m128i C0_uv_8x16;
450
5.06k
    __m128i p0_uv_8x16_1, p0_uv_8x16_2, q0_uv_8x16_1, q0_uv_8x16_2;
451
5.06k
452
5.06k
    u1_Bs0 = (u4_bs >> 24) & 0xff;
453
5.06k
    u1_Bs1 = (u4_bs >> 16) & 0xff;
454
5.06k
    u1_Bs2 = (u4_bs >> 8) & 0xff;
455
5.06k
    u1_Bs3 = (u4_bs >> 0) & 0xff;
456
5.06k
457
5.06k
    flag_bs = _mm_set_epi8(u1_Bs3, u1_Bs3, u1_Bs3, u1_Bs3, u1_Bs2, u1_Bs2,
458
5.06k
                           u1_Bs2, u1_Bs2, u1_Bs1, u1_Bs1, u1_Bs1, u1_Bs1,
459
5.06k
                           u1_Bs0, u1_Bs0, u1_Bs0, u1_Bs0);
460
5.06k
    flag_bs = _mm_cmpeq_epi8(flag_bs, zero); //Set flag to 1s and 0s
461
5.06k
    flag_bs = _mm_xor_si128(flag_bs, _mm_set1_epi8(0xFF)); //Invert for required mask
462
5.06k
463
5.06k
    /* Load and transpose the pixel values */
464
5.06k
    linea = _mm_loadl_epi64((__m128i *)(pu1_src_uv - 4));
465
5.06k
    lineb = _mm_loadl_epi64((__m128i *)(pu1_src_uv - 4 + src_strd));
466
5.06k
    linec = _mm_loadl_epi64((__m128i *)(pu1_src_uv - 4 + 2 * src_strd));
467
5.06k
    lined = _mm_loadl_epi64((__m128i *)(pu1_src_uv - 4 + 3 * src_strd));
468
5.06k
    linee = _mm_loadl_epi64((__m128i *)(pu1_src_uv - 4 + 4 * src_strd));
469
5.06k
    linef = _mm_loadl_epi64((__m128i *)(pu1_src_uv - 4 + 5 * src_strd));
470
5.06k
    lineg = _mm_loadl_epi64((__m128i *)(pu1_src_uv - 4 + 6 * src_strd));
471
5.06k
    lineh = _mm_loadl_epi64((__m128i *)(pu1_src_uv - 4 + 7 * src_strd));
472
5.06k
473
5.06k
    temp1 = _mm_unpacklo_epi16(linea, lineb);
474
5.06k
    temp2 = _mm_unpacklo_epi16(linec, lined);
475
5.06k
    temp3 = _mm_unpacklo_epi16(linee, linef);
476
5.06k
    temp4 = _mm_unpacklo_epi16(lineg, lineh);
477
5.06k
478
5.06k
    p1_uv_8x16 = _mm_unpacklo_epi32(temp1, temp2);
479
5.06k
    p0_uv_8x16 = _mm_unpacklo_epi32(temp3, temp4);
480
5.06k
    q0_uv_8x16 = _mm_unpackhi_epi32(temp1, temp2);
481
5.06k
    q1_uv_8x16 = _mm_unpackhi_epi32(temp3, temp4);
482
5.06k
483
5.06k
    p1_uv_16x8 = _mm_unpacklo_epi64(p1_uv_8x16, p0_uv_8x16);
484
5.06k
    p0_uv_16x8 = _mm_unpackhi_epi64(p1_uv_8x16, p0_uv_8x16);
485
5.06k
    q0_uv_16x8 = _mm_unpacklo_epi64(q0_uv_8x16, q1_uv_8x16);
486
5.06k
    q1_uv_16x8 = _mm_unpackhi_epi64(q0_uv_8x16, q1_uv_8x16);
487
5.06k
    /* End of transpose */
488
5.06k
489
5.06k
    q0_uv_8x16 = _mm_unpacklo_epi8(q0_uv_16x8, zero);
490
5.06k
    q1_uv_8x16 = _mm_unpacklo_epi8(q1_uv_16x8, zero);
491
5.06k
    p1_uv_8x16 = _mm_unpacklo_epi8(p1_uv_16x8, zero);
492
5.06k
    p0_uv_8x16 = _mm_unpacklo_epi8(p0_uv_16x8, zero);
493
5.06k
494
5.06k
    diff = _mm_subs_epi16(p0_uv_8x16, q0_uv_8x16); //Condn 1
495
5.06k
    diff = _mm_abs_epi16(diff);
496
5.06k
    alpha_cbcr_16x8 = _mm_set1_epi32(alpha_cbcr);
497
5.06k
    flag1 = _mm_cmpgt_epi16(alpha_cbcr_16x8, diff);
498
5.06k
499
5.06k
    diff = _mm_subs_epi16(q1_uv_8x16, q0_uv_8x16); //Condtn 2
500
5.06k
    diff = _mm_abs_epi16(diff);
501
5.06k
    beta_cbcr_16x8 = _mm_set1_epi32(beta_cbcr);
502
5.06k
    flag1 = _mm_and_si128(flag1, _mm_cmpgt_epi16(beta_cbcr_16x8, diff));
503
5.06k
504
5.06k
    diff = _mm_subs_epi16(p1_uv_8x16, p0_uv_8x16); //Condtn 3
505
5.06k
    diff = _mm_abs_epi16(diff);
506
5.06k
    flag1 = _mm_and_si128(flag1, _mm_cmpgt_epi16(beta_cbcr_16x8, diff));
507
5.06k
508
5.06k
    diff = _mm_subs_epi16(q0_uv_8x16, p0_uv_8x16);
509
5.06k
    diff = _mm_slli_epi16(diff, 2);
510
5.06k
    diff1 = _mm_subs_epi16(p1_uv_8x16, q1_uv_8x16);
511
5.06k
    diff = _mm_add_epi16(diff, diff1);
512
5.06k
    diff = _mm_add_epi16(diff, _mm_set1_epi16(4));
513
5.06k
    in_macro = _mm_srai_epi16(diff, 3);
514
5.06k
515
5.06k
    C0_uv_8x16 = _mm_set_epi16(pu1_cliptab_cr[u1_Bs1], pu1_cliptab_cb[u1_Bs1],
516
5.06k
                               pu1_cliptab_cr[u1_Bs1], pu1_cliptab_cb[u1_Bs1],
517
5.06k
                               pu1_cliptab_cr[u1_Bs0], pu1_cliptab_cb[u1_Bs0],
518
5.06k
                               pu1_cliptab_cr[u1_Bs0], pu1_cliptab_cb[u1_Bs0]);
519
5.06k
520
5.06k
    C0_uv_8x16 = _mm_add_epi16(C0_uv_8x16, _mm_set1_epi16(1));
521
5.06k
522
5.06k
    in_macro = _mm_min_epi16(C0_uv_8x16, in_macro); //CLIP3
523
5.06k
    C0_uv_8x16 = _mm_subs_epi16(zero, C0_uv_8x16);
524
5.06k
    in_macro = _mm_max_epi16(C0_uv_8x16, in_macro);
525
5.06k
526
5.06k
    p0_uv_8x16_1 = _mm_add_epi16(p0_uv_8x16, in_macro);
527
5.06k
    q0_uv_8x16_1 = _mm_sub_epi16(q0_uv_8x16, in_macro);
528
5.06k
529
5.06k
    q0_uv_8x16 = _mm_unpackhi_epi8(q0_uv_16x8, zero);
530
5.06k
    q1_uv_8x16 = _mm_unpackhi_epi8(q1_uv_16x8, zero);
531
5.06k
    p1_uv_8x16 = _mm_unpackhi_epi8(p1_uv_16x8, zero);
532
5.06k
    p0_uv_8x16 = _mm_unpackhi_epi8(p0_uv_16x8, zero);
533
5.06k
534
5.06k
    diff = _mm_subs_epi16(p0_uv_8x16, q0_uv_8x16); //Condn 1
535
5.06k
    diff = _mm_abs_epi16(diff);
536
5.06k
    alpha_cbcr_16x8 = _mm_set1_epi32(alpha_cbcr);
537
5.06k
    flag2 = _mm_cmpgt_epi16(alpha_cbcr_16x8, diff);
538
5.06k
539
5.06k
    diff = _mm_subs_epi16(q1_uv_8x16, q0_uv_8x16); //Condtn 2
540
5.06k
    diff = _mm_abs_epi16(diff);
541
5.06k
    beta_cbcr_16x8 = _mm_set1_epi32(beta_cbcr);
542
5.06k
    flag2 = _mm_and_si128(flag2, _mm_cmpgt_epi16(beta_cbcr_16x8, diff));
543
5.06k
544
5.06k
    diff = _mm_subs_epi16(p1_uv_8x16, p0_uv_8x16); //Condtn 3
545
5.06k
    diff = _mm_abs_epi16(diff);
546
5.06k
    flag2 = _mm_and_si128(flag2, _mm_cmpgt_epi16(beta_cbcr_16x8, diff));
547
5.06k
548
5.06k
    diff = _mm_subs_epi16(q0_uv_8x16, p0_uv_8x16);
549
5.06k
    diff = _mm_slli_epi16(diff, 2);
550
5.06k
    diff1 = _mm_subs_epi16(p1_uv_8x16, q1_uv_8x16);
551
5.06k
    diff = _mm_add_epi16(diff, diff1);
552
5.06k
    diff = _mm_add_epi16(diff, _mm_set1_epi16(4));
553
5.06k
    in_macro = _mm_srai_epi16(diff, 3);
554
5.06k
555
5.06k
    C0_uv_8x16 = _mm_set_epi16(pu1_cliptab_cr[u1_Bs3], pu1_cliptab_cb[u1_Bs3],
556
5.06k
                               pu1_cliptab_cr[u1_Bs3], pu1_cliptab_cb[u1_Bs3],
557
5.06k
                               pu1_cliptab_cr[u1_Bs2], pu1_cliptab_cb[u1_Bs2],
558
5.06k
                               pu1_cliptab_cr[u1_Bs2], pu1_cliptab_cb[u1_Bs2]);
559
5.06k
560
5.06k
    C0_uv_8x16 = _mm_add_epi16(C0_uv_8x16, _mm_set1_epi16(1));
561
5.06k
562
5.06k
    in_macro = _mm_min_epi16(C0_uv_8x16, in_macro); //CLIP3
563
5.06k
    C0_uv_8x16 = _mm_subs_epi16(zero, C0_uv_8x16);
564
5.06k
    in_macro = _mm_max_epi16(C0_uv_8x16, in_macro);
565
5.06k
566
5.06k
    p0_uv_8x16_2 = _mm_add_epi16(p0_uv_8x16, in_macro);
567
5.06k
    q0_uv_8x16_2 = _mm_sub_epi16(q0_uv_8x16, in_macro);
568
5.06k
569
5.06k
    p0_uv_8x16_2 = _mm_packus_epi16(p0_uv_8x16_1, p0_uv_8x16_2);
570
5.06k
    q0_uv_8x16_2 = _mm_packus_epi16(q0_uv_8x16_1, q0_uv_8x16_2);
571
5.06k
572
5.06k
    flag1 = _mm_packs_epi16(flag1, flag2);
573
5.06k
    flag1 = _mm_and_si128(flag1, flag_bs); //Final flag (BS condition + other 3 conditions)
574
5.06k
575
5.06k
    p0_uv_8x16_1 = _mm_and_si128(p0_uv_16x8,
576
5.06k
                                 _mm_xor_si128(flag1, _mm_set1_epi8(0xFF)));
577
5.06k
    p0_uv_8x16_2 = _mm_and_si128(p0_uv_8x16_2, flag1);
578
5.06k
    p0_uv_16x8 = _mm_add_epi8(p0_uv_8x16_1, p0_uv_8x16_2);
579
5.06k
580
5.06k
    q0_uv_8x16_1 = _mm_and_si128(q0_uv_16x8,
581
5.06k
                                 _mm_xor_si128(flag1, _mm_set1_epi8(0xFF)));
582
5.06k
    q0_uv_8x16_2 = _mm_and_si128(q0_uv_8x16_2, flag1);
583
5.06k
    q0_uv_16x8 = _mm_add_epi8(q0_uv_8x16_1, q0_uv_8x16_2);
584
5.06k
585
5.06k
    /* Inverse-transpose and store back */
586
5.06k
    temp1 = _mm_unpacklo_epi16(p1_uv_16x8, p0_uv_16x8);
587
5.06k
    temp2 = _mm_unpackhi_epi16(p1_uv_16x8, p0_uv_16x8);
588
5.06k
    temp3 = _mm_unpacklo_epi16(q0_uv_16x8, q1_uv_16x8);
589
5.06k
    temp4 = _mm_unpackhi_epi16(q0_uv_16x8, q1_uv_16x8);
590
5.06k
591
5.06k
    linea = _mm_unpacklo_epi32(temp1, temp3);
592
5.06k
    lineb = _mm_srli_si128(linea, 8);
593
5.06k
    linec = _mm_unpackhi_epi32(temp1, temp3);
594
5.06k
    lined = _mm_srli_si128(linec, 8);
595
5.06k
    linee = _mm_unpacklo_epi32(temp2, temp4);
596
5.06k
    linef = _mm_srli_si128(linee, 8);
597
5.06k
    lineg = _mm_unpackhi_epi32(temp2, temp4);
598
5.06k
    lineh = _mm_srli_si128(lineg, 8);
599
5.06k
600
5.06k
    _mm_storel_epi64((__m128i *)(pu1_src_uv - 4), linea);
601
5.06k
    _mm_storel_epi64((__m128i *)(pu1_src_uv - 4 + src_strd), lineb);
602
5.06k
    _mm_storel_epi64((__m128i *)(pu1_src_uv - 4 + 2 * src_strd), linec);
603
5.06k
    _mm_storel_epi64((__m128i *)(pu1_src_uv - 4 + 3 * src_strd), lined);
604
5.06k
    _mm_storel_epi64((__m128i *)(pu1_src_uv - 4 + 4 * src_strd), linee);
605
5.06k
    _mm_storel_epi64((__m128i *)(pu1_src_uv - 4 + 5 * src_strd), linef);
606
5.06k
    _mm_storel_epi64((__m128i *)(pu1_src_uv - 4 + 6 * src_strd), lineg);
607
5.06k
    _mm_storel_epi64((__m128i *)(pu1_src_uv - 4 + 7 * src_strd), lineh);
608
5.06k
609
5.06k
}
610
611
/*****************************************************************************/
612
/*                                                                           */
613
/*  Function Name : ih264_deblk_chroma_horz_bslt4_ssse3()                    */
614
/*                                                                           */
615
/*  Description   : This function performs filtering of a chroma block       */
616
/*                  horizontal edge when the boundary strength is less than  */
617
/*                  4 in high profile.                                       */
618
/*                                                                           */
619
/*  Inputs        : pu1_src          - pointer to the src sample q0 of U     */
620
/*                  src_strd         - source stride                         */
621
/*                  alpha_cb         - alpha value for the boundary in U     */
622
/*                  beta_cb          - beta value for the boundary in U      */
623
/*                  alpha_cr         - alpha value for the boundary in V     */
624
/*                  beta_cr          - beta value for the boundary in V      */
625
/*                  u4_bs            - packed Boundary strength array        */
626
/*                  pu1_cliptab_cb   - tc0_table for U                       */
627
/*                  pu1_cliptab_cr   - tc0_table for V                       */
628
/*                                                                           */
629
/*  Globals       : None                                                     */
630
/*                                                                           */
631
/*  Processing    : This operation is described in Sec. 8.7.2.3 under the    */
632
/*                  title "Filtering process for edges for bS less than 4"   */
633
/*                  in ITU T Rec H.264 with alpha and beta values different  */
634
/*                  in U and V.                                              */
635
/*                                                                           */
636
/*  Outputs       : None                                                     */
637
/*                                                                           */
638
/*  Returns       : None                                                     */
639
/*                                                                           */
640
/*  Issues        : None                                                     */
641
/*                                                                           */
642
/*  Revision History:                                                        */
643
/*                                                                           */
644
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
645
/*         12 02 2015   Naveen Kumar P  Initial version                      */
646
/*                                                                           */
647
/*****************************************************************************/
648
void ih264_deblk_chroma_horz_bslt4_ssse3(UWORD8 *pu1_src,
649
                                         WORD32 src_strd,
650
                                         WORD32 alpha_cb,
651
                                         WORD32 beta_cb,
652
                                         WORD32 alpha_cr,
653
                                         WORD32 beta_cr,
654
                                         UWORD32 u4_bs,
655
                                         const UWORD8 *pu1_cliptab_cb,
656
                                         const UWORD8 *pu1_cliptab_cr)
657
5.06k
{
658
5.06k
    UWORD8 *pu1_src_uv = pu1_src; /* Pointer to the src sample q0 of plane U*/
659
5.06k
    WORD16 i16_posP1, i16_posP0, i16_posQ1;
660
5.06k
    UWORD8 u1_Bs0, u1_Bs1, u1_Bs2, u1_Bs3;
661
5.06k
662
5.06k
    UWORD8 *pu1_HorzPixelUV; /*! < Pointer to the first pixel of the boundary */
663
5.06k
    WORD32 alpha_cbcr = (alpha_cr << 16) + alpha_cb;
664
5.06k
    WORD32 beta_cbcr = (beta_cr << 16) + beta_cb;
665
5.06k
    __m128i q0_uv_16x8, p0_uv_16x8, q1_uv_16x8, p1_uv_16x8;
666
5.06k
    __m128i q0_uv_8x16, p0_uv_8x16, q1_uv_8x16, p1_uv_8x16;
667
5.06k
    __m128i flag_bs, flag1, flag2;
668
5.06k
    __m128i diff, diff1, alpha_cbcr_16x8, beta_cbcr_16x8, in_macro;
669
5.06k
    __m128i zero = _mm_setzero_si128();
670
5.06k
    __m128i C0_uv_8x16;
671
5.06k
    __m128i p0_uv_8x16_1, p0_uv_8x16_2, q0_uv_8x16_1, q0_uv_8x16_2;
672
5.06k
673
5.06k
    pu1_HorzPixelUV = pu1_src_uv - (src_strd << 1);
674
5.06k
675
5.06k
    i16_posQ1 = src_strd;
676
5.06k
    i16_posP0 = src_strd;
677
5.06k
    i16_posP1 = 0;
678
5.06k
679
5.06k
    u1_Bs0 = (u4_bs >> 24) & 0xff;
680
5.06k
    u1_Bs1 = (u4_bs >> 16) & 0xff;
681
5.06k
    u1_Bs2 = (u4_bs >> 8) & 0xff;
682
5.06k
    u1_Bs3 = (u4_bs >> 0) & 0xff;
683
5.06k
684
5.06k
    flag_bs = _mm_set_epi8(u1_Bs3, u1_Bs3, u1_Bs3, u1_Bs3, u1_Bs2, u1_Bs2,
685
5.06k
                           u1_Bs2, u1_Bs2, u1_Bs1, u1_Bs1, u1_Bs1, u1_Bs1,
686
5.06k
                           u1_Bs0, u1_Bs0, u1_Bs0, u1_Bs0);
687
5.06k
    flag_bs = _mm_cmpeq_epi8(flag_bs, zero); //Set flag to 1s and 0s
688
5.06k
    flag_bs = _mm_xor_si128(flag_bs, _mm_set1_epi8(0xFF)); //Invert for required mask
689
5.06k
690
5.06k
    q0_uv_16x8 = _mm_loadu_si128((__m128i *)(pu1_src_uv));
691
5.06k
    q1_uv_16x8 = _mm_loadu_si128((__m128i *)(pu1_src_uv + i16_posQ1));
692
5.06k
    p1_uv_16x8 = _mm_loadu_si128((__m128i *)(pu1_HorzPixelUV + i16_posP1));
693
5.06k
    p0_uv_16x8 = _mm_loadu_si128((__m128i *)(pu1_HorzPixelUV + i16_posP0));
694
5.06k
695
5.06k
    q0_uv_8x16 = _mm_unpacklo_epi8(q0_uv_16x8, zero);
696
5.06k
    q1_uv_8x16 = _mm_unpacklo_epi8(q1_uv_16x8, zero);
697
5.06k
    p1_uv_8x16 = _mm_unpacklo_epi8(p1_uv_16x8, zero);
698
5.06k
    p0_uv_8x16 = _mm_unpacklo_epi8(p0_uv_16x8, zero);
699
5.06k
700
5.06k
    diff = _mm_subs_epi16(p0_uv_8x16, q0_uv_8x16); //Condn 1
701
5.06k
    diff = _mm_abs_epi16(diff);
702
5.06k
    alpha_cbcr_16x8 = _mm_set1_epi32(alpha_cbcr);
703
5.06k
    flag1 = _mm_cmpgt_epi16(alpha_cbcr_16x8, diff);
704
5.06k
705
5.06k
    diff = _mm_subs_epi16(q1_uv_8x16, q0_uv_8x16); //Condtn 2
706
5.06k
    diff = _mm_abs_epi16(diff);
707
5.06k
    beta_cbcr_16x8 = _mm_set1_epi32(beta_cbcr);
708
5.06k
    flag1 = _mm_and_si128(flag1, _mm_cmpgt_epi16(beta_cbcr_16x8, diff));
709
5.06k
710
5.06k
    diff = _mm_subs_epi16(p1_uv_8x16, p0_uv_8x16); //Condtn 3
711
5.06k
    diff = _mm_abs_epi16(diff);
712
5.06k
    flag1 = _mm_and_si128(flag1, _mm_cmpgt_epi16(beta_cbcr_16x8, diff));
713
5.06k
714
5.06k
    diff = _mm_subs_epi16(q0_uv_8x16, p0_uv_8x16);
715
5.06k
    diff = _mm_slli_epi16(diff, 2);
716
5.06k
    diff1 = _mm_subs_epi16(p1_uv_8x16, q1_uv_8x16);
717
5.06k
    diff = _mm_add_epi16(diff, diff1);
718
5.06k
    diff = _mm_add_epi16(diff, _mm_set1_epi16(4));
719
5.06k
    in_macro = _mm_srai_epi16(diff, 3);
720
5.06k
721
5.06k
    C0_uv_8x16 = _mm_set_epi16(pu1_cliptab_cr[u1_Bs1], pu1_cliptab_cb[u1_Bs1],
722
5.06k
                               pu1_cliptab_cr[u1_Bs1], pu1_cliptab_cb[u1_Bs1],
723
5.06k
                               pu1_cliptab_cr[u1_Bs0], pu1_cliptab_cb[u1_Bs0],
724
5.06k
                               pu1_cliptab_cr[u1_Bs0], pu1_cliptab_cb[u1_Bs0]);
725
5.06k
726
5.06k
    C0_uv_8x16 = _mm_add_epi16(C0_uv_8x16, _mm_set1_epi16(1));
727
5.06k
728
5.06k
    in_macro = _mm_min_epi16(C0_uv_8x16, in_macro); //CLIP3
729
5.06k
    C0_uv_8x16 = _mm_subs_epi16(zero, C0_uv_8x16);
730
5.06k
    in_macro = _mm_max_epi16(C0_uv_8x16, in_macro);
731
5.06k
732
5.06k
    p0_uv_8x16_1 = _mm_add_epi16(p0_uv_8x16, in_macro);
733
5.06k
    q0_uv_8x16_1 = _mm_sub_epi16(q0_uv_8x16, in_macro);
734
5.06k
735
5.06k
    q0_uv_8x16 = _mm_unpackhi_epi8(q0_uv_16x8, zero);
736
5.06k
    q1_uv_8x16 = _mm_unpackhi_epi8(q1_uv_16x8, zero);
737
5.06k
    p1_uv_8x16 = _mm_unpackhi_epi8(p1_uv_16x8, zero);
738
5.06k
    p0_uv_8x16 = _mm_unpackhi_epi8(p0_uv_16x8, zero);
739
5.06k
740
5.06k
    diff = _mm_subs_epi16(p0_uv_8x16, q0_uv_8x16); //Condn 1
741
5.06k
    diff = _mm_abs_epi16(diff);
742
5.06k
    alpha_cbcr_16x8 = _mm_set1_epi32(alpha_cbcr);
743
5.06k
    flag2 = _mm_cmpgt_epi16(alpha_cbcr_16x8, diff);
744
5.06k
745
5.06k
    diff = _mm_subs_epi16(q1_uv_8x16, q0_uv_8x16); //Condtn 2
746
5.06k
    diff = _mm_abs_epi16(diff);
747
5.06k
    beta_cbcr_16x8 = _mm_set1_epi32(beta_cbcr);
748
5.06k
    flag2 = _mm_and_si128(flag2, _mm_cmpgt_epi16(beta_cbcr_16x8, diff));
749
5.06k
750
5.06k
    diff = _mm_subs_epi16(p1_uv_8x16, p0_uv_8x16); //Condtn 3
751
5.06k
    diff = _mm_abs_epi16(diff);
752
5.06k
    flag2 = _mm_and_si128(flag2, _mm_cmpgt_epi16(beta_cbcr_16x8, diff));
753
5.06k
754
5.06k
    diff = _mm_subs_epi16(q0_uv_8x16, p0_uv_8x16);
755
5.06k
    diff = _mm_slli_epi16(diff, 2);
756
5.06k
    diff1 = _mm_subs_epi16(p1_uv_8x16, q1_uv_8x16);
757
5.06k
    diff = _mm_add_epi16(diff, diff1);
758
5.06k
    diff = _mm_add_epi16(diff, _mm_set1_epi16(4));
759
5.06k
    in_macro = _mm_srai_epi16(diff, 3);
760
5.06k
761
5.06k
    C0_uv_8x16 = _mm_set_epi16(pu1_cliptab_cr[u1_Bs3], pu1_cliptab_cb[u1_Bs3],
762
5.06k
                               pu1_cliptab_cr[u1_Bs3], pu1_cliptab_cb[u1_Bs3],
763
5.06k
                               pu1_cliptab_cr[u1_Bs2], pu1_cliptab_cb[u1_Bs2],
764
5.06k
                               pu1_cliptab_cr[u1_Bs2], pu1_cliptab_cb[u1_Bs2]);
765
5.06k
766
5.06k
    C0_uv_8x16 = _mm_add_epi16(C0_uv_8x16, _mm_set1_epi16(1));
767
5.06k
768
5.06k
    in_macro = _mm_min_epi16(C0_uv_8x16, in_macro); //CLIP3
769
5.06k
    C0_uv_8x16 = _mm_subs_epi16(zero, C0_uv_8x16);
770
5.06k
    in_macro = _mm_max_epi16(C0_uv_8x16, in_macro);
771
5.06k
772
5.06k
    p0_uv_8x16_2 = _mm_add_epi16(p0_uv_8x16, in_macro);
773
5.06k
    q0_uv_8x16_2 = _mm_sub_epi16(q0_uv_8x16, in_macro);
774
5.06k
775
5.06k
    p0_uv_8x16_2 = _mm_packus_epi16(p0_uv_8x16_1, p0_uv_8x16_2);
776
5.06k
    q0_uv_8x16_2 = _mm_packus_epi16(q0_uv_8x16_1, q0_uv_8x16_2);
777
5.06k
778
5.06k
    flag1 = _mm_packs_epi16(flag1, flag2);
779
5.06k
    flag1 = _mm_and_si128(flag1, flag_bs); //Final flag (BS condition + other 3 conditions)
780
5.06k
781
5.06k
    p0_uv_8x16_1 = _mm_and_si128(p0_uv_16x8,
782
5.06k
                                 _mm_xor_si128(flag1, _mm_set1_epi8(0xFF)));
783
5.06k
    p0_uv_8x16_2 = _mm_and_si128(p0_uv_8x16_2, flag1);
784
5.06k
    p0_uv_8x16_1 = _mm_add_epi8(p0_uv_8x16_1, p0_uv_8x16_2);
785
5.06k
    _mm_storeu_si128((__m128i *)(pu1_HorzPixelUV + i16_posP0), p0_uv_8x16_1);
786
5.06k
787
5.06k
    q0_uv_8x16_1 = _mm_and_si128(q0_uv_16x8,
788
5.06k
                                 _mm_xor_si128(flag1, _mm_set1_epi8(0xFF)));
789
5.06k
    q0_uv_8x16_2 = _mm_and_si128(q0_uv_8x16_2, flag1);
790
5.06k
    q0_uv_8x16_1 = _mm_add_epi8(q0_uv_8x16_1, q0_uv_8x16_2);
791
5.06k
    _mm_storeu_si128((__m128i *)(pu1_src_uv), q0_uv_8x16_1);
792
5.06k
793
5.06k
}
794
795
/*****************************************************************************/
796
/*                                                                           */
797
/*  Function Name : ih264_deblk_chroma_vert_bs4_mbaff_ssse3()                */
798
/*                                                                           */
799
/*  Description   : This function performs filtering of a chroma block       */
800
/*                  vertical edge when boundary strength is set to 4 in high */
801
/*                  profile.                                                 */
802
/*                                                                           */
803
/*  Inputs        : pu1_src          - pointer to the src sample q0 of U     */
804
/*                  src_strd         - source stride                         */
805
/*                  alpha_cb         - alpha value for the boundary in U     */
806
/*                  beta_cb          - beta value for the boundary in U      */
807
/*                  alpha_cr         - alpha value for the boundary in V     */
808
/*                  beta_cr          - beta value for the boundary in V      */
809
/*                  u4_bs            - packed Boundary strength array        */
810
/*                  pu1_cliptab_cb   - tc0_table for U                       */
811
/*                  pu1_cliptab_cr   - tc0_table for V                       */
812
/*                                                                           */
813
/*  Globals       : None                                                     */
814
/*                                                                           */
815
/*  Processing    : When the function is called twice, this operation is as  */
816
/*                  described in Sec. 8.7.2.4 under the title "Filtering     */
817
/*                  process for edges for bS equal to 4" in ITU T Rec H.264  */
818
/*                  with alpha and beta values different in U and V.         */
819
/*                                                                           */
820
/*  Outputs       : None                                                     */
821
/*                                                                           */
822
/*  Returns       : None                                                     */
823
/*                                                                           */
824
/*  Issues        : None                                                     */
825
/*                                                                           */
826
/*  Revision History:                                                        */
827
/*                                                                           */
828
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
829
/*         12 02 2015   Naveen Kumar P  Initial version                      */
830
/*                                                                           */
831
/*****************************************************************************/
832
void ih264_deblk_chroma_vert_bs4_mbaff_ssse3(UWORD8 *pu1_src,
833
                                             WORD32 src_strd,
834
                                             WORD32 alpha_cb,
835
                                             WORD32 beta_cb,
836
                                             WORD32 alpha_cr,
837
                                             WORD32 beta_cr)
838
0
{
839
0
    UWORD8 *pu1_src_uv = pu1_src; /* Pointer to the src sample q0 of plane U*/
840
0
    WORD32 alpha_cbcr = (alpha_cr << 16) + alpha_cb;
841
0
    WORD32 beta_cbcr = (beta_cr << 16) + beta_cb;
842
0
    __m128i linea, lineb, linec, lined;
843
0
    __m128i temp1, temp2;
844
0
845
0
    __m128i q0_uv_16x8, p0_uv_16x8, q1_uv_16x8, p1_uv_16x8;
846
0
    __m128i q0_uv_8x16, p0_uv_8x16, q1_uv_8x16, p1_uv_8x16;
847
0
    __m128i flag1;
848
0
    __m128i diff, alpha_cbcr_16x8, beta_cbcr_16x8;
849
0
    __m128i zero = _mm_setzero_si128();
850
0
    __m128i p0_uv_8x16_1, p0_uv_8x16_2, q0_uv_8x16_1, q0_uv_8x16_2;
851
0
852
0
    /* Load and transpose the pixel values */
853
0
    linea = _mm_loadl_epi64((__m128i *)(pu1_src_uv - 4));
854
0
    lineb = _mm_loadl_epi64((__m128i *)(pu1_src_uv - 4 + src_strd));
855
0
    linec = _mm_loadl_epi64((__m128i *)(pu1_src_uv - 4 + 2 * src_strd));
856
0
    lined = _mm_loadl_epi64((__m128i *)(pu1_src_uv - 4 + 3 * src_strd));
857
0
858
0
    temp1 = _mm_unpacklo_epi16(linea, lineb);
859
0
    temp2 = _mm_unpacklo_epi16(linec, lined);
860
0
861
0
    p1_uv_16x8 = _mm_unpacklo_epi32(temp1, temp2);
862
0
    p0_uv_16x8 = _mm_srli_si128(p1_uv_16x8, 8);
863
0
    q0_uv_16x8 = _mm_unpackhi_epi32(temp1, temp2);
864
0
    q1_uv_16x8 = _mm_srli_si128(q0_uv_16x8, 8);
865
0
    /* End of transpose */
866
0
867
0
    q0_uv_8x16 = _mm_unpacklo_epi8(q0_uv_16x8, zero);
868
0
    q1_uv_8x16 = _mm_unpacklo_epi8(q1_uv_16x8, zero);
869
0
    p1_uv_8x16 = _mm_unpacklo_epi8(p1_uv_16x8, zero);
870
0
    p0_uv_8x16 = _mm_unpacklo_epi8(p0_uv_16x8, zero);
871
0
872
0
    diff = _mm_subs_epi16(p0_uv_8x16, q0_uv_8x16); //Condn 1
873
0
    diff = _mm_abs_epi16(diff);
874
0
    alpha_cbcr_16x8 = _mm_set1_epi32(alpha_cbcr);
875
0
    flag1 = _mm_cmpgt_epi16(alpha_cbcr_16x8, diff);
876
0
877
0
    diff = _mm_subs_epi16(q1_uv_8x16, q0_uv_8x16); //Condtn 2
878
0
    diff = _mm_abs_epi16(diff);
879
0
    beta_cbcr_16x8 = _mm_set1_epi32(beta_cbcr);
880
0
    flag1 = _mm_and_si128(flag1, _mm_cmpgt_epi16(beta_cbcr_16x8, diff));
881
0
882
0
    diff = _mm_subs_epi16(p1_uv_8x16, p0_uv_8x16); //Condtn 3
883
0
    diff = _mm_abs_epi16(diff);
884
0
    flag1 = _mm_and_si128(flag1, _mm_cmpgt_epi16(beta_cbcr_16x8, diff));
885
0
886
0
    temp1 = _mm_slli_epi16(p1_uv_8x16, 1);
887
0
    temp2 = _mm_add_epi16(p0_uv_8x16, q1_uv_8x16);
888
0
    temp1 = _mm_add_epi16(temp1, _mm_set1_epi16(2));
889
0
    temp1 = _mm_add_epi16(temp1, temp2);
890
0
    p0_uv_8x16_1 = _mm_srai_epi16(temp1, 2);
891
0
892
0
    temp1 = _mm_slli_epi16(q1_uv_8x16, 1);
893
0
    temp2 = _mm_add_epi16(p1_uv_8x16, q0_uv_8x16);
894
0
    temp1 = _mm_add_epi16(temp1, _mm_set1_epi16(2));
895
0
    temp1 = _mm_add_epi16(temp1, temp2);
896
0
    q0_uv_8x16_1 = _mm_srai_epi16(temp1, 2);
897
0
898
0
    p0_uv_8x16_2 = _mm_packus_epi16(p0_uv_8x16_1, p0_uv_8x16_1);
899
0
    q0_uv_8x16_2 = _mm_packus_epi16(q0_uv_8x16_1, q0_uv_8x16_1);
900
0
901
0
    flag1 = _mm_packs_epi16(flag1, flag1);
902
0
903
0
    p0_uv_8x16_1 = _mm_and_si128(p0_uv_16x8,
904
0
                                 _mm_xor_si128(flag1, _mm_set1_epi8(0xFF)));
905
0
    p0_uv_8x16_2 = _mm_and_si128(p0_uv_8x16_2, flag1);
906
0
    p0_uv_16x8 = _mm_add_epi8(p0_uv_8x16_1, p0_uv_8x16_2);
907
0
908
0
    q0_uv_8x16_1 = _mm_and_si128(q0_uv_16x8,
909
0
                                 _mm_xor_si128(flag1, _mm_set1_epi8(0xFF)));
910
0
    q0_uv_8x16_2 = _mm_and_si128(q0_uv_8x16_2, flag1);
911
0
    q0_uv_16x8 = _mm_add_epi8(q0_uv_8x16_1, q0_uv_8x16_2);
912
0
913
0
    /* Inverse-transpose and store back */
914
0
    temp1 = _mm_unpacklo_epi16(p1_uv_16x8, p0_uv_16x8);
915
0
    temp2 = _mm_unpacklo_epi16(q0_uv_16x8, q1_uv_16x8);
916
0
917
0
    linea = _mm_unpacklo_epi32(temp1, temp2);
918
0
    lineb = _mm_srli_si128(linea, 8);
919
0
    linec = _mm_unpackhi_epi32(temp1, temp2);
920
0
    lined = _mm_srli_si128(linec, 8);
921
0
922
0
    _mm_storel_epi64((__m128i *)(pu1_src_uv - 4), linea);
923
0
    _mm_storel_epi64((__m128i *)(pu1_src_uv - 4 + src_strd), lineb);
924
0
    _mm_storel_epi64((__m128i *)(pu1_src_uv - 4 + 2 * src_strd), linec);
925
0
    _mm_storel_epi64((__m128i *)(pu1_src_uv - 4 + 3 * src_strd), lined);
926
0
927
0
}
928
929
/*****************************************************************************/
930
/*                                                                           */
931
/*  Function Name : ih264_deblk_chroma_vert_bslt4_mbaff_ssse3()              */
932
/*                                                                           */
933
/*  Description   : This function performs filtering of a chroma block       */
934
/*                  vertical edge when boundary strength is less than 4 in   */
935
/*                  high profile.                                            */
936
/*                                                                           */
937
/*  Inputs        : pu1_src          - pointer to the src sample q0 of U     */
938
/*                  src_strd         - source stride                         */
939
/*                  alpha_cb         - alpha value for the boundary in U     */
940
/*                  beta_cb          - beta value for the boundary in U      */
941
/*                  alpha_cr         - alpha value for the boundary in V     */
942
/*                  beta_cr          - beta value for the boundary in V      */
943
/*                  u4_bs            - packed Boundary strength array        */
944
/*                  pu1_cliptab_cb   - tc0_table for U                       */
945
/*                  pu1_cliptab_cr   - tc0_table for V                       */
946
/*                                                                           */
947
/*  Globals       : None                                                     */
948
/*                                                                           */
949
/*  Processing    : When the function is called twice, this operation is as  */
950
/*                  described in Sec. 8.7.2.4 under the title "Filtering     */
951
/*                  process for edges for bS less than 4" in ITU T Rec H.264 */
952
/*                  with alpha and beta values different in U and V.         */
953
/*                                                                           */
954
/*  Outputs       : None                                                     */
955
/*                                                                           */
956
/*  Returns       : None                                                     */
957
/*                                                                           */
958
/*  Issues        : None                                                     */
959
/*                                                                           */
960
/*  Revision History:                                                        */
961
/*                                                                           */
962
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
963
/*         12 02 2015   Naveen Kumar P  Initial version                      */
964
/*                                                                           */
965
/*****************************************************************************/
966
void ih264_deblk_chroma_vert_bslt4_mbaff_ssse3(UWORD8 *pu1_src,
967
                                               WORD32 src_strd,
968
                                               WORD32 alpha_cb,
969
                                               WORD32 beta_cb,
970
                                               WORD32 alpha_cr,
971
                                               WORD32 beta_cr,
972
                                               UWORD32 u4_bs,
973
                                               const UWORD8 *pu1_cliptab_cb,
974
                                               const UWORD8 *pu1_cliptab_cr)
975
0
{
976
0
    UWORD8 *pu1_src_uv = pu1_src; /* Pointer to the src sample q0 of plane U*/
977
0
    UWORD8 u1_Bs0, u1_Bs1, u1_Bs2, u1_Bs3;
978
0
    WORD32 alpha_cbcr = (alpha_cr << 16) + alpha_cb;
979
0
    WORD32 beta_cbcr = (beta_cr << 16) + beta_cb;
980
0
    __m128i linea, lineb, linec, lined;
981
0
    __m128i temp1, temp2;
982
0
983
0
    __m128i q0_uv_16x8, p0_uv_16x8, q1_uv_16x8, p1_uv_16x8;
984
0
    __m128i q0_uv_8x16, p0_uv_8x16, q1_uv_8x16, p1_uv_8x16;
985
0
    __m128i flag_bs, flag1;
986
0
    __m128i diff, diff1, alpha_cbcr_16x8, beta_cbcr_16x8, in_macro;
987
0
    __m128i zero = _mm_setzero_si128();
988
0
    __m128i C0_uv_8x16;
989
0
    __m128i p0_uv_8x16_1, p0_uv_8x16_2, q0_uv_8x16_1, q0_uv_8x16_2;
990
0
991
0
    u1_Bs0 = (u4_bs >> 24) & 0xff;
992
0
    u1_Bs1 = (u4_bs >> 16) & 0xff;
993
0
    u1_Bs2 = (u4_bs >> 8) & 0xff;
994
0
    u1_Bs3 = (u4_bs >> 0) & 0xff;
995
0
996
0
    flag_bs = _mm_set_epi8(0, 0, 0, 0, 0, 0, 0, 0, u1_Bs3, u1_Bs3, u1_Bs2,
997
0
                           u1_Bs2, u1_Bs1, u1_Bs1, u1_Bs0, u1_Bs0);
998
0
    flag_bs = _mm_cmpeq_epi8(flag_bs, zero); //Set flag to 1s and 0s
999
0
    flag_bs = _mm_xor_si128(flag_bs, _mm_set1_epi8(0xFF)); //Invert for required mask
1000
0
1001
0
    /* Load and transpose the pixel values */
1002
0
    linea = _mm_loadl_epi64((__m128i *)(pu1_src_uv - 4));
1003
0
    lineb = _mm_loadl_epi64((__m128i *)(pu1_src_uv - 4 + src_strd));
1004
0
    linec = _mm_loadl_epi64((__m128i *)(pu1_src_uv - 4 + 2 * src_strd));
1005
0
    lined = _mm_loadl_epi64((__m128i *)(pu1_src_uv - 4 + 3 * src_strd));
1006
0
1007
0
    temp1 = _mm_unpacklo_epi16(linea, lineb);
1008
0
    temp2 = _mm_unpacklo_epi16(linec, lined);
1009
0
1010
0
    p1_uv_16x8 = _mm_unpacklo_epi32(temp1, temp2);
1011
0
    p0_uv_16x8 = _mm_srli_si128(p1_uv_16x8, 8);
1012
0
    q0_uv_16x8 = _mm_unpackhi_epi32(temp1, temp2);
1013
0
    q1_uv_16x8 = _mm_srli_si128(q0_uv_16x8, 8);
1014
0
    /* End of transpose */
1015
0
1016
0
    q0_uv_8x16 = _mm_unpacklo_epi8(q0_uv_16x8, zero);
1017
0
    q1_uv_8x16 = _mm_unpacklo_epi8(q1_uv_16x8, zero);
1018
0
    p1_uv_8x16 = _mm_unpacklo_epi8(p1_uv_16x8, zero);
1019
0
    p0_uv_8x16 = _mm_unpacklo_epi8(p0_uv_16x8, zero);
1020
0
1021
0
    diff = _mm_subs_epi16(p0_uv_8x16, q0_uv_8x16); //Condn 1
1022
0
    diff = _mm_abs_epi16(diff);
1023
0
    alpha_cbcr_16x8 = _mm_set1_epi32(alpha_cbcr);
1024
0
    flag1 = _mm_cmpgt_epi16(alpha_cbcr_16x8, diff);
1025
0
1026
0
    diff = _mm_subs_epi16(q1_uv_8x16, q0_uv_8x16); //Condtn 2
1027
0
    diff = _mm_abs_epi16(diff);
1028
0
    beta_cbcr_16x8 = _mm_set1_epi32(beta_cbcr);
1029
0
    flag1 = _mm_and_si128(flag1, _mm_cmpgt_epi16(beta_cbcr_16x8, diff));
1030
0
1031
0
    diff = _mm_subs_epi16(p1_uv_8x16, p0_uv_8x16); //Condtn 3
1032
0
    diff = _mm_abs_epi16(diff);
1033
0
    flag1 = _mm_and_si128(flag1, _mm_cmpgt_epi16(beta_cbcr_16x8, diff));
1034
0
1035
0
    diff = _mm_subs_epi16(q0_uv_8x16, p0_uv_8x16);
1036
0
    diff = _mm_slli_epi16(diff, 2);
1037
0
    diff1 = _mm_subs_epi16(p1_uv_8x16, q1_uv_8x16);
1038
0
    diff = _mm_add_epi16(diff, diff1);
1039
0
    diff = _mm_add_epi16(diff, _mm_set1_epi16(4));
1040
0
    in_macro = _mm_srai_epi16(diff, 3);
1041
0
1042
0
    C0_uv_8x16 = _mm_set_epi16(pu1_cliptab_cr[u1_Bs3], pu1_cliptab_cb[u1_Bs3],
1043
0
                               pu1_cliptab_cr[u1_Bs2], pu1_cliptab_cb[u1_Bs2],
1044
0
                               pu1_cliptab_cr[u1_Bs1], pu1_cliptab_cb[u1_Bs1],
1045
0
                               pu1_cliptab_cr[u1_Bs0], pu1_cliptab_cb[u1_Bs0]);
1046
0
1047
0
    C0_uv_8x16 = _mm_add_epi16(C0_uv_8x16, _mm_set1_epi16(1));
1048
0
1049
0
    in_macro = _mm_min_epi16(C0_uv_8x16, in_macro); //CLIP3
1050
0
    C0_uv_8x16 = _mm_subs_epi16(zero, C0_uv_8x16);
1051
0
    in_macro = _mm_max_epi16(C0_uv_8x16, in_macro);
1052
0
1053
0
    p0_uv_8x16_1 = _mm_add_epi16(p0_uv_8x16, in_macro);
1054
0
    q0_uv_8x16_1 = _mm_sub_epi16(q0_uv_8x16, in_macro);
1055
0
1056
0
    p0_uv_8x16_2 = _mm_packus_epi16(p0_uv_8x16_1, p0_uv_8x16_1);
1057
0
    q0_uv_8x16_2 = _mm_packus_epi16(q0_uv_8x16_1, q0_uv_8x16_1);
1058
0
1059
0
    flag1 = _mm_packs_epi16(flag1, flag1);
1060
0
    flag1 = _mm_and_si128(flag1, flag_bs); //Final flag (BS condition + other 3 conditions)
1061
0
1062
0
    p0_uv_8x16_1 = _mm_and_si128(p0_uv_16x8,
1063
0
                                 _mm_xor_si128(flag1, _mm_set1_epi8(0xFF)));
1064
0
    p0_uv_8x16_2 = _mm_and_si128(p0_uv_8x16_2, flag1);
1065
0
    p0_uv_16x8 = _mm_add_epi8(p0_uv_8x16_1, p0_uv_8x16_2);
1066
0
1067
0
    q0_uv_8x16_1 = _mm_and_si128(q0_uv_16x8,
1068
0
                                 _mm_xor_si128(flag1, _mm_set1_epi8(0xFF)));
1069
0
    q0_uv_8x16_2 = _mm_and_si128(q0_uv_8x16_2, flag1);
1070
0
    q0_uv_16x8 = _mm_add_epi8(q0_uv_8x16_1, q0_uv_8x16_2);
1071
0
1072
0
    /* Inverse-transpose and store back */
1073
0
    temp1 = _mm_unpacklo_epi16(p1_uv_16x8, p0_uv_16x8);
1074
0
    temp2 = _mm_unpacklo_epi16(q0_uv_16x8, q1_uv_16x8);
1075
0
1076
0
    linea = _mm_unpacklo_epi32(temp1, temp2);
1077
0
    lineb = _mm_srli_si128(linea, 8);
1078
0
    linec = _mm_unpackhi_epi32(temp1, temp2);
1079
0
    lined = _mm_srli_si128(linec, 8);
1080
0
1081
0
    _mm_storel_epi64((__m128i *)(pu1_src_uv - 4), linea);
1082
0
    _mm_storel_epi64((__m128i *)(pu1_src_uv - 4 + src_strd), lineb);
1083
0
    _mm_storel_epi64((__m128i *)(pu1_src_uv - 4 + 2 * src_strd), linec);
1084
0
    _mm_storel_epi64((__m128i *)(pu1_src_uv - 4 + 3 * src_strd), lined);
1085
0
1086
0
}
1087
/proc/self/cwd/external/libavc/common/x86/ih264_deblk_luma_ssse3.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/*****************************************************************************/
21
/*                                                                           */
22
/*  File Name         : ih264_deblk_luma_ssse3.c                             */
23
/*                                                                           */
24
/*  Description       : Contains function definitions for deblocking         */
25
/*                                                                           */
26
/*  List of Functions : ih264_deblk_luma_vert_bs4_ssse3()                    */
27
/*                      ih264_deblk_luma_horz_bs4_ssse3()                    */
28
/*                      ih264_deblk_luma_vert_bslt4_ssse3()                  */
29
/*                      ih264_deblk_luma_horz_bslt4_ssse3()                  */
30
/*                      ih264_deblk_luma_vert_bs4_mbaff_ssse3()              */
31
/*                      ih264_deblk_luma_vert_bslt4_mbaff_ssse3()            */
32
/*                                                                           */
33
/*  Issues / Problems : None                                                 */
34
/*                                                                           */
35
/*  Revision History  :                                                      */
36
/*                                                                           */
37
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
38
/*         12 02 2015   Naveen Kumar P  Added luma deblocking ssse3          */
39
/*                                      intrinsics                           */
40
/*                                                                           */
41
/*****************************************************************************/
42
43
/*****************************************************************************/
44
/* File Includes                                                             */
45
/*****************************************************************************/
46
47
/* System include files */
48
#include <stdio.h>
49
50
/* User include files */
51
#include "ih264_typedefs.h"
52
#include "ih264_platform_macros.h"
53
#include "ih264_deblk_edge_filters.h"
54
#include "ih264_macros.h"
55
56
/*****************************************************************************/
57
/* Function Definitions                                                      */
58
/*****************************************************************************/
59
60
/*****************************************************************************/
61
/*                                                                           */
62
/*  Function Name : ih264_deblk_luma_vert_bs4_ssse3()                        */
63
/*                                                                           */
64
/*  Description   : This function performs filtering of a luma block         */
65
/*                  vertical edge when the boundary strength is set to 4.    */
66
/*                                                                           */
67
/*  Inputs        : pu1_src    - pointer to the src sample q0                */
68
/*                  src_strd   - source stride                               */
69
/*                  alpha      - alpha value for the boundary                */
70
/*                  beta       - beta value for the boundary                 */
71
/*                                                                           */
72
/*  Globals       : None                                                     */
73
/*                                                                           */
74
/*  Processing    : This operation is described in Sec. 8.7.2.4 under the    */
75
/*                  title "Filtering process for edges for bS equal to 4" in */
76
/*                  ITU T Rec H.264.                                         */
77
/*                                                                           */
78
/*  Outputs       : None                                                     */
79
/*                                                                           */
80
/*  Returns       : None                                                     */
81
/*                                                                           */
82
/*  Issues        : None                                                     */
83
/*                                                                           */
84
/*  Revision History:                                                        */
85
/*                                                                           */
86
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
87
/*         12 02 2015   Naveen Kumar P  Initial version                      */
88
/*                                                                           */
89
/*****************************************************************************/
90
void ih264_deblk_luma_vert_bs4_ssse3(UWORD8 *pu1_src,
91
                                     WORD32 src_strd,
92
                                     WORD32 alpha,
93
                                     WORD32 beta)
94
4.84k
{
95
4.84k
    __m128i zero = _mm_setzero_si128();
96
4.84k
    __m128i q0_16x8, q1_16x8, q2_16x8, q3_16x8;
97
4.84k
    __m128i p0_16x8, p1_16x8, p2_16x8, p3_16x8;
98
4.84k
    __m128i q0_8x16, q1_8x16, q2_8x16, q3_8x16;
99
4.84k
    __m128i p0_8x16, p1_8x16, p2_8x16, p3_8x16;
100
4.84k
    __m128i q0_16x8_1;
101
4.84k
    __m128i p0_16x8_1;
102
4.84k
    __m128i q0_16x8_2, q1_16x8_2, q2_16x8_2;
103
4.84k
    __m128i p0_16x8_2, p1_16x8_2, p2_16x8_2;
104
4.84k
    __m128i temp1, temp2, temp3, temp4, temp5, temp6;
105
4.84k
    __m128i Alpha_8x16, Beta_8x16;
106
4.84k
    __m128i flag1_16x8, flag2_16x8, flag3_16x8, flag4_16x8;
107
4.84k
    __m128i const_val2_16x8 = _mm_set1_epi16(2);
108
4.84k
    __m128i line1, line2, line3, line4, line5, line6, line7, line8;
109
4.84k
110
4.84k
    Alpha_8x16 = _mm_set1_epi16(alpha);
111
4.84k
    Beta_8x16 = _mm_set1_epi16(beta);
112
4.84k
113
4.84k
    line1 = _mm_loadl_epi64((__m128i *)(pu1_src - 4 + 0 * src_strd));
114
4.84k
    line2 = _mm_loadl_epi64((__m128i *)(pu1_src - 4 + 1 * src_strd));
115
4.84k
    line3 = _mm_loadl_epi64((__m128i *)(pu1_src - 4 + 2 * src_strd));
116
4.84k
    line4 = _mm_loadl_epi64((__m128i *)(pu1_src - 4 + 3 * src_strd));
117
4.84k
    line5 = _mm_loadl_epi64((__m128i *)(pu1_src - 4 + 4 * src_strd));
118
4.84k
    line6 = _mm_loadl_epi64((__m128i *)(pu1_src - 4 + 5 * src_strd));
119
4.84k
    line7 = _mm_loadl_epi64((__m128i *)(pu1_src - 4 + 6 * src_strd));
120
4.84k
    line8 = _mm_loadl_epi64((__m128i *)(pu1_src - 4 + 7 * src_strd));
121
4.84k
122
4.84k
    temp1 = _mm_unpacklo_epi8(line1, line2);
123
4.84k
    temp2 = _mm_unpacklo_epi8(line3, line4);
124
4.84k
    temp3 = _mm_unpacklo_epi8(line5, line6);
125
4.84k
    temp4 = _mm_unpacklo_epi8(line7, line8);
126
4.84k
127
4.84k
    line1 = _mm_unpacklo_epi16(temp1, temp2);
128
4.84k
    line2 = _mm_unpackhi_epi16(temp1, temp2);
129
4.84k
    line3 = _mm_unpacklo_epi16(temp3, temp4);
130
4.84k
    line4 = _mm_unpackhi_epi16(temp3, temp4);
131
4.84k
132
4.84k
    p1_8x16 = _mm_unpacklo_epi32(line1, line3);
133
4.84k
    p0_8x16 = _mm_unpackhi_epi32(line1, line3);
134
4.84k
    q0_8x16 = _mm_unpacklo_epi32(line2, line4);
135
4.84k
    q1_8x16 = _mm_unpackhi_epi32(line2, line4);
136
4.84k
137
4.84k
    line1 = _mm_loadl_epi64((__m128i *)(pu1_src - 4 + 8 * src_strd));
138
4.84k
    line2 = _mm_loadl_epi64((__m128i *)(pu1_src - 4 + 9 * src_strd));
139
4.84k
    line3 = _mm_loadl_epi64((__m128i *)(pu1_src - 4 + 10 * src_strd));
140
4.84k
    line4 = _mm_loadl_epi64((__m128i *)(pu1_src - 4 + 11 * src_strd));
141
4.84k
    line5 = _mm_loadl_epi64((__m128i *)(pu1_src - 4 + 12 * src_strd));
142
4.84k
    line6 = _mm_loadl_epi64((__m128i *)(pu1_src - 4 + 13 * src_strd));
143
4.84k
    line7 = _mm_loadl_epi64((__m128i *)(pu1_src - 4 + 14 * src_strd));
144
4.84k
    line8 = _mm_loadl_epi64((__m128i *)(pu1_src - 4 + 15 * src_strd));
145
4.84k
146
4.84k
    temp1 = _mm_unpacklo_epi8(line1, line2);
147
4.84k
    temp2 = _mm_unpacklo_epi8(line3, line4);
148
4.84k
    temp3 = _mm_unpacklo_epi8(line5, line6);
149
4.84k
    temp4 = _mm_unpacklo_epi8(line7, line8);
150
4.84k
151
4.84k
    line1 = _mm_unpacklo_epi16(temp1, temp2);
152
4.84k
    line2 = _mm_unpackhi_epi16(temp1, temp2);
153
4.84k
    line3 = _mm_unpacklo_epi16(temp3, temp4);
154
4.84k
    line4 = _mm_unpackhi_epi16(temp3, temp4);
155
4.84k
156
4.84k
    temp1 = _mm_unpacklo_epi32(line1, line3);
157
4.84k
    temp2 = _mm_unpackhi_epi32(line1, line3);
158
4.84k
    temp3 = _mm_unpacklo_epi32(line2, line4);
159
4.84k
    temp4 = _mm_unpackhi_epi32(line2, line4);
160
4.84k
161
4.84k
    p3_16x8 = _mm_unpacklo_epi64(p1_8x16, temp1);
162
4.84k
    p2_16x8 = _mm_unpackhi_epi64(p1_8x16, temp1);
163
4.84k
    q2_16x8 = _mm_unpacklo_epi64(q1_8x16, temp4);
164
4.84k
    q3_16x8 = _mm_unpackhi_epi64(q1_8x16, temp4);
165
4.84k
    p1_16x8 = _mm_unpacklo_epi64(p0_8x16, temp2);
166
4.84k
    p0_16x8 = _mm_unpackhi_epi64(p0_8x16, temp2);
167
4.84k
    q0_16x8 = _mm_unpacklo_epi64(q0_8x16, temp3);
168
4.84k
    q1_16x8 = _mm_unpackhi_epi64(q0_8x16, temp3);
169
4.84k
170
4.84k
    //Cond1 (ABS(p0 - q0) < alpha)
171
4.84k
    temp1 = _mm_subs_epu8(q0_16x8, p0_16x8);
172
4.84k
    temp2 = _mm_subs_epu8(p0_16x8, q0_16x8);
173
4.84k
    temp1 = _mm_add_epi8(temp1, temp2);
174
4.84k
175
4.84k
    temp2 = _mm_unpacklo_epi8(temp1, zero);
176
4.84k
    temp1 = _mm_unpackhi_epi8(temp1, zero);
177
4.84k
178
4.84k
    temp2 = _mm_cmpgt_epi16(Alpha_8x16, temp2);
179
4.84k
    temp1 = _mm_cmpgt_epi16(Alpha_8x16, temp1);
180
4.84k
181
4.84k
    flag1_16x8 = _mm_packs_epi16(temp2, temp1);
182
4.84k
183
4.84k
    //Cond2 (ABS(q1 - q0) < beta)
184
4.84k
    temp1 = _mm_subs_epu8(q0_16x8, q1_16x8);
185
4.84k
    temp2 = _mm_subs_epu8(q1_16x8, q0_16x8);
186
4.84k
    temp1 = _mm_add_epi8(temp1, temp2);
187
4.84k
188
4.84k
    temp2 = _mm_unpacklo_epi8(temp1, zero);
189
4.84k
    temp1 = _mm_unpackhi_epi8(temp1, zero);
190
4.84k
191
4.84k
    temp2 = _mm_cmpgt_epi16(Beta_8x16, temp2);
192
4.84k
    temp1 = _mm_cmpgt_epi16(Beta_8x16, temp1);
193
4.84k
194
4.84k
    flag2_16x8 = _mm_packs_epi16(temp2, temp1);
195
4.84k
196
4.84k
    flag1_16x8 = _mm_and_si128(flag1_16x8, flag2_16x8);
197
4.84k
198
4.84k
    //Cond3 (ABS(p1 - p0) < beta)
199
4.84k
    temp1 = _mm_subs_epu8(p0_16x8, p1_16x8);
200
4.84k
    temp2 = _mm_subs_epu8(p1_16x8, p0_16x8);
201
4.84k
    temp1 = _mm_add_epi8(temp1, temp2);
202
4.84k
203
4.84k
    temp2 = _mm_unpacklo_epi8(temp1, zero);
204
4.84k
    temp1 = _mm_unpackhi_epi8(temp1, zero);
205
4.84k
206
4.84k
    temp2 = _mm_cmpgt_epi16(Beta_8x16, temp2);
207
4.84k
    temp1 = _mm_cmpgt_epi16(Beta_8x16, temp1);
208
4.84k
209
4.84k
    flag2_16x8 = _mm_packs_epi16(temp2, temp1);
210
4.84k
211
4.84k
    // !((ABS(p0 - q0) < alpha) || (ABS(q1 - q0) < beta) || (ABS(p1 - p0) < beta))
212
4.84k
    flag1_16x8 = _mm_and_si128(flag1_16x8, flag2_16x8);
213
4.84k
214
4.84k
    // (ABS(p0 - q0) < ((alpha >> 2) + 2))
215
4.84k
    temp1 = _mm_subs_epu8(p0_16x8, q0_16x8);
216
4.84k
    temp2 = _mm_subs_epu8(q0_16x8, p0_16x8);
217
4.84k
    temp1 = _mm_add_epi8(temp1, temp2);
218
4.84k
    Alpha_8x16 = _mm_srai_epi16(Alpha_8x16, 2);
219
4.84k
    Alpha_8x16 = _mm_add_epi16(Alpha_8x16, const_val2_16x8);
220
4.84k
221
4.84k
    temp2 = _mm_unpacklo_epi8(temp1, zero);
222
4.84k
    temp1 = _mm_unpackhi_epi8(temp1, zero);
223
4.84k
    temp2 = _mm_cmpgt_epi16(Alpha_8x16, temp2);
224
4.84k
    temp1 = _mm_cmpgt_epi16(Alpha_8x16, temp1);
225
4.84k
226
4.84k
    flag2_16x8 = _mm_packs_epi16(temp2, temp1);
227
4.84k
    flag2_16x8 = _mm_and_si128(flag1_16x8, flag2_16x8);
228
4.84k
229
4.84k
    // (ABS(p2 - p0) < beta)
230
4.84k
    temp1 = _mm_subs_epu8(p0_16x8, p2_16x8);
231
4.84k
    temp2 = _mm_subs_epu8(p2_16x8, p0_16x8);
232
4.84k
    temp1 = _mm_add_epi8(temp1, temp2);
233
4.84k
234
4.84k
    temp2 = _mm_unpacklo_epi8(temp1, zero);
235
4.84k
    temp1 = _mm_unpackhi_epi8(temp1, zero);
236
4.84k
    temp2 = _mm_cmpgt_epi16(Beta_8x16, temp2);
237
4.84k
    temp1 = _mm_cmpgt_epi16(Beta_8x16, temp1);
238
4.84k
239
4.84k
    flag3_16x8 = _mm_packs_epi16(temp2, temp1);
240
4.84k
    flag3_16x8 = _mm_and_si128(flag3_16x8, flag2_16x8);
241
4.84k
242
4.84k
    // (ABS(q2 - q0) < beta)
243
4.84k
    temp1 = _mm_subs_epu8(q0_16x8, q2_16x8);
244
4.84k
    temp2 = _mm_subs_epu8(q2_16x8, q0_16x8);
245
4.84k
    temp1 = _mm_add_epi8(temp1, temp2);
246
4.84k
247
4.84k
    temp2 = _mm_unpacklo_epi8(temp1, zero);
248
4.84k
    temp1 = _mm_unpackhi_epi8(temp1, zero);
249
4.84k
    temp2 = _mm_cmpgt_epi16(Beta_8x16, temp2);
250
4.84k
    temp1 = _mm_cmpgt_epi16(Beta_8x16, temp1);
251
4.84k
252
4.84k
    flag4_16x8 = _mm_packs_epi16(temp2, temp1);
253
4.84k
    flag4_16x8 = _mm_and_si128(flag4_16x8, flag2_16x8);
254
4.84k
255
4.84k
    // First 8 pixels
256
4.84k
    p3_8x16 = _mm_unpacklo_epi8(p3_16x8, zero);
257
4.84k
    p2_8x16 = _mm_unpacklo_epi8(p2_16x8, zero);
258
4.84k
    p1_8x16 = _mm_unpacklo_epi8(p1_16x8, zero);
259
4.84k
    p0_8x16 = _mm_unpacklo_epi8(p0_16x8, zero);
260
4.84k
    q0_8x16 = _mm_unpacklo_epi8(q0_16x8, zero);
261
4.84k
    q1_8x16 = _mm_unpacklo_epi8(q1_16x8, zero);
262
4.84k
    q2_8x16 = _mm_unpacklo_epi8(q2_16x8, zero);
263
4.84k
    q3_8x16 = _mm_unpacklo_epi8(q3_16x8, zero);
264
4.84k
265
4.84k
    // p0_1 and q0_1
266
4.84k
    temp1 = _mm_add_epi16(p0_8x16, q1_8x16);
267
4.84k
    temp2 = _mm_add_epi16(p1_8x16, q0_8x16);
268
4.84k
    temp5 = _mm_add_epi16(temp1, const_val2_16x8);
269
4.84k
    temp6 = _mm_add_epi16(temp2, const_val2_16x8);
270
4.84k
    temp3 = _mm_slli_epi16(p1_8x16, 1);
271
4.84k
    temp4 = _mm_slli_epi16(q1_8x16, 1);
272
4.84k
    temp1 = _mm_add_epi16(temp5, temp3);
273
4.84k
    temp2 = _mm_add_epi16(temp6, temp4);
274
4.84k
    p0_16x8_1 = _mm_srai_epi16(temp1, 2);
275
4.84k
    q0_16x8_1 = _mm_srai_epi16(temp2, 2);
276
4.84k
277
4.84k
    // p1_2 and q1_2
278
4.84k
    temp6 = _mm_add_epi16(temp6, p0_8x16);
279
4.84k
    temp5 = _mm_add_epi16(temp5, q0_8x16);
280
4.84k
    temp1 = _mm_add_epi16(temp6, p2_8x16);
281
4.84k
    temp2 = _mm_add_epi16(temp5, q2_8x16);
282
4.84k
    p1_16x8_2 = _mm_srai_epi16(temp1, 2);
283
4.84k
    q1_16x8_2 = _mm_srai_epi16(temp2, 2);
284
4.84k
285
4.84k
    // p0_2 and q0_2
286
4.84k
    temp1 = _mm_add_epi16(temp3, p2_8x16);
287
4.84k
    temp2 = _mm_add_epi16(temp4, q2_8x16);
288
4.84k
    temp1 = _mm_add_epi16(temp1, q1_8x16);
289
4.84k
    temp2 = _mm_add_epi16(temp2, p1_8x16);
290
4.84k
    temp3 = _mm_add_epi16(p0_8x16, q0_8x16);
291
4.84k
    temp3 = _mm_slli_epi16(temp3, 1);
292
4.84k
    temp1 = _mm_add_epi16(temp1, temp3);
293
4.84k
    temp2 = _mm_add_epi16(temp2, temp3);
294
4.84k
    temp1 = _mm_add_epi16(temp1, _mm_set1_epi16(4));
295
4.84k
    temp2 = _mm_add_epi16(temp2, _mm_set1_epi16(4));
296
4.84k
    p0_16x8_2 = _mm_srai_epi16(temp1, 3);
297
4.84k
    q0_16x8_2 = _mm_srai_epi16(temp2, 3);
298
4.84k
299
4.84k
    // p2_2 and q2_2
300
4.84k
    temp1 = _mm_add_epi16(temp6, const_val2_16x8);
301
4.84k
    temp2 = _mm_add_epi16(temp5, const_val2_16x8);
302
4.84k
    temp3 = _mm_slli_epi16(p2_8x16, 1);
303
4.84k
    temp4 = _mm_slli_epi16(q2_8x16, 1);
304
4.84k
    temp3 = _mm_add_epi16(p2_8x16, temp3);
305
4.84k
    temp4 = _mm_add_epi16(q2_8x16, temp4);
306
4.84k
    temp5 = _mm_slli_epi16(p3_8x16, 1);
307
4.84k
    temp6 = _mm_slli_epi16(q3_8x16, 1);
308
4.84k
    temp1 = _mm_add_epi16(temp1, temp3);
309
4.84k
    temp2 = _mm_add_epi16(temp2, temp4);
310
4.84k
    temp1 = _mm_add_epi16(temp1, temp5);
311
4.84k
    temp2 = _mm_add_epi16(temp2, temp6);
312
4.84k
    p2_16x8_2 = _mm_srai_epi16(temp1, 3);
313
4.84k
    q2_16x8_2 = _mm_srai_epi16(temp2, 3);
314
4.84k
315
4.84k
    // Second 8 pixels and packing with first 8 pixels
316
4.84k
    p3_8x16 = _mm_unpackhi_epi8(p3_16x8, zero);
317
4.84k
    p2_8x16 = _mm_unpackhi_epi8(p2_16x8, zero);
318
4.84k
    p1_8x16 = _mm_unpackhi_epi8(p1_16x8, zero);
319
4.84k
    p0_8x16 = _mm_unpackhi_epi8(p0_16x8, zero);
320
4.84k
    q0_8x16 = _mm_unpackhi_epi8(q0_16x8, zero);
321
4.84k
    q1_8x16 = _mm_unpackhi_epi8(q1_16x8, zero);
322
4.84k
    q2_8x16 = _mm_unpackhi_epi8(q2_16x8, zero);
323
4.84k
    q3_8x16 = _mm_unpackhi_epi8(q3_16x8, zero);
324
4.84k
325
4.84k
    // p0_1 and q0_1
326
4.84k
    temp1 = _mm_add_epi16(p0_8x16, q1_8x16);
327
4.84k
    temp2 = _mm_add_epi16(p1_8x16, q0_8x16);
328
4.84k
    temp5 = _mm_add_epi16(temp1, const_val2_16x8);
329
4.84k
    temp6 = _mm_add_epi16(temp2, const_val2_16x8);
330
4.84k
    temp3 = _mm_slli_epi16(p1_8x16, 1);
331
4.84k
    temp4 = _mm_slli_epi16(q1_8x16, 1);
332
4.84k
    temp1 = _mm_add_epi16(temp5, temp3);
333
4.84k
    temp2 = _mm_add_epi16(temp6, temp4);
334
4.84k
    temp1 = _mm_srai_epi16(temp1, 2);
335
4.84k
    temp2 = _mm_srai_epi16(temp2, 2);
336
4.84k
    p0_16x8_1 = _mm_packus_epi16(p0_16x8_1, temp1);
337
4.84k
    q0_16x8_1 = _mm_packus_epi16(q0_16x8_1, temp2);
338
4.84k
339
4.84k
    // p1_2 and q1_2
340
4.84k
    temp6 = _mm_add_epi16(temp6, p0_8x16);
341
4.84k
    temp5 = _mm_add_epi16(temp5, q0_8x16);
342
4.84k
    temp1 = _mm_add_epi16(temp6, p2_8x16);
343
4.84k
    temp2 = _mm_add_epi16(temp5, q2_8x16);
344
4.84k
    temp1 = _mm_srai_epi16(temp1, 2);
345
4.84k
    temp2 = _mm_srai_epi16(temp2, 2);
346
4.84k
    p1_16x8_2 = _mm_packus_epi16(p1_16x8_2, temp1);
347
4.84k
    q1_16x8_2 = _mm_packus_epi16(q1_16x8_2, temp2);
348
4.84k
349
4.84k
    // p0_2 and q0_2
350
4.84k
    temp1 = _mm_add_epi16(temp3, p2_8x16);
351
4.84k
    temp2 = _mm_add_epi16(temp4, q2_8x16);
352
4.84k
    temp1 = _mm_add_epi16(temp1, q1_8x16);
353
4.84k
    temp2 = _mm_add_epi16(temp2, p1_8x16);
354
4.84k
    temp3 = _mm_add_epi16(p0_8x16, q0_8x16);
355
4.84k
    temp3 = _mm_slli_epi16(temp3, 1);
356
4.84k
    temp1 = _mm_add_epi16(temp1, temp3);
357
4.84k
    temp2 = _mm_add_epi16(temp2, temp3);
358
4.84k
    temp1 = _mm_add_epi16(temp1, _mm_set1_epi16(4));
359
4.84k
    temp2 = _mm_add_epi16(temp2, _mm_set1_epi16(4));
360
4.84k
    temp1 = _mm_srai_epi16(temp1, 3);
361
4.84k
    temp2 = _mm_srai_epi16(temp2, 3);
362
4.84k
    p0_16x8_2 = _mm_packus_epi16(p0_16x8_2, temp1);
363
4.84k
    q0_16x8_2 = _mm_packus_epi16(q0_16x8_2, temp2);
364
4.84k
365
4.84k
    // p2_2 and q2_2
366
4.84k
    temp1 = _mm_add_epi16(temp6, const_val2_16x8);
367
4.84k
    temp2 = _mm_add_epi16(temp5, const_val2_16x8);
368
4.84k
    temp3 = _mm_slli_epi16(p2_8x16, 1);
369
4.84k
    temp4 = _mm_slli_epi16(q2_8x16, 1);
370
4.84k
    temp3 = _mm_add_epi16(p2_8x16, temp3);
371
4.84k
    temp4 = _mm_add_epi16(q2_8x16, temp4);
372
4.84k
    temp5 = _mm_slli_epi16(p3_8x16, 1);
373
4.84k
    temp6 = _mm_slli_epi16(q3_8x16, 1);
374
4.84k
    temp1 = _mm_add_epi16(temp1, temp3);
375
4.84k
    temp2 = _mm_add_epi16(temp2, temp4);
376
4.84k
    temp1 = _mm_add_epi16(temp1, temp5);
377
4.84k
    temp2 = _mm_add_epi16(temp2, temp6);
378
4.84k
    temp1 = _mm_srai_epi16(temp1, 3);
379
4.84k
    temp2 = _mm_srai_epi16(temp2, 3);
380
4.84k
    p2_16x8_2 = _mm_packus_epi16(p2_16x8_2, temp1);
381
4.84k
    q2_16x8_2 = _mm_packus_epi16(q2_16x8_2, temp2);
382
4.84k
383
4.84k
    // p0 and q0
384
4.84k
    p0_16x8 = _mm_and_si128(p0_16x8,
385
4.84k
                            _mm_xor_si128(flag1_16x8, _mm_set1_epi8(0xFF)));
386
4.84k
    p0_16x8_1 = _mm_and_si128(p0_16x8_1, flag1_16x8);
387
4.84k
    p0_16x8 = _mm_add_epi8(p0_16x8, p0_16x8_1);
388
4.84k
    q0_16x8 = _mm_and_si128(q0_16x8,
389
4.84k
                            _mm_xor_si128(flag1_16x8, _mm_set1_epi8(0xFF)));
390
4.84k
    q0_16x8_1 = _mm_and_si128(q0_16x8_1, flag1_16x8);
391
4.84k
    q0_16x8 = _mm_add_epi8(q0_16x8, q0_16x8_1);
392
4.84k
393
4.84k
    // p0 and q0
394
4.84k
    p0_16x8 = _mm_and_si128(p0_16x8,
395
4.84k
                            _mm_xor_si128(flag3_16x8, _mm_set1_epi8(0xFF)));
396
4.84k
    p0_16x8_2 = _mm_and_si128(p0_16x8_2, flag3_16x8);
397
4.84k
    p0_16x8 = _mm_add_epi8(p0_16x8, p0_16x8_2);
398
4.84k
    q0_16x8 = _mm_and_si128(q0_16x8,
399
4.84k
                            _mm_xor_si128(flag4_16x8, _mm_set1_epi8(0xFF)));
400
4.84k
    q0_16x8_2 = _mm_and_si128(q0_16x8_2, flag4_16x8);
401
4.84k
    q0_16x8 = _mm_add_epi8(q0_16x8, q0_16x8_2);
402
4.84k
403
4.84k
    // p1 and q1
404
4.84k
    p1_16x8 = _mm_and_si128(p1_16x8,
405
4.84k
                            _mm_xor_si128(flag3_16x8, _mm_set1_epi8(0xFF)));
406
4.84k
    p1_16x8_2 = _mm_and_si128(p1_16x8_2, flag3_16x8);
407
4.84k
    p1_16x8 = _mm_add_epi8(p1_16x8, p1_16x8_2);
408
4.84k
    q1_16x8 = _mm_and_si128(q1_16x8,
409
4.84k
                            _mm_xor_si128(flag4_16x8, _mm_set1_epi8(0xFF)));
410
4.84k
    q1_16x8_2 = _mm_and_si128(q1_16x8_2, flag4_16x8);
411
4.84k
    q1_16x8 = _mm_add_epi8(q1_16x8, q1_16x8_2);
412
4.84k
413
4.84k
    // p2 and q2
414
4.84k
    p2_16x8 = _mm_and_si128(p2_16x8,
415
4.84k
                            _mm_xor_si128(flag3_16x8, _mm_set1_epi8(0xFF)));
416
4.84k
    p2_16x8_2 = _mm_and_si128(p2_16x8_2, flag3_16x8);
417
4.84k
    p2_16x8 = _mm_add_epi8(p2_16x8, p2_16x8_2);
418
4.84k
    q2_16x8 = _mm_and_si128(q2_16x8,
419
4.84k
                            _mm_xor_si128(flag4_16x8, _mm_set1_epi8(0xFF)));
420
4.84k
    q2_16x8_2 = _mm_and_si128(q2_16x8_2, flag4_16x8);
421
4.84k
    q2_16x8 = _mm_add_epi8(q2_16x8, q2_16x8_2);
422
4.84k
423
4.84k
    temp1 = _mm_unpacklo_epi8(p3_16x8, p2_16x8);
424
4.84k
    temp2 = _mm_unpacklo_epi8(p1_16x8, p0_16x8);
425
4.84k
    temp3 = _mm_unpacklo_epi8(q0_16x8, q1_16x8);
426
4.84k
    temp4 = _mm_unpacklo_epi8(q2_16x8, q3_16x8);
427
4.84k
428
4.84k
    p3_8x16 = _mm_unpacklo_epi16(temp1, temp2);
429
4.84k
    p2_8x16 = _mm_unpackhi_epi16(temp1, temp2);
430
4.84k
    q2_8x16 = _mm_unpacklo_epi16(temp3, temp4);
431
4.84k
    q3_8x16 = _mm_unpackhi_epi16(temp3, temp4);
432
4.84k
433
4.84k
    line1 = _mm_unpacklo_epi32(p3_8x16, q2_8x16);
434
4.84k
    line2 = _mm_srli_si128(line1, 8);
435
4.84k
    line3 = _mm_unpackhi_epi32(p3_8x16, q2_8x16);
436
4.84k
    line4 = _mm_srli_si128(line3, 8);
437
4.84k
    line5 = _mm_unpacklo_epi32(p2_8x16, q3_8x16);
438
4.84k
    line6 = _mm_srli_si128(line5, 8);
439
4.84k
    line7 = _mm_unpackhi_epi32(p2_8x16, q3_8x16);
440
4.84k
    line8 = _mm_srli_si128(line7, 8);
441
4.84k
442
4.84k
    _mm_storel_epi64((__m128i *)(pu1_src - 4 + 0 * src_strd), line1);
443
4.84k
    _mm_storel_epi64((__m128i *)(pu1_src - 4 + 1 * src_strd), line2);
444
4.84k
    _mm_storel_epi64((__m128i *)(pu1_src - 4 + 2 * src_strd), line3);
445
4.84k
    _mm_storel_epi64((__m128i *)(pu1_src - 4 + 3 * src_strd), line4);
446
4.84k
    _mm_storel_epi64((__m128i *)(pu1_src - 4 + 4 * src_strd), line5);
447
4.84k
    _mm_storel_epi64((__m128i *)(pu1_src - 4 + 5 * src_strd), line6);
448
4.84k
    _mm_storel_epi64((__m128i *)(pu1_src - 4 + 6 * src_strd), line7);
449
4.84k
    _mm_storel_epi64((__m128i *)(pu1_src - 4 + 7 * src_strd), line8);
450
4.84k
451
4.84k
    temp1 = _mm_unpackhi_epi8(p3_16x8, p2_16x8);
452
4.84k
    temp2 = _mm_unpackhi_epi8(p1_16x8, p0_16x8);
453
4.84k
    temp3 = _mm_unpackhi_epi8(q0_16x8, q1_16x8);
454
4.84k
    temp4 = _mm_unpackhi_epi8(q2_16x8, q3_16x8);
455
4.84k
456
4.84k
    p3_8x16 = _mm_unpacklo_epi16(temp1, temp2);
457
4.84k
    p2_8x16 = _mm_unpackhi_epi16(temp1, temp2);
458
4.84k
    q2_8x16 = _mm_unpacklo_epi16(temp3, temp4);
459
4.84k
    q3_8x16 = _mm_unpackhi_epi16(temp3, temp4);
460
4.84k
461
4.84k
    line1 = _mm_unpacklo_epi32(p3_8x16, q2_8x16);
462
4.84k
    line2 = _mm_srli_si128(line1, 8);
463
4.84k
    line3 = _mm_unpackhi_epi32(p3_8x16, q2_8x16);
464
4.84k
    line4 = _mm_srli_si128(line3, 8);
465
4.84k
    line5 = _mm_unpacklo_epi32(p2_8x16, q3_8x16);
466
4.84k
    line6 = _mm_srli_si128(line5, 8);
467
4.84k
    line7 = _mm_unpackhi_epi32(p2_8x16, q3_8x16);
468
4.84k
    line8 = _mm_srli_si128(line7, 8);
469
4.84k
470
4.84k
    _mm_storel_epi64((__m128i *)(pu1_src - 4 + 8 * src_strd), line1);
471
4.84k
    _mm_storel_epi64((__m128i *)(pu1_src - 4 + 9 * src_strd), line2);
472
4.84k
    _mm_storel_epi64((__m128i *)(pu1_src - 4 + 10 * src_strd), line3);
473
4.84k
    _mm_storel_epi64((__m128i *)(pu1_src - 4 + 11 * src_strd), line4);
474
4.84k
    _mm_storel_epi64((__m128i *)(pu1_src - 4 + 12 * src_strd), line5);
475
4.84k
    _mm_storel_epi64((__m128i *)(pu1_src - 4 + 13 * src_strd), line6);
476
4.84k
    _mm_storel_epi64((__m128i *)(pu1_src - 4 + 14 * src_strd), line7);
477
4.84k
    _mm_storel_epi64((__m128i *)(pu1_src - 4 + 15 * src_strd), line8);
478
4.84k
479
4.84k
}
480
481
/*****************************************************************************/
482
/*                                                                           */
483
/*  Function Name : ih264_deblk_luma_horz_bs4_ssse3()                        */
484
/*                                                                           */
485
/*  Description   : This function performs filtering of a luma block         */
486
/*                  horizontal edge when the boundary strength is set to 4.  */
487
/*                                                                           */
488
/*  Inputs        : pu1_src    - pointer to the src sample q0                */
489
/*                  src_strd   - source stride                               */
490
/*                  alpha      - alpha value for the boundary                */
491
/*                  beta       - beta value for the boundary                 */
492
/*                                                                           */
493
/*  Globals       : None                                                     */
494
/*                                                                           */
495
/*  Processing    : This operation is described in Sec. 8.7.2.4 under the    */
496
/*                  title "Filtering process for edges for bS equal to 4" in */
497
/*                  ITU T Rec H.264.                                         */
498
/*                                                                           */
499
/*  Outputs       : None                                                     */
500
/*                                                                           */
501
/*  Returns       : None                                                     */
502
/*                                                                           */
503
/*  Issues        : None                                                     */
504
/*                                                                           */
505
/*  Revision History:                                                        */
506
/*                                                                           */
507
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
508
/*         12 02 2015   Naveen Kumar P  Initial version                      */
509
/*                                                                           */
510
/*****************************************************************************/
511
void ih264_deblk_luma_horz_bs4_ssse3(UWORD8 *pu1_src,
512
                                     WORD32 src_strd,
513
                                     WORD32 alpha,
514
                                     WORD32 beta)
515
4.80k
{
516
4.80k
    WORD16 i16_posP3, i16_posP2, i16_posP1, i16_posP0;
517
4.80k
    WORD16 i16_posQ1, i16_posQ2, i16_posQ3;
518
4.80k
    UWORD8 *pu1_HorzPixel;
519
4.80k
    __m128i zero = _mm_setzero_si128();
520
4.80k
    __m128i q0_16x8, q1_16x8, q2_16x8, q3_16x8;
521
4.80k
    __m128i p0_16x8, p1_16x8, p2_16x8, p3_16x8;
522
4.80k
    __m128i q0_8x16, q1_8x16, q2_8x16, q3_8x16;
523
4.80k
    __m128i p0_8x16, p1_8x16, p2_8x16, p3_8x16;
524
4.80k
    __m128i q0_16x8_1;
525
4.80k
    __m128i p0_16x8_1;
526
4.80k
    __m128i q0_16x8_2, q1_16x8_2, q2_16x8_2;
527
4.80k
    __m128i p0_16x8_2, p1_16x8_2, p2_16x8_2;
528
4.80k
    __m128i temp1, temp2, temp3, temp4, temp5, temp6;
529
4.80k
    __m128i Alpha_8x16, Beta_8x16;
530
4.80k
    __m128i flag1_16x8, flag2_16x8, flag3_16x8, flag4_16x8;
531
4.80k
    __m128i const_val2_16x8 = _mm_set1_epi16(2);
532
4.80k
533
4.80k
    pu1_HorzPixel = pu1_src - (src_strd << 2);
534
4.80k
535
4.80k
    i16_posQ1 = src_strd;
536
4.80k
    i16_posQ2 = X2(src_strd);
537
4.80k
    i16_posQ3 = X3(src_strd);
538
4.80k
    i16_posP0 = X3(src_strd);
539
4.80k
    i16_posP1 = X2(src_strd);
540
4.80k
    i16_posP2 = src_strd;
541
4.80k
    i16_posP3 = 0;
542
4.80k
543
4.80k
    Alpha_8x16 = _mm_set1_epi16(alpha);
544
4.80k
    Beta_8x16 = _mm_set1_epi16(beta);
545
4.80k
546
4.80k
    p3_16x8 = _mm_loadu_si128((__m128i *)(pu1_HorzPixel + i16_posP3));
547
4.80k
    p2_16x8 = _mm_loadu_si128((__m128i *)(pu1_HorzPixel + i16_posP2));
548
4.80k
    p1_16x8 = _mm_loadu_si128((__m128i *)(pu1_HorzPixel + i16_posP1));
549
4.80k
    p0_16x8 = _mm_loadu_si128((__m128i *)(pu1_HorzPixel + i16_posP0));
550
4.80k
    q0_16x8 = _mm_loadu_si128((__m128i *)(pu1_src));
551
4.80k
    q1_16x8 = _mm_loadu_si128((__m128i *)(pu1_src + i16_posQ1));
552
4.80k
    q2_16x8 = _mm_loadu_si128((__m128i *)(pu1_src + i16_posQ2));
553
4.80k
    q3_16x8 = _mm_loadu_si128((__m128i *)(pu1_src + i16_posQ3));
554
4.80k
555
4.80k
    //Cond1 (ABS(p0 - q0) < alpha)
556
4.80k
    temp1 = _mm_subs_epu8(q0_16x8, p0_16x8);
557
4.80k
    temp2 = _mm_subs_epu8(p0_16x8, q0_16x8);
558
4.80k
    temp1 = _mm_add_epi8(temp1, temp2);
559
4.80k
560
4.80k
    temp2 = _mm_unpacklo_epi8(temp1, zero);
561
4.80k
    temp1 = _mm_unpackhi_epi8(temp1, zero);
562
4.80k
563
4.80k
    temp2 = _mm_cmpgt_epi16(Alpha_8x16, temp2);
564
4.80k
    temp1 = _mm_cmpgt_epi16(Alpha_8x16, temp1);
565
4.80k
566
4.80k
    flag1_16x8 = _mm_packs_epi16(temp2, temp1);
567
4.80k
568
4.80k
    //Cond2 (ABS(q1 - q0) < beta)
569
4.80k
    temp1 = _mm_subs_epu8(q0_16x8, q1_16x8);
570
4.80k
    temp2 = _mm_subs_epu8(q1_16x8, q0_16x8);
571
4.80k
    temp1 = _mm_add_epi8(temp1, temp2);
572
4.80k
573
4.80k
    temp2 = _mm_unpacklo_epi8(temp1, zero);
574
4.80k
    temp1 = _mm_unpackhi_epi8(temp1, zero);
575
4.80k
576
4.80k
    temp2 = _mm_cmpgt_epi16(Beta_8x16, temp2);
577
4.80k
    temp1 = _mm_cmpgt_epi16(Beta_8x16, temp1);
578
4.80k
579
4.80k
    flag2_16x8 = _mm_packs_epi16(temp2, temp1);
580
4.80k
581
4.80k
    flag1_16x8 = _mm_and_si128(flag1_16x8, flag2_16x8);
582
4.80k
583
4.80k
    //Cond3 (ABS(p1 - p0) < beta)
584
4.80k
    temp1 = _mm_subs_epu8(p0_16x8, p1_16x8);
585
4.80k
    temp2 = _mm_subs_epu8(p1_16x8, p0_16x8);
586
4.80k
    temp1 = _mm_add_epi8(temp1, temp2);
587
4.80k
588
4.80k
    temp2 = _mm_unpacklo_epi8(temp1, zero);
589
4.80k
    temp1 = _mm_unpackhi_epi8(temp1, zero);
590
4.80k
591
4.80k
    temp2 = _mm_cmpgt_epi16(Beta_8x16, temp2);
592
4.80k
    temp1 = _mm_cmpgt_epi16(Beta_8x16, temp1);
593
4.80k
594
4.80k
    flag2_16x8 = _mm_packs_epi16(temp2, temp1);
595
4.80k
596
4.80k
    // !((ABS(p0 - q0) < alpha) || (ABS(q1 - q0) < beta) || (ABS(p1 - p0) < beta))
597
4.80k
    flag1_16x8 = _mm_and_si128(flag1_16x8, flag2_16x8);
598
4.80k
599
4.80k
    // (ABS(p0 - q0) < ((alpha >> 2) + 2))
600
4.80k
    temp1 = _mm_subs_epu8(p0_16x8, q0_16x8);
601
4.80k
    temp2 = _mm_subs_epu8(q0_16x8, p0_16x8);
602
4.80k
    temp1 = _mm_add_epi8(temp1, temp2);
603
4.80k
    Alpha_8x16 = _mm_srai_epi16(Alpha_8x16, 2);
604
4.80k
    Alpha_8x16 = _mm_add_epi16(Alpha_8x16, const_val2_16x8);
605
4.80k
606
4.80k
    temp2 = _mm_unpacklo_epi8(temp1, zero);
607
4.80k
    temp1 = _mm_unpackhi_epi8(temp1, zero);
608
4.80k
    temp2 = _mm_cmpgt_epi16(Alpha_8x16, temp2);
609
4.80k
    temp1 = _mm_cmpgt_epi16(Alpha_8x16, temp1);
610
4.80k
611
4.80k
    flag2_16x8 = _mm_packs_epi16(temp2, temp1);
612
4.80k
    flag2_16x8 = _mm_and_si128(flag1_16x8, flag2_16x8);
613
4.80k
614
4.80k
    // (ABS(p2 - p0) < beta)
615
4.80k
    temp1 = _mm_subs_epu8(p0_16x8, p2_16x8);
616
4.80k
    temp2 = _mm_subs_epu8(p2_16x8, p0_16x8);
617
4.80k
    temp1 = _mm_add_epi8(temp1, temp2);
618
4.80k
619
4.80k
    temp2 = _mm_unpacklo_epi8(temp1, zero);
620
4.80k
    temp1 = _mm_unpackhi_epi8(temp1, zero);
621
4.80k
    temp2 = _mm_cmpgt_epi16(Beta_8x16, temp2);
622
4.80k
    temp1 = _mm_cmpgt_epi16(Beta_8x16, temp1);
623
4.80k
624
4.80k
    flag3_16x8 = _mm_packs_epi16(temp2, temp1);
625
4.80k
    flag3_16x8 = _mm_and_si128(flag3_16x8, flag2_16x8);
626
4.80k
627
4.80k
    // (ABS(q2 - q0) < beta)
628
4.80k
    temp1 = _mm_subs_epu8(q0_16x8, q2_16x8);
629
4.80k
    temp2 = _mm_subs_epu8(q2_16x8, q0_16x8);
630
4.80k
    temp1 = _mm_add_epi8(temp1, temp2);
631
4.80k
632
4.80k
    temp2 = _mm_unpacklo_epi8(temp1, zero);
633
4.80k
    temp1 = _mm_unpackhi_epi8(temp1, zero);
634
4.80k
    temp2 = _mm_cmpgt_epi16(Beta_8x16, temp2);
635
4.80k
    temp1 = _mm_cmpgt_epi16(Beta_8x16, temp1);
636
4.80k
637
4.80k
    flag4_16x8 = _mm_packs_epi16(temp2, temp1);
638
4.80k
    flag4_16x8 = _mm_and_si128(flag4_16x8, flag2_16x8);
639
4.80k
640
4.80k
    // First 8 pixels
641
4.80k
    p3_8x16 = _mm_unpacklo_epi8(p3_16x8, zero);
642
4.80k
    p2_8x16 = _mm_unpacklo_epi8(p2_16x8, zero);
643
4.80k
    p1_8x16 = _mm_unpacklo_epi8(p1_16x8, zero);
644
4.80k
    p0_8x16 = _mm_unpacklo_epi8(p0_16x8, zero);
645
4.80k
    q0_8x16 = _mm_unpacklo_epi8(q0_16x8, zero);
646
4.80k
    q1_8x16 = _mm_unpacklo_epi8(q1_16x8, zero);
647
4.80k
    q2_8x16 = _mm_unpacklo_epi8(q2_16x8, zero);
648
4.80k
    q3_8x16 = _mm_unpacklo_epi8(q3_16x8, zero);
649
4.80k
650
4.80k
    // p0_1 and q0_1
651
4.80k
    temp1 = _mm_add_epi16(p0_8x16, q1_8x16);
652
4.80k
    temp2 = _mm_add_epi16(p1_8x16, q0_8x16);
653
4.80k
    temp5 = _mm_add_epi16(temp1, const_val2_16x8);
654
4.80k
    temp6 = _mm_add_epi16(temp2, const_val2_16x8);
655
4.80k
    temp3 = _mm_slli_epi16(p1_8x16, 1);
656
4.80k
    temp4 = _mm_slli_epi16(q1_8x16, 1);
657
4.80k
    temp1 = _mm_add_epi16(temp5, temp3);
658
4.80k
    temp2 = _mm_add_epi16(temp6, temp4);
659
4.80k
    p0_16x8_1 = _mm_srai_epi16(temp1, 2);
660
4.80k
    q0_16x8_1 = _mm_srai_epi16(temp2, 2);
661
4.80k
662
4.80k
    // p1_2 and q1_2
663
4.80k
    temp6 = _mm_add_epi16(temp6, p0_8x16);
664
4.80k
    temp5 = _mm_add_epi16(temp5, q0_8x16);
665
4.80k
    temp1 = _mm_add_epi16(temp6, p2_8x16);
666
4.80k
    temp2 = _mm_add_epi16(temp5, q2_8x16);
667
4.80k
    p1_16x8_2 = _mm_srai_epi16(temp1, 2);
668
4.80k
    q1_16x8_2 = _mm_srai_epi16(temp2, 2);
669
4.80k
670
4.80k
    // p0_2 and q0_2
671
4.80k
    temp1 = _mm_add_epi16(temp3, p2_8x16);
672
4.80k
    temp2 = _mm_add_epi16(temp4, q2_8x16);
673
4.80k
    temp1 = _mm_add_epi16(temp1, q1_8x16);
674
4.80k
    temp2 = _mm_add_epi16(temp2, p1_8x16);
675
4.80k
    temp3 = _mm_add_epi16(p0_8x16, q0_8x16);
676
4.80k
    temp3 = _mm_slli_epi16(temp3, 1);
677
4.80k
    temp1 = _mm_add_epi16(temp1, temp3);
678
4.80k
    temp2 = _mm_add_epi16(temp2, temp3);
679
4.80k
    temp1 = _mm_add_epi16(temp1, _mm_set1_epi16(4));
680
4.80k
    temp2 = _mm_add_epi16(temp2, _mm_set1_epi16(4));
681
4.80k
    p0_16x8_2 = _mm_srai_epi16(temp1, 3);
682
4.80k
    q0_16x8_2 = _mm_srai_epi16(temp2, 3);
683
4.80k
684
4.80k
    // p2_2 and q2_2
685
4.80k
    temp1 = _mm_add_epi16(temp6, const_val2_16x8);
686
4.80k
    temp2 = _mm_add_epi16(temp5, const_val2_16x8);
687
4.80k
    temp3 = _mm_slli_epi16(p2_8x16, 1);
688
4.80k
    temp4 = _mm_slli_epi16(q2_8x16, 1);
689
4.80k
    temp3 = _mm_add_epi16(p2_8x16, temp3);
690
4.80k
    temp4 = _mm_add_epi16(q2_8x16, temp4);
691
4.80k
    temp5 = _mm_slli_epi16(p3_8x16, 1);
692
4.80k
    temp6 = _mm_slli_epi16(q3_8x16, 1);
693
4.80k
    temp1 = _mm_add_epi16(temp1, temp3);
694
4.80k
    temp2 = _mm_add_epi16(temp2, temp4);
695
4.80k
    temp1 = _mm_add_epi16(temp1, temp5);
696
4.80k
    temp2 = _mm_add_epi16(temp2, temp6);
697
4.80k
    p2_16x8_2 = _mm_srai_epi16(temp1, 3);
698
4.80k
    q2_16x8_2 = _mm_srai_epi16(temp2, 3);
699
4.80k
700
4.80k
    // Second 8 pixels and packing with first 8 pixels
701
4.80k
    p3_8x16 = _mm_unpackhi_epi8(p3_16x8, zero);
702
4.80k
    p2_8x16 = _mm_unpackhi_epi8(p2_16x8, zero);
703
4.80k
    p1_8x16 = _mm_unpackhi_epi8(p1_16x8, zero);
704
4.80k
    p0_8x16 = _mm_unpackhi_epi8(p0_16x8, zero);
705
4.80k
    q0_8x16 = _mm_unpackhi_epi8(q0_16x8, zero);
706
4.80k
    q1_8x16 = _mm_unpackhi_epi8(q1_16x8, zero);
707
4.80k
    q2_8x16 = _mm_unpackhi_epi8(q2_16x8, zero);
708
4.80k
    q3_8x16 = _mm_unpackhi_epi8(q3_16x8, zero);
709
4.80k
710
4.80k
    // p0_1 and q0_1
711
4.80k
    temp1 = _mm_add_epi16(p0_8x16, q1_8x16);
712
4.80k
    temp2 = _mm_add_epi16(p1_8x16, q0_8x16);
713
4.80k
    temp5 = _mm_add_epi16(temp1, const_val2_16x8);
714
4.80k
    temp6 = _mm_add_epi16(temp2, const_val2_16x8);
715
4.80k
    temp3 = _mm_slli_epi16(p1_8x16, 1);
716
4.80k
    temp4 = _mm_slli_epi16(q1_8x16, 1);
717
4.80k
    temp1 = _mm_add_epi16(temp5, temp3);
718
4.80k
    temp2 = _mm_add_epi16(temp6, temp4);
719
4.80k
    temp1 = _mm_srai_epi16(temp1, 2);
720
4.80k
    temp2 = _mm_srai_epi16(temp2, 2);
721
4.80k
    p0_16x8_1 = _mm_packus_epi16(p0_16x8_1, temp1);
722
4.80k
    q0_16x8_1 = _mm_packus_epi16(q0_16x8_1, temp2);
723
4.80k
724
4.80k
    // p1_2 and q1_2
725
4.80k
    temp6 = _mm_add_epi16(temp6, p0_8x16);
726
4.80k
    temp5 = _mm_add_epi16(temp5, q0_8x16);
727
4.80k
    temp1 = _mm_add_epi16(temp6, p2_8x16);
728
4.80k
    temp2 = _mm_add_epi16(temp5, q2_8x16);
729
4.80k
    temp1 = _mm_srai_epi16(temp1, 2);
730
4.80k
    temp2 = _mm_srai_epi16(temp2, 2);
731
4.80k
    p1_16x8_2 = _mm_packus_epi16(p1_16x8_2, temp1);
732
4.80k
    q1_16x8_2 = _mm_packus_epi16(q1_16x8_2, temp2);
733
4.80k
734
4.80k
    // p0_2 and q0_2
735
4.80k
    temp1 = _mm_add_epi16(temp3, p2_8x16);
736
4.80k
    temp2 = _mm_add_epi16(temp4, q2_8x16);
737
4.80k
    temp1 = _mm_add_epi16(temp1, q1_8x16);
738
4.80k
    temp2 = _mm_add_epi16(temp2, p1_8x16);
739
4.80k
    temp3 = _mm_add_epi16(p0_8x16, q0_8x16);
740
4.80k
    temp3 = _mm_slli_epi16(temp3, 1);
741
4.80k
    temp1 = _mm_add_epi16(temp1, temp3);
742
4.80k
    temp2 = _mm_add_epi16(temp2, temp3);
743
4.80k
    temp1 = _mm_add_epi16(temp1, _mm_set1_epi16(4));
744
4.80k
    temp2 = _mm_add_epi16(temp2, _mm_set1_epi16(4));
745
4.80k
    temp1 = _mm_srai_epi16(temp1, 3);
746
4.80k
    temp2 = _mm_srai_epi16(temp2, 3);
747
4.80k
    p0_16x8_2 = _mm_packus_epi16(p0_16x8_2, temp1);
748
4.80k
    q0_16x8_2 = _mm_packus_epi16(q0_16x8_2, temp2);
749
4.80k
750
4.80k
    // p2_2 and q2_2
751
4.80k
    temp1 = _mm_add_epi16(temp6, const_val2_16x8);
752
4.80k
    temp2 = _mm_add_epi16(temp5, const_val2_16x8);
753
4.80k
    temp3 = _mm_slli_epi16(p2_8x16, 1);
754
4.80k
    temp4 = _mm_slli_epi16(q2_8x16, 1);
755
4.80k
    temp3 = _mm_add_epi16(p2_8x16, temp3);
756
4.80k
    temp4 = _mm_add_epi16(q2_8x16, temp4);
757
4.80k
    temp5 = _mm_slli_epi16(p3_8x16, 1);
758
4.80k
    temp6 = _mm_slli_epi16(q3_8x16, 1);
759
4.80k
    temp1 = _mm_add_epi16(temp1, temp3);
760
4.80k
    temp2 = _mm_add_epi16(temp2, temp4);
761
4.80k
    temp1 = _mm_add_epi16(temp1, temp5);
762
4.80k
    temp2 = _mm_add_epi16(temp2, temp6);
763
4.80k
    temp1 = _mm_srai_epi16(temp1, 3);
764
4.80k
    temp2 = _mm_srai_epi16(temp2, 3);
765
4.80k
    p2_16x8_2 = _mm_packus_epi16(p2_16x8_2, temp1);
766
4.80k
    q2_16x8_2 = _mm_packus_epi16(q2_16x8_2, temp2);
767
4.80k
768
4.80k
    // p0 and q0
769
4.80k
    p0_16x8 = _mm_and_si128(p0_16x8,
770
4.80k
                            _mm_xor_si128(flag1_16x8, _mm_set1_epi8(0xFF)));
771
4.80k
    p0_16x8_1 = _mm_and_si128(p0_16x8_1, flag1_16x8);
772
4.80k
    p0_16x8 = _mm_add_epi8(p0_16x8, p0_16x8_1);
773
4.80k
    q0_16x8 = _mm_and_si128(q0_16x8,
774
4.80k
                            _mm_xor_si128(flag1_16x8, _mm_set1_epi8(0xFF)));
775
4.80k
    q0_16x8_1 = _mm_and_si128(q0_16x8_1, flag1_16x8);
776
4.80k
    q0_16x8 = _mm_add_epi8(q0_16x8, q0_16x8_1);
777
4.80k
778
4.80k
    // p0 and q0
779
4.80k
    p0_16x8 = _mm_and_si128(p0_16x8,
780
4.80k
                            _mm_xor_si128(flag3_16x8, _mm_set1_epi8(0xFF)));
781
4.80k
    p0_16x8_2 = _mm_and_si128(p0_16x8_2, flag3_16x8);
782
4.80k
    p0_16x8 = _mm_add_epi8(p0_16x8, p0_16x8_2);
783
4.80k
    q0_16x8 = _mm_and_si128(q0_16x8,
784
4.80k
                            _mm_xor_si128(flag4_16x8, _mm_set1_epi8(0xFF)));
785
4.80k
    q0_16x8_2 = _mm_and_si128(q0_16x8_2, flag4_16x8);
786
4.80k
    q0_16x8 = _mm_add_epi8(q0_16x8, q0_16x8_2);
787
4.80k
788
4.80k
    // p1 and q1
789
4.80k
    p1_16x8 = _mm_and_si128(p1_16x8,
790
4.80k
                            _mm_xor_si128(flag3_16x8, _mm_set1_epi8(0xFF)));
791
4.80k
    p1_16x8_2 = _mm_and_si128(p1_16x8_2, flag3_16x8);
792
4.80k
    p1_16x8 = _mm_add_epi8(p1_16x8, p1_16x8_2);
793
4.80k
    q1_16x8 = _mm_and_si128(q1_16x8,
794
4.80k
                            _mm_xor_si128(flag4_16x8, _mm_set1_epi8(0xFF)));
795
4.80k
    q1_16x8_2 = _mm_and_si128(q1_16x8_2, flag4_16x8);
796
4.80k
    q1_16x8 = _mm_add_epi8(q1_16x8, q1_16x8_2);
797
4.80k
798
4.80k
    // p2 and q2
799
4.80k
    p2_16x8 = _mm_and_si128(p2_16x8,
800
4.80k
                            _mm_xor_si128(flag3_16x8, _mm_set1_epi8(0xFF)));
801
4.80k
    p2_16x8_2 = _mm_and_si128(p2_16x8_2, flag3_16x8);
802
4.80k
    p2_16x8 = _mm_add_epi8(p2_16x8, p2_16x8_2);
803
4.80k
    q2_16x8 = _mm_and_si128(q2_16x8,
804
4.80k
                            _mm_xor_si128(flag4_16x8, _mm_set1_epi8(0xFF)));
805
4.80k
    q2_16x8_2 = _mm_and_si128(q2_16x8_2, flag4_16x8);
806
4.80k
    q2_16x8 = _mm_add_epi8(q2_16x8, q2_16x8_2);
807
4.80k
808
4.80k
    _mm_storeu_si128((__m128i *)(pu1_HorzPixel + i16_posP2), p2_16x8);
809
4.80k
    _mm_storeu_si128((__m128i *)(pu1_HorzPixel + i16_posP1), p1_16x8);
810
4.80k
    _mm_storeu_si128((__m128i *)(pu1_HorzPixel + i16_posP0), p0_16x8);
811
4.80k
812
4.80k
    _mm_storeu_si128((__m128i *)(pu1_src), q0_16x8);
813
4.80k
    _mm_storeu_si128((__m128i *)(pu1_src + i16_posQ1), q1_16x8);
814
4.80k
    _mm_storeu_si128((__m128i *)(pu1_src + i16_posQ2), q2_16x8);
815
4.80k
816
4.80k
}
817
818
/*****************************************************************************/
819
/*                                                                           */
820
/*  Function Name : ih264_deblk_luma_vert_bslt4_ssse3()                      */
821
/*                                                                           */
822
/*  Description   : This function performs filtering of a luma block         */
823
/*                  vertical edge when the boundary strength is less than 4. */
824
/*                                                                           */
825
/*  Inputs        : pu1_src       - pointer to the src sample q0             */
826
/*                  src_strd      - source stride                            */
827
/*                  alpha         - alpha value for the boundary             */
828
/*                  beta          - beta value for the boundary              */
829
/*                  u4_bs         - packed Boundary strength array           */
830
/*                  pu1_cliptab   - tc0_table                                */
831
/*                                                                           */
832
/*  Globals       : None                                                     */
833
/*                                                                           */
834
/*  Processing    : This operation is described in Sec. 8.7.2.3 under the    */
835
/*                  title "Filtering process for edges for bS less than 4"   */
836
/*                  in ITU T Rec H.264.                                      */
837
/*                                                                           */
838
/*  Outputs       : None                                                     */
839
/*                                                                           */
840
/*  Returns       : None                                                     */
841
/*                                                                           */
842
/*  Issues        : None                                                     */
843
/*                                                                           */
844
/*  Revision History:                                                        */
845
/*                                                                           */
846
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
847
/*         12 02 2015   Naveen Kumar P  Initial version                      */
848
/*                                                                           */
849
/*****************************************************************************/
850
void ih264_deblk_luma_vert_bslt4_ssse3(UWORD8 *pu1_src,
851
                                       WORD32 src_strd,
852
                                       WORD32 alpha,
853
                                       WORD32 beta,
854
                                       UWORD32 u4_bs,
855
                                       const UWORD8 *pu1_cliptab)
856
15.1k
{
857
15.1k
    UWORD8 u1_Bs, u1_Bs1;
858
15.1k
859
15.1k
    WORD32 j = 0;
860
15.1k
861
15.1k
    __m128i linea, lineb, linec, lined, linee, linef, lineg, lineh;
862
15.1k
    __m128i int1, int2, int3, int4, high1, high2;
863
15.1k
    __m128i flag, flag1, i_C, i_C0;
864
15.1k
    __m128i i_Ap, i_Aq, diff, const1, const2, in_macro, in_macrotemp, temp,
865
15.1k
                    temp1;
866
15.1k
    __m128i zero = _mm_setzero_si128();
867
15.1k
868
45.5k
    for(j = 0; j <= 8 * src_strd; j += 8 * src_strd)
869
30.3k
    {
870
30.3k
        //Transpose
871
30.3k
        linea = _mm_loadl_epi64((__m128i *)(pu1_src - 3 + j));
872
30.3k
        lineb = _mm_loadl_epi64((__m128i *)(pu1_src - 3 + src_strd + j));
873
30.3k
        linec = _mm_loadl_epi64((__m128i *)(pu1_src - 3 + 2 * src_strd + j));
874
30.3k
        lined = _mm_loadl_epi64((__m128i *)(pu1_src - 3 + 3 * src_strd + j));
875
30.3k
876
30.3k
        linea = _mm_unpacklo_epi8(linea, zero);
877
30.3k
        lineb = _mm_unpacklo_epi8(lineb, zero);
878
30.3k
        linec = _mm_unpacklo_epi8(linec, zero);
879
30.3k
        lined = _mm_unpacklo_epi8(lined, zero);
880
30.3k
881
30.3k
        int1 = _mm_unpacklo_epi16(linea, lineb);
882
30.3k
        lineb = _mm_unpackhi_epi16(linea, lineb);
883
30.3k
884
30.3k
        int2 = _mm_unpacklo_epi16(linec, lined);
885
30.3k
        lined = _mm_unpackhi_epi16(linec, lined);
886
30.3k
887
30.3k
        linea = _mm_unpacklo_epi16(int1, int2);
888
30.3k
        int1 = _mm_unpackhi_epi16(int1, int2);
889
30.3k
890
30.3k
        linec = _mm_unpacklo_epi16(lineb, lined);
891
30.3k
        high1 = _mm_unpackhi_epi16(lineb, lined);
892
30.3k
893
30.3k
        linee = _mm_loadl_epi64((__m128i *)(pu1_src - 3 + 4 * src_strd + j));
894
30.3k
        linef = _mm_loadl_epi64((__m128i *)(pu1_src - 3 + 5 * src_strd + j));
895
30.3k
        lineg = _mm_loadl_epi64((__m128i *)(pu1_src - 3 + 6 * src_strd + j));
896
30.3k
        lineh = _mm_loadl_epi64((__m128i *)(pu1_src - 3 + 7 * src_strd + j));
897
30.3k
898
30.3k
        linee = _mm_unpacklo_epi8(linee, zero);
899
30.3k
        linef = _mm_unpacklo_epi8(linef, zero);
900
30.3k
        lineg = _mm_unpacklo_epi8(lineg, zero);
901
30.3k
        lineh = _mm_unpacklo_epi8(lineh, zero);
902
30.3k
903
30.3k
        int2 = _mm_unpacklo_epi16(linee, linef);
904
30.3k
        linef = _mm_unpackhi_epi16(linee, linef);
905
30.3k
906
30.3k
        int3 = _mm_unpacklo_epi16(lineg, lineh);
907
30.3k
        lineh = _mm_unpackhi_epi16(lineg, lineh);
908
30.3k
909
30.3k
        linee = _mm_unpacklo_epi16(int2, int3);
910
30.3k
        int2 = _mm_unpackhi_epi16(int2, int3);
911
30.3k
912
30.3k
        lineg = _mm_unpacklo_epi16(linef, lineh);
913
30.3k
        high2 = _mm_unpackhi_epi16(linef, lineh);
914
30.3k
915
30.3k
        int4 = _mm_unpacklo_epi16(linea, linee);
916
30.3k
        lineb = _mm_unpackhi_epi16(linea, linee);
917
30.3k
918
30.3k
        int3 = _mm_unpacklo_epi16(int1, int2);
919
30.3k
        lined = _mm_unpackhi_epi16(int1, int2);
920
30.3k
921
30.3k
        int2 = _mm_unpacklo_epi16(linec, lineg);
922
30.3k
        linef = _mm_unpackhi_epi16(linec, lineg);
923
30.3k
924
30.3k
        linea = int4;
925
30.3k
        linec = int3;
926
30.3k
        linee = int2;
927
30.3k
928
30.3k
        lineg = _mm_unpacklo_epi16(high1, high2);
929
30.3k
        lineh = _mm_unpackhi_epi16(high1, high2);
930
30.3k
931
30.3k
        //end of transpose
932
30.3k
933
30.3k
        u1_Bs = (u4_bs >> 24) & 0xff;
934
30.3k
        u1_Bs1 = (u4_bs >> 16) & 0xff;
935
30.3k
        u4_bs <<= 16;
936
30.3k
937
30.3k
        flag1 = _mm_set_epi16(u1_Bs1, u1_Bs, u1_Bs1, u1_Bs, u1_Bs1, u1_Bs,
938
30.3k
                              u1_Bs1, u1_Bs);
939
30.3k
        flag1 = _mm_cmpeq_epi16(flag1, zero); //Set flag to 1s and 0s
940
30.3k
        flag1 = _mm_xor_si128(flag1, _mm_set1_epi16(0xFFFF)); //Invert for required mask
941
30.3k
942
30.3k
        i_C0 = _mm_set_epi16(pu1_cliptab[u1_Bs1], pu1_cliptab[u1_Bs],
943
30.3k
                             pu1_cliptab[u1_Bs1], pu1_cliptab[u1_Bs],
944
30.3k
                             pu1_cliptab[u1_Bs1], pu1_cliptab[u1_Bs],
945
30.3k
                             pu1_cliptab[u1_Bs1], pu1_cliptab[u1_Bs]);
946
30.3k
947
30.3k
        diff = _mm_subs_epi16(linec, lined); //Condn 1
948
30.3k
        diff = _mm_abs_epi16(diff);
949
30.3k
        const1 = _mm_set1_epi16(alpha);
950
30.3k
        flag = _mm_cmpgt_epi16(const1, diff);
951
30.3k
952
30.3k
        diff = _mm_subs_epi16(linee, lined); //Condtn 2
953
30.3k
        diff = _mm_abs_epi16(diff);
954
30.3k
        const1 = _mm_set1_epi16(beta);
955
30.3k
        flag = _mm_and_si128(flag, _mm_cmpgt_epi16(const1, diff));
956
30.3k
957
30.3k
        diff = _mm_subs_epi16(lineb, linec); //Condtn 3
958
30.3k
        diff = _mm_abs_epi16(diff);
959
30.3k
        flag = _mm_and_si128(flag, _mm_cmpgt_epi16(const1, diff)); //Const 1= Beta from now on
960
30.3k
961
30.3k
        flag = _mm_and_si128(flag, flag1); //Final flag (ui_B condition + other 3 conditions)
962
30.3k
963
30.3k
        //Adding Ap<Beta and Aq<Beta
964
30.3k
        i_Ap = _mm_subs_epi16(linea, linec);
965
30.3k
        i_Ap = _mm_abs_epi16(i_Ap);
966
30.3k
        const2 = _mm_cmpgt_epi16(const1, i_Ap);
967
30.3k
        const2 = _mm_subs_epi16(zero, const2); //Make FFFF=1 and 0000=0
968
30.3k
        i_C = _mm_add_epi16(i_C0, const2);
969
30.3k
970
30.3k
        i_Aq = _mm_subs_epi16(linef, lined);
971
30.3k
        i_Aq = _mm_abs_epi16(i_Aq);
972
30.3k
        const2 = _mm_cmpgt_epi16(const1, i_Aq);
973
30.3k
        const2 = _mm_subs_epi16(zero, const2);
974
30.3k
        i_C = _mm_add_epi16(i_C, const2);
975
30.3k
976
30.3k
        //Calculate in_macro
977
30.3k
        diff = _mm_subs_epi16(lined, linec);
978
30.3k
        diff = _mm_slli_epi16(diff, 2);
979
30.3k
        const2 = _mm_subs_epi16(lineb, linee);
980
30.3k
        diff = _mm_add_epi16(diff, const2);
981
30.3k
        const2 = _mm_set1_epi16(4);
982
30.3k
        diff = _mm_add_epi16(diff, const2);
983
30.3k
        in_macro = _mm_srai_epi16(diff, 3);
984
30.3k
985
30.3k
        in_macro = _mm_min_epi16(i_C, in_macro); //CLIP3
986
30.3k
        i_C = _mm_subs_epi16(zero, i_C);
987
30.3k
        in_macro = _mm_max_epi16(i_C, in_macro);
988
30.3k
989
30.3k
        //Compute and store
990
30.3k
        in_macrotemp = _mm_add_epi16(linec, in_macro);
991
30.3k
        in_macrotemp = _mm_and_si128(in_macrotemp, flag);
992
30.3k
        temp = _mm_and_si128(linec,
993
30.3k
                             _mm_xor_si128(flag, _mm_set1_epi16(0xFFFF)));
994
30.3k
        temp = _mm_add_epi16(temp, in_macrotemp);
995
30.3k
        //temp= _mm_packus_epi16 (temp, zero);
996
30.3k
        //_mm_storel_epi64(uc_HorzPixel+i16_posP0+i, in_macrotemp);
997
30.3k
998
30.3k
        in_macrotemp = _mm_subs_epi16(lined, in_macro);
999
30.3k
        in_macrotemp = _mm_and_si128(in_macrotemp, flag);
1000
30.3k
        temp1 = _mm_and_si128(lined,
1001
30.3k
                              _mm_xor_si128(flag, _mm_set1_epi16(0xFFFF)));
1002
30.3k
        temp1 = _mm_add_epi16(temp1, in_macrotemp);
1003
30.3k
        //temp1= _mm_packus_epi16 (temp1, zero);
1004
30.3k
        //_mm_storel_epi64(pu1_src+i, in_macrotemp);
1005
30.3k
1006
30.3k
        //If Ap<Beta
1007
30.3k
        flag1 = _mm_cmpgt_epi16(const1, i_Ap);
1008
30.3k
        flag1 = _mm_and_si128(flag, flag1);
1009
30.3k
        in_macrotemp = _mm_add_epi16(linec, lined);
1010
30.3k
        in_macrotemp = _mm_add_epi16(in_macrotemp, _mm_set1_epi16(1));
1011
30.3k
        in_macrotemp = _mm_srai_epi16(in_macrotemp, 1);
1012
30.3k
        in_macro = _mm_add_epi16(in_macrotemp, linea);
1013
30.3k
        in_macro = _mm_subs_epi16(in_macro, _mm_slli_epi16(lineb, 1));
1014
30.3k
        in_macro = _mm_srai_epi16(in_macro, 1);
1015
30.3k
1016
30.3k
        in_macro = _mm_min_epi16(i_C0, in_macro); //CLIP3
1017
30.3k
        i_C0 = _mm_subs_epi16(zero, i_C0);
1018
30.3k
        in_macro = _mm_max_epi16(i_C0, in_macro);
1019
30.3k
1020
30.3k
        in_macro = _mm_and_si128(in_macro, flag1);
1021
30.3k
        lineb = _mm_add_epi16(lineb, in_macro);
1022
30.3k
        //in_macro= _mm_packus_epi16 (i_p1, zero);
1023
30.3k
        //_mm_storel_epi64(uc_HorzPixel+i16_posP1+i, in_macro);
1024
30.3k
1025
30.3k
        flag1 = _mm_cmpgt_epi16(const1, i_Aq);
1026
30.3k
        flag1 = _mm_and_si128(flag, flag1);
1027
30.3k
        in_macro = _mm_add_epi16(in_macrotemp, linef);
1028
30.3k
        in_macro = _mm_subs_epi16(in_macro, _mm_slli_epi16(linee, 1));
1029
30.3k
        in_macro = _mm_srai_epi16(in_macro, 1);
1030
30.3k
1031
30.3k
        i_C0 = _mm_abs_epi16(i_C0);
1032
30.3k
        in_macro = _mm_min_epi16(i_C0, in_macro); //CLIP3
1033
30.3k
        i_C0 = _mm_subs_epi16(zero, i_C0);
1034
30.3k
        in_macro = _mm_max_epi16(i_C0, in_macro);
1035
30.3k
1036
30.3k
        in_macro = _mm_and_si128(in_macro, flag1);
1037
30.3k
        linee = _mm_add_epi16(linee, in_macro);
1038
30.3k
        //in_macro= _mm_packus_epi16 (i_q1, zero);
1039
30.3k
        //_mm_storel_epi64(pu1_src+i16_posQ1+i, in_macro);
1040
30.3k
        linec = temp;
1041
30.3k
        lined = temp1;
1042
30.3k
        //End of filtering
1043
30.3k
1044
30.3k
        int1 = _mm_unpacklo_epi16(linea, linee);
1045
30.3k
        linee = _mm_unpackhi_epi16(linea, linee);
1046
30.3k
1047
30.3k
        int2 = _mm_unpacklo_epi16(linec, lineg);
1048
30.3k
        lineg = _mm_unpackhi_epi16(linec, lineg);
1049
30.3k
1050
30.3k
        linea = _mm_unpacklo_epi16(int1, int2);
1051
30.3k
        int3 = _mm_unpackhi_epi16(int1, int2);
1052
30.3k
1053
30.3k
        linec = _mm_unpacklo_epi16(linee, lineg);
1054
30.3k
        lineg = _mm_unpackhi_epi16(linee, lineg);
1055
30.3k
1056
30.3k
        int1 = _mm_unpacklo_epi16(lineb, linef);
1057
30.3k
        linef = _mm_unpackhi_epi16(lineb, linef);
1058
30.3k
1059
30.3k
        int2 = _mm_unpacklo_epi16(lined, lineh);
1060
30.3k
        lineh = _mm_unpackhi_epi16(lined, lineh);
1061
30.3k
1062
30.3k
        lineb = _mm_unpacklo_epi16(int1, int2);
1063
30.3k
        int4 = _mm_unpackhi_epi16(int1, int2);
1064
30.3k
1065
30.3k
        lined = _mm_unpacklo_epi16(linef, lineh);
1066
30.3k
        lineh = _mm_unpackhi_epi16(linef, lineh);
1067
30.3k
1068
30.3k
        int1 = _mm_unpackhi_epi16(linea, lineb);
1069
30.3k
        linea = _mm_unpacklo_epi16(linea, lineb);
1070
30.3k
1071
30.3k
        int2 = _mm_unpacklo_epi16(int3, int4);
1072
30.3k
        high1 = _mm_unpackhi_epi16(int3, int4);
1073
30.3k
1074
30.3k
        lineb = _mm_unpacklo_epi16(linec, lined);
1075
30.3k
        linef = _mm_unpackhi_epi16(linec, lined);
1076
30.3k
1077
30.3k
        lined = _mm_unpacklo_epi16(lineg, lineh);
1078
30.3k
        lineh = _mm_unpackhi_epi16(lineg, lineh);
1079
30.3k
1080
30.3k
        linee = int1;
1081
30.3k
        lineg = high1;
1082
30.3k
        linec = int2;
1083
30.3k
        //End of inverse transpose
1084
30.3k
1085
30.3k
        //Packs and stores
1086
30.3k
        linea = _mm_packus_epi16(linea, zero);
1087
30.3k
        _mm_storel_epi64((__m128i *)(pu1_src - 3 + j), linea);
1088
30.3k
1089
30.3k
        lineb = _mm_packus_epi16(lineb, zero);
1090
30.3k
        _mm_storel_epi64((__m128i *)(pu1_src - 3 + src_strd + j), lineb);
1091
30.3k
1092
30.3k
        linec = _mm_packus_epi16(linec, zero);
1093
30.3k
        _mm_storel_epi64((__m128i *)(pu1_src - 3 + 2 * src_strd + j), linec);
1094
30.3k
1095
30.3k
        lined = _mm_packus_epi16(lined, zero);
1096
30.3k
        _mm_storel_epi64((__m128i *)(pu1_src - 3 + 3 * src_strd + j), lined);
1097
30.3k
1098
30.3k
        linee = _mm_packus_epi16(linee, zero);
1099
30.3k
        _mm_storel_epi64((__m128i *)(pu1_src - 3 + 4 * src_strd + j), linee);
1100
30.3k
1101
30.3k
        linef = _mm_packus_epi16(linef, zero);
1102
30.3k
        _mm_storel_epi64((__m128i *)(pu1_src - 3 + 5 * src_strd + j), linef);
1103
30.3k
1104
30.3k
        lineg = _mm_packus_epi16(lineg, zero);
1105
30.3k
        _mm_storel_epi64((__m128i *)(pu1_src - 3 + 6 * src_strd + j), lineg);
1106
30.3k
1107
30.3k
        lineh = _mm_packus_epi16(lineh, zero);
1108
30.3k
        _mm_storel_epi64((__m128i *)(pu1_src - 3 + 7 * src_strd + j), lineh);
1109
30.3k
1110
30.3k
    }
1111
15.1k
}
1112
1113
/*****************************************************************************/
1114
/*                                                                           */
1115
/*  Function Name : ih264_deblk_luma_horz_bslt4_ssse3()                      */
1116
/*                                                                           */
1117
/*  Description   : This function performs filtering of a luma block         */
1118
/*                  horizontal edge when boundary strength is less than 4.   */
1119
/*                                                                           */
1120
/*  Inputs        : pu1_src       - pointer to the src sample q0             */
1121
/*                  src_strd      - source stride                            */
1122
/*                  alpha         - alpha value for the boundary             */
1123
/*                  beta          - beta value for the boundary              */
1124
/*                  u4_bs         - packed Boundary strength array           */
1125
/*                  pu1_cliptab   - tc0_table                                */
1126
/*                                                                           */
1127
/*  Globals       : None                                                     */
1128
/*                                                                           */
1129
/*  Processing    : This operation is described in Sec. 8.7.2.3 under the    */
1130
/*                  title "Filtering process for edges for bS less than 4"   */
1131
/*                  in ITU T Rec H.264.                                      */
1132
/*                                                                           */
1133
/*  Outputs       : None                                                     */
1134
/*                                                                           */
1135
/*  Returns       : None                                                     */
1136
/*                                                                           */
1137
/*  Issues        : None                                                     */
1138
/*                                                                           */
1139
/*  Revision History:                                                        */
1140
/*                                                                           */
1141
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1142
/*         12 02 2015   Naveen Kumar P  Initial version                      */
1143
/*                                                                           */
1144
/*****************************************************************************/
1145
void ih264_deblk_luma_horz_bslt4_ssse3(UWORD8 *pu1_src,
1146
                                       WORD32 src_strd,
1147
                                       WORD32 alpha,
1148
                                       WORD32 beta,
1149
                                       UWORD32 u4_bs,
1150
                                       const UWORD8 *pu1_cliptab)
1151
15.1k
{
1152
15.1k
    WORD16 i16_posP2, i16_posP1, i16_posP0, i16_posQ1, i16_posQ2;
1153
15.1k
    UWORD8 *pu1_HorzPixel;
1154
15.1k
    __m128i zero = _mm_setzero_si128();
1155
15.1k
    __m128i bs_flag_16x8b, C0_16x8, C0_8x16, C0_hi_8x16, C_8x16, C_hi_8x16;
1156
15.1k
    __m128i q0_16x8, q1_16x8, q2_16x8, p0_16x8, p1_16x8, p2_16x8;
1157
15.1k
    __m128i temp1, temp2;
1158
15.1k
    __m128i Alpha_8x16, Beta_8x16, flag1_16x8, flag2_16x8, flag3_16x8;
1159
15.1k
    __m128i in_macro_16x8, in_macro_hi_16x8;
1160
15.1k
    __m128i const_val4_8x16;
1161
15.1k
    UWORD8 u1_Bs0, u1_Bs1, u1_Bs2, u1_Bs3;
1162
15.1k
    UWORD8 clip0, clip1, clip2, clip3;
1163
15.1k
1164
15.1k
    pu1_HorzPixel = pu1_src - (src_strd << 2);
1165
15.1k
1166
15.1k
    i16_posQ1 = src_strd;
1167
15.1k
    i16_posQ2 = X2(src_strd);
1168
15.1k
    i16_posP0 = X3(src_strd);
1169
15.1k
    i16_posP1 = X2(src_strd);
1170
15.1k
    i16_posP2 = src_strd;
1171
15.1k
1172
15.1k
    q0_16x8 = _mm_loadu_si128((__m128i *)(pu1_src));
1173
15.1k
    q1_16x8 = _mm_loadu_si128((__m128i *)(pu1_src + i16_posQ1));
1174
15.1k
1175
15.1k
    u1_Bs0 = (u4_bs >> 24) & 0xff;
1176
15.1k
    u1_Bs1 = (u4_bs >> 16) & 0xff;
1177
15.1k
    u1_Bs2 = (u4_bs >> 8) & 0xff;
1178
15.1k
    u1_Bs3 = (u4_bs >> 0) & 0xff;
1179
15.1k
    clip0 = pu1_cliptab[u1_Bs0];
1180
15.1k
    clip1 = pu1_cliptab[u1_Bs1];
1181
15.1k
    clip2 = pu1_cliptab[u1_Bs2];
1182
15.1k
    clip3 = pu1_cliptab[u1_Bs3];
1183
15.1k
1184
15.1k
    Alpha_8x16 = _mm_set1_epi16(alpha);
1185
15.1k
    Beta_8x16 = _mm_set1_epi16(beta);
1186
15.1k
1187
15.1k
    bs_flag_16x8b = _mm_set_epi8(u1_Bs3, u1_Bs3, u1_Bs3, u1_Bs3, u1_Bs2, u1_Bs2,
1188
15.1k
                                 u1_Bs2, u1_Bs2, u1_Bs1, u1_Bs1, u1_Bs1, u1_Bs1,
1189
15.1k
                                 u1_Bs0, u1_Bs0, u1_Bs0, u1_Bs0);
1190
15.1k
1191
15.1k
    C0_16x8 = _mm_set_epi8(clip3, clip3, clip3, clip3, clip2, clip2, clip2,
1192
15.1k
                           clip2, clip1, clip1, clip1, clip1, clip0, clip0,
1193
15.1k
                           clip0, clip0);
1194
15.1k
1195
15.1k
    bs_flag_16x8b = _mm_cmpeq_epi8(bs_flag_16x8b, zero);
1196
15.1k
    bs_flag_16x8b = _mm_xor_si128(bs_flag_16x8b, _mm_set1_epi8(0xFF)); //Invert for required mask
1197
15.1k
    C0_8x16 = _mm_unpacklo_epi8(C0_16x8, zero);
1198
15.1k
    C0_hi_8x16 = _mm_unpackhi_epi8(C0_16x8, zero);
1199
15.1k
1200
15.1k
    p1_16x8 = _mm_loadu_si128((__m128i *)(pu1_HorzPixel + i16_posP1));
1201
15.1k
    p0_16x8 = _mm_loadu_si128((__m128i *)(pu1_HorzPixel + i16_posP0));
1202
15.1k
    p2_16x8 = _mm_loadu_si128((__m128i *)(pu1_HorzPixel + i16_posP2));
1203
15.1k
    q2_16x8 = _mm_loadu_si128((__m128i *)(pu1_src + i16_posQ2));
1204
15.1k
1205
15.1k
    //Cond1 (ABS(p0 - q0) < alpha)
1206
15.1k
    temp1 = _mm_subs_epu8(q0_16x8, p0_16x8);
1207
15.1k
    temp2 = _mm_subs_epu8(p0_16x8, q0_16x8);
1208
15.1k
    temp1 = _mm_add_epi8(temp1, temp2);
1209
15.1k
1210
15.1k
    temp2 = _mm_unpacklo_epi8(temp1, zero);
1211
15.1k
    temp1 = _mm_unpackhi_epi8(temp1, zero);
1212
15.1k
1213
15.1k
    temp2 = _mm_cmpgt_epi16(Alpha_8x16, temp2);
1214
15.1k
    temp1 = _mm_cmpgt_epi16(Alpha_8x16, temp1);
1215
15.1k
1216
15.1k
    flag1_16x8 = _mm_packs_epi16(temp2, temp1);
1217
15.1k
    flag1_16x8 = _mm_and_si128(flag1_16x8, bs_flag_16x8b);
1218
15.1k
1219
15.1k
    //Cond2 (ABS(q1 - q0) < beta)
1220
15.1k
    temp1 = _mm_subs_epu8(q0_16x8, q1_16x8);
1221
15.1k
    temp2 = _mm_subs_epu8(q1_16x8, q0_16x8);
1222
15.1k
    temp1 = _mm_add_epi8(temp1, temp2);
1223
15.1k
1224
15.1k
    temp2 = _mm_unpacklo_epi8(temp1, zero);
1225
15.1k
    temp1 = _mm_unpackhi_epi8(temp1, zero);
1226
15.1k
1227
15.1k
    temp2 = _mm_cmpgt_epi16(Beta_8x16, temp2);
1228
15.1k
    temp1 = _mm_cmpgt_epi16(Beta_8x16, temp1);
1229
15.1k
1230
15.1k
    flag2_16x8 = _mm_packs_epi16(temp2, temp1);
1231
15.1k
1232
15.1k
    flag1_16x8 = _mm_and_si128(flag1_16x8, flag2_16x8);
1233
15.1k
1234
15.1k
    //Cond3 (ABS(p1 - p0) < beta)
1235
15.1k
    temp1 = _mm_subs_epu8(p0_16x8, p1_16x8);
1236
15.1k
    temp2 = _mm_subs_epu8(p1_16x8, p0_16x8);
1237
15.1k
    temp1 = _mm_add_epi8(temp1, temp2);
1238
15.1k
1239
15.1k
    temp2 = _mm_unpacklo_epi8(temp1, zero);
1240
15.1k
    temp1 = _mm_unpackhi_epi8(temp1, zero);
1241
15.1k
1242
15.1k
    temp2 = _mm_cmpgt_epi16(Beta_8x16, temp2);
1243
15.1k
    temp1 = _mm_cmpgt_epi16(Beta_8x16, temp1);
1244
15.1k
1245
15.1k
    flag2_16x8 = _mm_packs_epi16(temp2, temp1);
1246
15.1k
1247
15.1k
    // !((ABS(p0 - q0) < alpha) || (ABS(q1 - q0) < beta) || (ABS(p1 - p0) < beta))
1248
15.1k
    flag1_16x8 = _mm_and_si128(flag1_16x8, flag2_16x8);
1249
15.1k
1250
15.1k
    // (ABS(p2 - p0) < beta)
1251
15.1k
    temp1 = _mm_subs_epu8(p0_16x8, p2_16x8);
1252
15.1k
    temp2 = _mm_subs_epu8(p2_16x8, p0_16x8);
1253
15.1k
    temp1 = _mm_add_epi8(temp1, temp2);
1254
15.1k
1255
15.1k
    temp2 = _mm_unpacklo_epi8(temp1, zero);
1256
15.1k
    temp1 = _mm_unpackhi_epi8(temp1, zero);
1257
15.1k
    temp2 = _mm_cmpgt_epi16(Beta_8x16, temp2);
1258
15.1k
    temp1 = _mm_cmpgt_epi16(Beta_8x16, temp1);
1259
15.1k
1260
15.1k
    flag2_16x8 = _mm_packs_epi16(temp2, temp1);
1261
15.1k
    flag2_16x8 = _mm_and_si128(flag1_16x8, flag2_16x8);
1262
15.1k
1263
15.1k
    temp2 = _mm_subs_epi16(zero, temp2);
1264
15.1k
    temp1 = _mm_subs_epi16(zero, temp1);
1265
15.1k
1266
15.1k
    C_8x16 = _mm_add_epi16(C0_8x16, temp2);
1267
15.1k
    C_hi_8x16 = _mm_add_epi16(C0_hi_8x16, temp1);
1268
15.1k
1269
15.1k
    // (ABS(q2 - q0) < beta)
1270
15.1k
    temp1 = _mm_subs_epu8(q0_16x8, q2_16x8);
1271
15.1k
    temp2 = _mm_subs_epu8(q2_16x8, q0_16x8);
1272
15.1k
    temp1 = _mm_add_epi8(temp1, temp2);
1273
15.1k
1274
15.1k
    temp2 = _mm_unpacklo_epi8(temp1, zero);
1275
15.1k
    temp1 = _mm_unpackhi_epi8(temp1, zero);
1276
15.1k
    temp2 = _mm_cmpgt_epi16(Beta_8x16, temp2);
1277
15.1k
    temp1 = _mm_cmpgt_epi16(Beta_8x16, temp1);
1278
15.1k
1279
15.1k
    flag3_16x8 = _mm_packs_epi16(temp2, temp1);
1280
15.1k
    flag3_16x8 = _mm_and_si128(flag1_16x8, flag3_16x8);
1281
15.1k
1282
15.1k
    temp2 = _mm_subs_epi16(zero, temp2);
1283
15.1k
    temp1 = _mm_subs_epi16(zero, temp1);
1284
15.1k
1285
15.1k
    C_8x16 = _mm_add_epi16(C_8x16, temp2);
1286
15.1k
    C_hi_8x16 = _mm_add_epi16(C_hi_8x16, temp1);
1287
15.1k
1288
15.1k
    const_val4_8x16 = _mm_set1_epi16(4);
1289
15.1k
    temp1 = _mm_subs_epi16(_mm_unpacklo_epi8(q0_16x8, zero),
1290
15.1k
                           _mm_unpacklo_epi8(p0_16x8, zero));
1291
15.1k
    temp2 = _mm_subs_epi16(_mm_unpacklo_epi8(p1_16x8, zero),
1292
15.1k
                           _mm_unpacklo_epi8(q1_16x8, zero));
1293
15.1k
    temp1 = _mm_slli_epi16(temp1, 2);
1294
15.1k
    temp1 = _mm_add_epi16(temp1, temp2);
1295
15.1k
    temp1 = _mm_add_epi16(temp1, const_val4_8x16);
1296
15.1k
    in_macro_16x8 = _mm_srai_epi16(temp1, 3);
1297
15.1k
1298
15.1k
    temp1 = _mm_subs_epi16(_mm_unpackhi_epi8(q0_16x8, zero),
1299
15.1k
                           _mm_unpackhi_epi8(p0_16x8, zero));
1300
15.1k
    temp2 = _mm_subs_epi16(_mm_unpackhi_epi8(p1_16x8, zero),
1301
15.1k
                           _mm_unpackhi_epi8(q1_16x8, zero));
1302
15.1k
    temp1 = _mm_slli_epi16(temp1, 2);
1303
15.1k
    temp1 = _mm_add_epi16(temp1, temp2);
1304
15.1k
    temp1 = _mm_add_epi16(temp1, const_val4_8x16);
1305
15.1k
    in_macro_hi_16x8 = _mm_srai_epi16(temp1, 3);
1306
15.1k
1307
15.1k
    in_macro_16x8 = _mm_min_epi16(C_8x16, in_macro_16x8); //CLIP3
1308
15.1k
    in_macro_hi_16x8 = _mm_min_epi16(C_hi_8x16, in_macro_hi_16x8); //CLIP3
1309
15.1k
    C_8x16 = _mm_subs_epi16(zero, C_8x16);
1310
15.1k
    C_hi_8x16 = _mm_subs_epi16(zero, C_hi_8x16);
1311
15.1k
    in_macro_16x8 = _mm_max_epi16(C_8x16, in_macro_16x8); //CLIP3
1312
15.1k
    in_macro_hi_16x8 = _mm_max_epi16(C_hi_8x16, in_macro_hi_16x8); //CLIP3
1313
15.1k
1314
15.1k
    temp1 = _mm_add_epi16(_mm_unpacklo_epi8(p0_16x8, zero), in_macro_16x8);
1315
15.1k
    temp2 = _mm_add_epi16(_mm_unpackhi_epi8(p0_16x8, zero), in_macro_hi_16x8);
1316
15.1k
1317
15.1k
    temp1 = _mm_packus_epi16(temp1, temp2);
1318
15.1k
1319
15.1k
    temp1 = _mm_and_si128(temp1, flag1_16x8);
1320
15.1k
    temp2 = _mm_and_si128(p0_16x8,
1321
15.1k
                          _mm_xor_si128(flag1_16x8, _mm_set1_epi16(0xFFFF)));
1322
15.1k
1323
15.1k
    temp1 = _mm_add_epi8(temp1, temp2);
1324
15.1k
1325
15.1k
    _mm_storeu_si128((__m128i *)(pu1_HorzPixel + i16_posP0), temp1);
1326
15.1k
1327
15.1k
    temp1 = _mm_sub_epi16(_mm_unpacklo_epi8(q0_16x8, zero), in_macro_16x8);
1328
15.1k
    temp2 = _mm_sub_epi16(_mm_unpackhi_epi8(q0_16x8, zero), in_macro_hi_16x8);
1329
15.1k
1330
15.1k
    temp1 = _mm_packus_epi16(temp1, temp2);
1331
15.1k
1332
15.1k
    temp1 = _mm_and_si128(temp1, flag1_16x8);
1333
15.1k
    temp2 = _mm_and_si128(q0_16x8,
1334
15.1k
                          _mm_xor_si128(flag1_16x8, _mm_set1_epi16(0xFFFF)));
1335
15.1k
1336
15.1k
    temp1 = _mm_add_epi8(temp1, temp2);
1337
15.1k
    _mm_storeu_si128((__m128i *)(pu1_src), temp1);
1338
15.1k
1339
15.1k
    //if(Ap < Beta)
1340
15.1k
    temp1 = _mm_avg_epu16(_mm_unpacklo_epi8(q0_16x8, zero),
1341
15.1k
                          _mm_unpacklo_epi8(p0_16x8, zero));
1342
15.1k
    temp2 = _mm_slli_epi16(_mm_unpacklo_epi8(p1_16x8, zero), 1);
1343
15.1k
    //temp2 = _mm_subs_epi16(zero,temp2);
1344
15.1k
    temp2 = _mm_subs_epi16(_mm_unpacklo_epi8(p2_16x8, zero), temp2);
1345
15.1k
    temp2 = _mm_add_epi16(temp1, temp2);
1346
15.1k
    in_macro_16x8 = _mm_srai_epi16(temp2, 1);
1347
15.1k
1348
15.1k
    temp1 = _mm_avg_epu16(_mm_unpackhi_epi8(q0_16x8, zero),
1349
15.1k
                          _mm_unpackhi_epi8(p0_16x8, zero));
1350
15.1k
    temp2 = _mm_slli_epi16(_mm_unpackhi_epi8(p1_16x8, zero), 1);
1351
15.1k
    //temp2 = _mm_subs_epi16(zero,temp2);
1352
15.1k
    temp2 = _mm_subs_epi16(_mm_unpackhi_epi8(p2_16x8, zero), temp2);
1353
15.1k
    temp2 = _mm_add_epi16(temp1, temp2);
1354
15.1k
    in_macro_hi_16x8 = _mm_srai_epi16(temp2, 1);
1355
15.1k
1356
15.1k
    in_macro_16x8 = _mm_min_epi16(C0_8x16, in_macro_16x8); //CLIP3
1357
15.1k
    in_macro_hi_16x8 = _mm_min_epi16(C0_hi_8x16, in_macro_hi_16x8); //CLIP3
1358
15.1k
    C0_8x16 = _mm_subs_epi16(zero, C0_8x16);
1359
15.1k
    C0_hi_8x16 = _mm_subs_epi16(zero, C0_hi_8x16);
1360
15.1k
    in_macro_16x8 = _mm_max_epi16(C0_8x16, in_macro_16x8); //CLIP3
1361
15.1k
    in_macro_hi_16x8 = _mm_max_epi16(C0_hi_8x16, in_macro_hi_16x8); //CLIP3
1362
15.1k
1363
15.1k
    temp1 = _mm_add_epi16(_mm_unpacklo_epi8(p1_16x8, zero), in_macro_16x8);
1364
15.1k
    temp2 = _mm_add_epi16(_mm_unpackhi_epi8(p1_16x8, zero), in_macro_hi_16x8);
1365
15.1k
1366
15.1k
    temp1 = _mm_packus_epi16(temp1, temp2);
1367
15.1k
1368
15.1k
    temp1 = _mm_and_si128(temp1, flag2_16x8);
1369
15.1k
    temp2 = _mm_and_si128(p1_16x8,
1370
15.1k
                          _mm_xor_si128(flag2_16x8, _mm_set1_epi16(0xFFFF)));
1371
15.1k
    temp1 = _mm_add_epi8(temp1, temp2);
1372
15.1k
    _mm_storeu_si128((__m128i *)(pu1_HorzPixel + i16_posP1), temp1);
1373
15.1k
1374
15.1k
    //if(Aq < Beta)
1375
15.1k
    temp1 = _mm_avg_epu16(_mm_unpacklo_epi8(q0_16x8, zero),
1376
15.1k
                          _mm_unpacklo_epi8(p0_16x8, zero));
1377
15.1k
    temp2 = _mm_slli_epi16(_mm_unpacklo_epi8(q1_16x8, zero), 1);
1378
15.1k
    //temp2 = _mm_slli_epi16 (temp2, 1);
1379
15.1k
    temp2 = _mm_subs_epi16(_mm_unpacklo_epi8(q2_16x8, zero), temp2);
1380
15.1k
    temp2 = _mm_add_epi16(temp1, temp2);
1381
15.1k
    in_macro_16x8 = _mm_srai_epi16(temp2, 1);
1382
15.1k
1383
15.1k
    temp1 = _mm_avg_epu16(_mm_unpackhi_epi8(q0_16x8, zero),
1384
15.1k
                          _mm_unpackhi_epi8(p0_16x8, zero));
1385
15.1k
    temp2 = _mm_slli_epi16(_mm_unpackhi_epi8(q1_16x8, zero), 1);
1386
15.1k
    //temp2 = _mm_slli_epi16 (temp2, 1);
1387
15.1k
    temp2 = _mm_subs_epi16(_mm_unpackhi_epi8(q2_16x8, zero), temp2);
1388
15.1k
    temp2 = _mm_add_epi16(temp1, temp2);
1389
15.1k
    in_macro_hi_16x8 = _mm_srai_epi16(temp2, 1);
1390
15.1k
1391
15.1k
    in_macro_16x8 = _mm_max_epi16(C0_8x16, in_macro_16x8); //CLIP3
1392
15.1k
    in_macro_hi_16x8 = _mm_max_epi16(C0_hi_8x16, in_macro_hi_16x8); //CLIP3
1393
15.1k
    C0_8x16 = _mm_subs_epi16(zero, C0_8x16);
1394
15.1k
    C0_hi_8x16 = _mm_subs_epi16(zero, C0_hi_8x16);
1395
15.1k
    in_macro_16x8 = _mm_min_epi16(C0_8x16, in_macro_16x8); //CLIP3
1396
15.1k
    in_macro_hi_16x8 = _mm_min_epi16(C0_hi_8x16, in_macro_hi_16x8); //CLIP3
1397
15.1k
1398
15.1k
    temp1 = _mm_add_epi16(_mm_unpacklo_epi8(q1_16x8, zero), in_macro_16x8);
1399
15.1k
    temp2 = _mm_add_epi16(_mm_unpackhi_epi8(q1_16x8, zero), in_macro_hi_16x8);
1400
15.1k
1401
15.1k
    temp1 = _mm_packus_epi16(temp1, temp2);
1402
15.1k
1403
15.1k
    temp1 = _mm_and_si128(temp1, flag3_16x8);
1404
15.1k
    temp2 = _mm_and_si128(q1_16x8,
1405
15.1k
                          _mm_xor_si128(flag3_16x8, _mm_set1_epi16(0xFFFF)));
1406
15.1k
    temp1 = _mm_add_epi8(temp1, temp2);
1407
15.1k
1408
15.1k
    _mm_storeu_si128((__m128i *)(pu1_src + i16_posQ1), temp1);
1409
15.1k
1410
15.1k
}
1411
1412
/*****************************************************************************/
1413
/*                                                                           */
1414
/*  Function Name : ih264_deblk_luma_vert_bs4_mbaff_ssse3()                  */
1415
/*                                                                           */
1416
/*  Description   : This function performs filtering of a luma block         */
1417
/*                  vertical edge when boundary strength is set to 4.        */
1418
/*                                                                           */
1419
/*  Inputs        : pu1_src       - pointer to the src sample q0             */
1420
/*                  src_strd      - source stride                            */
1421
/*                  alpha         - alpha value for the boundary             */
1422
/*                  beta          - beta value for the boundary              */
1423
/*                                                                           */
1424
/*  Globals       : None                                                     */
1425
/*                                                                           */
1426
/*  Processing    : When the function is called twice, this operation is as  */
1427
/*                  described in Sec. 8.7.2.3 under the title "Filtering     */
1428
/*                  process for edges for bS equal to 4" in ITU T Rec H.264. */
1429
/*                                                                           */
1430
/*  Outputs       : None                                                     */
1431
/*                                                                           */
1432
/*  Returns       : None                                                     */
1433
/*                                                                           */
1434
/*  Issues        : None                                                     */
1435
/*                                                                           */
1436
/*  Revision History:                                                        */
1437
/*                                                                           */
1438
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1439
/*         12 02 2015   Naveen Kumar P  Initial version                      */
1440
/*                                                                           */
1441
/*****************************************************************************/
1442
void ih264_deblk_luma_vert_bs4_mbaff_ssse3(UWORD8 *pu1_src,
1443
                                           WORD32 src_strd,
1444
                                           WORD32 alpha,
1445
                                           WORD32 beta)
1446
0
{
1447
0
    __m128i zero = _mm_setzero_si128();
1448
0
    __m128i q0_16x8, q1_16x8, q2_16x8, q3_16x8;
1449
0
    __m128i p0_16x8, p1_16x8, p2_16x8, p3_16x8;
1450
0
    __m128i q0_8x16, q1_8x16, q2_8x16, q3_8x16;
1451
0
    __m128i p0_8x16, p1_8x16, p2_8x16, p3_8x16;
1452
0
    __m128i q0_16x8_1;
1453
0
    __m128i p0_16x8_1;
1454
0
    __m128i q0_16x8_2, q1_16x8_2, q2_16x8_2;
1455
0
    __m128i p0_16x8_2, p1_16x8_2, p2_16x8_2;
1456
0
    __m128i temp1, temp2, temp3, temp4, temp5, temp6;
1457
0
    __m128i Alpha_8x16, Beta_8x16;
1458
0
    __m128i flag1_16x8, flag2_16x8, flag3_16x8, flag4_16x8;
1459
0
    __m128i const_val2_16x8 = _mm_set1_epi16(2);
1460
0
    __m128i line1, line2, line3, line4, line5, line6, line7, line8;
1461
0
1462
0
    Alpha_8x16 = _mm_set1_epi16(alpha);
1463
0
    Beta_8x16 = _mm_set1_epi16(beta);
1464
0
1465
0
    line1 = _mm_loadl_epi64((__m128i *)(pu1_src - 4 + 0 * src_strd));
1466
0
    line2 = _mm_loadl_epi64((__m128i *)(pu1_src - 4 + 1 * src_strd));
1467
0
    line3 = _mm_loadl_epi64((__m128i *)(pu1_src - 4 + 2 * src_strd));
1468
0
    line4 = _mm_loadl_epi64((__m128i *)(pu1_src - 4 + 3 * src_strd));
1469
0
    line5 = _mm_loadl_epi64((__m128i *)(pu1_src - 4 + 4 * src_strd));
1470
0
    line6 = _mm_loadl_epi64((__m128i *)(pu1_src - 4 + 5 * src_strd));
1471
0
    line7 = _mm_loadl_epi64((__m128i *)(pu1_src - 4 + 6 * src_strd));
1472
0
    line8 = _mm_loadl_epi64((__m128i *)(pu1_src - 4 + 7 * src_strd));
1473
0
1474
0
    temp1 = _mm_unpacklo_epi8(line1, line2);
1475
0
    temp2 = _mm_unpacklo_epi8(line3, line4);
1476
0
    temp3 = _mm_unpacklo_epi8(line5, line6);
1477
0
    temp4 = _mm_unpacklo_epi8(line7, line8);
1478
0
1479
0
    line1 = _mm_unpacklo_epi16(temp1, temp2);
1480
0
    line2 = _mm_unpackhi_epi16(temp1, temp2);
1481
0
    line3 = _mm_unpacklo_epi16(temp3, temp4);
1482
0
    line4 = _mm_unpackhi_epi16(temp3, temp4);
1483
0
1484
0
    p1_8x16 = _mm_unpacklo_epi32(line1, line3);
1485
0
    p0_8x16 = _mm_unpackhi_epi32(line1, line3);
1486
0
    q0_8x16 = _mm_unpacklo_epi32(line2, line4);
1487
0
    q1_8x16 = _mm_unpackhi_epi32(line2, line4);
1488
0
1489
0
    p3_16x8 = _mm_unpacklo_epi64(p1_8x16, zero);
1490
0
    p2_16x8 = _mm_unpackhi_epi64(p1_8x16, zero);
1491
0
    q2_16x8 = _mm_unpacklo_epi64(q1_8x16, zero);
1492
0
    q3_16x8 = _mm_unpackhi_epi64(q1_8x16, zero);
1493
0
    p1_16x8 = _mm_unpacklo_epi64(p0_8x16, zero);
1494
0
    p0_16x8 = _mm_unpackhi_epi64(p0_8x16, zero);
1495
0
    q0_16x8 = _mm_unpacklo_epi64(q0_8x16, zero);
1496
0
    q1_16x8 = _mm_unpackhi_epi64(q0_8x16, zero);
1497
0
1498
0
    //Cond1 (ABS(p0 - q0) < alpha)
1499
0
    temp1 = _mm_subs_epu8(q0_16x8, p0_16x8);
1500
0
    temp2 = _mm_subs_epu8(p0_16x8, q0_16x8);
1501
0
    temp1 = _mm_add_epi8(temp1, temp2);
1502
0
1503
0
    temp2 = _mm_unpacklo_epi8(temp1, zero);
1504
0
    temp1 = _mm_unpackhi_epi8(temp1, zero);
1505
0
1506
0
    temp2 = _mm_cmpgt_epi16(Alpha_8x16, temp2);
1507
0
    temp1 = _mm_cmpgt_epi16(Alpha_8x16, temp1);
1508
0
1509
0
    flag1_16x8 = _mm_packs_epi16(temp2, temp1);
1510
0
1511
0
    //Cond2 (ABS(q1 - q0) < beta)
1512
0
    temp1 = _mm_subs_epu8(q0_16x8, q1_16x8);
1513
0
    temp2 = _mm_subs_epu8(q1_16x8, q0_16x8);
1514
0
    temp1 = _mm_add_epi8(temp1, temp2);
1515
0
1516
0
    temp2 = _mm_unpacklo_epi8(temp1, zero);
1517
0
    temp1 = _mm_unpackhi_epi8(temp1, zero);
1518
0
1519
0
    temp2 = _mm_cmpgt_epi16(Beta_8x16, temp2);
1520
0
    temp1 = _mm_cmpgt_epi16(Beta_8x16, temp1);
1521
0
1522
0
    flag2_16x8 = _mm_packs_epi16(temp2, temp1);
1523
0
1524
0
    flag1_16x8 = _mm_and_si128(flag1_16x8, flag2_16x8);
1525
0
1526
0
    //Cond3 (ABS(p1 - p0) < beta)
1527
0
    temp1 = _mm_subs_epu8(p0_16x8, p1_16x8);
1528
0
    temp2 = _mm_subs_epu8(p1_16x8, p0_16x8);
1529
0
    temp1 = _mm_add_epi8(temp1, temp2);
1530
0
1531
0
    temp2 = _mm_unpacklo_epi8(temp1, zero);
1532
0
    temp1 = _mm_unpackhi_epi8(temp1, zero);
1533
0
1534
0
    temp2 = _mm_cmpgt_epi16(Beta_8x16, temp2);
1535
0
    temp1 = _mm_cmpgt_epi16(Beta_8x16, temp1);
1536
0
1537
0
    flag2_16x8 = _mm_packs_epi16(temp2, temp1);
1538
0
1539
0
    // !((ABS(p0 - q0) < alpha) || (ABS(q1 - q0) < beta) || (ABS(p1 - p0) < beta))
1540
0
    flag1_16x8 = _mm_and_si128(flag1_16x8, flag2_16x8);
1541
0
1542
0
    // (ABS(p0 - q0) < ((alpha >> 2) + 2))
1543
0
    temp1 = _mm_subs_epu8(p0_16x8, q0_16x8);
1544
0
    temp2 = _mm_subs_epu8(q0_16x8, p0_16x8);
1545
0
    temp1 = _mm_add_epi8(temp1, temp2);
1546
0
    Alpha_8x16 = _mm_srai_epi16(Alpha_8x16, 2);
1547
0
    Alpha_8x16 = _mm_add_epi16(Alpha_8x16, const_val2_16x8);
1548
0
1549
0
    temp2 = _mm_unpacklo_epi8(temp1, zero);
1550
0
    temp1 = _mm_unpackhi_epi8(temp1, zero);
1551
0
    temp2 = _mm_cmpgt_epi16(Alpha_8x16, temp2);
1552
0
    temp1 = _mm_cmpgt_epi16(Alpha_8x16, temp1);
1553
0
1554
0
    flag2_16x8 = _mm_packs_epi16(temp2, temp1);
1555
0
    flag2_16x8 = _mm_and_si128(flag1_16x8, flag2_16x8);
1556
0
1557
0
    // (ABS(p2 - p0) < beta)
1558
0
    temp1 = _mm_subs_epu8(p0_16x8, p2_16x8);
1559
0
    temp2 = _mm_subs_epu8(p2_16x8, p0_16x8);
1560
0
    temp1 = _mm_add_epi8(temp1, temp2);
1561
0
1562
0
    temp2 = _mm_unpacklo_epi8(temp1, zero);
1563
0
    temp1 = _mm_unpackhi_epi8(temp1, zero);
1564
0
    temp2 = _mm_cmpgt_epi16(Beta_8x16, temp2);
1565
0
    temp1 = _mm_cmpgt_epi16(Beta_8x16, temp1);
1566
0
1567
0
    flag3_16x8 = _mm_packs_epi16(temp2, temp1);
1568
0
    flag3_16x8 = _mm_and_si128(flag3_16x8, flag2_16x8);
1569
0
1570
0
    // (ABS(q2 - q0) < beta)
1571
0
    temp1 = _mm_subs_epu8(q0_16x8, q2_16x8);
1572
0
    temp2 = _mm_subs_epu8(q2_16x8, q0_16x8);
1573
0
    temp1 = _mm_add_epi8(temp1, temp2);
1574
0
1575
0
    temp2 = _mm_unpacklo_epi8(temp1, zero);
1576
0
    temp1 = _mm_unpackhi_epi8(temp1, zero);
1577
0
    temp2 = _mm_cmpgt_epi16(Beta_8x16, temp2);
1578
0
    temp1 = _mm_cmpgt_epi16(Beta_8x16, temp1);
1579
0
1580
0
    flag4_16x8 = _mm_packs_epi16(temp2, temp1);
1581
0
    flag4_16x8 = _mm_and_si128(flag4_16x8, flag2_16x8);
1582
0
1583
0
    // First 8 pixels
1584
0
    p3_8x16 = _mm_unpacklo_epi8(p3_16x8, zero);
1585
0
    p2_8x16 = _mm_unpacklo_epi8(p2_16x8, zero);
1586
0
    p1_8x16 = _mm_unpacklo_epi8(p1_16x8, zero);
1587
0
    p0_8x16 = _mm_unpacklo_epi8(p0_16x8, zero);
1588
0
    q0_8x16 = _mm_unpacklo_epi8(q0_16x8, zero);
1589
0
    q1_8x16 = _mm_unpacklo_epi8(q1_16x8, zero);
1590
0
    q2_8x16 = _mm_unpacklo_epi8(q2_16x8, zero);
1591
0
    q3_8x16 = _mm_unpacklo_epi8(q3_16x8, zero);
1592
0
1593
0
    // p0_1 and q0_1
1594
0
    temp1 = _mm_add_epi16(p0_8x16, q1_8x16);
1595
0
    temp2 = _mm_add_epi16(p1_8x16, q0_8x16);
1596
0
    temp5 = _mm_add_epi16(temp1, const_val2_16x8);
1597
0
    temp6 = _mm_add_epi16(temp2, const_val2_16x8);
1598
0
    temp3 = _mm_slli_epi16(p1_8x16, 1);
1599
0
    temp4 = _mm_slli_epi16(q1_8x16, 1);
1600
0
    temp1 = _mm_add_epi16(temp5, temp3);
1601
0
    temp2 = _mm_add_epi16(temp6, temp4);
1602
0
    p0_16x8_1 = _mm_srai_epi16(temp1, 2);
1603
0
    q0_16x8_1 = _mm_srai_epi16(temp2, 2);
1604
0
1605
0
    // p1_2 and q1_2
1606
0
    temp6 = _mm_add_epi16(temp6, p0_8x16);
1607
0
    temp5 = _mm_add_epi16(temp5, q0_8x16);
1608
0
    temp1 = _mm_add_epi16(temp6, p2_8x16);
1609
0
    temp2 = _mm_add_epi16(temp5, q2_8x16);
1610
0
    p1_16x8_2 = _mm_srai_epi16(temp1, 2);
1611
0
    q1_16x8_2 = _mm_srai_epi16(temp2, 2);
1612
0
1613
0
    // p0_2 and q0_2
1614
0
    temp1 = _mm_add_epi16(temp3, p2_8x16);
1615
0
    temp2 = _mm_add_epi16(temp4, q2_8x16);
1616
0
    temp1 = _mm_add_epi16(temp1, q1_8x16);
1617
0
    temp2 = _mm_add_epi16(temp2, p1_8x16);
1618
0
    temp3 = _mm_add_epi16(p0_8x16, q0_8x16);
1619
0
    temp3 = _mm_slli_epi16(temp3, 1);
1620
0
    temp1 = _mm_add_epi16(temp1, temp3);
1621
0
    temp2 = _mm_add_epi16(temp2, temp3);
1622
0
    temp1 = _mm_add_epi16(temp1, _mm_set1_epi16(4));
1623
0
    temp2 = _mm_add_epi16(temp2, _mm_set1_epi16(4));
1624
0
    p0_16x8_2 = _mm_srai_epi16(temp1, 3);
1625
0
    q0_16x8_2 = _mm_srai_epi16(temp2, 3);
1626
0
1627
0
    // p2_2 and q2_2
1628
0
    temp1 = _mm_add_epi16(temp6, const_val2_16x8);
1629
0
    temp2 = _mm_add_epi16(temp5, const_val2_16x8);
1630
0
    temp3 = _mm_slli_epi16(p2_8x16, 1);
1631
0
    temp4 = _mm_slli_epi16(q2_8x16, 1);
1632
0
    temp3 = _mm_add_epi16(p2_8x16, temp3);
1633
0
    temp4 = _mm_add_epi16(q2_8x16, temp4);
1634
0
    temp5 = _mm_slli_epi16(p3_8x16, 1);
1635
0
    temp6 = _mm_slli_epi16(q3_8x16, 1);
1636
0
    temp1 = _mm_add_epi16(temp1, temp3);
1637
0
    temp2 = _mm_add_epi16(temp2, temp4);
1638
0
    temp1 = _mm_add_epi16(temp1, temp5);
1639
0
    temp2 = _mm_add_epi16(temp2, temp6);
1640
0
    p2_16x8_2 = _mm_srai_epi16(temp1, 3);
1641
0
    q2_16x8_2 = _mm_srai_epi16(temp2, 3);
1642
0
1643
0
    // p0_1 and q0_1
1644
0
    p0_16x8_1 = _mm_packus_epi16(p0_16x8_1, zero);
1645
0
    q0_16x8_1 = _mm_packus_epi16(q0_16x8_1, zero);
1646
0
1647
0
    // p1_2 and q1_2
1648
0
    p1_16x8_2 = _mm_packus_epi16(p1_16x8_2, zero);
1649
0
    q1_16x8_2 = _mm_packus_epi16(q1_16x8_2, zero);
1650
0
1651
0
    // p0_2 and q0_2
1652
0
    p0_16x8_2 = _mm_packus_epi16(p0_16x8_2, zero);
1653
0
    q0_16x8_2 = _mm_packus_epi16(q0_16x8_2, zero);
1654
0
1655
0
    // p2_2 and q2_2
1656
0
    p2_16x8_2 = _mm_packus_epi16(p2_16x8_2, zero);
1657
0
    q2_16x8_2 = _mm_packus_epi16(q2_16x8_2, zero);
1658
0
1659
0
    // p0 and q0
1660
0
    p0_16x8 = _mm_and_si128(p0_16x8,
1661
0
                            _mm_xor_si128(flag1_16x8, _mm_set1_epi8(0xFF)));
1662
0
    p0_16x8_1 = _mm_and_si128(p0_16x8_1, flag1_16x8);
1663
0
    p0_16x8 = _mm_add_epi8(p0_16x8, p0_16x8_1);
1664
0
    q0_16x8 = _mm_and_si128(q0_16x8,
1665
0
                            _mm_xor_si128(flag1_16x8, _mm_set1_epi8(0xFF)));
1666
0
    q0_16x8_1 = _mm_and_si128(q0_16x8_1, flag1_16x8);
1667
0
    q0_16x8 = _mm_add_epi8(q0_16x8, q0_16x8_1);
1668
0
1669
0
    // p0 and q0
1670
0
    p0_16x8 = _mm_and_si128(p0_16x8,
1671
0
                            _mm_xor_si128(flag3_16x8, _mm_set1_epi8(0xFF)));
1672
0
    p0_16x8_2 = _mm_and_si128(p0_16x8_2, flag3_16x8);
1673
0
    p0_16x8 = _mm_add_epi8(p0_16x8, p0_16x8_2);
1674
0
    q0_16x8 = _mm_and_si128(q0_16x8,
1675
0
                            _mm_xor_si128(flag4_16x8, _mm_set1_epi8(0xFF)));
1676
0
    q0_16x8_2 = _mm_and_si128(q0_16x8_2, flag4_16x8);
1677
0
    q0_16x8 = _mm_add_epi8(q0_16x8, q0_16x8_2);
1678
0
1679
0
    // p1 and q1
1680
0
    p1_16x8 = _mm_and_si128(p1_16x8,
1681
0
                            _mm_xor_si128(flag3_16x8, _mm_set1_epi8(0xFF)));
1682
0
    p1_16x8_2 = _mm_and_si128(p1_16x8_2, flag3_16x8);
1683
0
    p1_16x8 = _mm_add_epi8(p1_16x8, p1_16x8_2);
1684
0
    q1_16x8 = _mm_and_si128(q1_16x8,
1685
0
                            _mm_xor_si128(flag4_16x8, _mm_set1_epi8(0xFF)));
1686
0
    q1_16x8_2 = _mm_and_si128(q1_16x8_2, flag4_16x8);
1687
0
    q1_16x8 = _mm_add_epi8(q1_16x8, q1_16x8_2);
1688
0
1689
0
    // p2 and q2
1690
0
    p2_16x8 = _mm_and_si128(p2_16x8,
1691
0
                            _mm_xor_si128(flag3_16x8, _mm_set1_epi8(0xFF)));
1692
0
    p2_16x8_2 = _mm_and_si128(p2_16x8_2, flag3_16x8);
1693
0
    p2_16x8 = _mm_add_epi8(p2_16x8, p2_16x8_2);
1694
0
    q2_16x8 = _mm_and_si128(q2_16x8,
1695
0
                            _mm_xor_si128(flag4_16x8, _mm_set1_epi8(0xFF)));
1696
0
    q2_16x8_2 = _mm_and_si128(q2_16x8_2, flag4_16x8);
1697
0
    q2_16x8 = _mm_add_epi8(q2_16x8, q2_16x8_2);
1698
0
1699
0
    temp1 = _mm_unpacklo_epi8(p3_16x8, p2_16x8);
1700
0
    temp2 = _mm_unpacklo_epi8(p1_16x8, p0_16x8);
1701
0
    temp3 = _mm_unpacklo_epi8(q0_16x8, q1_16x8);
1702
0
    temp4 = _mm_unpacklo_epi8(q2_16x8, q3_16x8);
1703
0
1704
0
    p3_8x16 = _mm_unpacklo_epi16(temp1, temp2);
1705
0
    p2_8x16 = _mm_unpackhi_epi16(temp1, temp2);
1706
0
    q2_8x16 = _mm_unpacklo_epi16(temp3, temp4);
1707
0
    q3_8x16 = _mm_unpackhi_epi16(temp3, temp4);
1708
0
1709
0
    line1 = _mm_unpacklo_epi32(p3_8x16, q2_8x16);
1710
0
    line2 = _mm_srli_si128(line1, 8);
1711
0
    line3 = _mm_unpackhi_epi32(p3_8x16, q2_8x16);
1712
0
    line4 = _mm_srli_si128(line3, 8);
1713
0
    line5 = _mm_unpacklo_epi32(p2_8x16, q3_8x16);
1714
0
    line6 = _mm_srli_si128(line5, 8);
1715
0
    line7 = _mm_unpackhi_epi32(p2_8x16, q3_8x16);
1716
0
    line8 = _mm_srli_si128(line7, 8);
1717
0
1718
0
    _mm_storel_epi64((__m128i *)(pu1_src - 4 + 0 * src_strd), line1);
1719
0
    _mm_storel_epi64((__m128i *)(pu1_src - 4 + 1 * src_strd), line2);
1720
0
    _mm_storel_epi64((__m128i *)(pu1_src - 4 + 2 * src_strd), line3);
1721
0
    _mm_storel_epi64((__m128i *)(pu1_src - 4 + 3 * src_strd), line4);
1722
0
    _mm_storel_epi64((__m128i *)(pu1_src - 4 + 4 * src_strd), line5);
1723
0
    _mm_storel_epi64((__m128i *)(pu1_src - 4 + 5 * src_strd), line6);
1724
0
    _mm_storel_epi64((__m128i *)(pu1_src - 4 + 6 * src_strd), line7);
1725
0
    _mm_storel_epi64((__m128i *)(pu1_src - 4 + 7 * src_strd), line8);
1726
0
1727
0
}
1728
1729
/*****************************************************************************/
1730
/*                                                                           */
1731
/*  Function Name : ih264_deblk_luma_vert_bslt4_mbaff_ssse3()                */
1732
/*                                                                           */
1733
/*  Description   : This function performs filtering of a luma block         */
1734
/*                  vertical edge when boundary strength is less than 4.     */
1735
/*                                                                           */
1736
/*  Inputs        : pu1_src       - pointer to the src sample q0             */
1737
/*                  src_strd      - source stride                            */
1738
/*                  alpha         - alpha value for the boundary             */
1739
/*                  beta          - beta value for the boundary              */
1740
/*                  u4_bs         - packed Boundary strength array           */
1741
/*                  pu1_cliptab   - tc0_table                                */
1742
/*                                                                           */
1743
/*  Globals       : None                                                     */
1744
/*                                                                           */
1745
/*  Processing    : When the function is called twice, this operation is as  */
1746
/*                  described in Sec. 8.7.2.3 under the title "Filtering     */
1747
/*                  process for edges for bS less than 4" in ITU T Rec H.264.*/
1748
/*                                                                           */
1749
/*  Outputs       : None                                                     */
1750
/*                                                                           */
1751
/*  Returns       : None                                                     */
1752
/*                                                                           */
1753
/*  Issues        : None                                                     */
1754
/*                                                                           */
1755
/*  Revision History:                                                        */
1756
/*                                                                           */
1757
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1758
/*         12 02 2015   Naveen Kumar P  Initial version                      */
1759
/*                                                                           */
1760
/*****************************************************************************/
1761
void ih264_deblk_luma_vert_bslt4_mbaff_ssse3(UWORD8 *pu1_src,
1762
                                             WORD32 src_strd,
1763
                                             WORD32 alpha,
1764
                                             WORD32 beta,
1765
                                             UWORD32 u4_bs,
1766
                                             const UWORD8 *pu1_cliptab)
1767
0
{
1768
0
    __m128i zero = _mm_setzero_si128();
1769
0
    __m128i bs_flag_16x8b, C0_16x8, C0_8x16, C_8x16;
1770
0
    __m128i q0_16x8, q1_16x8, q2_16x8, q3_16x8;
1771
0
    __m128i p0_16x8, p1_16x8, p2_16x8, p3_16x8;
1772
0
    __m128i temp1, temp2, temp3, temp4;
1773
0
    __m128i Alpha_8x16, Beta_8x16, flag1_16x8, flag2_16x8, flag3_16x8;
1774
0
    __m128i in_macro_16x8;
1775
0
    __m128i const_val4_8x16;
1776
0
    UWORD8 u1_Bs0, u1_Bs1, u1_Bs2, u1_Bs3;
1777
0
    UWORD8 clip0, clip1, clip2, clip3;
1778
0
    __m128i line1, line2, line3, line4, line5, line6, line7, line8;
1779
0
    __m128i q0_16x8_1, q1_16x8_1, q0_16x8_2;
1780
0
    __m128i p0_16x8_1, p1_16x8_1, p0_16x8_2;
1781
0
1782
0
    line1 = _mm_loadl_epi64((__m128i *)(pu1_src - 4 + 0 * src_strd));
1783
0
    line2 = _mm_loadl_epi64((__m128i *)(pu1_src - 4 + 1 * src_strd));
1784
0
    line3 = _mm_loadl_epi64((__m128i *)(pu1_src - 4 + 2 * src_strd));
1785
0
    line4 = _mm_loadl_epi64((__m128i *)(pu1_src - 4 + 3 * src_strd));
1786
0
    line5 = _mm_loadl_epi64((__m128i *)(pu1_src - 4 + 4 * src_strd));
1787
0
    line6 = _mm_loadl_epi64((__m128i *)(pu1_src - 4 + 5 * src_strd));
1788
0
    line7 = _mm_loadl_epi64((__m128i *)(pu1_src - 4 + 6 * src_strd));
1789
0
    line8 = _mm_loadl_epi64((__m128i *)(pu1_src - 4 + 7 * src_strd));
1790
0
1791
0
    temp1 = _mm_unpacklo_epi8(line1, line2);
1792
0
    temp2 = _mm_unpacklo_epi8(line3, line4);
1793
0
    temp3 = _mm_unpacklo_epi8(line5, line6);
1794
0
    temp4 = _mm_unpacklo_epi8(line7, line8);
1795
0
1796
0
    line1 = _mm_unpacklo_epi16(temp1, temp2);
1797
0
    line2 = _mm_unpackhi_epi16(temp1, temp2);
1798
0
    line3 = _mm_unpacklo_epi16(temp3, temp4);
1799
0
    line4 = _mm_unpackhi_epi16(temp3, temp4);
1800
0
1801
0
    temp1 = _mm_unpacklo_epi32(line1, line3);
1802
0
    temp2 = _mm_unpackhi_epi32(line1, line3);
1803
0
    temp3 = _mm_unpacklo_epi32(line2, line4);
1804
0
    temp4 = _mm_unpackhi_epi32(line2, line4);
1805
0
1806
0
    p3_16x8 = _mm_unpacklo_epi64(temp1, zero);
1807
0
    p2_16x8 = _mm_unpackhi_epi64(temp1, zero);
1808
0
    q2_16x8 = _mm_unpacklo_epi64(temp4, zero);
1809
0
    q3_16x8 = _mm_unpackhi_epi64(temp4, zero);
1810
0
    p1_16x8 = _mm_unpacklo_epi64(temp2, zero);
1811
0
    p0_16x8 = _mm_unpackhi_epi64(temp2, zero);
1812
0
    q0_16x8 = _mm_unpacklo_epi64(temp3, zero);
1813
0
    q1_16x8 = _mm_unpackhi_epi64(temp3, zero);
1814
0
1815
0
    u1_Bs0 = (u4_bs >> 24) & 0xff;
1816
0
    u1_Bs1 = (u4_bs >> 16) & 0xff;
1817
0
    u1_Bs2 = (u4_bs >> 8) & 0xff;
1818
0
    u1_Bs3 = (u4_bs >> 0) & 0xff;
1819
0
    clip0 = pu1_cliptab[u1_Bs0];
1820
0
    clip1 = pu1_cliptab[u1_Bs1];
1821
0
    clip2 = pu1_cliptab[u1_Bs2];
1822
0
    clip3 = pu1_cliptab[u1_Bs3];
1823
0
1824
0
    Alpha_8x16 = _mm_set1_epi16(alpha);
1825
0
    Beta_8x16 = _mm_set1_epi16(beta);
1826
0
1827
0
    bs_flag_16x8b = _mm_set_epi8(0, 0, 0, 0, 0, 0, 0, 0, u1_Bs3, u1_Bs3, u1_Bs2,
1828
0
                                 u1_Bs2, u1_Bs1, u1_Bs1, u1_Bs0, u1_Bs0);
1829
0
1830
0
    C0_16x8 = _mm_set_epi8(0, 0, 0, 0, 0, 0, 0, 0, clip3, clip3, clip2, clip2,
1831
0
                           clip1, clip1, clip0, clip0);
1832
0
1833
0
    bs_flag_16x8b = _mm_cmpeq_epi8(bs_flag_16x8b, zero);
1834
0
    bs_flag_16x8b = _mm_xor_si128(bs_flag_16x8b, _mm_set1_epi8(0xFF)); //Invert for required mask
1835
0
    C0_8x16 = _mm_unpacklo_epi8(C0_16x8, zero);
1836
0
1837
0
    //Cond1 (ABS(p0 - q0) < alpha)
1838
0
    temp1 = _mm_subs_epu8(q0_16x8, p0_16x8);
1839
0
    temp2 = _mm_subs_epu8(p0_16x8, q0_16x8);
1840
0
    temp1 = _mm_add_epi8(temp1, temp2);
1841
0
1842
0
    temp2 = _mm_unpacklo_epi8(temp1, zero);
1843
0
    temp2 = _mm_cmpgt_epi16(Alpha_8x16, temp2);
1844
0
1845
0
    flag1_16x8 = _mm_packs_epi16(temp2, zero);
1846
0
    flag1_16x8 = _mm_and_si128(flag1_16x8, bs_flag_16x8b);
1847
0
1848
0
    //Cond2 (ABS(q1 - q0) < beta)
1849
0
    temp1 = _mm_subs_epu8(q0_16x8, q1_16x8);
1850
0
    temp2 = _mm_subs_epu8(q1_16x8, q0_16x8);
1851
0
    temp1 = _mm_add_epi8(temp1, temp2);
1852
0
1853
0
    temp2 = _mm_unpacklo_epi8(temp1, zero);
1854
0
    temp2 = _mm_cmpgt_epi16(Beta_8x16, temp2);
1855
0
1856
0
    flag2_16x8 = _mm_packs_epi16(temp2, zero);
1857
0
    flag1_16x8 = _mm_and_si128(flag1_16x8, flag2_16x8);
1858
0
1859
0
    //Cond3 (ABS(p1 - p0) < beta)
1860
0
    temp1 = _mm_subs_epu8(p0_16x8, p1_16x8);
1861
0
    temp2 = _mm_subs_epu8(p1_16x8, p0_16x8);
1862
0
    temp1 = _mm_add_epi8(temp1, temp2);
1863
0
1864
0
    temp2 = _mm_unpacklo_epi8(temp1, zero);
1865
0
    temp2 = _mm_cmpgt_epi16(Beta_8x16, temp2);
1866
0
1867
0
    flag2_16x8 = _mm_packs_epi16(temp2, zero);
1868
0
1869
0
    // !((ABS(p0 - q0) < alpha) || (ABS(q1 - q0) < beta) || (ABS(p1 - p0) < beta))
1870
0
    flag1_16x8 = _mm_and_si128(flag1_16x8, flag2_16x8);
1871
0
1872
0
    // (ABS(p2 - p0) < beta)
1873
0
    temp1 = _mm_subs_epu8(p0_16x8, p2_16x8);
1874
0
    temp2 = _mm_subs_epu8(p2_16x8, p0_16x8);
1875
0
    temp1 = _mm_add_epi8(temp1, temp2);
1876
0
1877
0
    temp2 = _mm_unpacklo_epi8(temp1, zero);
1878
0
    temp2 = _mm_cmpgt_epi16(Beta_8x16, temp2);
1879
0
1880
0
    flag2_16x8 = _mm_packs_epi16(temp2, zero);
1881
0
    flag2_16x8 = _mm_and_si128(flag1_16x8, flag2_16x8);
1882
0
1883
0
    temp2 = _mm_subs_epi16(zero, temp2);
1884
0
1885
0
    C_8x16 = _mm_add_epi16(C0_8x16, temp2);
1886
0
1887
0
    // (ABS(q2 - q0) < beta)
1888
0
    temp1 = _mm_subs_epu8(q0_16x8, q2_16x8);
1889
0
    temp2 = _mm_subs_epu8(q2_16x8, q0_16x8);
1890
0
    temp1 = _mm_add_epi8(temp1, temp2);
1891
0
1892
0
    temp2 = _mm_unpacklo_epi8(temp1, zero);
1893
0
    temp2 = _mm_cmpgt_epi16(Beta_8x16, temp2);
1894
0
1895
0
    flag3_16x8 = _mm_packs_epi16(temp2, zero);
1896
0
    flag3_16x8 = _mm_and_si128(flag1_16x8, flag3_16x8);
1897
0
1898
0
    temp2 = _mm_subs_epi16(zero, temp2);
1899
0
1900
0
    C_8x16 = _mm_add_epi16(C_8x16, temp2);
1901
0
1902
0
    const_val4_8x16 = _mm_set1_epi16(4);
1903
0
    temp1 = _mm_subs_epi16(_mm_unpacklo_epi8(q0_16x8, zero),
1904
0
                           _mm_unpacklo_epi8(p0_16x8, zero));
1905
0
    temp2 = _mm_subs_epi16(_mm_unpacklo_epi8(p1_16x8, zero),
1906
0
                           _mm_unpacklo_epi8(q1_16x8, zero));
1907
0
    temp1 = _mm_slli_epi16(temp1, 2);
1908
0
    temp1 = _mm_add_epi16(temp1, temp2);
1909
0
    temp1 = _mm_add_epi16(temp1, const_val4_8x16);
1910
0
    in_macro_16x8 = _mm_srai_epi16(temp1, 3);
1911
0
1912
0
    in_macro_16x8 = _mm_min_epi16(C_8x16, in_macro_16x8); //CLIP3
1913
0
    C_8x16 = _mm_subs_epi16(zero, C_8x16);
1914
0
    in_macro_16x8 = _mm_max_epi16(C_8x16, in_macro_16x8); //CLIP3
1915
0
1916
0
    // p0
1917
0
    temp1 = _mm_add_epi16(_mm_unpacklo_epi8(p0_16x8, zero), in_macro_16x8);
1918
0
1919
0
    temp1 = _mm_packus_epi16(temp1, zero);
1920
0
1921
0
    p0_16x8_1 = _mm_and_si128(temp1, flag1_16x8);
1922
0
    p0_16x8_2 = _mm_and_si128(
1923
0
                    p0_16x8, _mm_xor_si128(flag1_16x8, _mm_set1_epi16(0xFFFF)));
1924
0
1925
0
    p0_16x8_1 = _mm_add_epi8(p0_16x8_1, p0_16x8_2);
1926
0
1927
0
    // q0
1928
0
    temp1 = _mm_sub_epi16(_mm_unpacklo_epi8(q0_16x8, zero), in_macro_16x8);
1929
0
1930
0
    temp1 = _mm_packus_epi16(temp1, zero);
1931
0
1932
0
    q0_16x8_1 = _mm_and_si128(temp1, flag1_16x8);
1933
0
    q0_16x8_2 = _mm_and_si128(
1934
0
                    q0_16x8, _mm_xor_si128(flag1_16x8, _mm_set1_epi16(0xFFFF)));
1935
0
1936
0
    q0_16x8_1 = _mm_add_epi8(q0_16x8_1, q0_16x8_2);
1937
0
1938
0
    //if(Ap < Beta)
1939
0
    temp1 = _mm_avg_epu16(_mm_unpacklo_epi8(q0_16x8, zero),
1940
0
                          _mm_unpacklo_epi8(p0_16x8, zero));
1941
0
    temp2 = _mm_slli_epi16(_mm_unpacklo_epi8(p1_16x8, zero), 1);
1942
0
    //temp2 = _mm_subs_epi16(zero,temp2);
1943
0
    temp2 = _mm_subs_epi16(_mm_unpacklo_epi8(p2_16x8, zero), temp2);
1944
0
    temp2 = _mm_add_epi16(temp1, temp2);
1945
0
    in_macro_16x8 = _mm_srai_epi16(temp2, 1);
1946
0
1947
0
    in_macro_16x8 = _mm_min_epi16(C0_8x16, in_macro_16x8); //CLIP3
1948
0
    C0_8x16 = _mm_subs_epi16(zero, C0_8x16);
1949
0
    in_macro_16x8 = _mm_max_epi16(C0_8x16, in_macro_16x8); //CLIP3
1950
0
1951
0
    // p1
1952
0
    temp1 = _mm_add_epi16(_mm_unpacklo_epi8(p1_16x8, zero), in_macro_16x8);
1953
0
1954
0
    temp1 = _mm_packus_epi16(temp1, zero);
1955
0
1956
0
    p1_16x8_1 = _mm_and_si128(temp1, flag2_16x8);
1957
0
    p1_16x8 = _mm_and_si128(p1_16x8,
1958
0
                            _mm_xor_si128(flag2_16x8, _mm_set1_epi16(0xFFFF)));
1959
0
    p1_16x8 = _mm_add_epi8(p1_16x8, p1_16x8_1);
1960
0
1961
0
    //if(Aq < Beta)
1962
0
    temp1 = _mm_avg_epu16(_mm_unpacklo_epi8(q0_16x8, zero),
1963
0
                          _mm_unpacklo_epi8(p0_16x8, zero));
1964
0
    temp2 = _mm_slli_epi16(_mm_unpacklo_epi8(q1_16x8, zero), 1);
1965
0
    //temp2 = _mm_slli_epi16 (temp2, 1);
1966
0
    temp2 = _mm_subs_epi16(_mm_unpacklo_epi8(q2_16x8, zero), temp2);
1967
0
    temp2 = _mm_add_epi16(temp1, temp2);
1968
0
    in_macro_16x8 = _mm_srai_epi16(temp2, 1);
1969
0
1970
0
    in_macro_16x8 = _mm_max_epi16(C0_8x16, in_macro_16x8); //CLIP3
1971
0
    C0_8x16 = _mm_subs_epi16(zero, C0_8x16);
1972
0
    in_macro_16x8 = _mm_min_epi16(C0_8x16, in_macro_16x8); //CLIP3
1973
0
1974
0
    temp1 = _mm_add_epi16(_mm_unpacklo_epi8(q1_16x8, zero), in_macro_16x8);
1975
0
1976
0
    // q1
1977
0
    temp1 = _mm_packus_epi16(temp1, zero);
1978
0
1979
0
    q1_16x8_1 = _mm_and_si128(temp1, flag3_16x8);
1980
0
    q1_16x8 = _mm_and_si128(q1_16x8,
1981
0
                            _mm_xor_si128(flag3_16x8, _mm_set1_epi16(0xFFFF)));
1982
0
    q1_16x8 = _mm_add_epi8(q1_16x8, q1_16x8_1);
1983
0
1984
0
    temp1 = _mm_unpacklo_epi8(p3_16x8, p2_16x8);
1985
0
    temp2 = _mm_unpacklo_epi8(p1_16x8, p0_16x8_1);
1986
0
    temp3 = _mm_unpacklo_epi8(q0_16x8_1, q1_16x8);
1987
0
    temp4 = _mm_unpacklo_epi8(q2_16x8, q3_16x8);
1988
0
1989
0
    line7 = _mm_unpacklo_epi16(temp1, temp2);
1990
0
    temp1 = _mm_unpackhi_epi16(temp1, temp2);
1991
0
    line8 = _mm_unpacklo_epi16(temp3, temp4);
1992
0
    temp2 = _mm_unpackhi_epi16(temp3, temp4);
1993
0
1994
0
    line1 = _mm_unpacklo_epi32(line7, line8);
1995
0
    line2 = _mm_srli_si128(line1, 8);
1996
0
    line3 = _mm_unpackhi_epi32(line7, line8);
1997
0
    line4 = _mm_srli_si128(line3, 8);
1998
0
    line5 = _mm_unpacklo_epi32(temp1, temp2);
1999
0
    line6 = _mm_srli_si128(line5, 8);
2000
0
    line7 = _mm_unpackhi_epi32(temp1, temp2);
2001
0
    line8 = _mm_srli_si128(line7, 8);
2002
0
2003
0
    _mm_storel_epi64((__m128i *)(pu1_src - 4 + 0 * src_strd), line1);
2004
0
    _mm_storel_epi64((__m128i *)(pu1_src - 4 + 1 * src_strd), line2);
2005
0
    _mm_storel_epi64((__m128i *)(pu1_src - 4 + 2 * src_strd), line3);
2006
0
    _mm_storel_epi64((__m128i *)(pu1_src - 4 + 3 * src_strd), line4);
2007
0
    _mm_storel_epi64((__m128i *)(pu1_src - 4 + 4 * src_strd), line5);
2008
0
    _mm_storel_epi64((__m128i *)(pu1_src - 4 + 5 * src_strd), line6);
2009
0
    _mm_storel_epi64((__m128i *)(pu1_src - 4 + 6 * src_strd), line7);
2010
0
    _mm_storel_epi64((__m128i *)(pu1_src - 4 + 7 * src_strd), line8);
2011
0
}
2012
/proc/self/cwd/external/libavc/common/x86/ih264_ihadamard_scaling_sse42.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/**
21
 *******************************************************************************
22
 * @file
23
 *  ih264_ihadamard_scaling_sse42.c
24
 *
25
 * @brief
26
 *  Contains definition of functions for h264 inverse hadamard 4x4 transform and scaling
27
 *
28
 * @author
29
 *  Mohit
30
 *
31
 *  @par List of Functions:
32
 *  - ih264_ihadamard_scaling_4x4_sse42()
33
 *  - ih264_ihadamard_scaling_2x2_uv_ssse42()
34
 *
35
 * @remarks
36
 *
37
 *******************************************************************************
38
 */
39
/*****************************************************************************/
40
/* File Includes                                                             */
41
/*****************************************************************************/
42
43
/* User include files */
44
#include "ih264_typedefs.h"
45
#include "ih264_defs.h"
46
#include "ih264_trans_macros.h"
47
#include "ih264_macros.h"
48
#include "ih264_trans_data.h"
49
#include "ih264_size_defs.h"
50
#include "ih264_structs.h"
51
#include "ih264_trans_quant_itrans_iquant.h"
52
#include <immintrin.h>
53
54
/*
55
 ********************************************************************************
56
 *
57
 * @brief This function performs a 4x4 inverse hadamard transform on the 4x4 DC coefficients
58
 * of a 16x16 intra prediction macroblock, and then performs scaling.
59
 * prediction buffer
60
 *
61
 * @par Description:
62
 *  The DC coefficients pass through a 2-stage inverse hadamard transform.
63
 *  This inverse transformed content is scaled to based on Qp value.
64
 *
65
 * @param[in] pi2_src
66
 *  input 4x4 block of DC coefficients
67
 *
68
 * @param[out] pi2_out
69
 *  output 4x4 block
70
 *
71
 * @param[in] pu2_iscal_mat
72
 *  pointer to scaling list
73
 *
74
 * @param[in] pu2_weigh_mat
75
 *  pointer to weight matrix
76
 *
77
 * @param[in] u4_qp_div_6
78
 *  Floor (qp/6)
79
 *
80
 * @param[in] pi4_tmp
81
 * temporary buffer of size 1*16
82
 *
83
 * @returns none
84
 *
85
 * @remarks none
86
 *
87
 *******************************************************************************
88
 */
89
void ih264_ihadamard_scaling_4x4_sse42(WORD16* pi2_src,
90
                                       WORD16* pi2_out,
91
                                       const UWORD16 *pu2_iscal_mat,
92
                                       const UWORD16 *pu2_weigh_mat,
93
                                       UWORD32 u4_qp_div_6,
94
                                       WORD32* pi4_tmp)
95
0
{
96
0
    __m128i src_r0_r1, src_r2_r3;
97
0
    __m128i src_r0, src_r1, src_r2, src_r3;
98
0
    __m128i temp0, temp1, temp2, temp3;
99
0
    __m128i add_rshift = _mm_set1_epi32((1 << (5 - u4_qp_div_6)));
100
0
    __m128i mult_val = _mm_set1_epi32(pu2_iscal_mat[0] * pu2_weigh_mat[0]);
101
0
    UNUSED (pi4_tmp);
102
0
103
0
    src_r0_r1 = _mm_loadu_si128((__m128i *) (pi2_src)); //a00 a01 a02 a03 a10 a11 a12 a13 -- the source matrix 0th,1st row
104
0
    src_r2_r3 = _mm_loadu_si128((__m128i *) (pi2_src + 8)); //a20 a21 a22 a23 a30 a31 a32 a33 -- the source matrix 2nd,3rd row
105
0
    //sign_reg = _mm_cmpgt_epi16(zero_8x16b, src_r0_r1);
106
0
    src_r0 = _mm_cvtepi16_epi32(src_r0_r1);
107
0
    src_r0_r1 = _mm_srli_si128(src_r0_r1, 8);
108
0
    src_r1 = _mm_cvtepi16_epi32(src_r0_r1);
109
0
110
0
    src_r2 = _mm_cvtepi16_epi32(src_r2_r3);
111
0
    src_r2_r3 = _mm_srli_si128(src_r2_r3, 8);
112
0
    src_r3 = _mm_cvtepi16_epi32(src_r2_r3);
113
0
114
0
    /* Perform Inverse transform */
115
0
    /*-------------------------------------------------------------*/
116
0
    /* IDCT [ Horizontal transformation ]                          */
117
0
    /*-------------------------------------------------------------*/
118
0
    // Matrix transpose
119
0
    /*
120
0
     *  a0 a1 a2 a3
121
0
     *  b0 b1 b2 b3
122
0
     *  c0 c1 c2 c3
123
0
     *  d0 d1 d2 d3
124
0
     */
125
0
    temp0 = _mm_unpacklo_epi32(src_r0, src_r1);                  //a0 b0 a1 b1
126
0
    temp2 = _mm_unpacklo_epi32(src_r2, src_r3);                  //c0 d0 c1 d1
127
0
    temp1 = _mm_unpackhi_epi32(src_r0, src_r1);                  //a2 b2 a3 b3
128
0
    temp3 = _mm_unpackhi_epi32(src_r2, src_r3);                  //c2 d2 c3 d3
129
0
    src_r0 = _mm_unpacklo_epi64(temp0, temp2);                    //a0 b0 c0 d0
130
0
    src_r1 = _mm_unpackhi_epi64(temp0, temp2);                    //a1 b1 c1 d1
131
0
    src_r2 = _mm_unpacklo_epi64(temp1, temp3);                    //a2 b2 c2 d2
132
0
    src_r3 = _mm_unpackhi_epi64(temp1, temp3);                    //a3 b3 c3 d3
133
0
134
0
    temp0 = _mm_add_epi32(src_r0, src_r3);
135
0
    temp1 = _mm_add_epi32(src_r1, src_r2);
136
0
    temp2 = _mm_sub_epi32(src_r1, src_r2);
137
0
    temp3 = _mm_sub_epi32(src_r0, src_r3);
138
0
139
0
    src_r0 = _mm_add_epi32(temp0, temp1);
140
0
    src_r1 = _mm_add_epi32(temp2, temp3);
141
0
    src_r2 = _mm_sub_epi32(temp0, temp1);
142
0
    src_r3 = _mm_sub_epi32(temp3, temp2);
143
0
144
0
    /*-------------------------------------------------------------*/
145
0
    /* IDCT [ Vertical transformation ]                          */
146
0
    /*-------------------------------------------------------------*/
147
0
    // Matrix transpose
148
0
    /*
149
0
     *  a0 b0 c0 d0
150
0
     *  a1 b1 c1 d1
151
0
     *  a2 b2 c2 d2
152
0
     *  a3 b3 c3 d3
153
0
     */
154
0
    temp0 = _mm_unpacklo_epi32(src_r0, src_r1);                  //a0 a1 b0 b1
155
0
    temp2 = _mm_unpacklo_epi32(src_r2, src_r3);                  //a2 a3 b2 b3
156
0
    temp1 = _mm_unpackhi_epi32(src_r0, src_r1);                  //c0 c1 d0 d1
157
0
    temp3 = _mm_unpackhi_epi32(src_r2, src_r3);                  //c2 c3 d2 d3
158
0
    src_r0 = _mm_unpacklo_epi64(temp0, temp2);                   //a0 a1 a2 a3
159
0
    src_r1 = _mm_unpackhi_epi64(temp0, temp2);                   //b0 b1 b2 b3
160
0
    src_r2 = _mm_unpacklo_epi64(temp1, temp3);                   //c0 c1 c2 c3
161
0
    src_r3 = _mm_unpackhi_epi64(temp1, temp3);                   //d0 d1 d2 d3
162
0
163
0
    temp0 = _mm_add_epi32(src_r0, src_r3);
164
0
    temp1 = _mm_add_epi32(src_r1, src_r2);
165
0
    temp2 = _mm_sub_epi32(src_r1, src_r2);
166
0
    temp3 = _mm_sub_epi32(src_r0, src_r3);
167
0
168
0
    src_r0 = _mm_add_epi32(temp0, temp1);
169
0
    src_r1 = _mm_add_epi32(temp2, temp3);
170
0
    src_r2 = _mm_sub_epi32(temp0, temp1);
171
0
    src_r3 = _mm_sub_epi32(temp3, temp2);
172
0
173
0
    src_r0 = _mm_mullo_epi32(src_r0, mult_val);
174
0
    src_r1 = _mm_mullo_epi32(src_r1, mult_val);
175
0
    src_r2 = _mm_mullo_epi32(src_r2, mult_val);
176
0
    src_r3 = _mm_mullo_epi32(src_r3, mult_val);
177
0
178
0
    //Scaling
179
0
    if(u4_qp_div_6 >= 6)
180
0
    {
181
0
        src_r0 = _mm_slli_epi32(src_r0, u4_qp_div_6 - 6);
182
0
        src_r1 = _mm_slli_epi32(src_r1, u4_qp_div_6 - 6);
183
0
        src_r2 = _mm_slli_epi32(src_r2, u4_qp_div_6 - 6);
184
0
        src_r3 = _mm_slli_epi32(src_r3, u4_qp_div_6 - 6);
185
0
    }
186
0
    else
187
0
    {
188
0
        temp0 = _mm_add_epi32(src_r0, add_rshift);
189
0
        temp1 = _mm_add_epi32(src_r1, add_rshift);
190
0
        temp2 = _mm_add_epi32(src_r2, add_rshift);
191
0
        temp3 = _mm_add_epi32(src_r3, add_rshift);
192
0
        src_r0 = _mm_srai_epi32(temp0, 6 - u4_qp_div_6);
193
0
        src_r1 = _mm_srai_epi32(temp1, 6 - u4_qp_div_6);
194
0
        src_r2 = _mm_srai_epi32(temp2, 6 - u4_qp_div_6);
195
0
        src_r3 = _mm_srai_epi32(temp3, 6 - u4_qp_div_6);
196
0
    }
197
0
    src_r0_r1 = _mm_packs_epi32(src_r0, src_r1);
198
0
    src_r2_r3 = _mm_packs_epi32(src_r2, src_r3);
199
0
200
0
    _mm_storeu_si128((__m128i *) (&pi2_out[0]), src_r0_r1);
201
0
    _mm_storeu_si128((__m128i *) (&pi2_out[8]), src_r2_r3);
202
0
}
203
204
void ih264_ihadamard_scaling_2x2_uv_sse42(WORD16* pi2_src,
205
                                          WORD16* pi2_out,
206
                                          const UWORD16 *pu2_iscal_mat,
207
                                          const UWORD16 *pu2_weigh_mat,
208
                                          UWORD32 u4_qp_div_6,
209
                                          WORD32* pi4_tmp)
210
0
{
211
0
    __m128i src, plane_0, plane_1, temp0, temp1, sign_reg;
212
0
    __m128i zero_8x16b = _mm_setzero_si128();
213
0
    __m128i scale_val = _mm_set1_epi32((WORD32)(pu2_iscal_mat[0] * pu2_weigh_mat[0]));
214
0
    UNUSED(pi4_tmp);
215
0
216
0
    src = _mm_loadu_si128((__m128i *) pi2_src);         //a0 a1 a2 a3 b0 b1 b2 b3
217
0
    sign_reg = _mm_cmpgt_epi16(zero_8x16b, src);
218
0
    plane_0 = _mm_unpacklo_epi16(src, sign_reg);        //a0 a1 a2 a3 -- 32 bits
219
0
    plane_1 = _mm_unpackhi_epi16(src, sign_reg);        //b0 b1 b2 b3 -- 32 bits
220
0
221
0
    temp0 = _mm_hadd_epi32(plane_0, plane_1);           //a0+a1 a2+a3 b0+b1 b2+b3
222
0
    temp1 = _mm_hsub_epi32(plane_0, plane_1);           //a0-a1 a2-a3 b0-b1 b2-b3
223
0
    plane_0 = _mm_hadd_epi32(temp0, temp1);             //a0+a1+a2+a3 b0+b1+b2+b3 a0-a1+a2-a3 b0-b1+b2-b3
224
0
    plane_1 = _mm_hsub_epi32(temp0, temp1);             //a0+a1-a2-a3 b0+b1-b2-b3 a0-a1-a2+a3 b0-b1-b2+b3
225
0
    temp0 = _mm_unpacklo_epi32(plane_0, plane_1);       //a0+a1+a2+a3 a0+a1-a2-a3 b0+b1+b2+b3 b0+b1-b2-b3
226
0
    temp1 = _mm_unpackhi_epi32(plane_0, plane_1);       //a0-a1+a2-a3 a0-a1-a2+a3 b0-b1+b2-b3 b0-b1-b2+b3
227
0
228
0
    plane_0 = _mm_unpacklo_epi64(temp0, temp1);         //a0+a1+a2+a3 a0+a1-a2-a3 a0-a1+a2-a3 a0-a1-a2+a3
229
0
    plane_1 = _mm_unpackhi_epi64(temp0, temp1);         //b0+b1+b2+b3 b0+b1-b2-b3 b0-b1+b2-b3 b0-b1-b2+b3
230
0
231
0
    plane_0 = _mm_shuffle_epi32(plane_0, 0xd8);         //a0+a1+a2+a3 a0-a1+a2-a3 a0+a1-a2-a3 a0-a1-a2+a3
232
0
    plane_1 = _mm_shuffle_epi32(plane_1, 0xd8);         //b0+b1+b2+b3 b0-b1+b2-b3 b0+b1-b2-b3 b0-b1-b2+b3
233
0
234
0
    temp0 = _mm_mullo_epi32(scale_val, plane_0);        //multiply by pu2_iscal_mat[0] * pu2_weigh_mat[0]
235
0
    temp1 = _mm_mullo_epi32(scale_val, plane_1);        //multiply by pu2_iscal_mat[0] * pu2_weigh_mat[0]
236
0
237
0
    temp0 = _mm_slli_epi32(temp0, u4_qp_div_6);
238
0
    temp1 = _mm_slli_epi32(temp1, u4_qp_div_6);
239
0
240
0
    temp0 = _mm_srai_epi32(temp0, 5);
241
0
    temp1 = _mm_srai_epi32(temp1, 5);
242
0
243
0
    temp0 = _mm_packs_epi32(temp0, temp1);              //Final values are 16-bits only.
244
0
245
0
    _mm_storeu_si128((__m128i *) (&pi2_out[0]), temp0);
246
0
247
0
}
/proc/self/cwd/external/libavc/common/x86/ih264_inter_pred_filters_ssse3.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/*****************************************************************************/
21
/*                                                                           */
22
/*  File Name         : ih264_inter_pred_filters_intr_ssse3.c                */
23
/*                                                                           */
24
/*  Description       : Contains function definitions for weighted           */
25
/*                      prediction functions in x86 sse4 intrinsics          */
26
/*                                                                           */
27
/*  List of Functions : ih264_inter_pred_luma_copy_ssse3()                   */
28
/*                      ih264_inter_pred_luma_horz_ssse3()                   */
29
/*                      ih264_inter_pred_luma_vert_ssse3()                   */
30
/*                      ih264_inter_pred_luma_horz_hpel_vert_hpel_ssse3()    */
31
/*                      ih264_inter_pred_luma_horz_qpel_ssse3()              */
32
/*                      ih264_inter_pred_luma_vert_qpel_ssse3()              */
33
/*                      ih264_inter_pred_luma_horz_qpel_vert_qpel_ssse3()    */
34
/*                      ih264_inter_pred_luma_horz_hpel_vert_qpel_ssse3()    */
35
/*                      ih264_inter_pred_luma_horz_qpel_vert_hpel_ssse3()    */
36
/*                      ih264_inter_pred_chroma_ssse3()                      */
37
/*                                                                           */
38
/*  Issues / Problems : None                                                 */
39
/*                                                                           */
40
/*  Revision History  :                                                      */
41
/*                                                                           */
42
/*         DD MM YYYY   Author(s)       Changes                              */
43
/*         13 02 2015   Kaushik         Initial version                      */
44
/*                      Senthoor                                             */
45
/*                                                                           */
46
/*****************************************************************************/
47
/*****************************************************************************/
48
/* File Includes                                                             */
49
/*****************************************************************************/
50
51
#include <immintrin.h>
52
#include "ih264_typedefs.h"
53
#include "ih264_macros.h"
54
#include "ih264_platform_macros.h"
55
#include "ih264_inter_pred_filters.h"
56
57
/*****************************************************************************/
58
/* Constant Data variables                                                   */
59
/*****************************************************************************/
60
61
/* coefficients for 6 tap filtering*/
62
//const WORD32 ih264_g_six_tap[3] ={1,-5,20};
63
/*****************************************************************************/
64
/*  Function definitions .                                                   */
65
/*****************************************************************************/
66
/*****************************************************************************/
67
/*                                                                           */
68
/*  Function Name : ih264_inter_pred_luma_copy_ssse3                         */
69
/*                                                                           */
70
/*  Description   : This function copies the contents of ht x wd block from  */
71
/*                  source to destination. (ht,wd) can be (4,4), (8,4),      */
72
/*                  (4,8), (8,8), (16,8), (8,16) or (16,16).                 */
73
/*                                                                           */
74
/*  Inputs        : puc_src  - pointer to source                             */
75
/*                  puc_dst  - pointer to destination                        */
76
/*                  src_strd - stride for source                             */
77
/*                  dst_strd - stride for destination                        */
78
/*                  ht       - height of the block                           */
79
/*                  wd       - width of the block                            */
80
/*                                                                           */
81
/*  Issues        : None                                                     */
82
/*                                                                           */
83
/*  Revision History:                                                        */
84
/*                                                                           */
85
/*         DD MM YYYY   Author(s)       Changes                              */
86
/*         13 02 2015   Kaushik         Initial Version                      */
87
/*                      Senthoor                                             */
88
/*                                                                           */
89
/*****************************************************************************/
90
void ih264_inter_pred_luma_copy_ssse3(UWORD8 *pu1_src,
91
                                      UWORD8 *pu1_dst,
92
                                      WORD32 src_strd,
93
                                      WORD32 dst_strd,
94
                                      WORD32 ht,
95
                                      WORD32 wd,
96
                                      UWORD8* pu1_tmp,
97
                                      WORD32 dydx)
98
0
{
99
0
    __m128i y_0_16x8b, y_1_16x8b, y_2_16x8b, y_3_16x8b;
100
0
101
0
    WORD32 src_strd2, src_strd3, src_strd4, dst_strd2, dst_strd3, dst_strd4;
102
0
    UNUSED(pu1_tmp);
103
0
    UNUSED(dydx);
104
0
105
0
    src_strd2 = src_strd << 1;
106
0
    dst_strd2 = dst_strd << 1;
107
0
    src_strd4 = src_strd << 2;
108
0
    dst_strd4 = dst_strd << 2;
109
0
    src_strd3 = src_strd2 + src_strd;
110
0
    dst_strd3 = dst_strd2 + dst_strd;
111
0
112
0
    if(wd == 4)
113
0
    {
114
0
        do
115
0
        {
116
0
            *((WORD32 *)(pu1_dst)) =  *((WORD32 *)(pu1_src));
117
0
            *((WORD32 *)(pu1_dst + dst_strd)) = *((WORD32 *)(pu1_src + src_strd));
118
0
            *((WORD32 *)(pu1_dst + dst_strd2)) = *((WORD32 *)(pu1_src + src_strd2));
119
0
            *((WORD32 *)(pu1_dst + dst_strd3)) = *((WORD32 *)(pu1_src + src_strd3));
120
0
121
0
            ht -= 4;
122
0
            pu1_src += src_strd4;
123
0
            pu1_dst += dst_strd4;
124
0
        }
125
0
        while(ht > 0);
126
0
    }
127
0
    else if(wd == 8)
128
0
    {
129
0
        do
130
0
        {
131
0
            y_0_16x8b = _mm_loadl_epi64((__m128i *)pu1_src);
132
0
            y_1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src + src_strd));
133
0
            y_2_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src + src_strd2));
134
0
            y_3_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src + src_strd3));
135
0
136
0
            _mm_storel_epi64((__m128i *)pu1_dst, y_0_16x8b);
137
0
            _mm_storel_epi64((__m128i *)(pu1_dst + dst_strd), y_1_16x8b);
138
0
            _mm_storel_epi64((__m128i *)(pu1_dst + dst_strd2), y_2_16x8b);
139
0
            _mm_storel_epi64((__m128i *)(pu1_dst + dst_strd3), y_3_16x8b);
140
0
141
0
            ht -= 4;
142
0
            pu1_src += src_strd4;
143
0
            pu1_dst += dst_strd4;
144
0
        }
145
0
        while(ht > 0);
146
0
    }
147
0
    else // wd == 16
148
0
    {
149
0
        WORD32 src_strd5, src_strd6, src_strd7, src_strd8;
150
0
        WORD32 dst_strd5, dst_strd6, dst_strd7, dst_strd8;
151
0
152
0
        __m128i y_4_16x8b, y_5_16x8b, y_6_16x8b, y_7_16x8b;
153
0
154
0
        src_strd5 = src_strd2 + src_strd3;
155
0
        dst_strd5 = dst_strd2 + dst_strd3;
156
0
        src_strd6 = src_strd3 << 1;
157
0
        dst_strd6 = dst_strd3 << 1;
158
0
        src_strd7 = src_strd3 + src_strd4;
159
0
        dst_strd7 = dst_strd3 + dst_strd4;
160
0
        src_strd8 = src_strd << 3;
161
0
        dst_strd8 = dst_strd << 3;
162
0
163
0
        do
164
0
        {
165
0
            y_0_16x8b = _mm_loadu_si128((__m128i *)pu1_src);
166
0
            y_1_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + src_strd));
167
0
            y_2_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + src_strd2));
168
0
            y_3_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + src_strd3));
169
0
            y_4_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + src_strd4));
170
0
            y_5_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + src_strd5));
171
0
            y_6_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + src_strd6));
172
0
            y_7_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + src_strd7));
173
0
174
0
            _mm_storeu_si128((__m128i *)pu1_dst, y_0_16x8b);
175
0
            _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), y_1_16x8b);
176
0
            _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd2), y_2_16x8b);
177
0
            _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd3), y_3_16x8b);
178
0
            _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd4), y_4_16x8b);
179
0
            _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd5), y_5_16x8b);
180
0
            _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd6), y_6_16x8b);
181
0
            _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd7), y_7_16x8b);
182
0
183
0
            ht -= 8;
184
0
            pu1_src += src_strd8;
185
0
            pu1_dst += dst_strd8;
186
0
        }
187
0
        while(ht > 0);
188
0
    }
189
0
}
190
191
/*****************************************************************************/
192
/*                                                                           */
193
/*  Function Name : ih264_inter_pred_luma_horz_ssse3                         */
194
/*                                                                           */
195
/*  Description   : This function applies a horizontal 6-tap filter on       */
196
/*                  ht x wd block as mentioned in sec. 8.4.2.2.1 titled      */
197
/*                  "Luma sample interpolation process". (ht,wd) can be      */
198
/*                  (4,4), (8,4), (4,8), (8,8), (16,8), (8,16) or (16,16).   */
199
/*                                                                           */
200
/*  Inputs        : puc_src  - pointer to source                             */
201
/*                  puc_dst  - pointer to destination                        */
202
/*                  src_strd - stride for source                             */
203
/*                  dst_strd - stride for destination                        */
204
/*                  ht       - height of the block                           */
205
/*                  wd       - width of the block                            */
206
/*                                                                           */
207
/*  Issues        : None                                                     */
208
/*                                                                           */
209
/*  Revision History:                                                        */
210
/*                                                                           */
211
/*         DD MM YYYY   Author(s)       Changes                              */
212
/*         13 02 2015   Kaushik         Initial Version                      */
213
/*                      Senthoor                                             */
214
/*                                                                           */
215
/*****************************************************************************/
216
void ih264_inter_pred_luma_horz_ssse3(UWORD8 *pu1_src,
217
                                      UWORD8 *pu1_dst,
218
                                      WORD32 src_strd,
219
                                      WORD32 dst_strd,
220
                                      WORD32 ht,
221
                                      WORD32 wd,
222
                                      UWORD8* pu1_tmp,
223
                                      WORD32 dydx)
224
0
{
225
0
    __m128i coeff0_1_16x8b, coeff2_3_16x8b, coeff4_5_16x8b;
226
0
    __m128i const_val16_8x16b;
227
0
228
0
    UNUSED(pu1_tmp);
229
0
    UNUSED(dydx);
230
0
231
0
    pu1_src -= 2; // the filter input starts from x[-2] (till x[3])
232
0
233
0
    coeff0_1_16x8b = _mm_set1_epi32(0xFB01FB01); //c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1
234
0
    coeff2_3_16x8b = _mm_set1_epi32(0x14141414); //c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3
235
0
    coeff4_5_16x8b = _mm_set1_epi32(0x01FB01FB); //c4 c5 c4 c5 c4 c5 c4 c5 c4 c5 c4 c5 c4 c5 c4 c5
236
0
                                                 //c0 = c5 = 1, c1 = c4 = -5, c2 = c3 = 20
237
0
    const_val16_8x16b = _mm_set1_epi16(16);
238
0
239
0
    if(wd == 4)
240
0
    {
241
0
        __m128i src_r0_16x8b, src_r1_16x8b, src_r0r1_16x8b;
242
0
        __m128i src_r0_sht_16x8b, src_r1_sht_16x8b;
243
0
244
0
        __m128i res_r0r1_t1_8x16b, res_r0r1_t2_8x16b, res_r0r1_t3_8x16b;
245
0
        __m128i res_r0r1_16x8b;
246
0
247
0
        //Row0 : a0 a1 a2 a3 a4 a5 a6 a7 a8 a9.....
248
0
        //Row1 : b0 b1 b2 b3 b4 b5 b6 b7 b8 b9.....
249
0
250
0
        do
251
0
        {
252
0
            src_r0_16x8b = _mm_loadu_si128((__m128i *)pu1_src);                     //a0 a1 a2 a3 a4 a5 a6 a7 a8 a9....a15
253
0
            src_r1_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + src_strd));        //b0 b1 b2 b3 b4 b5 b6 b7 b8 b9....b15
254
0
255
0
            src_r0_sht_16x8b = _mm_srli_si128(src_r0_16x8b, 1);                     //a1 a2 a3 a4 a5 a6 a7 a8 a9....a15 0
256
0
            src_r1_sht_16x8b = _mm_srli_si128(src_r1_16x8b, 1);                     //b1 b2 b3 b4 b5 b6 b7 b8 b9....b15 0
257
0
258
0
            src_r0_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);       //a0 a1 a1 a2 a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8
259
0
            src_r1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);       //b0 b1 b1 b2 b2 b3 b3 b4 b4 b5 b5 b6 b6 b7 b7 b8
260
0
261
0
            src_r0r1_16x8b = _mm_unpacklo_epi64(src_r0_16x8b, src_r1_16x8b);        //a0 a1 a1 a2 a2 a3 a3 a4 b0 b1 b1 b2 b2 b3 b3 b4
262
0
            res_r0r1_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);  //a0*c0+a1*c1 a1*c0+a2*c1 a2*c0+a3*c1 a3*c0+a4*c1
263
0
                                                                                    //b0*c0+b1*c1 b1*c0+b2*c1 b2*c0+b3*c1 b3*c0+b4*c1
264
0
265
0
            src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 4);                         //a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8  0  0  0  0
266
0
            src_r1_16x8b = _mm_srli_si128(src_r1_16x8b, 4);                         //b2 b3 b3 b4 b4 b5 b5 b6 b6 b7 b7 b8  0  0  0  0
267
0
268
0
            src_r0r1_16x8b = _mm_unpacklo_epi64(src_r0_16x8b, src_r1_16x8b);        //a2 a3 a3 a4 a4 a5 a5 a6 b2 b3 b3 b4 b4 b5 b5 b6
269
0
            res_r0r1_t2_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff2_3_16x8b);  //a2*c2+a3*c3 a3*c2+a4*c3 a4*c2+a5*c3 a5*c2+a6*c3
270
0
                                                                                    //b2*c2+b3*c3 b3*c2+b4*c3 b4*c2+b5*c3 b5*c2+b6*c3
271
0
272
0
            src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 4);                         //a4 a5 a5 a6 a6 a7 a7 a8  0  0  0  0  0  0  0  0
273
0
            src_r1_16x8b = _mm_srli_si128(src_r1_16x8b, 4);                         //b4 b5 b5 b6 b6 b7 b7 b8  0  0  0  0  0  0  0  0
274
0
275
0
            src_r0r1_16x8b = _mm_unpacklo_epi64(src_r0_16x8b, src_r1_16x8b);        //a4 a5 a5 a6 a6 a7 a7 a8 b4 b5 b5 b6 b6 b7 b7 b8
276
0
            res_r0r1_t3_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff4_5_16x8b);  //a4*c4+a5*c5 a5*c4+a6*c5 a6*c4+a7*c5 a7*c4+a8*c5
277
0
                                                                                    //b4*c4+b5*c5 b5*c4+b6*c5 b4*c6+b7*c5 b7*c4+b8*c5
278
0
279
0
            res_r0r1_t1_8x16b = _mm_add_epi16(res_r0r1_t1_8x16b, res_r0r1_t2_8x16b);
280
0
            res_r0r1_t3_8x16b = _mm_add_epi16(const_val16_8x16b, res_r0r1_t3_8x16b);
281
0
            res_r0r1_t1_8x16b = _mm_add_epi16(res_r0r1_t1_8x16b, res_r0r1_t3_8x16b); //a0*c0+a1*c1+a2*c2+a3*c3+a4*a4+a5*c5 + 16;
282
0
                                                                                     //a1*c0+a2*c1+a2*c2+a3*c3+a5*a4+a6*c5 + 16;
283
0
                                                                                     //a2*c0+a3*c1+a4*c2+a5*c3+a6*a4+a7*c5 + 16;
284
0
                                                                                     //a3*c0+a4*c1+a5*c2+a6*c3+a6*a4+a8*c5 + 16;
285
0
                                                                                     //b0*c0+b1*c1+b2*c2+b3*c3+b4*b4+b5*c5 + 16;
286
0
                                                                                     //b1*c0+b2*c1+b2*c2+b3*c3+b5*b4+b6*c5 + 16;
287
0
                                                                                     //b2*c0+b3*c1+b4*c2+b5*c3+b6*b4+b7*c5 + 16;
288
0
                                                                                     //b3*c0+b4*c1+b5*c2+b6*c3+b6*b4+b8*c5 + 16;
289
0
290
0
            res_r0r1_t1_8x16b = _mm_srai_epi16(res_r0r1_t1_8x16b, 5);                //shifting right by 5 bits.
291
0
292
0
            res_r0r1_16x8b = _mm_packus_epi16(res_r0r1_t1_8x16b, res_r0r1_t1_8x16b);
293
0
294
0
            *((WORD32 *)(pu1_dst)) = _mm_cvtsi128_si32(res_r0r1_16x8b);
295
0
            res_r0r1_16x8b = _mm_srli_si128(res_r0r1_16x8b, 4);
296
0
            *((WORD32 *)(pu1_dst + dst_strd)) = _mm_cvtsi128_si32(res_r0r1_16x8b);
297
0
298
0
            ht -= 2;
299
0
            pu1_src += src_strd << 1;
300
0
            pu1_dst += dst_strd << 1;
301
0
        }
302
0
        while(ht > 0);
303
0
    }
304
0
    else if(wd == 8)
305
0
    {
306
0
        __m128i src_r0_16x8b, src_r1_16x8b, src_r0_sht_16x8b, src_r1_sht_16x8b;
307
0
        __m128i src_r0_t1_16x8b, src_r1_t1_16x8b;
308
0
309
0
        __m128i res_r0_t1_8x16b, res_r0_t2_8x16b, res_r0_t3_8x16b;
310
0
        __m128i res_r1_t1_8x16b, res_r1_t2_8x16b, res_r1_t3_8x16b;
311
0
312
0
        //Row0 : a0 a1 a2 a3 a4 a5 a6 a7 a8 a9.....
313
0
        //Row1 : b0 b1 b2 b3 b4 b5 b6 b7 b8 b9.....
314
0
315
0
        do
316
0
        {
317
0
            src_r0_16x8b = _mm_loadu_si128((__m128i *)pu1_src);                   //a0 a1 a2 a3 a4 a5 a6 a7 a8 a9....a15
318
0
            src_r1_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + src_strd));      //b0 b1 b2 b3 b4 b5 b6 b7 b8 b9....b15
319
0
320
0
            src_r0_sht_16x8b = _mm_srli_si128(src_r0_16x8b, 1);                   //a1 a2 a3 a4 a5 a6 a7 a8 a9....a15 0
321
0
            src_r1_sht_16x8b = _mm_srli_si128(src_r1_16x8b, 1);                   //b1 b2 b3 b4 b5 b6 b7 b8 b9....b15 0
322
0
323
0
            src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);  //a0 a1 a1 a2 a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8
324
0
            src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);  //b0 b1 b1 b2 b2 b3 b3 b4 b4 b5 b5 b6 b6 b7 b7 b8
325
0
326
0
            res_r0_t1_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff0_1_16x8b); //a0*c0+a1*c1 a1*c0+a2*c1 a2*c0+a3*c1 a3*c0+a4*c1
327
0
                                                                                  //a4*c0+a5*c1 a5*c0+a6*c1 a6*c0+a7*c1 a7*c0+a8*c1
328
0
            res_r1_t1_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff0_1_16x8b); //b0*c0+b1*c1 b1*c0+b2*c1 b2*c0+b3*c1 b3*c0+b4*c1
329
0
                                                                                  //b4*c0+b5*c1 b5*c0+b6*c1 b6*c0+b7*c1 b7*c0+b8*c1
330
0
331
0
            src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 2);                       //a2 a3 a4 a5 a6 a7 a8 a9....a15 0 0
332
0
            src_r1_16x8b = _mm_srli_si128(src_r1_16x8b, 2);                       //b2 b3 b4 b5 b6 b7 b8 b9....b15 0 0
333
0
334
0
            src_r0_sht_16x8b = _mm_srli_si128(src_r0_sht_16x8b, 2);               //a3 a4 a5 a6 a7 a8 a9....a15 0  0  0
335
0
            src_r1_sht_16x8b = _mm_srli_si128(src_r1_sht_16x8b, 2);               //b3 b4 b5 b6 b7 b8 b9....b15 0  0  0
336
0
337
0
            src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);  //a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8 a8 a9 a9 a10
338
0
            src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);  //b2 b3 b3 b4 b4 b5 b5 b6 b6 b7 b7 b8 a8 a9 a9 a10
339
0
340
0
            res_r0_t2_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff2_3_16x8b); //a2*c2+a3*c3 a3*c2+a4*c3 a4*c2+a5*c3 a5*c2+a6*c3
341
0
                                                                                  //a6*c2+a7*c3 a7*c2+a8*c3 a8*c2+a9*c3 a9*c2+a10*c3
342
0
            res_r1_t2_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff2_3_16x8b); //b2*c2+b3*c3 b3*c2+b4*c3 b2*c4+b5*c3 b5*c2+b6*c3
343
0
                                                                                  //b6*c2+b7*c3 b7*c2+b8*c3 b8*c2+b9*c3 b9*c2+b10*c3
344
0
345
0
            src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 2);                       //a4 a5 a6 a7 a8 a9....a15 0  0  0  0
346
0
            src_r1_16x8b = _mm_srli_si128(src_r1_16x8b, 2);                       //b4 b5 b6 b7 b8 b9....b15 0  0  0  0
347
0
348
0
            src_r0_sht_16x8b = _mm_srli_si128(src_r0_sht_16x8b, 2);               //a5 a6 a7 a8 a9....a15 0  0  0  0  0
349
0
            src_r1_sht_16x8b = _mm_srli_si128(src_r1_sht_16x8b, 2);               //b5 b6 b7 b8 b9....b15 0  0  0  0  0
350
0
351
0
            src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);  //a4 a5 a5 a6 a6 a7 a7 a8 a8 a9 a9 a10 a10 a11 a11 a12
352
0
            src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);  //b4 b5 b5 b6 b6 b7 b7 b8 b8 b9 b9 b10 b10 b11 b11 b12
353
0
354
0
            res_r0_t3_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff4_5_16x8b); //a4*c4+a5*c5 a5*c4+a6*c5 a6*c4+a7*c5 a7*c4+a8*c5
355
0
                                                                                  //a8*c4+a9*c5 a9*c4+a10*c5 a10*c4+a11*c5 a11*c4+a12*c5
356
0
            res_r1_t3_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff4_5_16x8b); //b4*c4+b5*c5 b5*c4+b6*c5 b6*c4+b7*c5 b7*c4+b8*c5
357
0
                                                                                  //b8*c4+b9*c5 b9*c4+b10*c5 b10*c4+b11*c5 b11*c4+b12*c5
358
0
            res_r0_t1_8x16b = _mm_add_epi16(res_r0_t1_8x16b, res_r0_t2_8x16b);
359
0
            res_r1_t1_8x16b = _mm_add_epi16(res_r1_t1_8x16b, res_r1_t2_8x16b);
360
0
            res_r0_t3_8x16b = _mm_add_epi16(res_r0_t3_8x16b, const_val16_8x16b);
361
0
            res_r1_t3_8x16b = _mm_add_epi16(res_r1_t3_8x16b, const_val16_8x16b);
362
0
            res_r0_t1_8x16b = _mm_add_epi16(res_r0_t1_8x16b, res_r0_t3_8x16b);
363
0
            res_r1_t1_8x16b = _mm_add_epi16(res_r1_t1_8x16b, res_r1_t3_8x16b);
364
0
365
0
            res_r0_t1_8x16b = _mm_srai_epi16(res_r0_t1_8x16b, 5);                 //shifting right by 5 bits.
366
0
            res_r1_t1_8x16b = _mm_srai_epi16(res_r1_t1_8x16b, 5);
367
0
368
0
            src_r0_16x8b = _mm_packus_epi16(res_r0_t1_8x16b, res_r0_t1_8x16b);
369
0
            src_r1_16x8b = _mm_packus_epi16(res_r1_t1_8x16b, res_r1_t1_8x16b);
370
0
371
0
            _mm_storel_epi64((__m128i *)pu1_dst, src_r0_16x8b);
372
0
            _mm_storel_epi64((__m128i *)(pu1_dst + dst_strd), src_r1_16x8b);
373
0
374
0
            ht -= 2;
375
0
            pu1_src += src_strd << 1;
376
0
            pu1_dst += dst_strd << 1;
377
0
        }
378
0
        while(ht > 0);
379
0
    }
380
0
    else // wd == 16
381
0
    {
382
0
        __m128i src_r0_16x8b, src_r1_16x8b, src_r0_sht_16x8b, src_r1_sht_16x8b;
383
0
        __m128i src_r0_t1_16x8b, src_r1_t1_16x8b;
384
0
385
0
        __m128i res_r0_t1_8x16b, res_r0_t2_8x16b, res_r0_t3_8x16b;
386
0
        __m128i res_r1_t1_8x16b, res_r1_t2_8x16b, res_r1_t3_8x16b;
387
0
388
0
        //Row0 : a0 a1 a2 a3 a4 a5 a6 a7 a8 a9.....
389
0
        //Row0 :                         b0 b1 b2 b3 b4 b5 b6 b7 b8 b9.....
390
0
        //b0 is same a8. Similarly other bn pixels are same as a(n+8) pixels.
391
0
392
0
        do
393
0
        {
394
0
            src_r0_16x8b = _mm_loadu_si128((__m128i *)pu1_src);                  //a0 a1 a2 a3 a4 a5 a6 a7 a8 a9....a15
395
0
            src_r1_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + 8));            //b0 b1 b2 b3 b4 b5 b6 b7 b8 b9....b15
396
0
397
0
            src_r0_sht_16x8b = _mm_srli_si128(src_r0_16x8b, 1);                   //a1 a2 a3 a4 a5 a6 a7 a8 a9....a15 0
398
0
            src_r1_sht_16x8b = _mm_srli_si128(src_r1_16x8b, 1);                   //b1 b2 b3 b4 b5 b6 b7 b8 b9....b15 0
399
0
400
0
            src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);  //a0 a1 a1 a2 a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8
401
0
            src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);  //b0 b1 b1 b2 b2 b3 b3 b4 b4 b5 b5 b6 b6 b7 b7 b8
402
0
403
0
            res_r0_t1_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff0_1_16x8b); //a0*c0+a1*c1 a1*c0+a2*c1 a2*c0+a3*c1 a3*c0+a4*c1
404
0
                                                                                  //a4*c0+a5*c1 a5*c0+a6*c1 a6*c0+a7*c1 a7*c0+a8*c1
405
0
            res_r1_t1_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff0_1_16x8b); //b0*c0+b1*c1 b1*c0+b2*c1 b2*c0+b3*c1 b3*c0+b4*c1
406
0
                                                                                  //b4*c0+b5*c1 b5*c0+b6*c1 b6*c0+b7*c1 b7*c0+b8*c1
407
0
408
0
            src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 2);                       //a2 a3 a4 a5 a6 a7 a8 a9....a15 0 0
409
0
            src_r1_16x8b = _mm_srli_si128(src_r1_16x8b, 2);                       //b2 b3 b4 b5 b6 b7 b8 b9....b15 0 0
410
0
411
0
            src_r0_sht_16x8b = _mm_srli_si128(src_r0_sht_16x8b, 2);               //a3 a4 a5 a6 a7 a8 a9....a15 0  0  0
412
0
            src_r1_sht_16x8b = _mm_srli_si128(src_r1_sht_16x8b, 2);               //b3 b4 b5 b6 b7 b8 b9....b15 0  0  0
413
0
414
0
            src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);  //a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8 a8 a9 a9 a10
415
0
            src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);  //b2 b3 b3 b4 b4 b5 b5 b6 b6 b7 b7 b8 a8 a9 a9 a10
416
0
417
0
            res_r0_t2_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff2_3_16x8b); //a2*c2+a3*c3 a3*c2+a4*c3 a4*c2+a5*c3 a5*c2+a6*c3
418
0
                                                                                  //a6*c2+a7*c3 a7*c2+a8*c3 a8*c2+a9*c3 a9*c2+a10*c3
419
0
            res_r1_t2_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff2_3_16x8b); //b2*c2+b3*c3 b3*c2+b4*c3 b2*c4+b5*c3 b5*c2+b6*c3
420
0
                                                                                  //b6*c2+b7*c3 b7*c2+b8*c3 b8*c2+b9*c3 b9*c2+b10*c3
421
0
422
0
            src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 2);                       //a4 a5 a6 a7 a8 a9....a15 0  0  0  0
423
0
            src_r1_16x8b = _mm_srli_si128(src_r1_16x8b, 2);                       //b4 b5 b6 b7 b8 b9....b15 0  0  0  0
424
0
425
0
            src_r0_sht_16x8b = _mm_srli_si128(src_r0_sht_16x8b, 2);               //a5 a6 a7 a8 a9....a15 0  0  0  0  0
426
0
            src_r1_sht_16x8b = _mm_srli_si128(src_r1_sht_16x8b, 2);               //b5 b6 b7 b8 b9....b15 0  0  0  0  0
427
0
428
0
            src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);  //a4 a5 a5 a6 a6 a7 a7 a8 a8 a9 a9 a10 a10 a11 a11 a12
429
0
            src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);  //b4 b5 b5 b6 b6 b7 b7 b8 b8 b9 b9 b10 b10 b11 b11 b12
430
0
431
0
            res_r0_t3_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff4_5_16x8b); //a4*c4+a5*c5 a5*c4+a6*c5 a6*c4+a7*c5 a7*c4+a8*c5
432
0
                                                                                  //a8*c4+a9*c5 a9*c4+a10*c5 a10*c4+a11*c5 a11*c4+a12*c5
433
0
            res_r1_t3_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff4_5_16x8b); //b4*c4+b5*c5 b5*c4+b6*c5 b6*c4+b7*c5 b7*c4+b8*c5
434
0
                                                                                  //b8*c4+b9*c5 b9*c4+b10*c5 b10*c4+b11*c5 b11*c4+b12*c5
435
0
            res_r0_t1_8x16b = _mm_add_epi16(res_r0_t1_8x16b, res_r0_t2_8x16b);
436
0
            res_r1_t1_8x16b = _mm_add_epi16(res_r1_t1_8x16b, res_r1_t2_8x16b);
437
0
            res_r0_t3_8x16b = _mm_add_epi16(res_r0_t3_8x16b, const_val16_8x16b);
438
0
            res_r1_t3_8x16b = _mm_add_epi16(res_r1_t3_8x16b, const_val16_8x16b);
439
0
            res_r0_t1_8x16b = _mm_add_epi16(res_r0_t1_8x16b, res_r0_t3_8x16b);
440
0
            res_r1_t1_8x16b = _mm_add_epi16(res_r1_t1_8x16b, res_r1_t3_8x16b);
441
0
442
0
            res_r0_t1_8x16b = _mm_srai_epi16(res_r0_t1_8x16b, 5);                 //shifting right by 5 bits.
443
0
            res_r1_t1_8x16b = _mm_srai_epi16(res_r1_t1_8x16b, 5);
444
0
445
0
            src_r0_16x8b = _mm_packus_epi16(res_r0_t1_8x16b, res_r1_t1_8x16b);
446
0
            _mm_storeu_si128((__m128i *)pu1_dst, src_r0_16x8b);
447
0
448
0
            ht--;
449
0
            pu1_src += src_strd;
450
0
            pu1_dst += dst_strd;
451
0
        }
452
0
        while(ht > 0);
453
0
    }
454
0
}
455
456
/*****************************************************************************/
457
/*                                                                           */
458
/*  Function Name : ih264_inter_pred_luma_vert_ssse3                         */
459
/*                                                                           */
460
/*  Description   : This function applies a vertical 6-tap filter on         */
461
/*                  ht x wd block as mentioned in sec. 8.4.2.2.1 titled      */
462
/*                  "Luma sample interpolation process". (ht,wd) can be      */
463
/*                  (4,4), (8,4), (4,8), (8,8), (16,8), (8,16) or (16,16).   */
464
/*                                                                           */
465
/*  Inputs        : puc_src  - pointer to source                             */
466
/*                  puc_dst  - pointer to destination                        */
467
/*                  src_strd - stride for source                             */
468
/*                  dst_strd - stride for destination                        */
469
/*                  ht       - height of the block                           */
470
/*                  wd       - width of the block                            */
471
/*                                                                           */
472
/*  Issues        : None                                                     */
473
/*                                                                           */
474
/*  Revision History:                                                        */
475
/*                                                                           */
476
/*         DD MM YYYY   Author(s)       Changes                              */
477
/*         13 02 2015   Kaushik         Initial Version                      */
478
/*                      Senthoor                                             */
479
/*                                                                           */
480
/*****************************************************************************/
481
void ih264_inter_pred_luma_vert_ssse3(UWORD8 *pu1_src,
482
                                      UWORD8 *pu1_dst,
483
                                      WORD32 src_strd,
484
                                      WORD32 dst_strd,
485
                                      WORD32 ht,
486
                                      WORD32 wd,
487
                                      UWORD8* pu1_tmp,
488
                                      WORD32 dydx)
489
0
{
490
0
    __m128i src_r0_16x8b, src_r1_16x8b, src_r2_16x8b, src_r3_16x8b, src_r4_16x8b;
491
0
    __m128i src_r5_16x8b, src_r6_16x8b;
492
0
    __m128i src_r0r1_16x8b, src_r2r3_16x8b, src_r4r5_16x8b;
493
0
494
0
    __m128i res_16x8b, res_t1_8x16b, res_t2_8x16b, res_t3_8x16b;
495
0
496
0
    __m128i coeff0_1_16x8b, coeff2_3_16x8b, coeff4_5_16x8b;
497
0
    __m128i const_val16_8x16b;
498
0
499
0
    UNUSED(pu1_tmp);
500
0
    UNUSED(dydx);
501
0
502
0
    coeff0_1_16x8b = _mm_set1_epi32(0xFB01FB01); //c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1
503
0
    coeff2_3_16x8b = _mm_set1_epi32(0x14141414); //c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3
504
0
    coeff4_5_16x8b = _mm_set1_epi32(0x01FB01FB); //c4 c5 c4 c5 c4 c5 c4 c5 c4 c5 c4 c5 c4 c5 c4 c5
505
0
                                                 //c0 = c5 = 1, c1 = c4 = -5, c2 = c3 = 20
506
0
    const_val16_8x16b = _mm_set1_epi16(16);
507
0
508
0
    pu1_src -= src_strd << 1; // the filter input starts from x[-2] (till x[3])
509
0
510
0
    if(wd == 4)
511
0
    {
512
0
        //Epilogue: Load all the pred rows except sixth and seventh row
513
0
        //          for the first and second row processing.
514
0
        src_r0_16x8b = _mm_loadl_epi64((__m128i *)pu1_src);
515
0
        pu1_src += src_strd;
516
0
        src_r1_16x8b = _mm_loadl_epi64((__m128i *)pu1_src);
517
0
        pu1_src += src_strd;
518
0
        src_r2_16x8b = _mm_loadl_epi64((__m128i *)pu1_src);
519
0
        pu1_src += src_strd;
520
0
        src_r3_16x8b = _mm_loadl_epi64((__m128i *)pu1_src);
521
0
        pu1_src += src_strd;
522
0
        src_r4_16x8b = _mm_loadl_epi64((__m128i *)pu1_src);
523
0
        pu1_src += src_strd;
524
0
525
0
        src_r0_16x8b = _mm_unpacklo_epi32(src_r0_16x8b, src_r1_16x8b);
526
0
        src_r1_16x8b = _mm_unpacklo_epi32(src_r1_16x8b, src_r2_16x8b);
527
0
        src_r2_16x8b = _mm_unpacklo_epi32(src_r2_16x8b, src_r3_16x8b);
528
0
        src_r3_16x8b = _mm_unpacklo_epi32(src_r3_16x8b, src_r4_16x8b);
529
0
530
0
        do
531
0
        {
532
0
            src_r5_16x8b = _mm_loadl_epi64((__m128i *)pu1_src);
533
0
            src_r6_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src + src_strd));
534
0
535
0
            src_r4_16x8b = _mm_unpacklo_epi32(src_r4_16x8b, src_r5_16x8b);
536
0
            src_r5_16x8b = _mm_unpacklo_epi32(src_r5_16x8b, src_r6_16x8b);
537
0
538
0
            src_r0r1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r1_16x8b);
539
0
            src_r2r3_16x8b = _mm_unpacklo_epi8(src_r2_16x8b, src_r3_16x8b);
540
0
            src_r4r5_16x8b = _mm_unpacklo_epi8(src_r4_16x8b, src_r5_16x8b);
541
0
542
0
            res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
543
0
            res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
544
0
            res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);
545
0
546
0
            res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t2_8x16b);
547
0
            res_t3_8x16b = _mm_add_epi16(res_t3_8x16b, const_val16_8x16b);
548
0
            res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t3_8x16b);
549
0
550
0
            res_t1_8x16b = _mm_srai_epi16(res_t1_8x16b, 5); //shifting right by 5 bits.
551
0
            res_16x8b = _mm_packus_epi16(res_t1_8x16b, res_t1_8x16b);
552
0
553
0
            *((WORD32 *)(pu1_dst)) = _mm_cvtsi128_si32(res_16x8b);
554
0
            res_16x8b = _mm_srli_si128(res_16x8b, 4);
555
0
            *((WORD32 *)(pu1_dst + dst_strd)) = _mm_cvtsi128_si32(res_16x8b);
556
0
557
0
            src_r0_16x8b = src_r2_16x8b;
558
0
            src_r1_16x8b = src_r3_16x8b;
559
0
            src_r2_16x8b = src_r4_16x8b;
560
0
            src_r3_16x8b = src_r5_16x8b;
561
0
            src_r4_16x8b = src_r6_16x8b;
562
0
563
0
            ht -= 2;
564
0
            pu1_src += src_strd << 1;
565
0
            pu1_dst += dst_strd << 1;
566
0
        }
567
0
        while(ht > 0);
568
0
    }
569
0
570
0
    else if(wd == 8)
571
0
    {
572
0
        //Epilogue: Load all the pred rows except sixth and seventh row
573
0
        //          for the first and second row processing.
574
0
        src_r0_16x8b = _mm_loadl_epi64((__m128i *)pu1_src);
575
0
        pu1_src += src_strd;
576
0
        src_r1_16x8b = _mm_loadl_epi64((__m128i *)pu1_src);
577
0
        pu1_src += src_strd;
578
0
        src_r2_16x8b = _mm_loadl_epi64((__m128i *)pu1_src);
579
0
        pu1_src += src_strd;
580
0
        src_r3_16x8b = _mm_loadl_epi64((__m128i *)pu1_src);
581
0
        pu1_src += src_strd;
582
0
        src_r4_16x8b = _mm_loadl_epi64((__m128i *)pu1_src);
583
0
        pu1_src += src_strd;
584
0
585
0
        src_r0_16x8b = _mm_unpacklo_epi64(src_r0_16x8b, src_r1_16x8b);
586
0
        src_r1_16x8b = _mm_unpacklo_epi64(src_r1_16x8b, src_r2_16x8b);
587
0
        src_r2_16x8b = _mm_unpacklo_epi64(src_r2_16x8b, src_r3_16x8b);
588
0
        src_r3_16x8b = _mm_unpacklo_epi64(src_r3_16x8b, src_r4_16x8b);
589
0
590
0
        do
591
0
        {
592
0
            src_r5_16x8b = _mm_loadl_epi64((__m128i *)pu1_src);
593
0
            src_r6_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src + src_strd));
594
0
595
0
            src_r4_16x8b = _mm_unpacklo_epi64(src_r4_16x8b, src_r5_16x8b);
596
0
            src_r5_16x8b = _mm_unpacklo_epi64(src_r5_16x8b, src_r6_16x8b);
597
0
598
0
            src_r0r1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r1_16x8b);
599
0
            src_r2r3_16x8b = _mm_unpacklo_epi8(src_r2_16x8b, src_r3_16x8b);
600
0
            src_r4r5_16x8b = _mm_unpacklo_epi8(src_r4_16x8b, src_r5_16x8b);
601
0
602
0
            res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
603
0
            res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
604
0
            res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);
605
0
606
0
            res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t2_8x16b);
607
0
            res_t3_8x16b = _mm_add_epi16(res_t3_8x16b, const_val16_8x16b);
608
0
            res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t3_8x16b);
609
0
610
0
            res_t1_8x16b = _mm_srai_epi16(res_t1_8x16b, 5); //shifting right by 5 bits.
611
0
            res_16x8b = _mm_packus_epi16(res_t1_8x16b, res_t1_8x16b);
612
0
613
0
            _mm_storel_epi64((__m128i *)pu1_dst, res_16x8b);
614
0
615
0
            src_r0r1_16x8b = _mm_unpackhi_epi8(src_r0_16x8b, src_r1_16x8b);
616
0
            src_r2r3_16x8b = _mm_unpackhi_epi8(src_r2_16x8b, src_r3_16x8b);
617
0
            src_r4r5_16x8b = _mm_unpackhi_epi8(src_r4_16x8b, src_r5_16x8b);
618
0
619
0
            res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
620
0
            res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
621
0
            res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);
622
0
623
0
            res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t2_8x16b);
624
0
            res_t3_8x16b = _mm_add_epi16(res_t3_8x16b, const_val16_8x16b);
625
0
            res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t3_8x16b);
626
0
627
0
            res_t1_8x16b = _mm_srai_epi16(res_t1_8x16b, 5); //shifting right by 5 bits.
628
0
            res_16x8b = _mm_packus_epi16(res_t1_8x16b, res_t1_8x16b);
629
0
630
0
            _mm_storel_epi64((__m128i *)(pu1_dst + dst_strd), res_16x8b);
631
0
632
0
            src_r0_16x8b = src_r2_16x8b;
633
0
            src_r1_16x8b = src_r3_16x8b;
634
0
            src_r2_16x8b = src_r4_16x8b;
635
0
            src_r3_16x8b = src_r5_16x8b;
636
0
            src_r4_16x8b = src_r6_16x8b;
637
0
638
0
            ht -= 2;
639
0
            pu1_src += src_strd << 1;
640
0
            pu1_dst += dst_strd << 1;
641
0
        }
642
0
        while(ht > 0);
643
0
    }
644
0
    else // wd == 16
645
0
    {
646
0
        __m128i res_t0_8x16b;
647
0
648
0
        //Epilogue: Load all the pred rows except sixth and seventh row
649
0
        //          for the first and second row processing.
650
0
        src_r0_16x8b = _mm_loadu_si128((__m128i *)pu1_src);
651
0
        pu1_src += src_strd;
652
0
        src_r1_16x8b = _mm_loadu_si128((__m128i *)pu1_src);
653
0
        pu1_src += src_strd;
654
0
        src_r2_16x8b = _mm_loadu_si128((__m128i *)pu1_src);
655
0
        pu1_src += src_strd;
656
0
        src_r3_16x8b = _mm_loadu_si128((__m128i *)pu1_src);
657
0
        pu1_src += src_strd;
658
0
        src_r4_16x8b = _mm_loadu_si128((__m128i *)pu1_src);
659
0
        pu1_src += src_strd;
660
0
661
0
        do
662
0
        {
663
0
            src_r5_16x8b  = _mm_loadu_si128((__m128i *)pu1_src);
664
0
            src_r6_16x8b  = _mm_loadu_si128((__m128i *)(pu1_src + src_strd));
665
0
666
0
            src_r0r1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r1_16x8b);
667
0
            src_r2r3_16x8b = _mm_unpacklo_epi8(src_r2_16x8b, src_r3_16x8b);
668
0
            src_r4r5_16x8b = _mm_unpacklo_epi8(src_r4_16x8b, src_r5_16x8b);
669
0
670
0
            res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
671
0
            res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
672
0
            res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);
673
0
674
0
            res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t2_8x16b);
675
0
            res_t3_8x16b = _mm_add_epi16(res_t3_8x16b, const_val16_8x16b);
676
0
            res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t3_8x16b);
677
0
            res_t0_8x16b = _mm_srai_epi16(res_t1_8x16b, 5); //shifting right by 5 bits.
678
0
679
0
            src_r0r1_16x8b = _mm_unpackhi_epi8(src_r0_16x8b, src_r1_16x8b);
680
0
            src_r2r3_16x8b = _mm_unpackhi_epi8(src_r2_16x8b, src_r3_16x8b);
681
0
            src_r4r5_16x8b = _mm_unpackhi_epi8(src_r4_16x8b, src_r5_16x8b);
682
0
683
0
            res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
684
0
            res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
685
0
            res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);
686
0
687
0
            res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t2_8x16b);
688
0
            res_t3_8x16b = _mm_add_epi16(res_t3_8x16b, const_val16_8x16b);
689
0
            res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t3_8x16b);
690
0
            res_t1_8x16b = _mm_srai_epi16(res_t1_8x16b, 5); //shifting right by 5 bits.
691
0
692
0
            res_16x8b = _mm_packus_epi16(res_t0_8x16b, res_t1_8x16b);
693
0
694
0
            _mm_storeu_si128((__m128i *)pu1_dst, res_16x8b);
695
0
696
0
            src_r0r1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r2_16x8b);
697
0
            src_r2r3_16x8b = _mm_unpacklo_epi8(src_r3_16x8b, src_r4_16x8b);
698
0
            src_r4r5_16x8b = _mm_unpacklo_epi8(src_r5_16x8b, src_r6_16x8b);
699
0
700
0
            res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
701
0
            res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
702
0
            res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);
703
0
704
0
            res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t2_8x16b);
705
0
            res_t3_8x16b = _mm_add_epi16(res_t3_8x16b, const_val16_8x16b);
706
0
            res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t3_8x16b);
707
0
            res_t0_8x16b = _mm_srai_epi16(res_t1_8x16b, 5); //shifting right by 5 bits.
708
0
709
0
            src_r0r1_16x8b = _mm_unpackhi_epi8(src_r1_16x8b, src_r2_16x8b);
710
0
            src_r2r3_16x8b = _mm_unpackhi_epi8(src_r3_16x8b, src_r4_16x8b);
711
0
            src_r4r5_16x8b = _mm_unpackhi_epi8(src_r5_16x8b, src_r6_16x8b);
712
0
713
0
            res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
714
0
            res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
715
0
            res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);
716
0
717
0
            res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t2_8x16b);
718
0
            res_t3_8x16b = _mm_add_epi16(res_t3_8x16b, const_val16_8x16b);
719
0
            res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t3_8x16b);
720
0
            res_t1_8x16b = _mm_srai_epi16(res_t1_8x16b, 5); //shifting right by 5 bits.
721
0
722
0
            res_16x8b = _mm_packus_epi16(res_t0_8x16b, res_t1_8x16b);
723
0
724
0
            _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), res_16x8b);
725
0
726
0
            src_r0_16x8b = src_r2_16x8b;
727
0
            src_r1_16x8b = src_r3_16x8b;
728
0
            src_r2_16x8b = src_r4_16x8b;
729
0
            src_r3_16x8b = src_r5_16x8b;
730
0
            src_r4_16x8b = src_r6_16x8b;
731
0
732
0
            ht -= 2;
733
0
            pu1_src += src_strd << 1;
734
0
            pu1_dst += dst_strd << 1;
735
0
        }
736
0
        while(ht > 0);
737
0
    }
738
0
}
739
740
/*****************************************************************************/
741
/*                                                                           */
742
/*  Function Name : ih264_inter_pred_luma_horz_hpel_vert_hpel_ssse3          */
743
/*                                                                           */
744
/*  Description   : This function implements a two stage cascaded six tap    */
745
/*                  filter, horizontally and then vertically on ht x wd      */
746
/*                  block as mentioned in sec. 8.4.2.2.1 titled "Luma sample */
747
/*                  interpolation process". (ht,wd) can be (4,4), (8,4),     */
748
/*                  (4,8), (8,8), (16,8), (8,16) or (16,16).                 */
749
/*                                                                           */
750
/*  Inputs        : puc_src  - pointer to source                             */
751
/*                  puc_dst  - pointer to destination                        */
752
/*                  src_strd - stride for source                             */
753
/*                  dst_strd - stride for destination                        */
754
/*                  ht       - height of the block                           */
755
/*                  wd       - width of the block                            */
756
/*                  pu1_tmp  - pointer to temporary buffer                   */
757
/*                                                                           */
758
/*  Issues        : None                                                     */
759
/*                                                                           */
760
/*  Revision History:                                                        */
761
/*                                                                           */
762
/*         DD MM YYYY   Author(s)       Changes                              */
763
/*         13 02 2015   Kaushik         Initial Version                      */
764
/*                      Senthoor                                             */
765
/*                                                                           */
766
/*****************************************************************************/
767
void ih264_inter_pred_luma_horz_hpel_vert_hpel_ssse3(UWORD8 *pu1_src,
768
                                                     UWORD8 *pu1_dst,
769
                                                     WORD32 src_strd,
770
                                                     WORD32 dst_strd,
771
                                                     WORD32 ht,
772
                                                     WORD32 wd,
773
                                                     UWORD8* pu1_tmp,
774
                                                     WORD32 dydx)
775
0
{
776
0
    UNUSED(dydx);
777
0
778
0
    if(wd == 4)
779
0
    {
780
0
        WORD16 *pi2_temp;
781
0
782
0
        pu1_tmp += 4;
783
0
        pu1_src -= src_strd << 1;
784
0
        pi2_temp = (WORD16 *)pu1_tmp;
785
0
        pu1_src -= 2; // the filter input starts from x[-2] (till x[3])
786
0
787
0
        // Horizontal 6-tap filtering
788
0
        {
789
0
            WORD32 ht_tmp = ht + 4;
790
0
791
0
            __m128i src_r0_16x8b, src_r1_16x8b;
792
0
            __m128i src_r0_sht_16x8b, src_r1_sht_16x8b;
793
0
            __m128i src_r0r1_t1_16x8b;
794
0
            __m128i res_r0r1_t1_8x16b, res_r0r1_t2_8x16b, res_r0r1_t3_8x16b;
795
0
            __m128i coeff0_1_16x8b, coeff2_3_16x8b, coeff4_5_16x8b;
796
0
797
0
            coeff0_1_16x8b = _mm_set1_epi32(0xFB01FB01);  //c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1
798
0
            coeff2_3_16x8b = _mm_set1_epi32(0x14141414);  //c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3
799
0
            coeff4_5_16x8b = _mm_set1_epi32(0x01FB01FB);  //c4 c5 c5 c5 c4 c5 c5 c5 c4 c5 c5 c5 c4 c5 c5 c5
800
0
                                                          //c0 = c5 = 1, c1 = c4 = -5, c2 = c3 = 20
801
0
            //Row0 : a0 a1 a2 a3 a4 a5 a6 a7 a8 a9.....
802
0
            //Row1 : b0 b1 b2 b3 b4 b5 b6 b7 b8 b9.....
803
0
804
0
            do
805
0
            {
806
0
                src_r0_16x8b = _mm_loadu_si128((__m128i *)pu1_src);                       //a0 a1 a2 a3 a4 a5 a6 a7 a8 a9....a15
807
0
                src_r1_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + src_strd));          //b0 b1 b2 b3 b4 b5 b6 b7 b8 b9....b15
808
0
809
0
                src_r0_sht_16x8b = _mm_srli_si128(src_r0_16x8b, 1);                       //a1 a2 a3 a4 a5 a6 a7 a8 a9....a15 0
810
0
                src_r1_sht_16x8b = _mm_srli_si128(src_r1_16x8b, 1);                       //b1 b2 b3 b4 b5 b6 b7 b8 b9....b15 0
811
0
812
0
                src_r0_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);         //a0 a1 a1 a2 a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8
813
0
                src_r1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);         //b0 b1 b1 b2 b2 b3 b3 b4 b4 b5 b5 b6 b6 b7 b7 b8
814
0
815
0
                src_r0r1_t1_16x8b = _mm_unpacklo_epi64(src_r0_16x8b, src_r1_16x8b);       //a0 a1 a1 a2 a2 a3 a3 a4 b0 b1 b1 b2 b2 b3 b3 b4
816
0
                res_r0r1_t1_8x16b = _mm_maddubs_epi16(src_r0r1_t1_16x8b, coeff0_1_16x8b); //a0*c0+a1*c1 a1*c0+a2*c1 a2*c0+a3*c1 a3*c0+a4*c1
817
0
                                                                                          //b0*c0+b1*c1 b1*c0+b2*c1 b2*c0+b3*c1 b3*c0+b4*c1
818
0
819
0
                src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 4);                           //a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8  0  0  0  0
820
0
                src_r1_16x8b = _mm_srli_si128(src_r1_16x8b, 4);                           //b2 b3 b3 b4 b4 b5 b5 b6 b6 b7 b7 b8  0  0  0  0
821
0
822
0
                src_r0r1_t1_16x8b = _mm_unpacklo_epi64(src_r0_16x8b, src_r1_16x8b);       //a2 a3 a3 a4 a4 a5 a5 a6 b2 b3 b3 b4 b4 b5 b5 b6
823
0
                res_r0r1_t2_8x16b = _mm_maddubs_epi16(src_r0r1_t1_16x8b, coeff2_3_16x8b); //a2*c2+a3*c3 a3*c2+a4*c3 a4*c2+a5*c3 a5*c2+a6*c3
824
0
                                                                                          //b2*c2+b3*c3 b3*c2+b4*c3 b4*c2+b5*c3 b5*c2+b6*c3
825
0
826
0
                src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 4);                           //a4 a5 a5 a6 a6 a7 a7 a8  0  0  0  0  0  0  0  0
827
0
                src_r1_16x8b = _mm_srli_si128(src_r1_16x8b, 4);                           //b4 b5 b5 b6 b6 b7 b7 b8  0  0  0  0  0  0  0  0
828
0
829
0
                src_r0r1_t1_16x8b = _mm_unpacklo_epi64(src_r0_16x8b, src_r1_16x8b);       //a4 a5 a5 a6 a6 a7 a7 a8 b4 b5 b5 b6 b6 b7 b7 b8
830
0
                res_r0r1_t3_8x16b = _mm_maddubs_epi16(src_r0r1_t1_16x8b, coeff4_5_16x8b); //a4*c4+a5*c5 a5*c4+a6*c5 a6*c4+a7*c5 a7*c4+a8*c5
831
0
                                                                                          //b4*c4+b5*c5 b5*c4+b6*c5 b4*c6+b7*c5 b7*c4+b8*c5
832
0
                res_r0r1_t1_8x16b = _mm_add_epi16(res_r0r1_t1_8x16b, res_r0r1_t2_8x16b);
833
0
                res_r0r1_t1_8x16b = _mm_add_epi16(res_r0r1_t3_8x16b, res_r0r1_t1_8x16b);
834
0
835
0
                _mm_storeu_si128((__m128i *)pi2_temp, res_r0r1_t1_8x16b);
836
0
837
0
                ht_tmp -= 2;
838
0
                pu1_src += src_strd << 1;
839
0
                pi2_temp += 8;
840
0
            }
841
0
            while(ht_tmp > 0);
842
0
843
0
            src_r0_16x8b = _mm_loadu_si128((__m128i *)pu1_src);                           //a0 a1 a2 a3 a4 a5 a6 a7 a8 a9....a15
844
0
            src_r0_sht_16x8b = _mm_srli_si128(src_r0_16x8b, 1);                           //a1 a2 a3 a4 a5 a6 a7 a8 a9....a15 0
845
0
846
0
            src_r0_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);             //a0 a1 a1 a2 a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8
847
0
            res_r0r1_t1_8x16b = _mm_maddubs_epi16(src_r0_16x8b, coeff0_1_16x8b);          //a0*c0+a1*c1 a1*c0+a2*c1 a2*c0+a3*c1 a3*c0+a4*c1
848
0
849
0
            src_r0_16x8b = _mm_srli_si128(src_r0_16x8b,4);                                //a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8  0  0  0  0
850
0
            res_r0r1_t2_8x16b = _mm_maddubs_epi16(src_r0_16x8b, coeff2_3_16x8b);          //a2*c2+a3*c3 a3*c2+a4*c3 a4*c2+a5*c3 a5*c2+a6*c3
851
0
852
0
            src_r0_16x8b = _mm_srli_si128(src_r0_16x8b,4);                                //a4 a5 a5 a6 a6 a7 a7 a8  0  0  0  0  0  0  0  0
853
0
            res_r0r1_t3_8x16b = _mm_maddubs_epi16(src_r0_16x8b, coeff4_5_16x8b);          //a4*c4+a5*c5 a5*c4+a6*c5 a6*c4+a7*c5 a7*c4+a8*c5
854
0
855
0
            res_r0r1_t1_8x16b = _mm_add_epi16(res_r0r1_t1_8x16b, res_r0r1_t2_8x16b);
856
0
            res_r0r1_t1_8x16b = _mm_add_epi16(res_r0r1_t3_8x16b, res_r0r1_t1_8x16b);
857
0
858
0
            _mm_storel_epi64((__m128i *)pi2_temp, res_r0r1_t1_8x16b);
859
0
        }
860
0
861
0
        pi2_temp = (WORD16 *)pu1_tmp;
862
0
863
0
        // Vertical 6-tap filtering
864
0
        {
865
0
            __m128i src_r0_8x16b, src_r1_8x16b, src_r2_8x16b, src_r3_8x16b,
866
0
                            src_r4_8x16b;
867
0
            __m128i src_r5_8x16b, src_r6_8x16b;
868
0
            __m128i src_t1_8x16b, src_t2_8x16b;
869
0
870
0
            __m128i res_t0_4x32b, res_t1_4x32b, res_t2_4x32b, res_t3_4x32b;
871
0
            __m128i res_8x16b, res_16x8b;
872
0
873
0
            __m128i coeff0_1_8x16b, coeff2_3_8x16b, coeff4_5_8x16b;
874
0
            __m128i const_val512_4x32b;
875
0
876
0
            coeff0_1_8x16b = _mm_set1_epi32(0xFFFB0001);
877
0
            coeff2_3_8x16b = _mm_set1_epi32(0x00140014);
878
0
            coeff4_5_8x16b = _mm_set1_epi32(0x0001FFFB);
879
0
880
0
            const_val512_4x32b = _mm_set1_epi32(512);
881
0
882
0
            src_r0_8x16b = _mm_loadl_epi64((__m128i *)(pi2_temp));
883
0
            src_r1_8x16b = _mm_loadl_epi64((__m128i *)(pi2_temp + 4));
884
0
            src_r2_8x16b = _mm_loadl_epi64((__m128i *)(pi2_temp + 8));
885
0
            src_r3_8x16b = _mm_loadl_epi64((__m128i *)(pi2_temp + 12));
886
0
            src_r4_8x16b = _mm_loadl_epi64((__m128i *)(pi2_temp + 16));
887
0
            pi2_temp += 20;
888
0
889
0
            do
890
0
            {
891
0
                src_r5_8x16b = _mm_loadl_epi64((__m128i *)pi2_temp);
892
0
                src_r6_8x16b = _mm_loadl_epi64((__m128i *)(pi2_temp + 4));
893
0
894
0
                src_r0_8x16b = _mm_unpacklo_epi16(src_r0_8x16b, src_r1_8x16b);
895
0
                src_t1_8x16b = _mm_unpacklo_epi16(src_r2_8x16b, src_r3_8x16b);
896
0
                src_t2_8x16b = _mm_unpacklo_epi16(src_r4_8x16b, src_r5_8x16b);
897
0
898
0
                res_t1_4x32b = _mm_madd_epi16(src_r0_8x16b, coeff0_1_8x16b);
899
0
                res_t2_4x32b = _mm_madd_epi16(src_t1_8x16b, coeff2_3_8x16b);
900
0
                res_t3_4x32b = _mm_madd_epi16(src_t2_8x16b, coeff4_5_8x16b);
901
0
902
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
903
0
                res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
904
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
905
0
906
0
                res_t0_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
907
0
908
0
                src_r1_8x16b = _mm_unpacklo_epi16(src_r1_8x16b, src_r2_8x16b);
909
0
                src_t1_8x16b = _mm_unpacklo_epi16(src_r3_8x16b, src_r4_8x16b);
910
0
                src_t2_8x16b = _mm_unpacklo_epi16(src_r5_8x16b, src_r6_8x16b);
911
0
912
0
                res_t1_4x32b = _mm_madd_epi16(src_r1_8x16b, coeff0_1_8x16b);
913
0
                res_t2_4x32b = _mm_madd_epi16(src_t1_8x16b, coeff2_3_8x16b);
914
0
                res_t3_4x32b = _mm_madd_epi16(src_t2_8x16b, coeff4_5_8x16b);
915
0
916
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
917
0
                res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
918
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
919
0
920
0
                res_t1_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
921
0
922
0
                res_8x16b = _mm_packs_epi32(res_t0_4x32b, res_t1_4x32b);
923
0
                res_16x8b = _mm_packus_epi16(res_8x16b, res_8x16b);
924
0
925
0
                *((WORD32 *)(pu1_dst)) = _mm_cvtsi128_si32(res_16x8b);
926
0
                res_16x8b = _mm_srli_si128(res_16x8b, 4);
927
0
                *((WORD32 *)(pu1_dst + dst_strd)) = _mm_cvtsi128_si32(res_16x8b);
928
0
929
0
                src_r0_8x16b = src_r2_8x16b;
930
0
                src_r1_8x16b = src_r3_8x16b;
931
0
                src_r2_8x16b = src_r4_8x16b;
932
0
                src_r3_8x16b = src_r5_8x16b;
933
0
                src_r4_8x16b = src_r6_8x16b;
934
0
935
0
                ht -= 2;
936
0
                pi2_temp += 8;
937
0
                pu1_dst += dst_strd << 1;
938
0
            }
939
0
            while(ht > 0);
940
0
        }
941
0
    }
942
0
    else if(wd == 8)
943
0
    {
944
0
        WORD16 *pi2_temp;
945
0
946
0
        pu1_tmp += 4;
947
0
        pu1_src -= src_strd << 1;
948
0
        pi2_temp = (WORD16 *)pu1_tmp;
949
0
        pu1_src -= 2; // the filter input starts from x[-2] (till x[3])
950
0
951
0
        // Horizontal 6-tap filtering
952
0
        {
953
0
            WORD32 ht_tmp = ht + 4;
954
0
955
0
            __m128i src_r0_16x8b, src_r1_16x8b;
956
0
            __m128i src_r0_sht_16x8b, src_r1_sht_16x8b;
957
0
            __m128i src_r0_t1_16x8b, src_r1_t1_16x8b;
958
0
            __m128i res_r0_t1_8x16b, res_r0_t2_8x16b, res_r0_t3_8x16b;
959
0
            __m128i res_r1_t1_8x16b, res_r1_t2_8x16b, res_r1_t3_8x16b;
960
0
            __m128i coeff0_1_16x8b, coeff2_3_16x8b, coeff4_5_16x8b;
961
0
962
0
            coeff0_1_16x8b = _mm_set1_epi32(0xFB01FB01);  //c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1
963
0
            coeff2_3_16x8b = _mm_set1_epi32(0x14141414);  //c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3
964
0
            coeff4_5_16x8b = _mm_set1_epi32(0x01FB01FB);  //c4 c5 c5 c5 c4 c5 c5 c5 c4 c5 c5 c5 c4 c5 c5 c5
965
0
                                                          //c0 = c5 = 1, c1 = c4 = -5, c2 = c3 = 20
966
0
            //Row0 : a0 a1 a2 a3 a4 a5 a6 a7 a8 a9.....
967
0
            //Row1 : b0 b1 b2 b3 b4 b5 b6 b7 b8 b9.....
968
0
969
0
            do
970
0
            {
971
0
                src_r0_16x8b = _mm_loadu_si128((__m128i *)pu1_src);                      //a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15
972
0
                src_r1_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + src_strd));         //b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15
973
0
974
0
                src_r0_sht_16x8b = _mm_srli_si128(src_r0_16x8b, 1);                      //a1 a2 a3 a4 a5 a6 a7 a8 a9....a15 0
975
0
                src_r1_sht_16x8b = _mm_srli_si128(src_r1_16x8b, 1);                      //b1 b2 b3 b4 b5 b6 b7 b8 b9....b15 0
976
0
977
0
                src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);     //a0 a1 a1 a2 a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8
978
0
                src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);     //b0 b1 b1 b2 b2 b3 b3 b4 b4 b5 b5 b6 b6 b7 b7 b8
979
0
980
0
                res_r0_t1_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff0_1_16x8b);    //a0*c0+a1*c1 a1*c0+a2*c1 a2*c0+a3*c1 a3*c0+a4*c1
981
0
                                                                                         //a4*c0+a5*c1 a5*c0+a6*c1 a6*c0+a7*c1 a7*c0+a8*c1
982
0
                res_r1_t1_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff0_1_16x8b);    //b0*c0+b1*c1 b1*c0+b2*c1 b2*c0+b3*c1 b3*c0+b4*c1
983
0
                                                                                         //b4*c0+b5*c1 b5*c0+b6*c1 b6*c0+b7*c1 b7*c0+b8*c1
984
0
985
0
                src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 2);                          //a2 a3 a4 a5 a6 a7 a8 a9....a15 0 0
986
0
                src_r1_16x8b = _mm_srli_si128(src_r1_16x8b, 2);                          //b2 b3 b4 b5 b6 b7 b8 b9....b15 0 0
987
0
988
0
                src_r0_sht_16x8b = _mm_srli_si128(src_r0_sht_16x8b, 2);                  //a3 a4 a5 a6 a7 a8 a9....a15 0  0  0
989
0
                src_r1_sht_16x8b = _mm_srli_si128(src_r1_sht_16x8b, 2);                  //b3 b4 b5 b6 b7 b8 b9....b15 0  0  0
990
0
991
0
                src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);     //a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8 a8 a9 a9 a10
992
0
                src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);     //b2 b3 b3 b4 b4 b5 b5 b6 b6 b7 b7 b8 a8 a9 a9 a10
993
0
994
0
                res_r0_t2_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff2_3_16x8b);    //a2*c2+a3*c3 a3*c2+a4*c3 a4*c2+a5*c3 a5*c2+a6*c3
995
0
                                                                                         //a6*c2+a7*c3 a7*c2+a8*c3 a8*c2+a9*c3 a9*c2+a10*c3
996
0
                res_r1_t2_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff2_3_16x8b);    //b2*c2+b3*c3 b3*c2+b4*c3 b2*c4+b5*c3 b5*c2+b6*c3
997
0
                                                                                         //b6*c2+b7*c3 b7*c2+b8*c3 b8*c2+b9*c3 b9*c2+b10*c3
998
0
999
0
                src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 2);                          //a4 a5 a6 a7 a8 a9....a15 0  0  0  0
1000
0
                src_r1_16x8b = _mm_srli_si128(src_r1_16x8b, 2);                          //b4 b5 b6 b7 b8 b9....b15 0  0  0  0
1001
0
1002
0
                src_r0_sht_16x8b = _mm_srli_si128(src_r0_sht_16x8b, 2);                  //a5 a6 a7 a8 a9....a15 0  0  0  0  0
1003
0
                src_r1_sht_16x8b = _mm_srli_si128(src_r1_sht_16x8b, 2);                  //b5 b6 b7 b8 b9....b15 0  0  0  0  0
1004
0
1005
0
                src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);     //a4 a5 a5 a6 a6 a7 a7 a8 a8 a9 a9 a10 a10 a11 a11 a12
1006
0
                src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);     //b4 b5 b5 b6 b6 b7 b7 b8 b8 b9 b9 b10 b10 b11 b11 b12
1007
0
1008
0
                res_r0_t3_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff4_5_16x8b);    //a4*c4+a5*c5 a5*c4+a6*c5 a6*c4+a7*c5 a7*c4+a8*c5
1009
0
                                                                                         //a8*c4+a9*c5 a9*c4+a10*c5 a10*c4+a11*c5 a11*c4+a12*c5
1010
0
                res_r1_t3_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff4_5_16x8b);    //b4*c4+b5*c5 b5*c4+b6*c5 b6*c4+b7*c5 b7*c4+b8*c5
1011
0
                                                                                         //b8*c4+b9*c5 b9*c4+b10*c5 b10*c4+b11*c5 b11*c4+b12*c5
1012
0
                res_r0_t1_8x16b = _mm_add_epi16(res_r0_t1_8x16b, res_r0_t2_8x16b);
1013
0
                res_r0_t1_8x16b = _mm_add_epi16(res_r0_t1_8x16b, res_r0_t3_8x16b);
1014
0
1015
0
                res_r1_t1_8x16b = _mm_add_epi16(res_r1_t1_8x16b, res_r1_t2_8x16b);
1016
0
                res_r1_t1_8x16b = _mm_add_epi16(res_r1_t1_8x16b, res_r1_t3_8x16b);
1017
0
1018
0
                _mm_storeu_si128((__m128i *)pi2_temp, res_r0_t1_8x16b);
1019
0
                _mm_storeu_si128((__m128i *)(pi2_temp + 8), res_r1_t1_8x16b);
1020
0
1021
0
                ht_tmp -= 2;
1022
0
                pu1_src += src_strd << 1;
1023
0
                pi2_temp += 16;
1024
0
            }
1025
0
            while(ht_tmp > 0);
1026
0
1027
0
            src_r0_16x8b = _mm_loadu_si128((__m128i *)pu1_src);                          //a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15
1028
0
            src_r0_sht_16x8b = _mm_srli_si128(src_r0_16x8b, 1);                          //a1 a2 a3 a4 a5 a6 a7 a8 a9....a15 0
1029
0
1030
0
            src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b,src_r0_sht_16x8b);          //a0 a1 a1 a2 a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8
1031
0
            res_r0_t1_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b,coeff0_1_16x8b);         //a0*c0+a1*c1 a1*c0+a2*c1 a2*c0+a3*c1 a3*c0+a4*c1
1032
0
                                                                                         //a4*c0+a5*c1 a5*c0+a6*c1 a6*c0+a7*c1 a7*c0+a8*c1
1033
0
1034
0
            src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 2);                              //a2 a3 a4 a5 a6 a7 a8 a9....a15 0 0
1035
0
            src_r0_sht_16x8b = _mm_srli_si128(src_r0_sht_16x8b, 2);                      //a3 a4 a5 a6 a7 a8 a9....a15 0  0  0
1036
0
1037
0
            src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);         //a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8 a8 a9 a9 a10
1038
0
            res_r0_t2_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff2_3_16x8b);        //a2*c2+a3*c3 a3*c2+a4*c3 a4*c2+a5*c3 a5*c2+a6*c3
1039
0
                                                                                         //a6*c2+a7*c3 a7*c2+a8*c3 a8*c2+a9*c3 a9*c2+a10*c3
1040
0
1041
0
            src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 2);                              //a4 a5 a6 a7 a8 a9....a15 0  0  0  0
1042
0
            src_r0_sht_16x8b = _mm_srli_si128(src_r0_sht_16x8b, 2);                      //a5 a6 a7 a8 a9....a15 0  0  0  0  0
1043
0
1044
0
            src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);         //a4 a5 a5 a6 a6 a7 a7 a8 a8 a9 a9 a10 a10 a11 a11 a12
1045
0
            res_r0_t3_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff4_5_16x8b);        //a4*c4+a5*c5 a5*c4+a6*c5 a6*c4+a7*c5 a7*c4+a8*c5
1046
0
                                                                                         //a8*c4+a9*c5 a9*c4+a10*c5 a10*c4+a11*c5 a11*c4+a12*c5
1047
0
            res_r0_t1_8x16b = _mm_add_epi16(res_r0_t1_8x16b, res_r0_t2_8x16b);
1048
0
            res_r0_t1_8x16b = _mm_add_epi16(res_r0_t1_8x16b, res_r0_t3_8x16b);
1049
0
1050
0
            _mm_storeu_si128((__m128i *)pi2_temp, res_r0_t1_8x16b);
1051
0
        }
1052
0
1053
0
        pi2_temp = (WORD16 *)pu1_tmp;
1054
0
1055
0
        // Vertical 6-tap filtering
1056
0
        {
1057
0
            __m128i src_r0_8x16b, src_r1_8x16b, src_r2_8x16b, src_r3_8x16b,
1058
0
                            src_r4_8x16b;
1059
0
            __m128i src_r5_8x16b, src_r6_8x16b;
1060
0
            __m128i src_r0r1_8x16b, src_r2r3_8x16b, src_r4r5_8x16b;
1061
0
1062
0
            __m128i res_t1_4x32b, res_t2_4x32b, res_t3_4x32b;
1063
0
            __m128i res_c0_4x32b, res_c1_4x32b;
1064
0
            __m128i res_8x16b, res_16x8b;
1065
0
1066
0
            __m128i coeff0_1_8x16b, coeff2_3_8x16b, coeff4_5_8x16b;
1067
0
            __m128i const_val512_4x32b;
1068
0
1069
0
            coeff0_1_8x16b = _mm_set1_epi32(0xFFFB0001);
1070
0
            coeff2_3_8x16b = _mm_set1_epi32(0x00140014);
1071
0
            coeff4_5_8x16b = _mm_set1_epi32(0x0001FFFB);
1072
0
1073
0
            const_val512_4x32b = _mm_set1_epi32(512);
1074
0
1075
0
            src_r0_8x16b = _mm_loadu_si128((__m128i *)pi2_temp);
1076
0
            src_r1_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp + 8));
1077
0
            src_r2_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp + 16));
1078
0
            src_r3_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp + 24));
1079
0
            src_r4_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp + 32));
1080
0
            pi2_temp += 40;
1081
0
1082
0
            do
1083
0
            {
1084
0
                src_r5_8x16b = _mm_loadu_si128((__m128i *)pi2_temp);
1085
0
                src_r6_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp + 8));
1086
0
1087
0
                src_r0r1_8x16b = _mm_unpacklo_epi16(src_r0_8x16b, src_r1_8x16b);
1088
0
                src_r2r3_8x16b = _mm_unpacklo_epi16(src_r2_8x16b, src_r3_8x16b);
1089
0
                src_r4r5_8x16b = _mm_unpacklo_epi16(src_r4_8x16b, src_r5_8x16b);
1090
0
1091
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_8x16b, coeff0_1_8x16b);
1092
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_8x16b, coeff2_3_8x16b);
1093
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_8x16b, coeff4_5_8x16b);
1094
0
1095
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
1096
0
                res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
1097
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
1098
0
                res_c0_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
1099
0
1100
0
                src_r0r1_8x16b = _mm_unpackhi_epi16(src_r0_8x16b, src_r1_8x16b);
1101
0
                src_r2r3_8x16b = _mm_unpackhi_epi16(src_r2_8x16b, src_r3_8x16b);
1102
0
                src_r4r5_8x16b = _mm_unpackhi_epi16(src_r4_8x16b, src_r5_8x16b);
1103
0
1104
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_8x16b, coeff0_1_8x16b);
1105
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_8x16b, coeff2_3_8x16b);
1106
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_8x16b, coeff4_5_8x16b);
1107
0
1108
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
1109
0
                res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
1110
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
1111
0
                res_c1_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
1112
0
1113
0
                res_8x16b = _mm_packs_epi32(res_c0_4x32b, res_c1_4x32b);
1114
0
                res_16x8b = _mm_packus_epi16(res_8x16b, res_8x16b);
1115
0
1116
0
                _mm_storel_epi64((__m128i *)pu1_dst, res_16x8b);
1117
0
1118
0
                src_r0r1_8x16b = _mm_unpacklo_epi16(src_r1_8x16b, src_r2_8x16b);
1119
0
                src_r2r3_8x16b = _mm_unpacklo_epi16(src_r3_8x16b, src_r4_8x16b);
1120
0
                src_r4r5_8x16b = _mm_unpacklo_epi16(src_r5_8x16b, src_r6_8x16b);
1121
0
1122
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_8x16b, coeff0_1_8x16b);
1123
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_8x16b, coeff2_3_8x16b);
1124
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_8x16b, coeff4_5_8x16b);
1125
0
1126
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
1127
0
                res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
1128
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
1129
0
                res_c0_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
1130
0
1131
0
                src_r0r1_8x16b = _mm_unpackhi_epi16(src_r1_8x16b, src_r2_8x16b);
1132
0
                src_r2r3_8x16b = _mm_unpackhi_epi16(src_r3_8x16b, src_r4_8x16b);
1133
0
                src_r4r5_8x16b = _mm_unpackhi_epi16(src_r5_8x16b, src_r6_8x16b);
1134
0
1135
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_8x16b, coeff0_1_8x16b);
1136
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_8x16b, coeff2_3_8x16b);
1137
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_8x16b, coeff4_5_8x16b);
1138
0
1139
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
1140
0
                res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
1141
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
1142
0
                res_c1_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
1143
0
1144
0
                res_8x16b = _mm_packs_epi32(res_c0_4x32b, res_c1_4x32b);
1145
0
                res_16x8b = _mm_packus_epi16(res_8x16b, res_8x16b);
1146
0
1147
0
                _mm_storel_epi64((__m128i *)(pu1_dst + dst_strd), res_16x8b);
1148
0
1149
0
                src_r0_8x16b = src_r2_8x16b;
1150
0
                src_r1_8x16b = src_r3_8x16b;
1151
0
                src_r2_8x16b = src_r4_8x16b;
1152
0
                src_r3_8x16b = src_r5_8x16b;
1153
0
                src_r4_8x16b = src_r6_8x16b;
1154
0
1155
0
                ht -= 2;
1156
0
                pi2_temp += 16;
1157
0
                pu1_dst += dst_strd << 1;
1158
0
            }
1159
0
            while(ht > 0);
1160
0
        }
1161
0
    }
1162
0
    else // wd == 16
1163
0
    {
1164
0
        WORD16 *pi2_temp;
1165
0
        WORD32 ht_tmp;
1166
0
1167
0
        pu1_tmp += 4;
1168
0
        pu1_src -= src_strd << 1;
1169
0
        pi2_temp = (WORD16 *)pu1_tmp;
1170
0
        pu1_src -= 2; // the filter input starts from x[-2] (till x[3])
1171
0
1172
0
        // Horizontal 6-tap filtering
1173
0
        {
1174
0
            __m128i src_r0_16x8b, src_r1_16x8b, src_r0_sht_16x8b, src_r1_sht_16x8b;
1175
0
            __m128i src_r0_t1_16x8b, src_r1_t1_16x8b;
1176
0
1177
0
            __m128i res_r0_t1_8x16b, res_r0_t2_8x16b, res_r0_t3_8x16b;
1178
0
            __m128i res_r1_t1_8x16b, res_r1_t2_8x16b, res_r1_t3_8x16b;
1179
0
1180
0
            __m128i coeff0_1_16x8b, coeff2_3_16x8b, coeff4_5_16x8b;
1181
0
1182
0
            ht_tmp = ht + 5;
1183
0
1184
0
            coeff0_1_16x8b = _mm_set1_epi32(0xFB01FB01);  //c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1
1185
0
            coeff2_3_16x8b = _mm_set1_epi32(0x14141414);  //c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3
1186
0
            coeff4_5_16x8b = _mm_set1_epi32(0x01FB01FB);  //c4 c5 c5 c5 c4 c5 c5 c5 c4 c5 c5 c5 c4 c5 c5 c5
1187
0
                                                          //c0 = c5 = 1, c1 = c4 = -5, c2 = c3 = 20
1188
0
            //Row0 : a0 a1 a2 a3 a4 a5 a6 a7 a8 a9.....
1189
0
            //Row0 :                         b0 b1 b2 b3 b4 b5 b6 b7 b8 b9.....
1190
0
            //b0 is same a8. Similarly other bn pixels are same as a(n+8) pixels.
1191
0
1192
0
            do
1193
0
            {
1194
0
                src_r0_16x8b = _mm_loadu_si128((__m128i *)pu1_src);                      //a0 a1 a2 a3 a4 a5 a6 a7 a8 a9....a15
1195
0
                src_r1_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + 8));                //b0 b1 b2 b3 b4 b5 b6 b7 b8 b9....b15
1196
0
1197
0
                src_r0_sht_16x8b = _mm_srli_si128(src_r0_16x8b, 1);                      //a1 a2 a3 a4 a5 a6 a7 a8 a9....a15 0
1198
0
                src_r1_sht_16x8b = _mm_srli_si128(src_r1_16x8b, 1);                      //b1 b2 b3 b4 b5 b6 b7 b8 b9....b15 0
1199
0
1200
0
                src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);     //a0 a1 a1 a2 a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8
1201
0
                src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);     //b0 b1 b1 b2 b2 b3 b3 b4 b4 b5 b5 b6 b6 b7 b7 b8
1202
0
1203
0
                res_r0_t1_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff0_1_16x8b);    //a0*c0+a1*c1 a1*c0+a2*c1 a2*c0+a3*c1 a3*c0+a4*c1
1204
0
                                                                                         //a4*c0+a5*c1 a5*c0+a6*c1 a6*c0+a7*c1 a7*c0+a8*c1
1205
0
                res_r1_t1_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff0_1_16x8b);    //b0*c0+b1*c1 b1*c0+b2*c1 b2*c0+b3*c1 b3*c0+b4*c1
1206
0
                                                                                         //b4*c0+b5*c1 b5*c0+b6*c1 b6*c0+b7*c1 b7*c0+b8*c1
1207
0
1208
0
                src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 2);                          //a2 a3 a4 a5 a6 a7 a8 a9....a15 0 0
1209
0
                src_r1_16x8b = _mm_srli_si128(src_r1_16x8b, 2);                          //b2 b3 b4 b5 b6 b7 b8 b9....b15 0 0
1210
0
1211
0
                src_r0_sht_16x8b = _mm_srli_si128(src_r0_sht_16x8b, 2);                  //a3 a4 a5 a6 a7 a8 a9....a15 0  0  0
1212
0
                src_r1_sht_16x8b = _mm_srli_si128(src_r1_sht_16x8b, 2);                  //b3 b4 b5 b6 b7 b8 b9....b15 0  0  0
1213
0
1214
0
                src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);     //a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8 a8 a9 a9 a10
1215
0
                src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);     //b2 b3 b3 b4 b4 b5 b5 b6 b6 b7 b7 b8 a8 a9 a9 a10
1216
0
1217
0
                res_r0_t2_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff2_3_16x8b);    //a2*c2+a3*c3 a3*c2+a4*c3 a4*c2+a5*c3 a5*c2+a6*c3
1218
0
                                                                                         //a6*c2+a7*c3 a7*c2+a8*c3 a8*c2+a9*c3 a9*c2+a10*c3
1219
0
                res_r1_t2_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff2_3_16x8b);    //b2*c2+b3*c3 b3*c2+b4*c3 b2*c4+b5*c3 b5*c2+b6*c3
1220
0
                                                                                         //b6*c2+b7*c3 b7*c2+b8*c3 b8*c2+b9*c3 b9*c2+b10*c3
1221
0
1222
0
                src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 2);                          //a4 a5 a6 a7 a8 a9....a15 0  0  0  0
1223
0
                src_r1_16x8b = _mm_srli_si128(src_r1_16x8b, 2);                          //b4 b5 b6 b7 b8 b9....b15 0  0  0  0
1224
0
1225
0
                src_r0_sht_16x8b = _mm_srli_si128(src_r0_sht_16x8b, 2);                  //a5 a6 a7 a8 a9....a15 0  0  0  0  0
1226
0
                src_r1_sht_16x8b = _mm_srli_si128(src_r1_sht_16x8b, 2);                  //b5 b6 b7 b8 b9....b15 0  0  0  0  0
1227
0
1228
0
                src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);     //a4 a5 a5 a6 a6 a7 a7 a8 a8 a9 a9 a10 a10 a11 a11 a12
1229
0
                src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);     //b4 b5 b5 b6 b6 b7 b7 b8 b8 b9 b9 b10 b10 b11 b11 b12
1230
0
1231
0
                res_r0_t3_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff4_5_16x8b);    //a4*c4+a5*c5 a5*c4+a6*c5 a6*c4+a7*c5 a7*c4+a8*c5
1232
0
                                                                                         //a8*c4+a9*c5 a9*c4+a10*c5 a10*c4+a11*c5 a11*c4+a12*c5
1233
0
                res_r1_t3_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff4_5_16x8b);    //b4*c4+b5*c5 b5*c4+b6*c5 b6*c4+b7*c5 b7*c4+b8*c5
1234
0
                                                                                         //b8*c4+b9*c5 b9*c4+b10*c5 b10*c4+b11*c5 b11*c4+b12*c5
1235
0
                res_r0_t1_8x16b = _mm_add_epi16(res_r0_t1_8x16b, res_r0_t2_8x16b);
1236
0
                res_r0_t1_8x16b = _mm_add_epi16(res_r0_t1_8x16b, res_r0_t3_8x16b);
1237
0
1238
0
                res_r1_t1_8x16b = _mm_add_epi16(res_r1_t1_8x16b, res_r1_t2_8x16b);
1239
0
                res_r1_t1_8x16b = _mm_add_epi16(res_r1_t1_8x16b, res_r1_t3_8x16b);
1240
0
1241
0
                _mm_storeu_si128((__m128i *)pi2_temp, res_r0_t1_8x16b);
1242
0
                _mm_storeu_si128((__m128i *)(pi2_temp + 8), res_r1_t1_8x16b);
1243
0
1244
0
                ht_tmp--;
1245
0
                pu1_src += src_strd;
1246
0
                pi2_temp += 16;
1247
0
            }
1248
0
            while(ht_tmp > 0);
1249
0
        }
1250
0
1251
0
        pi2_temp = (WORD16 *)pu1_tmp;
1252
0
1253
0
        // Vertical 6-tap filtering
1254
0
        {
1255
0
            WORD16 *pi2_temp2;
1256
0
            UWORD8 *pu1_dst2;
1257
0
            WORD32 ht_tmp;
1258
0
1259
0
            __m128i src_r0_8x16b, src_r1_8x16b, src_r2_8x16b, src_r3_8x16b, src_r4_8x16b;
1260
0
            __m128i src_r5_8x16b, src_r6_8x16b;
1261
0
            __m128i src_r0r1_8x16b, src_r2r3_8x16b, src_r4r5_8x16b;
1262
0
1263
0
            __m128i res_t1_4x32b, res_t2_4x32b, res_t3_4x32b;
1264
0
            __m128i res_c0_4x32b, res_c1_4x32b;
1265
0
            __m128i res_8x16b, res_16x8b;
1266
0
1267
0
            __m128i coeff0_1_8x16b, coeff2_3_8x16b, coeff4_5_8x16b;
1268
0
            __m128i const_val512_4x32b;
1269
0
1270
0
            coeff0_1_8x16b = _mm_set1_epi32(0xFFFB0001);
1271
0
            coeff2_3_8x16b = _mm_set1_epi32(0x00140014);
1272
0
            coeff4_5_8x16b = _mm_set1_epi32(0x0001FFFB);
1273
0
1274
0
            const_val512_4x32b = _mm_set1_epi32(512);
1275
0
1276
0
            pi2_temp2 = pi2_temp + 8;
1277
0
            pu1_dst2 = pu1_dst + 8;
1278
0
            ht_tmp = ht;
1279
0
1280
0
            /**********************************************************/
1281
0
            /*     Do first height x 8 block                          */
1282
0
            /**********************************************************/
1283
0
            src_r0_8x16b = _mm_loadu_si128((__m128i *)pi2_temp);
1284
0
            src_r1_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp + 16));
1285
0
            src_r2_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp + 32));
1286
0
            src_r3_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp + 48));
1287
0
            src_r4_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp + 64));
1288
0
            pi2_temp += 80;
1289
0
1290
0
            do
1291
0
            {
1292
0
                src_r5_8x16b = _mm_loadu_si128((__m128i *)pi2_temp);
1293
0
                src_r6_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp + 16));
1294
0
1295
0
                src_r0r1_8x16b = _mm_unpacklo_epi16(src_r0_8x16b, src_r1_8x16b);
1296
0
                src_r2r3_8x16b = _mm_unpacklo_epi16(src_r2_8x16b, src_r3_8x16b);
1297
0
                src_r4r5_8x16b = _mm_unpacklo_epi16(src_r4_8x16b, src_r5_8x16b);
1298
0
1299
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_8x16b, coeff0_1_8x16b);
1300
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_8x16b, coeff2_3_8x16b);
1301
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_8x16b, coeff4_5_8x16b);
1302
0
1303
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
1304
0
                res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
1305
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
1306
0
                res_c0_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
1307
0
1308
0
                src_r0r1_8x16b = _mm_unpackhi_epi16(src_r0_8x16b, src_r1_8x16b);
1309
0
                src_r2r3_8x16b = _mm_unpackhi_epi16(src_r2_8x16b, src_r3_8x16b);
1310
0
                src_r4r5_8x16b = _mm_unpackhi_epi16(src_r4_8x16b, src_r5_8x16b);
1311
0
1312
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_8x16b, coeff0_1_8x16b);
1313
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_8x16b, coeff2_3_8x16b);
1314
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_8x16b, coeff4_5_8x16b);
1315
0
1316
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
1317
0
                res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
1318
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
1319
0
                res_c1_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
1320
0
1321
0
                res_8x16b = _mm_packs_epi32(res_c0_4x32b, res_c1_4x32b);
1322
0
                res_16x8b = _mm_packus_epi16(res_8x16b, res_8x16b);
1323
0
1324
0
                _mm_storel_epi64((__m128i *)pu1_dst, res_16x8b);
1325
0
1326
0
                src_r0r1_8x16b = _mm_unpacklo_epi16(src_r1_8x16b, src_r2_8x16b);
1327
0
                src_r2r3_8x16b = _mm_unpacklo_epi16(src_r3_8x16b, src_r4_8x16b);
1328
0
                src_r4r5_8x16b = _mm_unpacklo_epi16(src_r5_8x16b, src_r6_8x16b);
1329
0
1330
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_8x16b, coeff0_1_8x16b);
1331
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_8x16b, coeff2_3_8x16b);
1332
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_8x16b, coeff4_5_8x16b);
1333
0
1334
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
1335
0
                res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
1336
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
1337
0
                res_c0_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
1338
0
1339
0
                src_r0r1_8x16b = _mm_unpackhi_epi16(src_r1_8x16b, src_r2_8x16b);
1340
0
                src_r2r3_8x16b = _mm_unpackhi_epi16(src_r3_8x16b, src_r4_8x16b);
1341
0
                src_r4r5_8x16b = _mm_unpackhi_epi16(src_r5_8x16b, src_r6_8x16b);
1342
0
1343
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_8x16b, coeff0_1_8x16b);
1344
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_8x16b, coeff2_3_8x16b);
1345
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_8x16b, coeff4_5_8x16b);
1346
0
1347
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
1348
0
                res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
1349
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
1350
0
                res_c1_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
1351
0
1352
0
                res_8x16b = _mm_packs_epi32(res_c0_4x32b, res_c1_4x32b);
1353
0
                res_16x8b = _mm_packus_epi16(res_8x16b, res_8x16b);
1354
0
1355
0
                _mm_storel_epi64((__m128i *)(pu1_dst + dst_strd), res_16x8b);
1356
0
1357
0
                src_r0_8x16b = src_r2_8x16b;
1358
0
                src_r1_8x16b = src_r3_8x16b;
1359
0
                src_r2_8x16b = src_r4_8x16b;
1360
0
                src_r3_8x16b = src_r5_8x16b;
1361
0
                src_r4_8x16b = src_r6_8x16b;
1362
0
1363
0
                ht_tmp -= 2;
1364
0
                pi2_temp += 32;
1365
0
                pu1_dst += dst_strd << 1;
1366
0
            }
1367
0
            while(ht_tmp > 0);
1368
0
1369
0
            /**********************************************************/
1370
0
            /*     Do second ht x 8 block                          */
1371
0
            /**********************************************************/
1372
0
            src_r0_8x16b = _mm_loadu_si128((__m128i *)pi2_temp2);
1373
0
            src_r1_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2 + 16));
1374
0
            src_r2_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2 + 32));
1375
0
            src_r3_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2 + 48));
1376
0
            src_r4_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2 + 64));
1377
0
            pi2_temp2 += 80;
1378
0
1379
0
            do
1380
0
            {
1381
0
                src_r5_8x16b = _mm_loadu_si128((__m128i *)pi2_temp2);
1382
0
                src_r6_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2 + 16));
1383
0
1384
0
                src_r0r1_8x16b = _mm_unpacklo_epi16(src_r0_8x16b, src_r1_8x16b);
1385
0
                src_r2r3_8x16b = _mm_unpacklo_epi16(src_r2_8x16b, src_r3_8x16b);
1386
0
                src_r4r5_8x16b = _mm_unpacklo_epi16(src_r4_8x16b, src_r5_8x16b);
1387
0
1388
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_8x16b, coeff0_1_8x16b);
1389
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_8x16b, coeff2_3_8x16b);
1390
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_8x16b, coeff4_5_8x16b);
1391
0
1392
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
1393
0
                res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
1394
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
1395
0
                res_c0_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
1396
0
1397
0
                src_r0r1_8x16b = _mm_unpackhi_epi16(src_r0_8x16b, src_r1_8x16b);
1398
0
                src_r2r3_8x16b = _mm_unpackhi_epi16(src_r2_8x16b, src_r3_8x16b);
1399
0
                src_r4r5_8x16b = _mm_unpackhi_epi16(src_r4_8x16b, src_r5_8x16b);
1400
0
1401
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_8x16b, coeff0_1_8x16b);
1402
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_8x16b, coeff2_3_8x16b);
1403
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_8x16b, coeff4_5_8x16b);
1404
0
1405
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
1406
0
                res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
1407
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
1408
0
                res_c1_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
1409
0
1410
0
                res_8x16b = _mm_packs_epi32(res_c0_4x32b, res_c1_4x32b);
1411
0
                res_16x8b = _mm_packus_epi16(res_8x16b, res_8x16b);
1412
0
1413
0
                _mm_storel_epi64((__m128i *)pu1_dst2, res_16x8b);
1414
0
1415
0
                src_r0r1_8x16b = _mm_unpacklo_epi16(src_r1_8x16b, src_r2_8x16b);
1416
0
                src_r2r3_8x16b = _mm_unpacklo_epi16(src_r3_8x16b, src_r4_8x16b);
1417
0
                src_r4r5_8x16b = _mm_unpacklo_epi16(src_r5_8x16b, src_r6_8x16b);
1418
0
1419
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_8x16b, coeff0_1_8x16b);
1420
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_8x16b, coeff2_3_8x16b);
1421
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_8x16b, coeff4_5_8x16b);
1422
0
1423
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
1424
0
                res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
1425
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
1426
0
                res_c0_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
1427
0
1428
0
                src_r0r1_8x16b = _mm_unpackhi_epi16(src_r1_8x16b, src_r2_8x16b);
1429
0
                src_r2r3_8x16b = _mm_unpackhi_epi16(src_r3_8x16b, src_r4_8x16b);
1430
0
                src_r4r5_8x16b = _mm_unpackhi_epi16(src_r5_8x16b, src_r6_8x16b);
1431
0
1432
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_8x16b, coeff0_1_8x16b);
1433
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_8x16b, coeff2_3_8x16b);
1434
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_8x16b, coeff4_5_8x16b);
1435
0
1436
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
1437
0
                res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
1438
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
1439
0
                res_c1_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
1440
0
1441
0
                res_8x16b = _mm_packs_epi32(res_c0_4x32b, res_c1_4x32b);
1442
0
                res_16x8b = _mm_packus_epi16(res_8x16b, res_8x16b);
1443
0
1444
0
                _mm_storel_epi64((__m128i *)(pu1_dst2 + dst_strd), res_16x8b);
1445
0
1446
0
                src_r0_8x16b = src_r2_8x16b;
1447
0
                src_r1_8x16b = src_r3_8x16b;
1448
0
                src_r2_8x16b = src_r4_8x16b;
1449
0
                src_r3_8x16b = src_r5_8x16b;
1450
0
                src_r4_8x16b = src_r6_8x16b;
1451
0
1452
0
                ht -= 2;
1453
0
                pi2_temp2 += 32;
1454
0
                pu1_dst2 += dst_strd << 1;
1455
0
            }
1456
0
            while(ht > 0);
1457
0
        }
1458
0
    }
1459
0
}
1460
1461
/*****************************************************************************/
1462
/*                                                                           */
1463
/*  Function Name : ih264_inter_pred_luma_horz_qpel_ssse3                    */
1464
/*                                                                           */
1465
/*  Description   : This function implements a six-tap filter horizontally   */
1466
/*                  on ht x wd block and averages the values with the source */
1467
/*                  pixels to calculate horizontal quarter-pel as mentioned  */
1468
/*                  in sec. 8.4.2.2.1 titled "Luma sample interpolation      */
1469
/*                  process". (ht,wd) can be (4,4), (8,4), (4,8), (8,8),     */
1470
/*                  (16,8), (8,16) or (16,16).                               */
1471
/*                                                                           */
1472
/*  Inputs        : puc_src  - pointer to source                             */
1473
/*                  puc_dst  - pointer to destination                        */
1474
/*                  src_strd - stride for source                             */
1475
/*                  dst_strd - stride for destination                        */
1476
/*                  ht       - height of the block                           */
1477
/*                  wd       - width of the block                            */
1478
/*                  pu1_tmp  - pointer to temporary buffer                   */
1479
/*                  dydx     - x and y reference offset for q-pel            */
1480
/*                             calculations                                  */
1481
/*                                                                           */
1482
/*  Issues        : None                                                     */
1483
/*                                                                           */
1484
/*  Revision History:                                                        */
1485
/*                                                                           */
1486
/*         DD MM YYYY   Author(s)       Changes                              */
1487
/*         13 02 2015   Kaushik         Initial Version                      */
1488
/*                      Senthoor                                             */
1489
/*                                                                           */
1490
/*****************************************************************************/
1491
void ih264_inter_pred_luma_horz_qpel_ssse3(UWORD8 *pu1_src,
1492
                                           UWORD8 *pu1_dst,
1493
                                           WORD32 src_strd,
1494
                                           WORD32 dst_strd,
1495
                                           WORD32 ht,
1496
                                           WORD32 wd,
1497
                                           UWORD8* pu1_tmp,
1498
                                           WORD32 dydx)
1499
0
{
1500
0
    WORD32 x_offset;
1501
0
    UWORD8 *pu1_pred1;
1502
0
1503
0
    __m128i src_r0_16x8b, src_r1_16x8b;
1504
0
    __m128i src_r0_sht_16x8b, src_r1_sht_16x8b;
1505
0
    __m128i coeff0_1_16x8b, coeff2_3_16x8b, coeff4_5_16x8b;
1506
0
    __m128i const_val16_8x16b;
1507
0
1508
0
    UNUSED(pu1_tmp);
1509
0
1510
0
    x_offset = dydx & 3;
1511
0
1512
0
    coeff0_1_16x8b = _mm_set1_epi32(0xFB01FB01); //c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1
1513
0
    coeff2_3_16x8b = _mm_set1_epi32(0x14141414); //c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3
1514
0
    coeff4_5_16x8b = _mm_set1_epi32(0x01FB01FB); //c4 c5 c4 c5 c4 c5 c4 c5 c4 c5 c4 c5 c4 c5 c4 c5
1515
0
                                                 //c0 = c5 = 1, c1 = c4 = -5, c2 = c3 = 20
1516
0
    pu1_pred1 = pu1_src + (x_offset >> 1);
1517
0
1518
0
    const_val16_8x16b = _mm_set1_epi16(16);
1519
0
1520
0
    pu1_src -= 2; // the filter input starts from x[-2] (till x[3])
1521
0
1522
0
    if(wd == 4)
1523
0
    {
1524
0
        __m128i src_r0r1_16x8b;
1525
0
1526
0
        __m128i res_r0r1_t1_8x16b, res_r0r1_t2_8x16b, res_r0r1_t3_8x16b;
1527
0
        __m128i res_r0r1_16x8b;
1528
0
1529
0
        //Row0 : a0 a1 a2 a3 a4 a5 a6 a7 a8 a9.....
1530
0
        //Row1 : b0 b1 b2 b3 b4 b5 b6 b7 b8 b9.....
1531
0
1532
0
        do
1533
0
        {
1534
0
            src_r0_16x8b = _mm_loadu_si128((__m128i *)pu1_src);                         //a0 a1 a2 a3 a4 a5 a6 a7 a8 a9....a15
1535
0
            src_r1_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + src_strd));            //b0 b1 b2 b3 b4 b5 b6 b7 b8 b9....b15
1536
0
1537
0
            src_r0_sht_16x8b = _mm_srli_si128(src_r0_16x8b, 1);                         //a1 a2 a3 a4 a5 a6 a7 a8 a9....a15 0
1538
0
            src_r1_sht_16x8b = _mm_srli_si128(src_r1_16x8b, 1);                         //b1 b2 b3 b4 b5 b6 b7 b8 b9....b15 0
1539
0
1540
0
            src_r0_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);           //a0 a1 a1 a2 a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8
1541
0
            src_r1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);           //b0 b1 b1 b2 b2 b3 b3 b4 b4 b5 b5 b6 b6 b7 b7 b8
1542
0
1543
0
            src_r0r1_16x8b = _mm_unpacklo_epi64(src_r0_16x8b, src_r1_16x8b);            //a0 a1 a1 a2 a2 a3 a3 a4 b0 b1 b1 b2 b2 b3 b3 b4
1544
0
            res_r0r1_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);      //a0*c0+a1*c1 a1*c0+a2*c1 a2*c0+a3*c1 a3*c0+a4*c1
1545
0
                                                                                        //b0*c0+b1*c1 b1*c0+b2*c1 b2*c0+b3*c1 b3*c0+b4*c1
1546
0
1547
0
            src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 4);                             //a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8  0  0  0  0
1548
0
            src_r1_16x8b = _mm_srli_si128(src_r1_16x8b, 4);                             //b2 b3 b3 b4 b4 b5 b5 b6 b6 b7 b7 b8  0  0  0  0
1549
0
1550
0
            src_r0r1_16x8b = _mm_unpacklo_epi64(src_r0_16x8b, src_r1_16x8b);            //a2 a3 a3 a4 a4 a5 a5 a6 b2 b3 b3 b4 b4 b5 b5 b6
1551
0
            res_r0r1_t2_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff2_3_16x8b);      //a2*c2+a3*c3 a3*c2+a4*c3 a4*c2+a5*c3 a5*c2+a6*c3
1552
0
                                                                                        //b2*c2+b3*c3 b3*c2+b4*c3 b4*c2+b5*c3 b5*c2+b6*c3
1553
0
1554
0
            src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 4);                             //a4 a5 a5 a6 a6 a7 a7 a8  0  0  0  0  0  0  0  0
1555
0
            src_r1_16x8b = _mm_srli_si128(src_r1_16x8b, 4);                             //b4 b5 b5 b6 b6 b7 b7 b8  0  0  0  0  0  0  0  0
1556
0
1557
0
            src_r0r1_16x8b = _mm_unpacklo_epi64(src_r0_16x8b, src_r1_16x8b);            //a4 a5 a5 a6 a6 a7 a7 a8 b4 b5 b5 b6 b6 b7 b7 b8
1558
0
            res_r0r1_t3_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff4_5_16x8b);      //a4*c4+a5*c5 a5*c4+a6*c5 a6*c4+a7*c5 a7*c4+a8*c5
1559
0
                                                                                        //b4*c4+b5*c5 b5*c4+b6*c5 b4*c6+b7*c5 b7*c4+b8*c5
1560
0
            src_r0_16x8b = _mm_loadl_epi64((__m128i *)pu1_pred1);
1561
0
            src_r1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_pred1 + src_strd));
1562
0
1563
0
            res_r0r1_t1_8x16b = _mm_add_epi16(res_r0r1_t1_8x16b, res_r0r1_t2_8x16b);
1564
0
            res_r0r1_t3_8x16b = _mm_add_epi16(const_val16_8x16b, res_r0r1_t3_8x16b);
1565
0
            res_r0r1_t1_8x16b = _mm_add_epi16(res_r0r1_t1_8x16b, res_r0r1_t3_8x16b);    //a0*c0+a1*c1+a2*c2+a3*c3+a4*a4+a5*c5 + 16;
1566
0
                                                                                        //a1*c0+a2*c1+a2*c2+a3*c3+a5*a4+a6*c5 + 16;
1567
0
                                                                                        //a2*c0+a3*c1+a4*c2+a5*c3+a6*a4+a7*c5 + 16;
1568
0
                                                                                        //a3*c0+a4*c1+a5*c2+a6*c3+a6*a4+a8*c5 + 16;
1569
0
                                                                                        //b0*c0+b1*c1+b2*c2+b3*c3+b4*b4+b5*c5 + 16;
1570
0
                                                                                        //b1*c0+b2*c1+b2*c2+b3*c3+b5*b4+b6*c5 + 16;
1571
0
                                                                                        //b2*c0+b3*c1+b4*c2+b5*c3+b6*b4+b7*c5 + 16;
1572
0
                                                                                        //b3*c0+b4*c1+b5*c2+b6*c3+b6*b4+b8*c5 + 16;
1573
0
            src_r0r1_16x8b = _mm_unpacklo_epi32(src_r0_16x8b,src_r1_16x8b);
1574
0
1575
0
            res_r0r1_t1_8x16b = _mm_srai_epi16(res_r0r1_t1_8x16b, 5);                   //shifting right by 5 bits.
1576
0
1577
0
            res_r0r1_16x8b = _mm_packus_epi16(res_r0r1_t1_8x16b, res_r0r1_t1_8x16b);
1578
0
            res_r0r1_16x8b = _mm_avg_epu8(src_r0r1_16x8b, res_r0r1_16x8b);              //computing q-pel
1579
0
1580
0
            *((WORD32 *)(pu1_dst)) = _mm_cvtsi128_si32(res_r0r1_16x8b);
1581
0
            res_r0r1_16x8b = _mm_srli_si128(res_r0r1_16x8b, 4);
1582
0
            *((WORD32 *)(pu1_dst + dst_strd)) = _mm_cvtsi128_si32(res_r0r1_16x8b);
1583
0
1584
0
            ht -= 2;
1585
0
            pu1_src += src_strd << 1;
1586
0
            pu1_pred1 += src_strd << 1;
1587
0
            pu1_dst += dst_strd << 1;
1588
0
        }
1589
0
        while(ht > 0);
1590
0
    }
1591
0
    else if(wd == 8)
1592
0
    {
1593
0
        __m128i src_r0_t1_16x8b, src_r1_t1_16x8b;
1594
0
1595
0
        __m128i res_r0_t1_8x16b, res_r0_t2_8x16b, res_r0_t3_8x16b;
1596
0
        __m128i res_r1_t1_8x16b, res_r1_t2_8x16b, res_r1_t3_8x16b;
1597
0
        __m128i res_r0_16x8b, res_r1_16x8b;
1598
0
1599
0
        //Row0 : a0 a1 a2 a3 a4 a5 a6 a7 a8 a9.....
1600
0
        //Row1 : b0 b1 b2 b3 b4 b5 b6 b7 b8 b9.....
1601
0
1602
0
        do
1603
0
        {
1604
0
            src_r0_16x8b = _mm_loadu_si128((__m128i *)pu1_src);                      //a0 a1 a2 a3 a4 a5 a6 a7 a8 a9....a15
1605
0
            src_r1_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + src_strd));         //b0 b1 b2 b3 b4 b5 b6 b7 b8 b9....b15
1606
0
1607
0
            src_r0_sht_16x8b = _mm_srli_si128(src_r0_16x8b, 1);                      //a1 a2 a3 a4 a5 a6 a7 a8 a9....a15 0
1608
0
            src_r1_sht_16x8b = _mm_srli_si128(src_r1_16x8b, 1);                      //b1 b2 b3 b4 b5 b6 b7 b8 b9....b15 0
1609
0
1610
0
            src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);     //a0 a1 a1 a2 a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8
1611
0
            src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);     //b0 b1 b1 b2 b2 b3 b3 b4 b4 b5 b5 b6 b6 b7 b7 b8
1612
0
1613
0
            res_r0_t1_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff0_1_16x8b);    //a0*c0+a1*c1 a1*c0+a2*c1 a2*c0+a3*c1 a3*c0+a4*c1
1614
0
                                                                                     //a4*c0+a5*c1 a5*c0+a6*c1 a6*c0+a7*c1 a7*c0+a8*c1
1615
0
            res_r1_t1_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff0_1_16x8b);    //b0*c0+b1*c1 b1*c0+b2*c1 b2*c0+b3*c1 b3*c0+b4*c1
1616
0
                                                                                     //b4*c0+b5*c1 b5*c0+b6*c1 b6*c0+b7*c1 b7*c0+b8*c1
1617
0
1618
0
            src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 2);                          //a2 a3 a4 a5 a6 a7 a8 a9....a15 0 0
1619
0
            src_r1_16x8b = _mm_srli_si128(src_r1_16x8b, 2);                          //b2 b3 b4 b5 b6 b7 b8 b9....b15 0 0
1620
0
1621
0
            src_r0_sht_16x8b = _mm_srli_si128(src_r0_sht_16x8b, 2);                  //a3 a4 a5 a6 a7 a8 a9....a15 0  0  0
1622
0
            src_r1_sht_16x8b = _mm_srli_si128(src_r1_sht_16x8b, 2);                  //b3 b4 b5 b6 b7 b8 b9....b15 0  0  0
1623
0
1624
0
            src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);     //a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8 a8 a9 a9 a10
1625
0
            src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);     //b2 b3 b3 b4 b4 b5 b5 b6 b6 b7 b7 b8 a8 a9 a9 a10
1626
0
1627
0
            res_r0_t2_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff2_3_16x8b);    //a2*c2+a3*c3 a3*c2+a4*c3 a4*c2+a5*c3 a5*c2+a6*c3
1628
0
                                                                                     //a6*c2+a7*c3 a7*c2+a8*c3 a8*c2+a9*c3 a9*c2+a10*c3
1629
0
            res_r1_t2_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff2_3_16x8b);    //b2*c2+b3*c3 b3*c2+b4*c3 b2*c4+b5*c3 b5*c2+b6*c3
1630
0
                                                                                     //b6*c2+b7*c3 b7*c2+b8*c3 b8*c2+b9*c3 b9*c2+b10*c3
1631
0
1632
0
            src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 2);                          //a4 a5 a6 a7 a8 a9....a15 0  0  0  0
1633
0
            src_r1_16x8b = _mm_srli_si128(src_r1_16x8b, 2);                          //b4 b5 b6 b7 b8 b9....b15 0  0  0  0
1634
0
1635
0
            src_r0_sht_16x8b = _mm_srli_si128(src_r0_sht_16x8b, 2);                  //a5 a6 a7 a8 a9....a15 0  0  0  0  0
1636
0
            src_r1_sht_16x8b = _mm_srli_si128(src_r1_sht_16x8b, 2);                  //b5 b6 b7 b8 b9....b15 0  0  0  0  0
1637
0
1638
0
            src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);     //a4 a5 a5 a6 a6 a7 a7 a8 a8 a9 a9 a10 a10 a11 a11 a12
1639
0
            src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);     //b4 b5 b5 b6 b6 b7 b7 b8 b8 b9 b9 b10 b10 b11 b11 b12
1640
0
1641
0
            res_r0_t3_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff4_5_16x8b);    //a4*c4+a5*c5 a5*c4+a6*c5 a6*c4+a7*c5 a7*c4+a8*c5
1642
0
                                                                                     //a8*c4+a9*c5 a9*c4+a10*c5 a10*c4+a11*c5 a11*c4+a12*c5
1643
0
            res_r1_t3_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff4_5_16x8b);    //b4*c4+b5*c5 b5*c4+b6*c5 b6*c4+b7*c5 b7*c4+b8*c5
1644
0
                                                                                     //b8*c4+b9*c5 b9*c4+b10*c5 b10*c4+b11*c5 b11*c4+b12*c5
1645
0
            src_r0_16x8b = _mm_loadl_epi64((__m128i *)pu1_pred1);
1646
0
            src_r1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_pred1 + src_strd));
1647
0
1648
0
            res_r0_t1_8x16b = _mm_add_epi16(res_r0_t1_8x16b, res_r0_t2_8x16b);
1649
0
            res_r1_t1_8x16b = _mm_add_epi16(res_r1_t1_8x16b, res_r1_t2_8x16b);
1650
0
            res_r0_t3_8x16b = _mm_add_epi16(const_val16_8x16b, res_r0_t3_8x16b);
1651
0
            res_r1_t3_8x16b = _mm_add_epi16(const_val16_8x16b, res_r1_t3_8x16b);
1652
0
            res_r0_t1_8x16b = _mm_add_epi16(res_r0_t1_8x16b, res_r0_t3_8x16b);
1653
0
            res_r1_t1_8x16b = _mm_add_epi16(res_r1_t1_8x16b, res_r1_t3_8x16b);
1654
0
1655
0
            res_r0_t1_8x16b = _mm_srai_epi16(res_r0_t1_8x16b, 5);
1656
0
            res_r1_t1_8x16b = _mm_srai_epi16(res_r1_t1_8x16b, 5);                    //shifting right by 5 bits.
1657
0
1658
0
            res_r0_16x8b = _mm_packus_epi16(res_r0_t1_8x16b, res_r0_t1_8x16b);
1659
0
            res_r1_16x8b = _mm_packus_epi16(res_r1_t1_8x16b, res_r1_t1_8x16b);
1660
0
1661
0
            res_r0_16x8b = _mm_avg_epu8(src_r0_16x8b, res_r0_16x8b);
1662
0
            res_r1_16x8b = _mm_avg_epu8(src_r1_16x8b, res_r1_16x8b);                 //computing q-pel
1663
0
1664
0
            _mm_storel_epi64((__m128i *)pu1_dst, res_r0_16x8b);
1665
0
            _mm_storel_epi64((__m128i *)(pu1_dst + dst_strd), res_r1_16x8b);
1666
0
1667
0
            ht -= 2;
1668
0
            pu1_src += src_strd << 1;
1669
0
            pu1_pred1 += src_strd << 1;
1670
0
            pu1_dst += dst_strd << 1;
1671
0
        }
1672
0
        while(ht > 0);
1673
0
    }
1674
0
    else // wd == 16
1675
0
    {
1676
0
        __m128i src_r0_t1_16x8b, src_r1_t1_16x8b;
1677
0
1678
0
        __m128i res_r0_t1_8x16b, res_r0_t2_8x16b, res_r0_t3_8x16b;
1679
0
        __m128i res_r1_t1_8x16b, res_r1_t2_8x16b, res_r1_t3_8x16b;
1680
0
        __m128i res_16x8b;
1681
0
1682
0
        //Row0 : a0 a1 a2 a3 a4 a5 a6 a7 a8 a9.....
1683
0
        //Row0 :                         b0 b1 b2 b3 b4 b5 b6 b7 b8 b9.....
1684
0
        //b0 is same a8. Similarly other bn pixels are same as a(n+8) pixels.
1685
0
1686
0
        do
1687
0
        {
1688
0
            src_r0_16x8b = _mm_loadu_si128((__m128i *)pu1_src);                      //a0 a1 a2 a3 a4 a5 a6 a7 a8 a9....a15
1689
0
            src_r1_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + 8));                //b0 b1 b2 b3 b4 b5 b6 b7 b8 b9....b15
1690
0
1691
0
            src_r0_sht_16x8b = _mm_srli_si128(src_r0_16x8b, 1);                      //a1 a2 a3 a4 a5 a6 a7 a8 a9....a15 0
1692
0
            src_r1_sht_16x8b = _mm_srli_si128(src_r1_16x8b, 1);                      //b1 b2 b3 b4 b5 b6 b7 b8 b9....b15 0
1693
0
1694
0
            src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);     //a0 a1 a1 a2 a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8
1695
0
            src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);     //b0 b1 b1 b2 b2 b3 b3 b4 b4 b5 b5 b6 b6 b7 b7 b8
1696
0
1697
0
            res_r0_t1_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff0_1_16x8b);    //a0*c0+a1*c1 a1*c0+a2*c1 a2*c0+a3*c1 a3*c0+a4*c1
1698
0
                                                                                     //a4*c0+a5*c1 a5*c0+a6*c1 a6*c0+a7*c1 a7*c0+a8*c1
1699
0
            res_r1_t1_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff0_1_16x8b);    //b0*c0+b1*c1 b1*c0+b2*c1 b2*c0+b3*c1 b3*c0+b4*c1
1700
0
                                                                                     //b4*c0+b5*c1 b5*c0+b6*c1 b6*c0+b7*c1 b7*c0+b8*c1
1701
0
1702
0
            src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 2);                          //a2 a3 a4 a5 a6 a7 a8 a9....a15 0 0
1703
0
            src_r1_16x8b = _mm_srli_si128(src_r1_16x8b, 2);                          //b2 b3 b4 b5 b6 b7 b8 b9....b15 0 0
1704
0
1705
0
            src_r0_sht_16x8b = _mm_srli_si128(src_r0_sht_16x8b, 2);                  //a3 a4 a5 a6 a7 a8 a9....a15 0  0  0
1706
0
            src_r1_sht_16x8b = _mm_srli_si128(src_r1_sht_16x8b, 2);                  //b3 b4 b5 b6 b7 b8 b9....b15 0  0  0
1707
0
1708
0
            src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);     //a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8 a8 a9 a9 a10
1709
0
            src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);     //b2 b3 b3 b4 b4 b5 b5 b6 b6 b7 b7 b8 a8 a9 a9 a10
1710
0
1711
0
            res_r0_t2_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff2_3_16x8b);    //a2*c2+a3*c3 a3*c2+a4*c3 a4*c2+a5*c3 a5*c2+a6*c3
1712
0
                                                                                     //a6*c2+a7*c3 a7*c2+a8*c3 a8*c2+a9*c3 a9*c2+a10*c3
1713
0
            res_r1_t2_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff2_3_16x8b);    //b2*c2+b3*c3 b3*c2+b4*c3 b2*c4+b5*c3 b5*c2+b6*c3
1714
0
                                                                                     //b6*c2+b7*c3 b7*c2+b8*c3 b8*c2+b9*c3 b9*c2+b10*c3
1715
0
1716
0
            src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 2);                          //a4 a5 a6 a7 a8 a9....a15 0  0  0  0
1717
0
            src_r1_16x8b = _mm_srli_si128(src_r1_16x8b, 2);                          //b4 b5 b6 b7 b8 b9....b15 0  0  0  0
1718
0
1719
0
            src_r0_sht_16x8b = _mm_srli_si128(src_r0_sht_16x8b, 2);                  //a5 a6 a7 a8 a9....a15 0  0  0  0  0
1720
0
            src_r1_sht_16x8b = _mm_srli_si128(src_r1_sht_16x8b, 2);                  //b5 b6 b7 b8 b9....b15 0  0  0  0  0
1721
0
1722
0
            src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);     //a4 a5 a5 a6 a6 a7 a7 a8 a8 a9 a9 a10 a10 a11 a11 a12
1723
0
            src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);     //b4 b5 b5 b6 b6 b7 b7 b8 b8 b9 b9 b10 b10 b11 b11 b12
1724
0
1725
0
            res_r0_t3_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff4_5_16x8b);    //a4*c4+a5*c5 a5*c4+a6*c5 a6*c4+a7*c5 a7*c4+a8*c5
1726
0
                                                                                     //a8*c4+a9*c5 a9*c4+a10*c5 a10*c4+a11*c5 a11*c4+a12*c5
1727
0
            res_r1_t3_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff4_5_16x8b);    //b4*c4+b5*c5 b5*c4+b6*c5 b6*c4+b7*c5 b7*c4+b8*c5
1728
0
                                                                                     //b8*c4+b9*c5 b9*c4+b10*c5 b10*c4+b11*c5 b11*c4+b12*c5
1729
0
            src_r0_16x8b = _mm_loadu_si128((__m128i *)pu1_pred1);
1730
0
1731
0
            res_r0_t1_8x16b = _mm_add_epi16(res_r0_t1_8x16b, res_r0_t2_8x16b);
1732
0
            res_r1_t1_8x16b = _mm_add_epi16(res_r1_t1_8x16b, res_r1_t2_8x16b);
1733
0
            res_r0_t3_8x16b = _mm_add_epi16(const_val16_8x16b, res_r0_t3_8x16b);
1734
0
            res_r1_t3_8x16b = _mm_add_epi16(const_val16_8x16b, res_r1_t3_8x16b);
1735
0
            res_r0_t1_8x16b = _mm_add_epi16(res_r0_t1_8x16b, res_r0_t3_8x16b);
1736
0
            res_r1_t1_8x16b = _mm_add_epi16(res_r1_t1_8x16b, res_r1_t3_8x16b);
1737
0
1738
0
            res_r0_t1_8x16b = _mm_srai_epi16(res_r0_t1_8x16b, 5);
1739
0
            res_r1_t1_8x16b = _mm_srai_epi16(res_r1_t1_8x16b, 5);                    //shifting right by 5 bits
1740
0
1741
0
            res_16x8b = _mm_packus_epi16(res_r0_t1_8x16b, res_r1_t1_8x16b);
1742
0
            res_16x8b = _mm_avg_epu8(src_r0_16x8b, res_16x8b);                       //computing q-pel
1743
0
1744
0
            _mm_storeu_si128((__m128i *)pu1_dst, res_16x8b);
1745
0
1746
0
            ht--;
1747
0
            pu1_src += src_strd;
1748
0
            pu1_pred1 += src_strd;
1749
0
            pu1_dst += dst_strd;
1750
0
        }
1751
0
        while(ht > 0);
1752
0
    }
1753
0
}
1754
1755
/*****************************************************************************/
1756
/*                                                                           */
1757
/*  Function Name : ih264_inter_pred_luma_vert_qpel_ssse3                    */
1758
/*                                                                           */
1759
/*  Description   : This function implements a six-tap filter vertically on  */
1760
/*                  ht x wd block and averages the values with the source    */
1761
/*                  pixels to calculate vertical quarter-pel as mentioned in */
1762
/*                  sec. 8.4.2.2.1 titled "Luma sample interpolation         */
1763
/*                  process". (ht,wd) can be (4,4), (8,4), (4,8), (8,8),     */
1764
/*                  (16,8), (8,16) or (16,16).                               */
1765
/*                                                                           */
1766
/*  Inputs        : puc_src  - pointer to source                             */
1767
/*                  puc_dst  - pointer to destination                        */
1768
/*                  src_strd - stride for source                             */
1769
/*                  dst_strd - stride for destination                        */
1770
/*                  ht       - height of the block                           */
1771
/*                  wd       - width of the block                            */
1772
/*                  pu1_tmp  - pointer to temporary buffer                   */
1773
/*                  dydx     - x and y reference offset for q-pel            */
1774
/*                             calculations                                  */
1775
/*                                                                           */
1776
/*  Issues        : None                                                     */
1777
/*                                                                           */
1778
/*  Revision History:                                                        */
1779
/*                                                                           */
1780
/*         DD MM YYYY   Author(s)       Changes                              */
1781
/*         13 02 2015   Kaushik         Initial Version                      */
1782
/*                      Senthoor                                             */
1783
/*                                                                           */
1784
/*****************************************************************************/
1785
void ih264_inter_pred_luma_vert_qpel_ssse3(UWORD8 *pu1_src,
1786
                                           UWORD8 *pu1_dst,
1787
                                           WORD32 src_strd,
1788
                                           WORD32 dst_strd,
1789
                                           WORD32 ht,
1790
                                           WORD32 wd,
1791
                                           UWORD8* pu1_tmp,
1792
                                           WORD32 dydx)
1793
0
{
1794
0
    WORD32 y_offset;
1795
0
    UWORD8 *pu1_pred1;
1796
0
1797
0
1798
0
    __m128i src_r0_16x8b, src_r1_16x8b, src_r2_16x8b, src_r3_16x8b, src_r4_16x8b;
1799
0
    __m128i src_r5_16x8b, src_r6_16x8b;
1800
0
    __m128i src_r0r1_16x8b, src_r2r3_16x8b, src_r4r5_16x8b;
1801
0
    __m128i res_16x8b, res_t1_8x16b, res_t2_8x16b, res_t3_8x16b;
1802
0
1803
0
    __m128i coeff0_1_16x8b, coeff2_3_16x8b, coeff4_5_16x8b;
1804
0
    __m128i const_val16_8x16b;
1805
0
1806
0
    UNUSED(pu1_tmp);
1807
0
    y_offset = dydx & 0xf;
1808
0
1809
0
    coeff0_1_16x8b = _mm_set1_epi32(0xFB01FB01); //c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1
1810
0
    coeff2_3_16x8b = _mm_set1_epi32(0x14141414); //c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3
1811
0
    coeff4_5_16x8b = _mm_set1_epi32(0x01FB01FB); //c4 c5 c4 c5 c4 c5 c4 c5 c4 c5 c4 c5 c4 c5 c4 c5
1812
0
                                                 //c0 = c5 = 1, c1 = c4 = -5, c2 = c3 = 20
1813
0
1814
0
    pu1_pred1 = pu1_src + (y_offset >> 3) * src_strd;
1815
0
1816
0
    const_val16_8x16b = _mm_set1_epi16(16);
1817
0
1818
0
    pu1_src -= src_strd << 1; // the filter input starts from x[-2] (till x[3])
1819
0
1820
0
    if(wd == 4)
1821
0
    {
1822
0
        //Epilogue: Load all the pred rows except sixth and seventh row
1823
0
        //          for the first and second row processing.
1824
0
        src_r0_16x8b = _mm_loadl_epi64((__m128i *)pu1_src);
1825
0
        pu1_src += src_strd;
1826
0
        src_r1_16x8b = _mm_loadl_epi64((__m128i *)pu1_src);
1827
0
        pu1_src += src_strd;
1828
0
        src_r2_16x8b = _mm_loadl_epi64((__m128i *)pu1_src);
1829
0
        pu1_src += src_strd;
1830
0
        src_r3_16x8b = _mm_loadl_epi64((__m128i *)pu1_src);
1831
0
        pu1_src += src_strd;
1832
0
        src_r4_16x8b = _mm_loadl_epi64((__m128i *)pu1_src);
1833
0
        pu1_src += src_strd;
1834
0
1835
0
        src_r0_16x8b = _mm_unpacklo_epi32(src_r0_16x8b, src_r1_16x8b);
1836
0
        src_r1_16x8b = _mm_unpacklo_epi32(src_r1_16x8b, src_r2_16x8b);
1837
0
        src_r2_16x8b = _mm_unpacklo_epi32(src_r2_16x8b, src_r3_16x8b);
1838
0
        src_r3_16x8b = _mm_unpacklo_epi32(src_r3_16x8b, src_r4_16x8b);
1839
0
1840
0
        do
1841
0
        {
1842
0
            src_r5_16x8b = _mm_loadl_epi64((__m128i *)pu1_src);
1843
0
            src_r6_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src + src_strd));
1844
0
1845
0
            src_r4_16x8b = _mm_unpacklo_epi32(src_r4_16x8b, src_r5_16x8b);
1846
0
            src_r5_16x8b = _mm_unpacklo_epi32(src_r5_16x8b, src_r6_16x8b);
1847
0
1848
0
            src_r0r1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r1_16x8b);
1849
0
            src_r2r3_16x8b = _mm_unpacklo_epi8(src_r2_16x8b, src_r3_16x8b);
1850
0
            src_r4r5_16x8b = _mm_unpacklo_epi8(src_r4_16x8b, src_r5_16x8b);
1851
0
1852
0
            res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
1853
0
            res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
1854
0
            res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);
1855
0
1856
0
            src_r0_16x8b = _mm_loadl_epi64((__m128i *)pu1_pred1);
1857
0
            src_r1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_pred1 + src_strd));
1858
0
1859
0
            res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t2_8x16b);
1860
0
            res_t3_8x16b = _mm_add_epi16(const_val16_8x16b, res_t3_8x16b);
1861
0
            res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t3_8x16b);
1862
0
1863
0
            src_r0r1_16x8b = _mm_unpacklo_epi32(src_r0_16x8b,src_r1_16x8b);
1864
0
1865
0
            res_t1_8x16b = _mm_srai_epi16(res_t1_8x16b, 5); //shifting right by 5 bits.
1866
0
1867
0
            res_16x8b = _mm_packus_epi16(res_t1_8x16b, res_t1_8x16b);
1868
0
1869
0
            res_16x8b = _mm_avg_epu8(src_r0r1_16x8b, res_16x8b); //computing q-pel
1870
0
1871
0
            *((WORD32 *)(pu1_dst)) = _mm_cvtsi128_si32(res_16x8b);
1872
0
            res_16x8b = _mm_srli_si128(res_16x8b, 4);
1873
0
            *((WORD32 *)(pu1_dst + dst_strd)) = _mm_cvtsi128_si32(res_16x8b);
1874
0
1875
0
            src_r0_16x8b = src_r2_16x8b;
1876
0
            src_r1_16x8b = src_r3_16x8b;
1877
0
            src_r2_16x8b = src_r4_16x8b;
1878
0
            src_r3_16x8b = src_r5_16x8b;
1879
0
            src_r4_16x8b = src_r6_16x8b;
1880
0
1881
0
            ht -= 2;
1882
0
            pu1_src += src_strd << 1;
1883
0
            pu1_pred1 += src_strd << 1;
1884
0
            pu1_dst += dst_strd << 1;
1885
0
        }
1886
0
        while(ht > 0);
1887
0
    }
1888
0
1889
0
    else if(wd == 8)
1890
0
    {
1891
0
        //Epilogue: Load all the pred rows except sixth and seventh row
1892
0
        //          for the first and second row processing.
1893
0
        src_r0_16x8b = _mm_loadl_epi64((__m128i *)pu1_src);
1894
0
        pu1_src += src_strd;
1895
0
        src_r1_16x8b = _mm_loadl_epi64((__m128i *)pu1_src);
1896
0
        pu1_src += src_strd;
1897
0
        src_r2_16x8b = _mm_loadl_epi64((__m128i *)pu1_src);
1898
0
        pu1_src += src_strd;
1899
0
        src_r3_16x8b = _mm_loadl_epi64((__m128i *)pu1_src);
1900
0
        pu1_src += src_strd;
1901
0
        src_r4_16x8b = _mm_loadl_epi64((__m128i *)pu1_src);
1902
0
        pu1_src += src_strd;
1903
0
1904
0
        src_r0_16x8b = _mm_unpacklo_epi64(src_r0_16x8b, src_r1_16x8b);
1905
0
        src_r1_16x8b = _mm_unpacklo_epi64(src_r1_16x8b, src_r2_16x8b);
1906
0
        src_r2_16x8b = _mm_unpacklo_epi64(src_r2_16x8b, src_r3_16x8b);
1907
0
        src_r3_16x8b = _mm_unpacklo_epi64(src_r3_16x8b, src_r4_16x8b);
1908
0
1909
0
        do
1910
0
        {
1911
0
            src_r5_16x8b = _mm_loadl_epi64((__m128i *)pu1_src);
1912
0
            src_r6_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src + src_strd));
1913
0
1914
0
            src_r4_16x8b = _mm_unpacklo_epi64(src_r4_16x8b, src_r5_16x8b);
1915
0
            src_r5_16x8b = _mm_unpacklo_epi64(src_r5_16x8b, src_r6_16x8b);
1916
0
1917
0
            src_r0r1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r1_16x8b);
1918
0
            src_r2r3_16x8b = _mm_unpacklo_epi8(src_r2_16x8b, src_r3_16x8b);
1919
0
            src_r4r5_16x8b = _mm_unpacklo_epi8(src_r4_16x8b, src_r5_16x8b);
1920
0
1921
0
            res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
1922
0
            res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
1923
0
            res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);
1924
0
1925
0
            src_r0r1_16x8b = _mm_loadl_epi64((__m128i *)pu1_pred1);
1926
0
1927
0
            res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t2_8x16b);
1928
0
            res_t3_8x16b = _mm_add_epi16(const_val16_8x16b, res_t3_8x16b);
1929
0
            res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t3_8x16b);
1930
0
1931
0
            res_t1_8x16b = _mm_srai_epi16(res_t1_8x16b, 5); //shifting right by 5 bits.
1932
0
1933
0
            res_16x8b = _mm_packus_epi16(res_t1_8x16b, res_t1_8x16b);
1934
0
            res_16x8b = _mm_avg_epu8(src_r0r1_16x8b, res_16x8b); //computing q-pel
1935
0
1936
0
            _mm_storel_epi64((__m128i *)pu1_dst, res_16x8b);
1937
0
1938
0
            src_r0r1_16x8b = _mm_unpackhi_epi8(src_r0_16x8b, src_r1_16x8b);
1939
0
            src_r2r3_16x8b = _mm_unpackhi_epi8(src_r2_16x8b, src_r3_16x8b);
1940
0
            src_r4r5_16x8b = _mm_unpackhi_epi8(src_r4_16x8b, src_r5_16x8b);
1941
0
1942
0
            res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
1943
0
            res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
1944
0
            res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);
1945
0
1946
0
            src_r0r1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_pred1 + src_strd));
1947
0
1948
0
            res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t2_8x16b);
1949
0
            res_t3_8x16b = _mm_add_epi16(const_val16_8x16b, res_t3_8x16b);
1950
0
            res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t3_8x16b);
1951
0
1952
0
            res_t1_8x16b = _mm_srai_epi16(res_t1_8x16b, 5); //shifting right by 5 bits.
1953
0
1954
0
            res_16x8b = _mm_packus_epi16(res_t1_8x16b, res_t1_8x16b);
1955
0
            res_16x8b = _mm_avg_epu8(src_r0r1_16x8b, res_16x8b); //computing q-pel
1956
0
1957
0
            _mm_storel_epi64((__m128i *)(pu1_dst + dst_strd), res_16x8b);
1958
0
1959
0
            src_r0_16x8b = src_r2_16x8b;
1960
0
            src_r1_16x8b = src_r3_16x8b;
1961
0
            src_r2_16x8b = src_r4_16x8b;
1962
0
            src_r3_16x8b = src_r5_16x8b;
1963
0
            src_r4_16x8b = src_r6_16x8b;
1964
0
1965
0
            ht -= 2;
1966
0
            pu1_src += src_strd << 1;
1967
0
            pu1_pred1 += src_strd << 1;
1968
0
            pu1_dst += dst_strd << 1;
1969
0
        }
1970
0
        while(ht > 0);
1971
0
    }
1972
0
    else // wd == 16
1973
0
    {
1974
0
        __m128i res_t0_8x16b;
1975
0
1976
0
        //Epilogue: Load all the pred rows except sixth and seventh row
1977
0
        //          for the first and second row processing.
1978
0
        src_r0_16x8b = _mm_loadu_si128((__m128i *)pu1_src);
1979
0
        pu1_src += src_strd;
1980
0
        src_r1_16x8b = _mm_loadu_si128((__m128i *)pu1_src);
1981
0
        pu1_src += src_strd;
1982
0
        src_r2_16x8b = _mm_loadu_si128((__m128i *)pu1_src);
1983
0
        pu1_src += src_strd;
1984
0
        src_r3_16x8b = _mm_loadu_si128((__m128i *)pu1_src);
1985
0
        pu1_src += src_strd;
1986
0
        src_r4_16x8b = _mm_loadu_si128((__m128i *)pu1_src);
1987
0
        pu1_src += src_strd;
1988
0
1989
0
        do
1990
0
        {
1991
0
            src_r5_16x8b  = _mm_loadu_si128((__m128i *)pu1_src);
1992
0
            src_r6_16x8b  = _mm_loadu_si128((__m128i *)(pu1_src + src_strd));
1993
0
1994
0
            src_r0r1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r1_16x8b);
1995
0
            src_r2r3_16x8b = _mm_unpacklo_epi8(src_r2_16x8b, src_r3_16x8b);
1996
0
            src_r4r5_16x8b = _mm_unpacklo_epi8(src_r4_16x8b, src_r5_16x8b);
1997
0
1998
0
            res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
1999
0
            res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
2000
0
            res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);
2001
0
2002
0
            res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t2_8x16b);
2003
0
            res_t3_8x16b = _mm_add_epi16(const_val16_8x16b, res_t3_8x16b);
2004
0
            res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t3_8x16b);
2005
0
2006
0
            res_t0_8x16b = _mm_srai_epi16(res_t1_8x16b, 5); //shifting right by 5 bits.
2007
0
2008
0
            src_r0r1_16x8b = _mm_unpackhi_epi8(src_r0_16x8b, src_r1_16x8b);
2009
0
            src_r2r3_16x8b = _mm_unpackhi_epi8(src_r2_16x8b, src_r3_16x8b);
2010
0
            src_r4r5_16x8b = _mm_unpackhi_epi8(src_r4_16x8b, src_r5_16x8b);
2011
0
2012
0
            res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
2013
0
            res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
2014
0
            res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);
2015
0
2016
0
            src_r0r1_16x8b = _mm_loadu_si128((__m128i *)pu1_pred1);
2017
0
2018
0
            res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t2_8x16b);
2019
0
            res_t3_8x16b = _mm_add_epi16(const_val16_8x16b, res_t3_8x16b);
2020
0
            res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t3_8x16b);
2021
0
2022
0
            res_t1_8x16b = _mm_srai_epi16(res_t1_8x16b, 5); //shifting right by 5 bits.
2023
0
2024
0
            res_16x8b = _mm_packus_epi16(res_t0_8x16b, res_t1_8x16b);
2025
0
            res_16x8b = _mm_avg_epu8(src_r0r1_16x8b, res_16x8b); //computing q-pel
2026
0
2027
0
            _mm_storeu_si128((__m128i *)pu1_dst, res_16x8b);
2028
0
2029
0
            src_r0r1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r2_16x8b);
2030
0
            src_r2r3_16x8b = _mm_unpacklo_epi8(src_r3_16x8b, src_r4_16x8b);
2031
0
            src_r4r5_16x8b = _mm_unpacklo_epi8(src_r5_16x8b, src_r6_16x8b);
2032
0
2033
0
            res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
2034
0
            res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
2035
0
            res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);
2036
0
2037
0
            res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t2_8x16b);
2038
0
            res_t3_8x16b = _mm_add_epi16(const_val16_8x16b, res_t3_8x16b);
2039
0
            res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t3_8x16b);
2040
0
2041
0
            res_t0_8x16b = _mm_srai_epi16(res_t1_8x16b, 5); //shifting right by 5 bits.
2042
0
2043
0
            src_r0r1_16x8b = _mm_unpackhi_epi8(src_r1_16x8b, src_r2_16x8b);
2044
0
            src_r2r3_16x8b = _mm_unpackhi_epi8(src_r3_16x8b, src_r4_16x8b);
2045
0
            src_r4r5_16x8b = _mm_unpackhi_epi8(src_r5_16x8b, src_r6_16x8b);
2046
0
2047
0
            res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
2048
0
            res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
2049
0
            res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);
2050
0
2051
0
            src_r0r1_16x8b = _mm_loadu_si128((__m128i *)(pu1_pred1 + src_strd));
2052
0
2053
0
            res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t2_8x16b);
2054
0
            res_t3_8x16b = _mm_add_epi16(const_val16_8x16b, res_t3_8x16b);
2055
0
            res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t3_8x16b);
2056
0
2057
0
            res_t1_8x16b = _mm_srai_epi16(res_t1_8x16b, 5); //shifting right by 5 bits.
2058
0
2059
0
            res_16x8b = _mm_packus_epi16(res_t0_8x16b, res_t1_8x16b);
2060
0
            res_16x8b = _mm_avg_epu8(src_r0r1_16x8b, res_16x8b); //computing q-pel
2061
0
2062
0
            _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), res_16x8b);
2063
0
2064
0
            src_r0_16x8b = src_r2_16x8b;
2065
0
            src_r1_16x8b = src_r3_16x8b;
2066
0
            src_r2_16x8b = src_r4_16x8b;
2067
0
            src_r3_16x8b = src_r5_16x8b;
2068
0
            src_r4_16x8b = src_r6_16x8b;
2069
0
2070
0
            ht -= 2;
2071
0
            pu1_src += src_strd << 1;
2072
0
            pu1_pred1 += src_strd << 1;
2073
0
            pu1_dst += dst_strd << 1;
2074
0
        }
2075
0
        while(ht > 0);
2076
0
    }
2077
0
}
2078
2079
/*****************************************************************************/
2080
/*                                                                           */
2081
/*  Function Name : ih264_inter_pred_luma_horz_qpel_vert_qpel_ssse3          */
2082
/*                                                                           */
2083
/*  Description   : This function implements a six-tap filter vertically and */
2084
/*                  horizontally on ht x wd block separately and averages    */
2085
/*                  the two sets of values to calculate values at (1/4,1/4), */
2086
/*                  (1/4, 3/4), (3/4, 1/4) or (3/4, 3/4) as mentioned in     */
2087
/*                  sec. 8.4.2.2.1 titled "Luma sample interpolation         */
2088
/*                  process". (ht,wd) can be (4,4), (8,4), (4,8), (8,8),     */
2089
/*                  (16,8), (8,16) or (16,16).                               */
2090
/*                                                                           */
2091
/*  Inputs        : puc_src  - pointer to source                             */
2092
/*                  puc_dst  - pointer to destination                        */
2093
/*                  src_strd - stride for source                             */
2094
/*                  dst_strd - stride for destination                        */
2095
/*                  ht       - height of the block                           */
2096
/*                  wd       - width of the block                            */
2097
/*                  pu1_tmp  - pointer to temporary buffer                   */
2098
/*                  dydx     - x and y reference offset for q-pel            */
2099
/*                             calculations                                  */
2100
/*                                                                           */
2101
/*  Issues        : None                                                     */
2102
/*                                                                           */
2103
/*  Revision History:                                                        */
2104
/*                                                                           */
2105
/*         DD MM YYYY   Author(s)       Changes                              */
2106
/*         13 02 2015   Kaushik         Initial Version                      */
2107
/*                      Senthoor                                             */
2108
/*                                                                           */
2109
/*****************************************************************************/
2110
void ih264_inter_pred_luma_horz_qpel_vert_qpel_ssse3(UWORD8 *pu1_src,
2111
                                                     UWORD8 *pu1_dst,
2112
                                                     WORD32 src_strd,
2113
                                                     WORD32 dst_strd,
2114
                                                     WORD32 ht,
2115
                                                     WORD32 wd,
2116
                                                     UWORD8* pu1_tmp,
2117
                                                     WORD32 dydx)
2118
0
{
2119
0
    WORD32 ht_temp;
2120
0
    UWORD8 *pu1_pred_vert,*pu1_pred_horiz;
2121
0
    UWORD8 *pu1_tmp1, *pu1_tmp2;
2122
0
    WORD32 x_offset, y_offset;
2123
0
2124
0
    __m128i coeff0_1_16x8b, coeff2_3_16x8b, coeff4_5_16x8b;
2125
0
    __m128i const_val16_8x16b;
2126
0
2127
0
    pu1_tmp1 = pu1_tmp;
2128
0
2129
0
    dydx &= 0xf;
2130
0
    ht_temp = ht;
2131
0
    x_offset = dydx & 0x3;
2132
0
    y_offset = dydx >> 2;
2133
0
    pu1_tmp2 = pu1_tmp1;
2134
0
2135
0
    pu1_pred_vert  = pu1_src + (x_offset >> 1) - 2*src_strd;
2136
0
    pu1_pred_horiz = pu1_src + (y_offset >> 1) * src_strd - 2;
2137
0
    //the filter input starts from x[-2] (till x[3])
2138
0
2139
0
    coeff0_1_16x8b = _mm_set1_epi32(0xFB01FB01);  //c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1
2140
0
    coeff2_3_16x8b = _mm_set1_epi32(0x14141414);  //c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3
2141
0
    coeff4_5_16x8b = _mm_set1_epi32(0x01FB01FB);  //c4 c5 c5 c5 c4 c5 c5 c5 c4 c5 c5 c5 c4 c5 c5 c5
2142
0
                                                  //c0 = c5 = 1, c1 = c4 = -5, c2 = c3 = 20
2143
0
    const_val16_8x16b = _mm_set1_epi16(16);
2144
0
2145
0
    if(wd == 4)
2146
0
    {
2147
0
        //vertical q-pel filter
2148
0
        {
2149
0
            __m128i src_r0_16x8b, src_r1_16x8b, src_r2_16x8b, src_r3_16x8b, src_r4_16x8b;
2150
0
            __m128i src_r5_16x8b, src_r6_16x8b;
2151
0
            __m128i src_r0r1_16x8b, src_r2r3_16x8b, src_r4r5_16x8b;
2152
0
2153
0
            __m128i res_r0r1_16x8b, res_t1_8x16b, res_t2_8x16b, res_t3_8x16b;
2154
0
2155
0
            //epilogue: Load all the pred rows except sixth  and seventh row for the
2156
0
            //first and second row processing.
2157
0
            src_r0_16x8b = _mm_loadl_epi64((__m128i *)(pu1_pred_vert));
2158
0
            pu1_pred_vert = pu1_pred_vert + src_strd;
2159
0
2160
0
            src_r1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_pred_vert));
2161
0
            pu1_pred_vert = pu1_pred_vert + src_strd;
2162
0
            src_r0_16x8b = _mm_unpacklo_epi32(src_r0_16x8b, src_r1_16x8b);
2163
0
2164
0
            src_r2_16x8b = _mm_loadl_epi64((__m128i *)(pu1_pred_vert));
2165
0
            pu1_pred_vert = pu1_pred_vert + src_strd;
2166
0
            src_r1_16x8b = _mm_unpacklo_epi32(src_r1_16x8b, src_r2_16x8b);
2167
0
2168
0
            src_r3_16x8b = _mm_loadl_epi64((__m128i *)(pu1_pred_vert));
2169
0
            pu1_pred_vert = pu1_pred_vert + src_strd;
2170
0
            src_r2_16x8b = _mm_unpacklo_epi32(src_r2_16x8b, src_r3_16x8b);
2171
0
2172
0
            src_r4_16x8b = _mm_loadl_epi64((__m128i *)(pu1_pred_vert));
2173
0
            pu1_pred_vert = pu1_pred_vert + src_strd;
2174
0
            src_r3_16x8b = _mm_unpacklo_epi32(src_r3_16x8b, src_r4_16x8b);
2175
0
2176
0
            //Core Loop: Process all the rows.
2177
0
            do
2178
0
            {
2179
0
                src_r5_16x8b = _mm_loadl_epi64((__m128i *)(pu1_pred_vert));
2180
0
                src_r4_16x8b = _mm_unpacklo_epi32(src_r4_16x8b, src_r5_16x8b);
2181
0
2182
0
                src_r6_16x8b = _mm_loadl_epi64((__m128i *)(pu1_pred_vert + src_strd));
2183
0
                src_r5_16x8b = _mm_unpacklo_epi32(src_r5_16x8b, src_r6_16x8b);
2184
0
2185
0
                src_r0r1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r1_16x8b);
2186
0
                src_r2r3_16x8b = _mm_unpacklo_epi8(src_r2_16x8b, src_r3_16x8b);
2187
0
                src_r4r5_16x8b = _mm_unpacklo_epi8(src_r4_16x8b, src_r5_16x8b);
2188
0
2189
0
                res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
2190
0
                res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
2191
0
                res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);
2192
0
2193
0
                res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t2_8x16b);
2194
0
                res_t3_8x16b = _mm_add_epi16(const_val16_8x16b, res_t3_8x16b);
2195
0
                res_t1_8x16b = _mm_add_epi16(res_t3_8x16b, res_t1_8x16b);
2196
0
2197
0
                res_t1_8x16b = _mm_srai_epi16(res_t1_8x16b, 5); //shifting right by 5 bits.
2198
0
                res_r0r1_16x8b = _mm_packus_epi16(res_t1_8x16b, res_t1_8x16b);
2199
0
2200
0
                _mm_storel_epi64((__m128i *)pu1_tmp1, res_r0r1_16x8b);
2201
0
2202
0
                src_r0_16x8b = src_r2_16x8b;
2203
0
                src_r1_16x8b = src_r3_16x8b;
2204
0
                src_r2_16x8b = src_r4_16x8b;
2205
0
                src_r3_16x8b = src_r5_16x8b;
2206
0
                src_r4_16x8b = src_r6_16x8b;
2207
0
2208
0
                ht_temp -= 2;
2209
0
                pu1_pred_vert += src_strd << 1;
2210
0
                pu1_tmp1 += 8;
2211
0
            }
2212
0
            while(ht_temp > 0);
2213
0
        }
2214
0
2215
0
        //horizontal q-pel filter
2216
0
        {
2217
0
            __m128i src_r0_16x8b, src_r1_16x8b;
2218
0
            __m128i src_r0_sht_16x8b, src_r1_sht_16x8b;
2219
0
            __m128i src_r0r1_vpel_16x8b, src_r0r1_t1_16x8b;
2220
0
2221
0
            __m128i res_r0r1_t1_8x16b, res_r0r1_t2_8x16b, res_r0r1_t3_8x16b;
2222
0
            __m128i res_r0r1_16x8b;
2223
0
2224
0
            //Row0 : a0 a1 a2 a3 a4 a5 a6 a7 a8 a9.....
2225
0
            //Row1 : b0 b1 b2 b3 b4 b5 b6 b7 b8 b9.....
2226
0
2227
0
            do
2228
0
            {
2229
0
                src_r0_16x8b = _mm_loadu_si128((__m128i *)pu1_pred_horiz);                  //a0 a1 a2 a3 a4 a5 a6 a7 a8 a9....a15
2230
0
                src_r1_16x8b = _mm_loadu_si128((__m128i *)(pu1_pred_horiz + src_strd));     //b0 b1 b2 b3 b4 b5 b6 b7 b8 b9....b15
2231
0
2232
0
                src_r0r1_vpel_16x8b = _mm_loadl_epi64((__m128i *)pu1_tmp2);
2233
0
2234
0
                src_r0_sht_16x8b = _mm_srli_si128(src_r0_16x8b, 1);                          //a1 a2 a3 a4 a5 a6 a7 a8 a9....a15 0
2235
0
                src_r1_sht_16x8b = _mm_srli_si128(src_r1_16x8b, 1);                          //b1 b2 b3 b4 b5 b6 b7 b8 b9....b15 0
2236
0
2237
0
                src_r0_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);            //a0 a1 a1 a2 a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8
2238
0
                src_r1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);            //b0 b1 b1 b2 b2 b3 b3 b4 b4 b5 b5 b6 b6 b7 b7 b8
2239
0
2240
0
                src_r0r1_t1_16x8b = _mm_unpacklo_epi64(src_r0_16x8b, src_r1_16x8b);          //a0 a1 a1 a2 a2 a3 a3 a4 b0 b1 b1 b2 b2 b3 b3 b4
2241
0
                res_r0r1_t1_8x16b = _mm_maddubs_epi16(src_r0r1_t1_16x8b, coeff0_1_16x8b);    //a0*c0+a1*c1 a1*c0+a2*c1 a2*c0+a3*c1 a3*c0+a4*c1
2242
0
                                                                                             //b0*c0+b1*c1 b1*c0+b2*c1 b2*c0+b3*c1 b3*c0+b4*c1
2243
0
2244
0
                src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 4);                              //a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8  0  0  0  0
2245
0
                src_r1_16x8b = _mm_srli_si128(src_r1_16x8b, 4);                              //b2 b3 b3 b4 b4 b5 b5 b6 b6 b7 b7 b8  0  0  0  0
2246
0
2247
0
                src_r0r1_t1_16x8b = _mm_unpacklo_epi64(src_r0_16x8b, src_r1_16x8b);          //a2 a3 a3 a4 a4 a5 a5 a6 b2 b3 b3 b4 b4 b5 b5 b6
2248
0
                res_r0r1_t2_8x16b = _mm_maddubs_epi16(src_r0r1_t1_16x8b, coeff2_3_16x8b);    //a2*c2+a3*c3 a3*c2+a4*c3 a4*c2+a5*c3 a5*c2+a6*c3
2249
0
                                                                                             //b2*c2+b3*c3 b3*c2+b4*c3 b4*c2+b5*c3 b5*c2+b6*c3
2250
0
2251
0
                src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 4);                              //a4 a5 a5 a6 a6 a7 a7 a8  0  0  0  0  0  0  0  0
2252
0
                src_r1_16x8b = _mm_srli_si128(src_r1_16x8b, 4);                              //b4 b5 b5 b6 b6 b7 b7 b8  0  0  0  0  0  0  0  0
2253
0
2254
0
                src_r0r1_t1_16x8b = _mm_unpacklo_epi64(src_r0_16x8b, src_r1_16x8b);          //a4 a5 a5 a6 a6 a7 a7 a8 b4 b5 b5 b6 b6 b7 b7 b8
2255
0
                res_r0r1_t3_8x16b = _mm_maddubs_epi16(src_r0r1_t1_16x8b, coeff4_5_16x8b);    //a4*c4+a5*c5 a5*c4+a6*c5 a6*c4+a7*c5 a7*c4+a8*c5
2256
0
                                                                                             //b4*c4+b5*c5 b5*c4+b6*c5 b4*c6+b7*c5 b7*c4+b8*c5
2257
0
2258
0
                res_r0r1_t1_8x16b = _mm_add_epi16(res_r0r1_t1_8x16b, res_r0r1_t2_8x16b);
2259
0
                res_r0r1_t3_8x16b = _mm_add_epi16(const_val16_8x16b, res_r0r1_t3_8x16b);
2260
0
                res_r0r1_t1_8x16b = _mm_add_epi16(res_r0r1_t1_8x16b, res_r0r1_t3_8x16b);     //a0*c0+a1*c1+a2*c2+a3*c3+a4*a4+a5*c5 + 15;
2261
0
                                                                                             //a1*c0+a2*c1+a2*c2+a3*c3+a5*a4+a6*c5 + 15;
2262
0
                                                                                             //a2*c0+a3*c1+a4*c2+a5*c3+a6*a4+a7*c5 + 15;
2263
0
                                                                                             //a3*c0+a4*c1+a5*c2+a6*c3+a6*a4+a8*c5 + 15;
2264
0
                                                                                             //b0*c0+b1*c1+b2*c2+b3*c3+b4*b4+b5*c5 + 15;
2265
0
                                                                                             //b1*c0+b2*c1+b2*c2+b3*c3+b5*b4+b6*c5 + 15;
2266
0
                                                                                             //b2*c0+b3*c1+b4*c2+b5*c3+b6*b4+b7*c5 + 15;
2267
0
                                                                                             //b3*c0+b4*c1+b5*c2+b6*c3+b6*b4+b8*c5 + 15;
2268
0
2269
0
                res_r0r1_t1_8x16b = _mm_srai_epi16(res_r0r1_t1_8x16b, 5);                    //shifting right by 5 bits.
2270
0
2271
0
                res_r0r1_16x8b = _mm_packus_epi16(res_r0r1_t1_8x16b,res_r0r1_t1_8x16b);
2272
0
2273
0
                res_r0r1_16x8b = _mm_avg_epu8(res_r0r1_16x8b,src_r0r1_vpel_16x8b);
2274
0
2275
0
                *((WORD32 *)(pu1_dst)) = _mm_cvtsi128_si32(res_r0r1_16x8b);
2276
0
                res_r0r1_16x8b = _mm_srli_si128(res_r0r1_16x8b, 4);
2277
0
                *((WORD32 *)(pu1_dst + dst_strd)) = _mm_cvtsi128_si32(res_r0r1_16x8b);
2278
0
2279
0
                ht -= 2;
2280
0
                pu1_pred_horiz += src_strd << 1;
2281
0
                pu1_tmp2 += 8;
2282
0
                pu1_dst += dst_strd << 1;
2283
0
            }
2284
0
            while(ht > 0);
2285
0
        }
2286
0
    }
2287
0
    else if(wd == 8)
2288
0
    {
2289
0
        //vertical q-pel filter
2290
0
        {
2291
0
            __m128i src_r0_16x8b, src_r1_16x8b, src_r2_16x8b, src_r3_16x8b;
2292
0
            __m128i src_r4_16x8b, src_r5_16x8b, src_r6_16x8b;
2293
0
            __m128i src_r0r1_16x8b, src_r2r3_16x8b, src_r4r5_16x8b;
2294
0
2295
0
            __m128i res_16x8b, res_t1_8x16b, res_t2_8x16b, res_t3_8x16b;
2296
0
2297
0
            //epilogue: Load all the pred rows except sixth  and seventh row for the
2298
0
            //first and second row processing.
2299
0
            src_r0_16x8b = _mm_loadl_epi64((__m128i *)(pu1_pred_vert));
2300
0
            pu1_pred_vert = pu1_pred_vert + src_strd;
2301
0
2302
0
            src_r1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_pred_vert));
2303
0
            pu1_pred_vert = pu1_pred_vert + src_strd;
2304
0
            src_r0_16x8b = _mm_unpacklo_epi64(src_r0_16x8b, src_r1_16x8b);
2305
0
2306
0
            src_r2_16x8b = _mm_loadl_epi64((__m128i *)(pu1_pred_vert));
2307
0
            pu1_pred_vert = pu1_pred_vert + src_strd;
2308
0
            src_r1_16x8b = _mm_unpacklo_epi64(src_r1_16x8b, src_r2_16x8b);
2309
0
2310
0
            src_r3_16x8b = _mm_loadl_epi64((__m128i *)(pu1_pred_vert));
2311
0
            pu1_pred_vert = pu1_pred_vert + src_strd;
2312
0
            src_r2_16x8b = _mm_unpacklo_epi64(src_r2_16x8b, src_r3_16x8b);
2313
0
2314
0
            src_r4_16x8b = _mm_loadl_epi64((__m128i *)(pu1_pred_vert));
2315
0
            pu1_pred_vert = pu1_pred_vert + src_strd;
2316
0
            src_r3_16x8b = _mm_unpacklo_epi64(src_r3_16x8b, src_r4_16x8b);
2317
0
2318
0
            //Core Loop: Process all the rows.
2319
0
            do
2320
0
            {
2321
0
                src_r5_16x8b = _mm_loadl_epi64((__m128i *)(pu1_pred_vert));
2322
0
                src_r4_16x8b = _mm_unpacklo_epi64(src_r4_16x8b, src_r5_16x8b);
2323
0
2324
0
                src_r6_16x8b = _mm_loadl_epi64((__m128i *)(pu1_pred_vert + src_strd));
2325
0
                src_r5_16x8b = _mm_unpacklo_epi64(src_r5_16x8b, src_r6_16x8b);
2326
0
2327
0
                src_r0r1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r1_16x8b);
2328
0
                src_r2r3_16x8b = _mm_unpacklo_epi8(src_r2_16x8b, src_r3_16x8b);
2329
0
                src_r4r5_16x8b = _mm_unpacklo_epi8(src_r4_16x8b, src_r5_16x8b);
2330
0
2331
0
                res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
2332
0
                res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
2333
0
                res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);
2334
0
2335
0
                res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t2_8x16b);
2336
0
                res_t3_8x16b = _mm_add_epi16(const_val16_8x16b, res_t3_8x16b);
2337
0
                res_t1_8x16b = _mm_add_epi16(res_t3_8x16b, res_t1_8x16b);
2338
0
2339
0
                res_t1_8x16b = _mm_srai_epi16(res_t1_8x16b, 5); //shifting right by 5 bits.
2340
0
                res_16x8b = _mm_packus_epi16(res_t1_8x16b, res_t1_8x16b);
2341
0
2342
0
                _mm_storel_epi64((__m128i *)(pu1_tmp1), res_16x8b);
2343
0
2344
0
                src_r0r1_16x8b = _mm_unpackhi_epi8(src_r0_16x8b, src_r1_16x8b);
2345
0
                src_r2r3_16x8b = _mm_unpackhi_epi8(src_r2_16x8b, src_r3_16x8b);
2346
0
                src_r4r5_16x8b = _mm_unpackhi_epi8(src_r4_16x8b, src_r5_16x8b);
2347
0
2348
0
                res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
2349
0
                res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
2350
0
                res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);
2351
0
2352
0
                res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t2_8x16b);
2353
0
                res_t3_8x16b = _mm_add_epi16(const_val16_8x16b, res_t3_8x16b);
2354
0
                res_t1_8x16b = _mm_add_epi16(res_t3_8x16b, res_t1_8x16b);
2355
0
2356
0
                res_t1_8x16b = _mm_srai_epi16(res_t1_8x16b, 5); //shifting right by 5 bits.
2357
0
                res_16x8b = _mm_packus_epi16(res_t1_8x16b, res_t1_8x16b);
2358
0
2359
0
                _mm_storel_epi64((__m128i *)(pu1_tmp1 + 8), res_16x8b);
2360
0
2361
0
                src_r0_16x8b = src_r2_16x8b;
2362
0
                src_r1_16x8b = src_r3_16x8b;
2363
0
                src_r2_16x8b = src_r4_16x8b;
2364
0
                src_r3_16x8b = src_r5_16x8b;
2365
0
                src_r4_16x8b = src_r6_16x8b;
2366
0
2367
0
                ht_temp -= 2;
2368
0
                pu1_pred_vert += src_strd << 1;
2369
0
                pu1_tmp1 += 16;
2370
0
            }
2371
0
            while(ht_temp > 0);
2372
0
        }
2373
0
2374
0
        //horizontal q-pel filter
2375
0
        {
2376
0
            __m128i src_r0_16x8b, src_r1_16x8b, src_r0_sht_16x8b, src_r1_sht_16x8b;
2377
0
            __m128i src_r0_t1_16x8b, src_r1_t1_16x8b;
2378
0
            __m128i src_r0_vpel_16x8b, src_r1_vpel_16x8b;
2379
0
2380
0
            __m128i res_r0_t1_8x16b, res_r0_t2_8x16b, res_r0_t3_8x16b;
2381
0
            __m128i res_r1_t1_8x16b, res_r1_t2_8x16b, res_r1_t3_8x16b, res_16x8b;
2382
0
2383
0
            //Row0 : a0 a1 a2 a3 a4 a5 a6 a7 a8 a9.....
2384
0
            //Row1 : b0 b1 b2 b3 b4 b5 b6 b7 b8 b9.....
2385
0
2386
0
            do
2387
0
            {
2388
0
                src_r0_16x8b = _mm_loadu_si128((__m128i *)(pu1_pred_horiz));               //a0 a1 a2 a3 a4 a5 a6 a7 a8 a9....a15
2389
0
                src_r1_16x8b = _mm_loadu_si128((__m128i *)(pu1_pred_horiz + src_strd));    //b0 b1 b2 b3 b4 b5 b6 b7 b8 b9....b15
2390
0
2391
0
                src_r0_vpel_16x8b = _mm_loadl_epi64((__m128i *)(pu1_tmp2));                //a2 a3 a4 a5 a6 a7 a8....a15 0 or
2392
0
                                                                                           //a3 a4 a5 a6 a7 a8 a9....a15 0
2393
0
                src_r1_vpel_16x8b = _mm_loadl_epi64((__m128i *)(pu1_tmp2 + 8));
2394
0
                                                                                           //b2 b3 b4 b5 b6 b7 b8....b15 0 or
2395
0
                                                                                           //b3 b4 b5 b6 b7 b8 b9....b15 0
2396
0
2397
0
                src_r0_sht_16x8b = _mm_srli_si128(src_r0_16x8b, 1);                        //a1 a2 a3 a4 a5 a6 a7 a8 a9....a15 0
2398
0
                src_r1_sht_16x8b = _mm_srli_si128(src_r1_16x8b, 1);                        //b1 b2 b3 b4 b5 b6 b7 b8 b9....b15 0
2399
0
2400
0
                src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);       //a0 a1 a1 a2 a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8
2401
0
                src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);       //b0 b1 b1 b2 b2 b3 b3 b4 b4 b5 b5 b6 b6 b7 b7 b8
2402
0
2403
0
                res_r0_t1_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff0_1_16x8b);      //a0*c0+a1*c1 a1*c0+a2*c1 a2*c0+a3*c1 a3*c0+a4*c1
2404
0
                                                                                           //a4*c0+a5*c1 a5*c0+a6*c1 a6*c0+a7*c1 a7*c0+a8*c1
2405
0
                res_r1_t1_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff0_1_16x8b);      //b0*c0+b1*c1 b1*c0+b2*c1 b2*c0+b3*c1 b3*c0+b4*c1
2406
0
                                                                                           //b4*c0+b5*c1 b5*c0+b6*c1 b6*c0+b7*c1 b7*c0+b8*c1
2407
0
2408
0
                src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 2);                            //a2 a3 a4 a5 a6 a7 a8 a9....a15 0 0
2409
0
                src_r1_16x8b = _mm_srli_si128(src_r1_16x8b, 2);                            //b2 b3 b4 b5 b6 b7 b8 b9....b15 0 0
2410
0
2411
0
                src_r0_sht_16x8b = _mm_srli_si128(src_r0_sht_16x8b, 2);                    //a3 a4 a5 a6 a7 a8 a9....a15 0  0  0
2412
0
                src_r1_sht_16x8b = _mm_srli_si128(src_r1_sht_16x8b, 2);                    //b3 b4 b5 b6 b7 b8 b9....b15 0  0  0
2413
0
2414
0
                src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);       //a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8 a8 a9 a9 a10
2415
0
                src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);       //b2 b3 b3 b4 b4 b5 b5 b6 b6 b7 b7 b8 a8 a9 a9 a10
2416
0
2417
0
                res_r0_t2_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff2_3_16x8b);      //a2*c2+a3*c3 a3*c2+a4*c3 a4*c2+a5*c3 a5*c2+a6*c3
2418
0
                                                                                           //a6*c2+a7*c3 a7*c2+a8*c3 a8*c2+a9*c3 a9*c2+a10*c3
2419
0
                res_r1_t2_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff2_3_16x8b);      //b2*c2+b3*c3 b3*c2+b4*c3 b2*c4+b5*c3 b5*c2+b6*c3
2420
0
                                                                                           //b6*c2+b7*c3 b7*c2+b8*c3 b8*c2+b9*c3 b9*c2+b10*c3
2421
0
2422
0
                src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 2);                            //a4 a5 a6 a7 a8 a9....a15 0  0  0  0
2423
0
                src_r1_16x8b = _mm_srli_si128(src_r1_16x8b, 2);                            //b4 b5 b6 b7 b8 b9....b15 0  0  0  0
2424
0
2425
0
                src_r0_sht_16x8b = _mm_srli_si128(src_r0_sht_16x8b, 2);                    //a5 a6 a7 a8 a9....a15 0  0  0  0  0
2426
0
                src_r1_sht_16x8b = _mm_srli_si128(src_r1_sht_16x8b, 2);                    //b5 b6 b7 b8 b9....b15 0  0  0  0  0
2427
0
2428
0
                src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);       //a4 a5 a5 a6 a6 a7 a7 a8 a8 a9 a9 a10 a10 a11 a11 a12
2429
0
                src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);       //b4 b5 b5 b6 b6 b7 b7 b8 b8 b9 b9 b10 b10 b11 b11 b12
2430
0
2431
0
                res_r0_t3_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff4_5_16x8b);      //a4*c4+a5*c5 a5*c4+a6*c5 a6*c4+a7*c5 a7*c4+a8*c5
2432
0
                                                                                           //a8*c4+a9*c5 a9*c4+a10*c5 a10*c4+a11*c5 a11*c4+a12*c5
2433
0
                res_r1_t3_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff4_5_16x8b);      //b4*c4+b5*c5 b5*c4+b6*c5 b6*c4+b7*c5 b7*c4+b8*c5
2434
0
                                                                                           //b8*c4+b9*c5 b9*c4+b10*c5 b10*c4+b11*c5 b11*c4+b12*c5
2435
0
                res_r0_t1_8x16b = _mm_add_epi16(res_r0_t1_8x16b, res_r0_t2_8x16b);
2436
0
                res_r0_t3_8x16b = _mm_add_epi16(const_val16_8x16b, res_r0_t3_8x16b);
2437
0
                res_r0_t1_8x16b = _mm_add_epi16(res_r0_t1_8x16b, res_r0_t3_8x16b);
2438
0
                res_r0_t1_8x16b = _mm_srai_epi16(res_r0_t1_8x16b, 5);                      //shifting right by 5 bits.
2439
0
2440
0
                res_16x8b = _mm_packus_epi16(res_r0_t1_8x16b, res_r0_t1_8x16b);
2441
0
                res_16x8b = _mm_avg_epu8(res_16x8b, src_r0_vpel_16x8b);
2442
0
2443
0
                _mm_storel_epi64((__m128i *)(pu1_dst), res_16x8b);
2444
0
2445
0
                res_r1_t1_8x16b = _mm_add_epi16(res_r1_t1_8x16b, res_r1_t2_8x16b);
2446
0
                res_r1_t3_8x16b = _mm_add_epi16(const_val16_8x16b, res_r1_t3_8x16b);
2447
0
                res_r1_t1_8x16b = _mm_add_epi16(res_r1_t1_8x16b, res_r1_t3_8x16b);
2448
0
                res_r1_t1_8x16b = _mm_srai_epi16(res_r1_t1_8x16b, 5);                      //shifting right by 5 bits.
2449
0
2450
0
                res_16x8b = _mm_packus_epi16(res_r1_t1_8x16b, res_r1_t1_8x16b);
2451
0
                res_16x8b = _mm_avg_epu8(res_16x8b,src_r1_vpel_16x8b);
2452
0
2453
0
                _mm_storel_epi64((__m128i *)(pu1_dst + dst_strd), res_16x8b);
2454
0
2455
0
                ht -= 2;
2456
0
                pu1_pred_horiz += src_strd << 1;
2457
0
                pu1_dst += dst_strd << 1;
2458
0
                pu1_tmp2 += 16;
2459
0
            }
2460
0
            while(ht > 0);
2461
0
        }
2462
0
    }
2463
0
    else // wd == 16
2464
0
    {
2465
0
        //vertical q-pel filter
2466
0
        {
2467
0
            __m128i src_r0_16x8b, src_r1_16x8b, src_r2_16x8b, src_r3_16x8b;
2468
0
            __m128i src_r4_16x8b, src_r5_16x8b, src_r6_16x8b;
2469
0
            __m128i src_r0r1_16x8b, src_r2r3_16x8b, src_r4r5_16x8b;
2470
0
2471
0
            __m128i res_t0_8x16b, res_t1_8x16b, res_t2_8x16b, res_t3_8x16b;
2472
0
            __m128i res_16x8b;
2473
0
2474
0
            //epilogue: Load all the pred rows except sixth  and seventh row for the
2475
0
            //first and second row processing.
2476
0
            src_r0_16x8b = _mm_loadu_si128((__m128i *)(pu1_pred_vert));
2477
0
            pu1_pred_vert =  pu1_pred_vert + src_strd;
2478
0
            src_r1_16x8b = _mm_loadu_si128((__m128i *)(pu1_pred_vert));
2479
0
            pu1_pred_vert =  pu1_pred_vert + src_strd;
2480
0
            src_r2_16x8b = _mm_loadu_si128((__m128i *)(pu1_pred_vert));
2481
0
            pu1_pred_vert =  pu1_pred_vert + src_strd;
2482
0
            src_r3_16x8b = _mm_loadu_si128((__m128i *)(pu1_pred_vert));
2483
0
            pu1_pred_vert =  pu1_pred_vert + src_strd;
2484
0
            src_r4_16x8b = _mm_loadu_si128((__m128i *)(pu1_pred_vert));
2485
0
            pu1_pred_vert =  pu1_pred_vert + src_strd;
2486
0
2487
0
            //Core Loop: Process all the rows.
2488
0
            do
2489
0
            {
2490
0
                src_r5_16x8b = _mm_loadu_si128((__m128i *)(pu1_pred_vert));
2491
0
                src_r6_16x8b = _mm_loadu_si128((__m128i *)(pu1_pred_vert + src_strd));
2492
0
2493
0
                src_r0r1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r1_16x8b);
2494
0
                src_r2r3_16x8b = _mm_unpacklo_epi8(src_r2_16x8b, src_r3_16x8b);
2495
0
                src_r4r5_16x8b = _mm_unpacklo_epi8(src_r4_16x8b, src_r5_16x8b);
2496
0
2497
0
                res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
2498
0
                res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
2499
0
                res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);
2500
0
2501
0
                res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t2_8x16b);
2502
0
                res_t3_8x16b = _mm_add_epi16(const_val16_8x16b, res_t3_8x16b);
2503
0
                res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t3_8x16b);
2504
0
                res_t0_8x16b = _mm_srai_epi16(res_t1_8x16b, 5); //shifting right by 5 bits.
2505
0
2506
0
                src_r0r1_16x8b = _mm_unpackhi_epi8(src_r0_16x8b, src_r1_16x8b);
2507
0
                src_r2r3_16x8b = _mm_unpackhi_epi8(src_r2_16x8b, src_r3_16x8b);
2508
0
                src_r4r5_16x8b = _mm_unpackhi_epi8(src_r4_16x8b, src_r5_16x8b);
2509
0
2510
0
                res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
2511
0
                res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
2512
0
                res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);
2513
0
2514
0
                res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t2_8x16b);
2515
0
                res_t3_8x16b = _mm_add_epi16(const_val16_8x16b, res_t3_8x16b);
2516
0
                res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t3_8x16b);
2517
0
                res_t1_8x16b = _mm_srai_epi16(res_t1_8x16b, 5); //shifting right by 5 bits.
2518
0
2519
0
                res_16x8b = _mm_packus_epi16(res_t0_8x16b, res_t1_8x16b);
2520
0
2521
0
                _mm_storeu_si128((__m128i *)(pu1_tmp1), res_16x8b);
2522
0
2523
0
                src_r0r1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r2_16x8b);
2524
0
                src_r2r3_16x8b = _mm_unpacklo_epi8(src_r3_16x8b, src_r4_16x8b);
2525
0
                src_r4r5_16x8b = _mm_unpacklo_epi8(src_r5_16x8b, src_r6_16x8b);
2526
0
2527
0
                res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
2528
0
                res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
2529
0
                res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);
2530
0
2531
0
                res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t2_8x16b);
2532
0
                res_t3_8x16b = _mm_add_epi16(const_val16_8x16b, res_t3_8x16b);
2533
0
                res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t3_8x16b);
2534
0
                res_t0_8x16b = _mm_srai_epi16(res_t1_8x16b, 5); //shifting right by 5 bits.
2535
0
2536
0
                src_r0r1_16x8b = _mm_unpackhi_epi8(src_r1_16x8b, src_r2_16x8b);
2537
0
                src_r2r3_16x8b = _mm_unpackhi_epi8(src_r3_16x8b, src_r4_16x8b);
2538
0
                src_r4r5_16x8b = _mm_unpackhi_epi8(src_r5_16x8b, src_r6_16x8b);
2539
0
2540
0
                res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
2541
0
                res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
2542
0
                res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);
2543
0
2544
0
                res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t2_8x16b);
2545
0
                res_t3_8x16b = _mm_add_epi16(const_val16_8x16b, res_t3_8x16b);
2546
0
                res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t3_8x16b);
2547
0
                res_t1_8x16b = _mm_srai_epi16(res_t1_8x16b, 5); //shifting right by 5 bits.
2548
0
2549
0
                res_16x8b = _mm_packus_epi16(res_t0_8x16b, res_t1_8x16b);
2550
0
2551
0
                _mm_storeu_si128((__m128i *)(pu1_tmp1 + 16), res_16x8b);
2552
0
2553
0
                src_r0_16x8b = src_r2_16x8b;
2554
0
                src_r1_16x8b = src_r3_16x8b;
2555
0
                src_r2_16x8b = src_r4_16x8b;
2556
0
                src_r3_16x8b = src_r5_16x8b;
2557
0
                src_r4_16x8b = src_r6_16x8b;
2558
0
2559
0
                ht_temp -= 2;
2560
0
                pu1_pred_vert += src_strd << 1;
2561
0
                pu1_tmp1 += 32;
2562
0
            }
2563
0
            while(ht_temp > 0);
2564
0
        }
2565
0
        //horizontal q-pel filter
2566
0
        {
2567
0
            __m128i src_r0_16x8b, src_r1_16x8b, src_r0_sht_16x8b, src_r1_sht_16x8b;
2568
0
            __m128i src_r0_t1_16x8b, src_r1_t1_16x8b;
2569
0
            __m128i src_vpel_16x8b;
2570
0
2571
0
            __m128i res_r0_t1_8x16b, res_r0_t2_8x16b, res_r0_t3_8x16b;
2572
0
            __m128i res_r1_t1_8x16b, res_r1_t2_8x16b, res_r1_t3_8x16b;
2573
0
            __m128i res_16x8b;
2574
0
2575
0
            //Row0 : a0 a1 a2 a3 a4 a5 a6 a7 a8 a9.....
2576
0
            //Row0 :                         b0 b1 b2 b3 b4 b5 b6 b7 b8 b9.....
2577
0
            //b0 is same a8. Similarly other bn pixels are same as a(n+8) pixels.
2578
0
2579
0
            do
2580
0
            {
2581
0
                src_r0_16x8b = _mm_loadu_si128((__m128i *)(pu1_pred_horiz));             //a0 a1 a2 a3 a4 a5 a6 a7 a8 a9....a15
2582
0
                src_r1_16x8b = _mm_loadu_si128((__m128i *)(pu1_pred_horiz + 8));         //b0 b1 b2 b3 b4 b5 b6 b7 b8 b9....b15
2583
0
                src_vpel_16x8b = _mm_loadu_si128((__m128i *)(pu1_tmp2));
2584
0
2585
0
                src_r0_sht_16x8b = _mm_srli_si128(src_r0_16x8b, 1);                      //a1 a2 a3 a4 a5 a6 a7 a8 a9....a15 0
2586
0
                src_r1_sht_16x8b = _mm_srli_si128(src_r1_16x8b, 1);                      //b1 b2 b3 b4 b5 b6 b7 b8 b9....b15 0
2587
0
2588
0
                src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);     //a0 a1 a1 a2 a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8
2589
0
                src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);     //b0 b1 b1 b2 b2 b3 b3 b4 b4 b5 b5 b6 b6 b7 b7 b8
2590
0
2591
0
                res_r0_t1_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff0_1_16x8b);    //a0*c0+a1*c1 a1*c0+a2*c1 a2*c0+a3*c1 a3*c0+a4*c1
2592
0
                                                                                         //a4*c0+a5*c1 a5*c0+a6*c1 a6*c0+a7*c1 a7*c0+a8*c1
2593
0
                res_r1_t1_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff0_1_16x8b);    //b0*c0+b1*c1 b1*c0+b2*c1 b2*c0+b3*c1 b3*c0+b4*c1
2594
0
                                                                                         //b4*c0+b5*c1 b5*c0+b6*c1 b6*c0+b7*c1 b7*c0+b8*c1
2595
0
2596
0
                src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 2);                          //a2 a3 a4 a5 a6 a7 a8 a9....a15 0 0
2597
0
                src_r1_16x8b = _mm_srli_si128(src_r1_16x8b, 2);                          //b2 b3 b4 b5 b6 b7 b8 b9....b15 0 0
2598
0
2599
0
                src_r0_sht_16x8b = _mm_srli_si128(src_r0_sht_16x8b, 2);                  //a3 a4 a5 a6 a7 a8 a9....a15 0  0  0
2600
0
                src_r1_sht_16x8b = _mm_srli_si128(src_r1_sht_16x8b, 2);                  //b3 b4 b5 b6 b7 b8 b9....b15 0  0  0
2601
0
2602
0
                src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);     //a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8 a8 a9 a9 a10
2603
0
                src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);     //b2 b3 b3 b4 b4 b5 b5 b6 b6 b7 b7 b8 a8 a9 a9 a10
2604
0
2605
0
                res_r0_t2_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff2_3_16x8b);    //a2*c2+a3*c3 a3*c2+a4*c3 a4*c2+a5*c3 a5*c2+a6*c3
2606
0
                                                                                         //a6*c2+a7*c3 a7*c2+a8*c3 a8*c2+a9*c3 a9*c2+a10*c3
2607
0
                res_r1_t2_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff2_3_16x8b);    //b2*c2+b3*c3 b3*c2+b4*c3 b2*c4+b5*c3 b5*c2+b6*c3
2608
0
                                                                                         //b6*c2+b7*c3 b7*c2+b8*c3 b8*c2+b9*c3 b9*c2+b10*c3
2609
0
2610
0
                src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 2);                          //a4 a5 a6 a7 a8 a9....a15 0  0  0  0
2611
0
                src_r1_16x8b = _mm_srli_si128(src_r1_16x8b, 2);                          //b4 b5 b6 b7 b8 b9....b15 0  0  0  0
2612
0
2613
0
                src_r0_sht_16x8b = _mm_srli_si128(src_r0_sht_16x8b, 2);                  //a5 a6 a7 a8 a9....a15 0  0  0  0  0
2614
0
                src_r1_sht_16x8b = _mm_srli_si128(src_r1_sht_16x8b, 2);                  //b5 b6 b7 b8 b9....b15 0  0  0  0  0
2615
0
2616
0
                src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);     //a4 a5 a5 a6 a6 a7 a7 a8 a8 a9 a9 a10 a10 a11 a11 a12
2617
0
                src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);     //b4 b5 b5 b6 b6 b7 b7 b8 b8 b9 b9 b10 b10 b11 b11 b12
2618
0
2619
0
                res_r0_t3_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff4_5_16x8b);    //a4*c4+a5*c5 a5*c4+a6*c5 a6*c4+a7*c5 a7*c4+a8*c5
2620
0
                                                                                         //a8*c4+a9*c5 a9*c4+a10*c5 a10*c4+a11*c5 a11*c4+a12*c5
2621
0
                res_r1_t3_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff4_5_16x8b);    //b4*c4+b5*c5 b5*c4+b6*c5 b6*c4+b7*c5 b7*c4+b8*c5
2622
0
                                                                                         //b8*c4+b9*c5 b9*c4+b10*c5 b10*c4+b11*c5 b11*c4+b12*c5
2623
0
                res_r0_t1_8x16b = _mm_add_epi16(res_r0_t1_8x16b, res_r0_t2_8x16b);
2624
0
                res_r0_t3_8x16b = _mm_add_epi16(const_val16_8x16b, res_r0_t3_8x16b);
2625
0
                res_r0_t1_8x16b = _mm_add_epi16(res_r0_t1_8x16b, res_r0_t3_8x16b);
2626
0
                res_r0_t1_8x16b = _mm_srai_epi16(res_r0_t1_8x16b, 5);                    //shifting right by 5 bits.
2627
0
2628
0
                res_r1_t1_8x16b = _mm_add_epi16(res_r1_t1_8x16b, res_r1_t2_8x16b);
2629
0
                res_r1_t1_8x16b = _mm_add_epi16(res_r1_t1_8x16b, res_r1_t3_8x16b);
2630
0
                res_r1_t1_8x16b = _mm_add_epi16(res_r1_t1_8x16b, const_val16_8x16b);
2631
0
                res_r1_t1_8x16b = _mm_srai_epi16(res_r1_t1_8x16b, 5);                    //shifting right by 5 bits.
2632
0
2633
0
                res_16x8b = _mm_packus_epi16(res_r0_t1_8x16b, res_r1_t1_8x16b);
2634
0
2635
0
                res_16x8b = _mm_avg_epu8(res_16x8b, src_vpel_16x8b);
2636
0
                _mm_storeu_si128((__m128i *)(pu1_dst), res_16x8b);
2637
0
2638
0
                ht --;
2639
0
                pu1_pred_horiz  += src_strd;
2640
0
                pu1_dst += dst_strd;
2641
0
                pu1_tmp2 += 16;
2642
0
            }
2643
0
            while(ht > 0);
2644
0
        }
2645
0
    }
2646
0
}
2647
2648
/*****************************************************************************/
2649
/*                                                                           */
2650
/*  Function Name : ih264_inter_pred_luma_horz_qpel_vert_hpel_ssse3          */
2651
/*                                                                           */
2652
/*  Description   : This function implements a six-tap filter vertically and */
2653
/*                  horizontally on ht x wd block separately and averages    */
2654
/*                  the two sets of values to calculate values at (1/4,1/2), */
2655
/*                  or (3/4, 1/2) as mentioned in sec. 8.4.2.2.1 titled      */
2656
/*                  "Luma sample interpolation process". (ht,wd) can be      */
2657
/*                  (4,4), (8,4), (4,8), (8,8), (16,8), (8,16) or (16,16).   */
2658
/*                                                                           */
2659
/*  Inputs        : puc_src  - pointer to source                             */
2660
/*                  puc_dst  - pointer to destination                        */
2661
/*                  src_strd - stride for source                             */
2662
/*                  dst_strd - stride for destination                        */
2663
/*                  ht       - height of the block                           */
2664
/*                  wd       - width of the block                            */
2665
/*                  pu1_tmp  - pointer to temporary buffer                   */
2666
/*                  dydx     - x and y reference offset for q-pel            */
2667
/*                             calculations                                  */
2668
/*                                                                           */
2669
/*  Issues        : None                                                     */
2670
/*                                                                           */
2671
/*  Revision History:                                                        */
2672
/*                                                                           */
2673
/*         DD MM YYYY   Author(s)       Changes                              */
2674
/*         13 02 2015   Kaushik         Initial Version                      */
2675
/*                      Senthoor                                             */
2676
/*                                                                           */
2677
/*****************************************************************************/
2678
void ih264_inter_pred_luma_horz_qpel_vert_hpel_ssse3(UWORD8 *pu1_src,
2679
                                                     UWORD8 *pu1_dst,
2680
                                                     WORD32 src_strd,
2681
                                                     WORD32 dst_strd,
2682
                                                     WORD32 ht,
2683
                                                     WORD32 wd,
2684
                                                     UWORD8* pu1_tmp,
2685
                                                     WORD32 dydx)
2686
0
{
2687
0
    WORD32 ht_temp;
2688
0
    WORD32 x_offset;
2689
0
    WORD32 off0,off1, off2, off3, off4, off5;
2690
0
    WORD16 *pi2_temp1,*pi2_temp2,*pi2_temp3;
2691
0
2692
0
    ht_temp = ht;
2693
0
    x_offset = dydx & 0x3;
2694
0
    pi2_temp1 = (WORD16 *)pu1_tmp;
2695
0
    pi2_temp2 = pi2_temp1;
2696
0
    pi2_temp3 = pi2_temp1 + (x_offset >> 1);
2697
0
2698
0
    pu1_src -= 2 * src_strd;
2699
0
    pu1_src -= 2;
2700
0
    pi2_temp3 += 2;
2701
0
    //the filter input starts from x[-2] (till x[3])
2702
0
2703
0
    if(wd == 4)
2704
0
    {
2705
0
        //vertical half-pel
2706
0
        {
2707
0
            __m128i src_r0_16x8b, src_r1_16x8b, src_r2_16x8b, src_r3_16x8b, src_r4_16x8b;
2708
0
            __m128i src_r5_16x8b, src_r6_16x8b;
2709
0
            __m128i src_r0r1_16x8b, src_r2r3_16x8b, src_r4r5_16x8b;
2710
0
2711
0
            __m128i res_t1_8x16b, res_t2_8x16b, res_t3_8x16b;
2712
0
2713
0
            __m128i coeff0_1_16x8b, coeff2_3_16x8b, coeff4_5_16x8b;
2714
0
2715
0
            coeff0_1_16x8b = _mm_set1_epi32(0xFB01FB01);  //c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1
2716
0
            coeff2_3_16x8b = _mm_set1_epi32(0x14141414);  //c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3
2717
0
            coeff4_5_16x8b = _mm_set1_epi32(0x01FB01FB);  //c4 c5 c5 c5 c4 c5 c5 c5 c4 c5 c5 c5 c4 c5 c5 c5
2718
0
                                                          //c0 = c5 = 1, c1 = c4 = -5, c2 = c3 = 20
2719
0
            off0 = -((src_strd << 2) + src_strd) + 8;
2720
0
            off1 = -(src_strd << 2) + 8;
2721
0
            off2 = -((src_strd << 1) + src_strd) + 8;
2722
0
            off3 = -(src_strd << 1) + 8;
2723
0
            off4 = -src_strd + 8;
2724
0
            off5 = 8;
2725
0
2726
0
            //epilogue: Load all the pred rows except sixth  and seventh row for the
2727
0
            //first and second row processing.
2728
0
            src_r0_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src));
2729
0
            pu1_src =  pu1_src + src_strd;
2730
0
2731
0
            src_r1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src));
2732
0
            pu1_src =  pu1_src + src_strd;
2733
0
2734
0
            src_r2_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src));
2735
0
            pu1_src =  pu1_src + src_strd;
2736
0
2737
0
            src_r3_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src));
2738
0
            pu1_src =  pu1_src + src_strd;
2739
0
2740
0
            src_r4_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src));
2741
0
            pu1_src =  pu1_src + src_strd;
2742
0
2743
0
            //Core Loop: Process all the rows.
2744
0
            do
2745
0
            {
2746
0
                src_r5_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src));
2747
0
2748
0
                src_r0r1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r1_16x8b);
2749
0
                src_r2r3_16x8b = _mm_unpacklo_epi8(src_r2_16x8b, src_r3_16x8b);
2750
0
                src_r4r5_16x8b = _mm_unpacklo_epi8(src_r4_16x8b, src_r5_16x8b);
2751
0
2752
0
                res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
2753
0
                res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
2754
0
                res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);
2755
0
2756
0
                res_t1_8x16b = _mm_add_epi16(res_t2_8x16b, res_t1_8x16b);
2757
0
                res_t1_8x16b = _mm_add_epi16(res_t3_8x16b, res_t1_8x16b);
2758
0
2759
0
                _mm_storeu_si128((__m128i *)(pi2_temp1), res_t1_8x16b);
2760
0
2761
0
                pi2_temp1[8] = pu1_src[off0] + pu1_src[off5]
2762
0
                                   - (pu1_src[off1] + pu1_src[off4])
2763
0
                                   + ((pu1_src[off2] + pu1_src[off3] - pu1_src[off1] - pu1_src[off4]) << 2)
2764
0
                                   + ((pu1_src[off2] + pu1_src[off3]) << 4);
2765
0
2766
0
                pu1_src = pu1_src + src_strd;
2767
0
                pi2_temp1 = pi2_temp1 + 9;
2768
0
2769
0
                src_r6_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src));
2770
0
2771
0
                src_r0r1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r2_16x8b);
2772
0
                src_r2r3_16x8b = _mm_unpacklo_epi8(src_r3_16x8b, src_r4_16x8b);
2773
0
                src_r4r5_16x8b = _mm_unpacklo_epi8(src_r5_16x8b, src_r6_16x8b);
2774
0
2775
0
                res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
2776
0
                res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
2777
0
                res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);
2778
0
2779
0
                res_t1_8x16b = _mm_add_epi16(res_t2_8x16b, res_t1_8x16b);
2780
0
                res_t1_8x16b = _mm_add_epi16(res_t3_8x16b, res_t1_8x16b);
2781
0
2782
0
                _mm_storeu_si128((__m128i *)(pi2_temp1), res_t1_8x16b);
2783
0
2784
0
                pi2_temp1[8] = pu1_src[off0] + pu1_src[off5]
2785
0
                                   - (pu1_src[off1] + pu1_src[off4])
2786
0
                                   + ((pu1_src[off2] + pu1_src[off3] - pu1_src[off1] - pu1_src[off4]) << 2)
2787
0
                                   + ((pu1_src[off2] + pu1_src[off3]) << 4);
2788
0
2789
0
                ht_temp -= 2;
2790
0
                pu1_src = pu1_src + src_strd;
2791
0
                pi2_temp1 = pi2_temp1 + 9;
2792
0
2793
0
                src_r0_16x8b = src_r2_16x8b;
2794
0
                src_r1_16x8b = src_r3_16x8b;
2795
0
                src_r2_16x8b = src_r4_16x8b;
2796
0
                src_r3_16x8b = src_r5_16x8b;
2797
0
                src_r4_16x8b = src_r6_16x8b;
2798
0
            }
2799
0
            while(ht_temp > 0);
2800
0
        }
2801
0
2802
0
        //horizontal q-pel
2803
0
        {
2804
0
            __m128i src_r0_8x16b, src_r1_8x16b, src_r2_8x16b;
2805
0
            __m128i src_r3_8x16b, src_r4_8x16b, src_r5_8x16b;
2806
0
            __m128i src_r0r1_c0_8x16b, src_r2r3_c0_8x16b, src_r4r5_c0_8x16b;
2807
0
            __m128i src_hpel_16x8b, src_hpel_8x16b;
2808
0
2809
0
            __m128i res_t1_4x32b, res_t2_4x32b, res_t3_4x32b;
2810
0
            __m128i res_8x16b, res_16x8b;
2811
0
2812
0
            __m128i coeff0_1_8x16b, coeff2_3_8x16b, coeff4_5_8x16b;
2813
0
            __m128i const_val512_4x32b, const_val16_8x16b;
2814
0
2815
0
            coeff0_1_8x16b = _mm_set1_epi32(0xFFFB0001);
2816
0
            coeff2_3_8x16b = _mm_set1_epi32(0x00140014);
2817
0
            coeff4_5_8x16b = _mm_set1_epi32(0x0001FFFB);
2818
0
2819
0
            const_val512_4x32b = _mm_set1_epi32(512);
2820
0
            const_val16_8x16b = _mm_set1_epi16(16);
2821
0
2822
0
            do
2823
0
            {
2824
0
                src_r0_8x16b = _mm_loadl_epi64((__m128i *)(pi2_temp2));
2825
0
                src_r1_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2 + 1));
2826
0
                src_r2_8x16b = _mm_srli_si128(src_r1_8x16b, 2);
2827
0
                src_r3_8x16b = _mm_srli_si128(src_r1_8x16b, 4);
2828
0
                src_r4_8x16b = _mm_srli_si128(src_r1_8x16b, 6);
2829
0
                src_r5_8x16b = _mm_srli_si128(src_r1_8x16b, 8);
2830
0
2831
0
                src_r0r1_c0_8x16b = _mm_unpacklo_epi16(src_r0_8x16b, src_r1_8x16b);
2832
0
                src_r2r3_c0_8x16b = _mm_unpacklo_epi16(src_r2_8x16b, src_r3_8x16b);
2833
0
                src_r4r5_c0_8x16b = _mm_unpacklo_epi16(src_r4_8x16b, src_r5_8x16b);
2834
0
2835
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_c0_8x16b, coeff0_1_8x16b);
2836
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_c0_8x16b, coeff2_3_8x16b);
2837
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_c0_8x16b, coeff4_5_8x16b);
2838
0
2839
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
2840
0
                res_t3_4x32b = _mm_add_epi32(const_val512_4x32b, res_t3_4x32b);
2841
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
2842
0
                res_t1_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
2843
0
2844
0
                res_8x16b = _mm_packs_epi32(res_t1_4x32b, res_t1_4x32b);
2845
0
                res_16x8b = _mm_packus_epi16(res_8x16b, res_8x16b);
2846
0
2847
0
                src_hpel_8x16b = _mm_loadl_epi64((__m128i *)(pi2_temp3));
2848
0
                src_hpel_8x16b = _mm_add_epi16(src_hpel_8x16b, const_val16_8x16b);
2849
0
                src_hpel_8x16b = _mm_srai_epi16(src_hpel_8x16b, 5); //shifting right by 5 bits.
2850
0
                src_hpel_16x8b = _mm_packus_epi16(src_hpel_8x16b, src_hpel_8x16b);
2851
0
2852
0
                res_16x8b = _mm_avg_epu8(res_16x8b, src_hpel_16x8b);
2853
0
2854
0
                *((WORD32 *)(pu1_dst)) = _mm_cvtsi128_si32(res_16x8b);
2855
0
2856
0
                ht--;
2857
0
                pi2_temp2 = pi2_temp2 + 4 + 5;
2858
0
                pi2_temp3 = pi2_temp3 + 4 + 5;
2859
0
                pu1_dst = pu1_dst + dst_strd;
2860
0
            }
2861
0
            while(ht > 0);
2862
0
        }
2863
0
    }
2864
0
    else if(wd == 8)
2865
0
    {
2866
0
        // vertical half-pel
2867
0
        {
2868
0
            __m128i src_r0_16x8b, src_r1_16x8b, src_r2_16x8b, src_r3_16x8b, src_r4_16x8b;
2869
0
            __m128i src_r5_16x8b, src_r6_16x8b;
2870
0
            __m128i src_r0r1_16x8b, src_r2r3_16x8b, src_r4r5_16x8b;
2871
0
2872
0
            __m128i res_t1_8x16b, res_t2_8x16b, res_t3_8x16b;
2873
0
2874
0
            __m128i coeff0_1_16x8b, coeff2_3_16x8b, coeff4_5_16x8b;
2875
0
2876
0
            coeff0_1_16x8b = _mm_set1_epi32(0xFB01FB01);  //c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1
2877
0
            coeff2_3_16x8b = _mm_set1_epi32(0x14141414);  //c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3
2878
0
            coeff4_5_16x8b = _mm_set1_epi32(0x01FB01FB);  //c4 c5 c5 c5 c4 c5 c5 c5 c4 c5 c5 c5 c4 c5 c5 c5
2879
0
2880
0
            //epilogue: Load all the pred rows except sixth  and seventh row for the
2881
0
            //first and second row processing.
2882
0
            src_r0_16x8b = _mm_loadu_si128((__m128i *)(pu1_src));
2883
0
            pu1_src =  pu1_src + src_strd;
2884
0
2885
0
            src_r1_16x8b = _mm_loadu_si128((__m128i *)(pu1_src));
2886
0
            pu1_src =  pu1_src + src_strd;
2887
0
2888
0
            src_r2_16x8b = _mm_loadu_si128((__m128i *)(pu1_src));
2889
0
            pu1_src =  pu1_src + src_strd;
2890
0
2891
0
            src_r3_16x8b = _mm_loadu_si128((__m128i *)(pu1_src));
2892
0
            pu1_src =  pu1_src + src_strd;
2893
0
2894
0
            src_r4_16x8b = _mm_loadu_si128((__m128i *)(pu1_src));
2895
0
            pu1_src =  pu1_src + src_strd;
2896
0
2897
0
            //Core Loop: Process all the rows.
2898
0
            do
2899
0
            {
2900
0
                src_r5_16x8b = _mm_loadu_si128((__m128i *)(pu1_src));
2901
0
                src_r6_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + src_strd));
2902
0
2903
0
                src_r0r1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r1_16x8b);
2904
0
                src_r2r3_16x8b = _mm_unpacklo_epi8(src_r2_16x8b, src_r3_16x8b);
2905
0
                src_r4r5_16x8b = _mm_unpacklo_epi8(src_r4_16x8b, src_r5_16x8b);
2906
0
2907
0
                res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
2908
0
                res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
2909
0
                res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);
2910
0
2911
0
                res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t2_8x16b);
2912
0
                res_t1_8x16b = _mm_add_epi16(res_t3_8x16b, res_t1_8x16b);
2913
0
2914
0
                _mm_storeu_si128((__m128i *)(pi2_temp1), res_t1_8x16b);
2915
0
2916
0
                src_r0r1_16x8b = _mm_unpackhi_epi8(src_r0_16x8b, src_r1_16x8b);
2917
0
                src_r2r3_16x8b = _mm_unpackhi_epi8(src_r2_16x8b, src_r3_16x8b);
2918
0
                src_r4r5_16x8b = _mm_unpackhi_epi8(src_r4_16x8b, src_r5_16x8b);
2919
0
2920
0
                res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
2921
0
                res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
2922
0
                res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);
2923
0
2924
0
                res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t2_8x16b);
2925
0
                res_t1_8x16b = _mm_add_epi16(res_t3_8x16b, res_t1_8x16b);
2926
0
2927
0
                _mm_storeu_si128((__m128i *)(pi2_temp1 + 8), res_t1_8x16b);
2928
0
2929
0
                src_r0r1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r2_16x8b);
2930
0
                src_r2r3_16x8b = _mm_unpacklo_epi8(src_r3_16x8b, src_r4_16x8b);
2931
0
                src_r4r5_16x8b = _mm_unpacklo_epi8(src_r5_16x8b, src_r6_16x8b);
2932
0
2933
0
                res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
2934
0
                res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
2935
0
                res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);
2936
0
2937
0
                res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t2_8x16b);
2938
0
                res_t1_8x16b = _mm_add_epi16(res_t3_8x16b, res_t1_8x16b);
2939
0
2940
0
                _mm_storeu_si128((__m128i *)(pi2_temp1 + 8 + 5), res_t1_8x16b);
2941
0
2942
0
                src_r0r1_16x8b = _mm_unpackhi_epi8(src_r1_16x8b, src_r2_16x8b);
2943
0
                src_r2r3_16x8b = _mm_unpackhi_epi8(src_r3_16x8b, src_r4_16x8b);
2944
0
                src_r4r5_16x8b = _mm_unpackhi_epi8(src_r5_16x8b, src_r6_16x8b);
2945
0
2946
0
                res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
2947
0
                res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
2948
0
                res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);
2949
0
2950
0
                res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t2_8x16b);
2951
0
                res_t1_8x16b = _mm_add_epi16(res_t3_8x16b, res_t1_8x16b);
2952
0
2953
0
                _mm_storeu_si128((__m128i *)(pi2_temp1 + 8 + 5 + 8), res_t1_8x16b);
2954
0
2955
0
                src_r0_16x8b = src_r2_16x8b;
2956
0
                src_r1_16x8b = src_r3_16x8b;
2957
0
                src_r2_16x8b = src_r4_16x8b;
2958
0
                src_r3_16x8b = src_r5_16x8b;
2959
0
                src_r4_16x8b = src_r6_16x8b;
2960
0
2961
0
                ht_temp -= 2;
2962
0
                pu1_src =  pu1_src + (src_strd << 1);
2963
0
                pi2_temp1 = pi2_temp1 + (13 << 1);
2964
0
            }
2965
0
            while(ht_temp > 0);
2966
0
        }
2967
0
        // horizontal q-pel
2968
0
        {
2969
0
            __m128i src_r0_8x16b, src_r1_8x16b, src_r2_8x16b, src_r3_8x16b;
2970
0
            __m128i src_r4_8x16b, src_r5_8x16b;
2971
0
            __m128i src_r0r1_c0_8x16b, src_r2r3_c0_8x16b, src_r4r5_c0_8x16b;
2972
0
            __m128i src_r0r1_c1_8x16b, src_r2r3_c1_8x16b, src_r4r5_c1_8x16b;
2973
0
            __m128i src_hpel_8x16b, src_hpel_16x8b;
2974
0
2975
0
            __m128i res_t0_4x32b, res_t1_4x32b, res_t2_4x32b, res_t3_4x32b;
2976
0
            __m128i res_8x16b, res_16x8b;
2977
0
2978
0
            __m128i coeff0_1_8x16b, coeff2_3_8x16b, coeff4_5_8x16b;
2979
0
            __m128i const_val512_4x32b, const_val16_8x16b;
2980
0
2981
0
            coeff0_1_8x16b = _mm_set1_epi32(0xFFFB0001);
2982
0
            coeff2_3_8x16b = _mm_set1_epi32(0x00140014);
2983
0
            coeff4_5_8x16b = _mm_set1_epi32(0x0001FFFB);
2984
0
2985
0
            const_val512_4x32b = _mm_set1_epi32(512);
2986
0
            const_val16_8x16b = _mm_set1_epi16(16);
2987
0
2988
0
            do
2989
0
            {
2990
0
                src_r0_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2));
2991
0
                src_r1_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2 + 1));
2992
0
                src_r2_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2 + 2));
2993
0
                src_r3_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2 + 3));
2994
0
                src_r4_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2 + 4));
2995
0
                src_r5_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2 + 5));
2996
0
2997
0
                src_r0r1_c0_8x16b = _mm_unpacklo_epi16(src_r0_8x16b, src_r1_8x16b);
2998
0
                src_r2r3_c0_8x16b = _mm_unpacklo_epi16(src_r2_8x16b, src_r3_8x16b);
2999
0
                src_r4r5_c0_8x16b = _mm_unpacklo_epi16(src_r4_8x16b, src_r5_8x16b);
3000
0
3001
0
                src_r0r1_c1_8x16b = _mm_unpackhi_epi16(src_r0_8x16b, src_r1_8x16b);
3002
0
                src_r2r3_c1_8x16b = _mm_unpackhi_epi16(src_r2_8x16b, src_r3_8x16b);
3003
0
                src_r4r5_c1_8x16b = _mm_unpackhi_epi16(src_r4_8x16b, src_r5_8x16b);
3004
0
3005
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_c0_8x16b, coeff0_1_8x16b);
3006
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_c0_8x16b, coeff2_3_8x16b);
3007
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_c0_8x16b, coeff4_5_8x16b);
3008
0
3009
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
3010
0
                res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
3011
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
3012
0
3013
0
                res_t0_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
3014
0
3015
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_c1_8x16b, coeff0_1_8x16b);
3016
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_c1_8x16b, coeff2_3_8x16b);
3017
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_c1_8x16b, coeff4_5_8x16b);
3018
0
3019
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
3020
0
                res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
3021
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
3022
0
3023
0
                res_t1_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
3024
0
3025
0
                res_8x16b = _mm_packs_epi32(res_t0_4x32b, res_t1_4x32b);
3026
0
                res_16x8b = _mm_packus_epi16(res_8x16b, res_8x16b);
3027
0
3028
0
                src_hpel_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp3));
3029
0
                src_hpel_8x16b = _mm_add_epi16(src_hpel_8x16b, const_val16_8x16b);
3030
0
                src_hpel_8x16b = _mm_srai_epi16(src_hpel_8x16b, 5); //shifting right by 5 bits.
3031
0
                src_hpel_16x8b = _mm_packus_epi16(src_hpel_8x16b, src_hpel_8x16b);
3032
0
3033
0
                res_16x8b = _mm_avg_epu8(res_16x8b, src_hpel_16x8b);
3034
0
3035
0
                _mm_storel_epi64((__m128i *)(pu1_dst), res_16x8b);
3036
0
3037
0
                ht--;
3038
0
                pi2_temp2 = pi2_temp2 + 8 + 5;
3039
0
                pi2_temp3 = pi2_temp3 + 8 + 5;
3040
0
                pu1_dst = pu1_dst + dst_strd;
3041
0
            }
3042
0
            while(ht > 0);
3043
0
        }
3044
0
    }
3045
0
    else // wd == 16
3046
0
    {
3047
0
        // vertical half-pel
3048
0
        {
3049
0
            __m128i src_r0_16x8b, src_r1_16x8b, src_r2_16x8b, src_r3_16x8b;
3050
0
            __m128i src_r4_16x8b, src_r5_16x8b;
3051
0
            __m128i src_r0_c2_16x8b, src_r1_c2_16x8b, src_r2_c2_16x8b, src_r3_c2_16x8b;
3052
0
            __m128i src_r4_c2_16x8b, src_r5_c2_16x8b;
3053
0
            __m128i src_r0r1_16x8b, src_r2r3_16x8b, src_r4r5_16x8b;
3054
0
3055
0
            __m128i res_t1_8x16b, res_t2_8x16b, res_t3_8x16b;
3056
0
3057
0
            __m128i coeff0_1_16x8b,coeff2_3_16x8b,coeff4_5_16x8b;
3058
0
3059
0
            coeff0_1_16x8b = _mm_set1_epi32(0xFB01FB01);  //c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1
3060
0
            coeff2_3_16x8b = _mm_set1_epi32(0x14141414);  //c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3
3061
0
            coeff4_5_16x8b = _mm_set1_epi32(0x01FB01FB);  //c4 c5 c5 c5 c4 c5 c5 c5 c4 c5 c5 c5 c4 c5 c5 c5
3062
0
3063
0
            src_r0_16x8b = _mm_loadu_si128((__m128i *)(pu1_src));
3064
0
            src_r0_c2_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + 16));
3065
0
            pu1_src =  pu1_src + src_strd;
3066
0
            src_r1_16x8b = _mm_loadu_si128((__m128i *)(pu1_src));
3067
0
            src_r1_c2_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + 16));
3068
0
            pu1_src =  pu1_src + src_strd;
3069
0
            src_r2_16x8b = _mm_loadu_si128((__m128i *)(pu1_src));
3070
0
            src_r2_c2_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + 16));
3071
0
            pu1_src =  pu1_src + src_strd;
3072
0
            src_r3_16x8b = _mm_loadu_si128((__m128i *)(pu1_src));
3073
0
            src_r3_c2_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + 16));
3074
0
            pu1_src =  pu1_src + src_strd;
3075
0
            src_r4_16x8b = _mm_loadu_si128((__m128i *)(pu1_src));
3076
0
            src_r4_c2_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + 16));
3077
0
            pu1_src =  pu1_src + src_strd;
3078
0
3079
0
            //Core Loop: Process all the rows.
3080
0
            do
3081
0
            {
3082
0
                src_r5_16x8b  = _mm_loadu_si128((__m128i *)(pu1_src));
3083
0
                src_r5_c2_16x8b  = _mm_loadu_si128((__m128i *)(pu1_src + 16));
3084
0
3085
0
                src_r0r1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r1_16x8b);
3086
0
                src_r2r3_16x8b = _mm_unpacklo_epi8(src_r2_16x8b, src_r3_16x8b);
3087
0
                src_r4r5_16x8b = _mm_unpacklo_epi8(src_r4_16x8b, src_r5_16x8b);
3088
0
3089
0
                res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
3090
0
                res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
3091
0
                res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);
3092
0
3093
0
                res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t2_8x16b);
3094
0
                res_t1_8x16b = _mm_add_epi16(res_t3_8x16b, res_t1_8x16b);
3095
0
3096
0
                _mm_storeu_si128((__m128i *)(pi2_temp1), res_t1_8x16b);
3097
0
3098
0
                src_r0r1_16x8b = _mm_unpackhi_epi8(src_r0_16x8b, src_r1_16x8b);
3099
0
                src_r2r3_16x8b = _mm_unpackhi_epi8(src_r2_16x8b, src_r3_16x8b);
3100
0
                src_r4r5_16x8b = _mm_unpackhi_epi8(src_r4_16x8b, src_r5_16x8b);
3101
0
3102
0
                res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
3103
0
                res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
3104
0
                res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);
3105
0
3106
0
                res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t2_8x16b);
3107
0
                res_t1_8x16b = _mm_add_epi16(res_t3_8x16b, res_t1_8x16b);
3108
0
3109
0
                _mm_storeu_si128((__m128i *)(pi2_temp1 + 8), res_t1_8x16b);
3110
0
3111
0
                src_r0r1_16x8b = _mm_unpacklo_epi8(src_r0_c2_16x8b, src_r1_c2_16x8b);
3112
0
                src_r2r3_16x8b = _mm_unpacklo_epi8(src_r2_c2_16x8b, src_r3_c2_16x8b);
3113
0
                src_r4r5_16x8b = _mm_unpacklo_epi8(src_r4_c2_16x8b, src_r5_c2_16x8b);
3114
0
3115
0
                res_t1_8x16b = _mm_maddubs_epi16(src_r0r1_16x8b, coeff0_1_16x8b);
3116
0
                res_t2_8x16b = _mm_maddubs_epi16(src_r2r3_16x8b, coeff2_3_16x8b);
3117
0
                res_t3_8x16b = _mm_maddubs_epi16(src_r4r5_16x8b, coeff4_5_16x8b);
3118
0
3119
0
                res_t1_8x16b = _mm_add_epi16(res_t1_8x16b, res_t2_8x16b);
3120
0
                res_t1_8x16b = _mm_add_epi16(res_t3_8x16b, res_t1_8x16b);
3121
0
3122
0
                _mm_storeu_si128((__m128i *)(pi2_temp1 + 16), res_t1_8x16b);
3123
0
3124
0
                src_r0_16x8b = src_r1_16x8b;
3125
0
                src_r1_16x8b = src_r2_16x8b;
3126
0
                src_r2_16x8b = src_r3_16x8b;
3127
0
                src_r3_16x8b = src_r4_16x8b;
3128
0
                src_r4_16x8b = src_r5_16x8b;
3129
0
3130
0
                src_r0_c2_16x8b = src_r1_c2_16x8b;
3131
0
                src_r1_c2_16x8b = src_r2_c2_16x8b;
3132
0
                src_r2_c2_16x8b = src_r3_c2_16x8b;
3133
0
                src_r3_c2_16x8b = src_r4_c2_16x8b;
3134
0
                src_r4_c2_16x8b = src_r5_c2_16x8b;
3135
0
3136
0
                ht_temp--;
3137
0
                pu1_src =  pu1_src + src_strd;
3138
0
                pi2_temp1 =  pi2_temp1 + 16 + 5;
3139
0
            }
3140
0
            while(ht_temp > 0);
3141
0
        }
3142
0
        // horizontal q-pel
3143
0
        {
3144
0
            __m128i src_r0_8x16b, src_r1_8x16b, src_r2_8x16b, src_r3_8x16b;
3145
0
            __m128i src_r4_8x16b, src_r5_8x16b;
3146
0
            __m128i src_r0r1_8x16b, src_r2r3_8x16b, src_r4r5_8x16b;
3147
0
            __m128i src_hpel1_8x16b, src_hpel2_8x16b, src_hpel_16x8b;
3148
0
3149
0
            __m128i res_t0_4x32b, res_t1_4x32b, res_t2_4x32b, res_t3_4x32b;
3150
0
            __m128i res_c0_8x16b, res_c1_8x16b, res_16x8b;
3151
0
3152
0
            __m128i coeff0_1_8x16b, coeff2_3_8x16b, coeff4_5_8x16b;
3153
0
            __m128i const_val512_4x32b, const_val16_8x16b;
3154
0
3155
0
            coeff0_1_8x16b = _mm_set1_epi32(0xFFFB0001);
3156
0
            coeff2_3_8x16b = _mm_set1_epi32(0x00140014);
3157
0
            coeff4_5_8x16b = _mm_set1_epi32(0x0001FFFB);
3158
0
3159
0
            const_val512_4x32b = _mm_set1_epi32(512);
3160
0
            const_val16_8x16b = _mm_set1_epi16(16);
3161
0
3162
0
            do
3163
0
            {
3164
0
                src_r0_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2));
3165
0
                src_r1_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2 + 1));
3166
0
                src_r2_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2 + 2));
3167
0
                src_r3_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2 + 3));
3168
0
                src_r4_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2 + 4));
3169
0
                src_r5_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2 + 5));
3170
0
3171
0
                src_r0r1_8x16b = _mm_unpacklo_epi16(src_r0_8x16b, src_r1_8x16b);
3172
0
                src_r2r3_8x16b = _mm_unpacklo_epi16(src_r2_8x16b, src_r3_8x16b);
3173
0
                src_r4r5_8x16b = _mm_unpacklo_epi16(src_r4_8x16b, src_r5_8x16b);
3174
0
3175
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_8x16b, coeff0_1_8x16b);
3176
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_8x16b, coeff2_3_8x16b);
3177
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_8x16b, coeff4_5_8x16b);
3178
0
3179
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
3180
0
                res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
3181
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
3182
0
                res_t0_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
3183
0
3184
0
                src_r0r1_8x16b = _mm_unpackhi_epi16(src_r0_8x16b, src_r1_8x16b);
3185
0
                src_r2r3_8x16b = _mm_unpackhi_epi16(src_r2_8x16b, src_r3_8x16b);
3186
0
                src_r4r5_8x16b = _mm_unpackhi_epi16(src_r4_8x16b, src_r5_8x16b);
3187
0
3188
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_8x16b, coeff0_1_8x16b);
3189
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_8x16b, coeff2_3_8x16b);
3190
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_8x16b, coeff4_5_8x16b);
3191
0
3192
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
3193
0
                res_t3_4x32b = _mm_add_epi32(const_val512_4x32b, res_t3_4x32b);
3194
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
3195
0
                res_t1_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
3196
0
3197
0
                res_c0_8x16b = _mm_packs_epi32(res_t0_4x32b, res_t1_4x32b);
3198
0
3199
0
                src_r0_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2 + 8));
3200
0
                src_r1_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2 + 8 + 1));
3201
0
                src_r2_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2 + 8 + 2));
3202
0
                src_r3_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2 + 8 + 3));
3203
0
                src_r4_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2 + 8 + 4));
3204
0
                src_r5_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2 + 8 + 5));
3205
0
3206
0
                src_r0r1_8x16b = _mm_unpacklo_epi16(src_r0_8x16b, src_r1_8x16b);
3207
0
                src_r2r3_8x16b = _mm_unpacklo_epi16(src_r2_8x16b, src_r3_8x16b);
3208
0
                src_r4r5_8x16b = _mm_unpacklo_epi16(src_r4_8x16b, src_r5_8x16b);
3209
0
3210
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_8x16b, coeff0_1_8x16b);
3211
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_8x16b, coeff2_3_8x16b);
3212
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_8x16b, coeff4_5_8x16b);
3213
0
3214
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
3215
0
                res_t3_4x32b = _mm_add_epi32(const_val512_4x32b, res_t3_4x32b);
3216
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
3217
0
                res_t0_4x32b = _mm_srai_epi32(res_t1_4x32b ,10);
3218
0
3219
0
                src_r0r1_8x16b = _mm_unpackhi_epi16(src_r0_8x16b, src_r1_8x16b);
3220
0
                src_r2r3_8x16b = _mm_unpackhi_epi16(src_r2_8x16b, src_r3_8x16b);
3221
0
                src_r4r5_8x16b = _mm_unpackhi_epi16(src_r4_8x16b, src_r5_8x16b);
3222
0
3223
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_8x16b, coeff0_1_8x16b);
3224
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_8x16b, coeff2_3_8x16b);
3225
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_8x16b, coeff4_5_8x16b);
3226
0
3227
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
3228
0
                res_t3_4x32b = _mm_add_epi32(const_val512_4x32b, res_t3_4x32b);
3229
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
3230
0
                res_t1_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
3231
0
3232
0
                res_c1_8x16b = _mm_packs_epi32(res_t0_4x32b, res_t1_4x32b);
3233
0
                res_16x8b = _mm_packus_epi16(res_c0_8x16b, res_c1_8x16b);
3234
0
3235
0
                src_hpel1_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp3));
3236
0
                src_hpel1_8x16b = _mm_add_epi16(src_hpel1_8x16b, const_val16_8x16b);
3237
0
                src_hpel1_8x16b = _mm_srai_epi16(src_hpel1_8x16b, 5); //shifting right by 5 bits.
3238
0
3239
0
                src_hpel2_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp3 + 8));
3240
0
                src_hpel2_8x16b = _mm_add_epi16(src_hpel2_8x16b, const_val16_8x16b);
3241
0
                src_hpel2_8x16b = _mm_srai_epi16(src_hpel2_8x16b, 5); //shifting right by 5 bits.
3242
0
3243
0
                src_hpel_16x8b = _mm_packus_epi16(src_hpel1_8x16b, src_hpel2_8x16b);
3244
0
                res_16x8b = _mm_avg_epu8(res_16x8b, src_hpel_16x8b);
3245
0
3246
0
                _mm_storeu_si128((__m128i *)(pu1_dst), res_16x8b);
3247
0
3248
0
                ht--;
3249
0
                pi2_temp2 = pi2_temp2 + 16 + 5;
3250
0
                pi2_temp3 = pi2_temp3 + 16 + 5;
3251
0
                pu1_dst = pu1_dst + dst_strd;
3252
0
            }
3253
0
            while(ht > 0);
3254
0
        }
3255
0
    }
3256
0
}
3257
3258
/*****************************************************************************/
3259
/*                                                                           */
3260
/*  Function Name : ih264_inter_pred_luma_horz_hpel_vert_qpel_ssse3          */
3261
/*                                                                           */
3262
/*  Description   : This function implements a six-tap filter vertically and */
3263
/*                  horizontally on ht x wd block separately and averages    */
3264
/*                  the two sets of values to calculate values at (1/2,1/4), */
3265
/*                  or (1/2, 3/4) as mentioned in sec. 8.4.2.2.1 titled      */
3266
/*                  "Luma sample interpolation process". (ht,wd) can be      */
3267
/*                  (4,4), (8,4), (4,8), (8,8), (16,8), (8,16) or (16,16).   */
3268
/*                                                                           */
3269
/*  Inputs        : puc_src  - pointer to source                             */
3270
/*                  puc_dst  - pointer to destination                        */
3271
/*                  src_strd - stride for source                             */
3272
/*                  dst_strd - stride for destination                        */
3273
/*                  ht       - height of the block                           */
3274
/*                  wd       - width of the block                            */
3275
/*                  pu1_tmp  - pointer to temporary buffer                   */
3276
/*                  dydx     - x and y reference offset for q-pel            */
3277
/*                             calculations                                  */
3278
/*                                                                           */
3279
/*  Issues        : None                                                     */
3280
/*                                                                           */
3281
/*  Revision History:                                                        */
3282
/*                                                                           */
3283
/*         DD MM YYYY   Author(s)       Changes                              */
3284
/*         13 02 2015   Kaushik         Initial Version                      */
3285
/*                      Senthoor                                             */
3286
/*                                                                           */
3287
/*****************************************************************************/
3288
void ih264_inter_pred_luma_horz_hpel_vert_qpel_ssse3(UWORD8 *pu1_src,
3289
                                                     UWORD8 *pu1_dst,
3290
                                                     WORD32 src_strd,
3291
                                                     WORD32 dst_strd,
3292
                                                     WORD32 ht,
3293
                                                     WORD32 wd,
3294
                                                     UWORD8* pu1_tmp,
3295
                                                     WORD32 dydx)
3296
0
{
3297
0
    WORD32 ht_temp;
3298
0
    WORD32 y_offset;
3299
0
    WORD16 *pi2_temp1,*pi2_temp2,*pi2_temp3;
3300
0
3301
0
    y_offset = (dydx & 0xf) >> 2;
3302
0
    pi2_temp1 = (WORD16 *)pu1_tmp;
3303
0
    pi2_temp2 = pi2_temp1;
3304
0
    pi2_temp3 = pi2_temp1 + (y_offset >> 1) * wd;
3305
0
3306
0
    ht_temp = ht + 5;
3307
0
    pu1_src -= src_strd << 1;
3308
0
    pu1_src -= 2;
3309
0
    pi2_temp3 += wd << 1;
3310
0
    //the filter input starts from x[-2] (till x[3])
3311
0
3312
0
    if(wd == 4)
3313
0
    {
3314
0
        // horizontal half-pel
3315
0
        {
3316
0
            __m128i src_r0_16x8b, src_r1_16x8b, src_r0r1_t1_16x8b;
3317
0
            __m128i src_r0_sht_16x8b, src_r1_sht_16x8b;
3318
0
            __m128i res_r0r1_t1_8x16b, res_r0r1_t2_8x16b, res_r0r1_t3_8x16b;
3319
0
            __m128i coeff0_1_16x8b, coeff2_3_16x8b, coeff4_5_16x8b;
3320
0
3321
0
            coeff0_1_16x8b = _mm_set1_epi32(0xFB01FB01);  //c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1
3322
0
            coeff2_3_16x8b = _mm_set1_epi32(0x14141414);  //c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3
3323
0
            coeff4_5_16x8b = _mm_set1_epi32(0x01FB01FB);  //c4 c5 c5 c5 c4 c5 c5 c5 c4 c5 c5 c5 c4 c5 c5 c5
3324
0
3325
0
            //Row0 : a0 a1 a2 a3 a4 a5 a6 a7 a8 a9.....
3326
0
            //Row1 : b0 b1 b2 b3 b4 b5 b6 b7 b8 b9.....
3327
0
3328
0
            do
3329
0
            {
3330
0
                src_r0_16x8b = _mm_loadu_si128((__m128i *)pu1_src);                         //a0 a1 a2 a3 a4 a5 a6 a7 a8 a9....a15
3331
0
                src_r1_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + src_strd));            //b0 b1 b2 b3 b4 b5 b6 b7 b8 b9....b15
3332
0
3333
0
                src_r0_sht_16x8b = _mm_srli_si128(src_r0_16x8b, 1);                         //a1 a2 a3 a4 a5 a6 a7 a8 a9....a15 0
3334
0
                src_r1_sht_16x8b = _mm_srli_si128(src_r1_16x8b, 1);                         //b1 b2 b3 b4 b5 b6 b7 b8 b9....b15 0
3335
0
3336
0
                src_r0_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);           //a0 a1 a1 a2 a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8
3337
0
                src_r1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);           //b0 b1 b1 b2 b2 b3 b3 b4 b4 b5 b5 b6 b6 b7 b7 b8
3338
0
3339
0
                src_r0r1_t1_16x8b = _mm_unpacklo_epi64(src_r0_16x8b, src_r1_16x8b);         //a0 a1 a1 a2 a2 a3 a3 a4 b0 b1 b1 b2 b2 b3 b3 b4
3340
0
                res_r0r1_t1_8x16b = _mm_maddubs_epi16(src_r0r1_t1_16x8b, coeff0_1_16x8b);   //a0*c0+a1*c1 a1*c0+a2*c1 a2*c0+a3*c1 a3*c0+a4*c1
3341
0
                                                                                            //b0*c0+b1*c1 b1*c0+b2*c1 b2*c0+b3*c1 b3*c0+b4*c1
3342
0
3343
0
                src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 4);                             //a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8  0  0  0  0
3344
0
                src_r1_16x8b = _mm_srli_si128(src_r1_16x8b, 4);                             //b2 b3 b3 b4 b4 b5 b5 b6 b6 b7 b7 b8  0  0  0  0
3345
0
3346
0
                src_r0r1_t1_16x8b = _mm_unpacklo_epi64(src_r0_16x8b, src_r1_16x8b);         //a2 a3 a3 a4 a4 a5 a5 a6 b2 b3 b3 b4 b4 b5 b5 b6
3347
0
                res_r0r1_t2_8x16b = _mm_maddubs_epi16(src_r0r1_t1_16x8b, coeff2_3_16x8b);   //a2*c2+a3*c3 a3*c2+a4*c3 a4*c2+a5*c3 a5*c2+a6*c3
3348
0
                                                                                            //b2*c2+b3*c3 b3*c2+b4*c3 b4*c2+b5*c3 b5*c2+b6*c3
3349
0
3350
0
                src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 4);                             //a4 a5 a5 a6 a6 a7 a7 a8  0  0  0  0  0  0  0  0
3351
0
                src_r1_16x8b = _mm_srli_si128(src_r1_16x8b, 4);                             //b4 b5 b5 b6 b6 b7 b7 b8  0  0  0  0  0  0  0  0
3352
0
3353
0
                src_r0r1_t1_16x8b = _mm_unpacklo_epi64(src_r0_16x8b, src_r1_16x8b);         //a4 a5 a5 a6 a6 a7 a7 a8 b4 b5 b5 b6 b6 b7 b7 b8
3354
0
                res_r0r1_t3_8x16b = _mm_maddubs_epi16(src_r0r1_t1_16x8b, coeff4_5_16x8b);   //a4*c4+a5*c5 a5*c4+a6*c5 a6*c4+a7*c5 a7*c4+a8*c5
3355
0
                                                                                            //b4*c4+b5*c5 b5*c4+b6*c5 b4*c6+b7*c5 b7*c4+b8*c5
3356
0
3357
0
                res_r0r1_t1_8x16b = _mm_add_epi16(res_r0r1_t1_8x16b, res_r0r1_t2_8x16b);
3358
0
                res_r0r1_t1_8x16b = _mm_add_epi16(res_r0r1_t1_8x16b, res_r0r1_t3_8x16b);
3359
0
3360
0
3361
0
                _mm_storeu_si128((__m128i *)(pi2_temp1), res_r0r1_t1_8x16b);
3362
0
3363
0
                ht_temp -= 2;
3364
0
                pu1_src =  pu1_src + (src_strd << 1);
3365
0
                pi2_temp1 =  pi2_temp1 + (4 << 1);
3366
0
            }
3367
0
            while(ht_temp > 0);
3368
0
        }
3369
0
        // vertical q-pel
3370
0
        {
3371
0
            __m128i src_r0_8x16b, src_r1_8x16b, src_r2_8x16b, src_r3_8x16b;
3372
0
            __m128i src_r4_8x16b, src_r5_8x16b, src_r6_8x16b;
3373
0
            __m128i src_r0r1_c0_8x16b, src_r2r3_c0_8x16b, src_r4r5_c0_8x16b;
3374
0
            __m128i src_hpel_16x8b, src_hpel_8x16b;
3375
0
3376
0
            __m128i res_t0_4x32b, res_t1_4x32b, res_t2_4x32b, res_t3_4x32b;
3377
0
            __m128i res_8x16b, res_16x8b;
3378
0
3379
0
            __m128i coeff0_1_8x16b, coeff2_3_8x16b, coeff4_5_8x16b;
3380
0
            __m128i const_val512_4x32b, const_val16_8x16b;
3381
0
3382
0
            const_val512_4x32b = _mm_set1_epi32(512);
3383
0
            const_val16_8x16b = _mm_set1_epi16(16);
3384
0
3385
0
            coeff0_1_8x16b = _mm_set1_epi32(0xFFFB0001);
3386
0
            coeff2_3_8x16b = _mm_set1_epi32(0x00140014);
3387
0
            coeff4_5_8x16b = _mm_set1_epi32(0x0001FFFB);
3388
0
3389
0
            src_r0_8x16b = _mm_loadl_epi64((__m128i *)(pi2_temp2));
3390
0
            src_r1_8x16b = _mm_loadl_epi64((__m128i *)(pi2_temp2 + 4));
3391
0
            src_r2_8x16b = _mm_loadl_epi64((__m128i *)(pi2_temp2 + 8));
3392
0
            src_r3_8x16b = _mm_loadl_epi64((__m128i *)(pi2_temp2 + 12));
3393
0
            src_r4_8x16b = _mm_loadl_epi64((__m128i *)(pi2_temp2 + 16));
3394
0
            pi2_temp2 += 20;
3395
0
3396
0
            do
3397
0
            {
3398
0
                src_r5_8x16b = _mm_loadl_epi64((__m128i *)(pi2_temp2));
3399
0
                src_r6_8x16b = _mm_loadl_epi64((__m128i *)(pi2_temp2 + 4));
3400
0
3401
0
                src_r0r1_c0_8x16b = _mm_unpacklo_epi16(src_r0_8x16b, src_r1_8x16b);
3402
0
                src_r2r3_c0_8x16b = _mm_unpacklo_epi16(src_r2_8x16b, src_r3_8x16b);
3403
0
                src_r4r5_c0_8x16b = _mm_unpacklo_epi16(src_r4_8x16b, src_r5_8x16b);
3404
0
3405
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_c0_8x16b, coeff0_1_8x16b);
3406
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_c0_8x16b, coeff2_3_8x16b);
3407
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_c0_8x16b, coeff4_5_8x16b);
3408
0
3409
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
3410
0
                res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
3411
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
3412
0
                res_t0_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
3413
0
3414
0
                src_r0r1_c0_8x16b = _mm_unpacklo_epi16(src_r1_8x16b, src_r2_8x16b);
3415
0
                src_r2r3_c0_8x16b = _mm_unpacklo_epi16(src_r3_8x16b, src_r4_8x16b);
3416
0
                src_r4r5_c0_8x16b = _mm_unpacklo_epi16(src_r5_8x16b, src_r6_8x16b);
3417
0
3418
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_c0_8x16b, coeff0_1_8x16b);
3419
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_c0_8x16b, coeff2_3_8x16b);
3420
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_c0_8x16b, coeff4_5_8x16b);
3421
0
3422
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
3423
0
                res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
3424
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
3425
0
                res_t1_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
3426
0
3427
0
                res_8x16b = _mm_packs_epi32(res_t0_4x32b, res_t1_4x32b);
3428
0
                res_16x8b = _mm_packus_epi16(res_8x16b, res_8x16b);
3429
0
3430
0
                src_hpel_8x16b = _mm_loadu_si128((__m128i *)pi2_temp3);
3431
0
                src_hpel_8x16b = _mm_add_epi16(src_hpel_8x16b, const_val16_8x16b);
3432
0
                src_hpel_8x16b = _mm_srai_epi16(src_hpel_8x16b, 5); //shifting right by 5 bits.
3433
0
                src_hpel_16x8b = _mm_packus_epi16(src_hpel_8x16b, src_hpel_8x16b);
3434
0
3435
0
                res_16x8b = _mm_avg_epu8(res_16x8b, src_hpel_16x8b);
3436
0
3437
0
                *((WORD32 *)(pu1_dst)) = _mm_cvtsi128_si32(res_16x8b);
3438
0
                res_16x8b = _mm_srli_si128(res_16x8b, 4);
3439
0
                *((WORD32 *)(pu1_dst + dst_strd)) = _mm_cvtsi128_si32(res_16x8b);
3440
0
3441
0
                src_r0_8x16b = src_r2_8x16b;
3442
0
                src_r1_8x16b = src_r3_8x16b;
3443
0
                src_r2_8x16b = src_r4_8x16b;
3444
0
                src_r3_8x16b = src_r5_8x16b;
3445
0
                src_r4_8x16b = src_r6_8x16b;
3446
0
3447
0
                ht -= 2;
3448
0
                pi2_temp2 =  pi2_temp2 + (4 << 1);
3449
0
                pi2_temp3 =  pi2_temp3 + (4 << 1);
3450
0
                pu1_dst = pu1_dst + (dst_strd << 1);
3451
0
            }
3452
0
            while(ht > 0);
3453
0
        }
3454
0
    }
3455
0
    else if(wd == 8)
3456
0
    {
3457
0
        // horizontal half-pel
3458
0
        {
3459
0
            __m128i src_r0_16x8b, src_r1_16x8b, src_r0_sht_16x8b, src_r1_sht_16x8b;
3460
0
            __m128i src_r0_t1_16x8b, src_r1_t1_16x8b;
3461
0
3462
0
            __m128i res_r0_t1_8x16b, res_r0_t2_8x16b, res_r0_t3_8x16b;
3463
0
            __m128i res_r1_t1_8x16b, res_r1_t2_8x16b, res_r1_t3_8x16b;
3464
0
3465
0
            __m128i coeff0_1_16x8b, coeff2_3_16x8b, coeff4_5_16x8b;
3466
0
3467
0
            coeff0_1_16x8b = _mm_set1_epi32(0xFB01FB01);  //c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1
3468
0
            coeff2_3_16x8b = _mm_set1_epi32(0x14141414);  //c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3
3469
0
            coeff4_5_16x8b = _mm_set1_epi32(0x01FB01FB);  //c4 c5 c5 c5 c4 c5 c5 c5 c4 c5 c5 c5 c4 c5 c5 c5
3470
0
3471
0
            //Row0 : a0 a1 a2 a3 a4 a5 a6 a7 a8 a9.....
3472
0
            //Row1 : b0 b1 b2 b3 b4 b5 b6 b7 b8 b9.....
3473
0
3474
0
            do
3475
0
            {
3476
0
                src_r0_16x8b = _mm_loadu_si128((__m128i *)(pu1_src));                   //a0 a1 a2 a3 a4 a5 a6 a7 a8 a9....a15
3477
0
                src_r1_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + src_strd));        //b0 b1 b2 b3 b4 b5 b6 b7 b8 b9....b15
3478
0
3479
0
                src_r0_sht_16x8b = _mm_srli_si128(src_r0_16x8b, 1);                     //a1 a2 a3 a4 a5 a6 a7 a8 a9....a15 0
3480
0
                src_r1_sht_16x8b = _mm_srli_si128(src_r1_16x8b, 1);                     //b1 b2 b3 b4 b5 b6 b7 b8 b9....b15 0
3481
0
3482
0
                src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);    //a0 a1 a1 a2 a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8
3483
0
                src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);    //b0 b1 b1 b2 b2 b3 b3 b4 b4 b5 b5 b6 b6 b7 b7 b8
3484
0
3485
0
                res_r0_t1_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff0_1_16x8b);   //a0*c0+a1*c1 a1*c0+a2*c1 a2*c0+a3*c1 a3*c0+a4*c1
3486
0
                                                                                        //a4*c0+a5*c1 a5*c0+a6*c1 a6*c0+a7*c1 a7*c0+a8*c1
3487
0
                res_r1_t1_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff0_1_16x8b);   //b0*c0+b1*c1 b1*c0+b2*c1 b2*c0+b3*c1 b3*c0+b4*c1
3488
0
                                                                                        //b4*c0+b5*c1 b5*c0+b6*c1 b6*c0+b7*c1 b7*c0+b8*c1
3489
0
3490
0
                src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 2);                         //a2 a3 a4 a5 a6 a7 a8 a9....a15 0 0
3491
0
                src_r1_16x8b = _mm_srli_si128(src_r1_16x8b, 2);                         //b2 b3 b4 b5 b6 b7 b8 b9....b15 0 0
3492
0
3493
0
                src_r0_sht_16x8b = _mm_srli_si128(src_r0_sht_16x8b, 2);                 //a3 a4 a5 a6 a7 a8 a9....a15 0  0  0
3494
0
                src_r1_sht_16x8b = _mm_srli_si128(src_r1_sht_16x8b, 2);                 //b3 b4 b5 b6 b7 b8 b9....b15 0  0  0
3495
0
3496
0
                src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);    //a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8 a8 a9 a9 a10
3497
0
                src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);    //b2 b3 b3 b4 b4 b5 b5 b6 b6 b7 b7 b8 a8 a9 a9 a10
3498
0
3499
0
                res_r0_t2_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff2_3_16x8b);   //a2*c2+a3*c3 a3*c2+a4*c3 a4*c2+a5*c3 a5*c2+a6*c3
3500
0
                                                                                        //a6*c2+a7*c3 a7*c2+a8*c3 a8*c2+a9*c3 a9*c2+a10*c3
3501
0
                res_r1_t2_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff2_3_16x8b);   //b2*c2+b3*c3 b3*c2+b4*c3 b2*c4+b5*c3 b5*c2+b6*c3
3502
0
                                                                                        //b6*c2+b7*c3 b7*c2+b8*c3 b8*c2+b9*c3 b9*c2+b10*c3
3503
0
3504
0
                src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 2);                         //a4 a5 a6 a7 a8 a9....a15 0  0  0  0
3505
0
                src_r1_16x8b = _mm_srli_si128(src_r1_16x8b, 2);                         //b4 b5 b6 b7 b8 b9....b15 0  0  0  0
3506
0
3507
0
                src_r0_sht_16x8b = _mm_srli_si128(src_r0_sht_16x8b, 2);                 //a5 a6 a7 a8 a9....a15 0  0  0  0  0
3508
0
                src_r1_sht_16x8b = _mm_srli_si128(src_r1_sht_16x8b, 2);                 //b5 b6 b7 b8 b9....b15 0  0  0  0  0
3509
0
3510
0
                src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);    //a4 a5 a5 a6 a6 a7 a7 a8 a8 a9 a9 a10 a10 a11 a11 a12
3511
0
                src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);    //b4 b5 b5 b6 b6 b7 b7 b8 b8 b9 b9 b10 b10 b11 b11 b12
3512
0
3513
0
                res_r0_t3_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff4_5_16x8b);   //a4*c4+a5*c5 a5*c4+a6*c5 a6*c4+a7*c5 a7*c4+a8*c5
3514
0
                                                                                        //a8*c4+a9*c5 a9*c4+a10*c5 a10*c4+a11*c5 a11*c4+a12*c5
3515
0
                res_r1_t3_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff4_5_16x8b);   //b4*c4+b5*c5 b5*c4+b6*c5 b6*c4+b7*c5 b7*c4+b8*c5
3516
0
                                                                                        //b8*c4+b9*c5 b9*c4+b10*c5 b10*c4+b11*c5 b11*c4+b12*c5
3517
0
                res_r0_t1_8x16b = _mm_add_epi16(res_r0_t1_8x16b, res_r0_t2_8x16b);
3518
0
                res_r0_t1_8x16b = _mm_add_epi16(res_r0_t1_8x16b, res_r0_t3_8x16b);
3519
0
3520
0
                res_r1_t1_8x16b = _mm_add_epi16(res_r1_t1_8x16b, res_r1_t2_8x16b);
3521
0
                res_r1_t1_8x16b = _mm_add_epi16(res_r1_t1_8x16b, res_r1_t3_8x16b);
3522
0
3523
0
                _mm_storeu_si128((__m128i *)(pi2_temp1), res_r0_t1_8x16b);
3524
0
                _mm_storeu_si128((__m128i *)(pi2_temp1 + 8), res_r1_t1_8x16b);
3525
0
3526
0
                ht_temp -= 2;
3527
0
                pu1_src =  pu1_src + (src_strd << 1);
3528
0
                pi2_temp1 =  pi2_temp1 + (8 << 1);
3529
0
            }
3530
0
            while(ht_temp > 0);
3531
0
        }
3532
0
        // vertical q-pel
3533
0
        {
3534
0
            __m128i src_r0_8x16b, src_r1_8x16b, src_r2_8x16b, src_r3_8x16b;
3535
0
            __m128i src_r4_8x16b, src_r5_8x16b, src_r6_8x16b;
3536
0
            __m128i src_r0r1_8x16b, src_r2r3_8x16b, src_r4r5_8x16b;
3537
0
            __m128i src_hpel_8x16b, src_hpel_16x8b;
3538
0
3539
0
            __m128i res_t0_4x32b, res_t1_4x32b, res_t2_4x32b, res_t3_4x32b;
3540
0
            __m128i res_8x16b, res_16x8b;
3541
0
3542
0
            __m128i coeff0_1_8x16b, coeff2_3_8x16b, coeff4_5_8x16b;
3543
0
            __m128i const_val512_4x32b, const_val16_8x16b;
3544
0
3545
0
            coeff0_1_8x16b = _mm_set1_epi32(0xFFFB0001);
3546
0
            coeff2_3_8x16b = _mm_set1_epi32(0x00140014);
3547
0
            coeff4_5_8x16b = _mm_set1_epi32(0x0001FFFB);
3548
0
3549
0
            const_val512_4x32b = _mm_set1_epi32(512);
3550
0
            const_val16_8x16b = _mm_set1_epi16(16);
3551
0
3552
0
            src_r0_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2));
3553
0
            src_r1_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2 + 8));
3554
0
            src_r2_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2 + 16));
3555
0
            src_r3_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2 + 24));
3556
0
            src_r4_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2 + 32));
3557
0
            pi2_temp2 += 40;
3558
0
3559
0
            do
3560
0
            {
3561
0
                src_r5_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2));
3562
0
                src_r6_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2 + 8));
3563
0
3564
0
                src_r0r1_8x16b = _mm_unpacklo_epi16(src_r0_8x16b, src_r1_8x16b);
3565
0
                src_r2r3_8x16b = _mm_unpacklo_epi16(src_r2_8x16b, src_r3_8x16b);
3566
0
                src_r4r5_8x16b = _mm_unpacklo_epi16(src_r4_8x16b, src_r5_8x16b);
3567
0
3568
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_8x16b, coeff0_1_8x16b);
3569
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_8x16b, coeff2_3_8x16b);
3570
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_8x16b, coeff4_5_8x16b);
3571
0
3572
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
3573
0
                res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
3574
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
3575
0
                res_t0_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
3576
0
3577
0
                src_r0r1_8x16b = _mm_unpackhi_epi16(src_r0_8x16b, src_r1_8x16b);
3578
0
                src_r2r3_8x16b = _mm_unpackhi_epi16(src_r2_8x16b, src_r3_8x16b);
3579
0
                src_r4r5_8x16b = _mm_unpackhi_epi16(src_r4_8x16b, src_r5_8x16b);
3580
0
3581
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_8x16b, coeff0_1_8x16b);
3582
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_8x16b, coeff2_3_8x16b);
3583
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_8x16b, coeff4_5_8x16b);
3584
0
3585
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
3586
0
                res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
3587
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
3588
0
                res_t1_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
3589
0
3590
0
                res_8x16b = _mm_packs_epi32(res_t0_4x32b, res_t1_4x32b);
3591
0
                res_16x8b = _mm_packus_epi16(res_8x16b, res_8x16b);
3592
0
3593
0
                src_hpel_8x16b = _mm_loadu_si128((__m128i *)pi2_temp3);
3594
0
                src_hpel_8x16b = _mm_add_epi16(const_val16_8x16b, src_hpel_8x16b);
3595
0
                src_hpel_8x16b = _mm_srai_epi16(src_hpel_8x16b, 5); //shifting right by 5 bits.
3596
0
                src_hpel_16x8b = _mm_packus_epi16(src_hpel_8x16b, src_hpel_8x16b);
3597
0
3598
0
                res_16x8b = _mm_avg_epu8(res_16x8b, src_hpel_16x8b);
3599
0
3600
0
                _mm_storel_epi64((__m128i *)(pu1_dst), res_16x8b);
3601
0
3602
0
                src_r0r1_8x16b = _mm_unpacklo_epi16(src_r1_8x16b, src_r2_8x16b);
3603
0
                src_r2r3_8x16b = _mm_unpacklo_epi16(src_r3_8x16b, src_r4_8x16b);
3604
0
                src_r4r5_8x16b = _mm_unpacklo_epi16(src_r5_8x16b, src_r6_8x16b);
3605
0
3606
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_8x16b, coeff0_1_8x16b);
3607
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_8x16b, coeff2_3_8x16b);
3608
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_8x16b, coeff4_5_8x16b);
3609
0
3610
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
3611
0
                res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
3612
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
3613
0
                res_t0_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
3614
0
3615
0
                src_r0r1_8x16b = _mm_unpackhi_epi16(src_r1_8x16b, src_r2_8x16b);
3616
0
                src_r2r3_8x16b = _mm_unpackhi_epi16(src_r3_8x16b, src_r4_8x16b);
3617
0
                src_r4r5_8x16b = _mm_unpackhi_epi16(src_r5_8x16b, src_r6_8x16b);
3618
0
3619
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_8x16b, coeff0_1_8x16b);
3620
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_8x16b, coeff2_3_8x16b);
3621
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_8x16b, coeff4_5_8x16b);
3622
0
3623
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
3624
0
                res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
3625
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
3626
0
                res_t1_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
3627
0
3628
0
                res_8x16b = _mm_packs_epi32(res_t0_4x32b, res_t1_4x32b);
3629
0
                res_16x8b = _mm_packus_epi16(res_8x16b, res_8x16b);
3630
0
3631
0
                src_hpel_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp3 + 8));
3632
0
                src_hpel_8x16b = _mm_add_epi16(const_val16_8x16b, src_hpel_8x16b);
3633
0
                src_hpel_8x16b = _mm_srai_epi16(src_hpel_8x16b, 5); //shifting right by 5 bits.
3634
0
                src_hpel_16x8b = _mm_packus_epi16(src_hpel_8x16b, src_hpel_8x16b);
3635
0
3636
0
                res_16x8b = _mm_avg_epu8(res_16x8b, src_hpel_16x8b);
3637
0
3638
0
                _mm_storel_epi64((__m128i *)(pu1_dst + dst_strd), res_16x8b);
3639
0
3640
0
                src_r0_8x16b = src_r2_8x16b;
3641
0
                src_r1_8x16b = src_r3_8x16b;
3642
0
                src_r2_8x16b = src_r4_8x16b;
3643
0
                src_r3_8x16b = src_r5_8x16b;
3644
0
                src_r4_8x16b = src_r6_8x16b;
3645
0
3646
0
                ht -= 2;
3647
0
                pi2_temp2 = pi2_temp2 + (8 << 1);
3648
0
                pi2_temp3 = pi2_temp3 + (8 << 1);
3649
0
                pu1_dst = pu1_dst + (dst_strd << 1);
3650
0
            }
3651
0
            while(ht > 0);
3652
0
        }
3653
0
    }
3654
0
    else // wd == 16
3655
0
    {
3656
0
        UWORD8 *pu1_dst1;
3657
0
        WORD16 *pi2_temp4,*pi2_temp5;
3658
0
3659
0
        pu1_dst1 = pu1_dst + 8;
3660
0
        pi2_temp4 = pi2_temp2 + 8;
3661
0
        pi2_temp5 = pi2_temp3 + 8;
3662
0
3663
0
        // horizontal half-pel
3664
0
        {
3665
0
            __m128i src_r0_16x8b, src_r1_16x8b, src_r0_sht_16x8b, src_r1_sht_16x8b;
3666
0
            __m128i src_r0_t1_16x8b, src_r1_t1_16x8b;
3667
0
3668
0
            __m128i res_r0_t1_8x16b, res_r0_t2_8x16b, res_r0_t3_8x16b;
3669
0
            __m128i res_r1_t1_8x16b, res_r1_t2_8x16b, res_r1_t3_8x16b;
3670
0
3671
0
            __m128i coeff0_1_16x8b, coeff2_3_16x8b, coeff4_5_16x8b;
3672
0
3673
0
            coeff0_1_16x8b = _mm_set1_epi32(0xFB01FB01);  //c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1 c0 c1
3674
0
            coeff2_3_16x8b = _mm_set1_epi32(0x14141414);  //c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3 c2 c3
3675
0
            coeff4_5_16x8b = _mm_set1_epi32(0x01FB01FB);  //c4 c5 c5 c5 c4 c5 c5 c5 c4 c5 c5 c5 c4 c5 c5 c5
3676
0
3677
0
            //Row0 : a0 a1 a2 a3 a4 a5 a6 a7 a8 a9.....
3678
0
            //Row0 :                         b0 b1 b2 b3 b4 b5 b6 b7 b8 b9.....
3679
0
            //b0 is same a8. Similarly other bn pixels are same as a(n+8) pixels.
3680
0
3681
0
            do
3682
0
            {
3683
0
                src_r0_16x8b = _mm_loadu_si128((__m128i *)(pu1_src));                  //a0 a1 a2 a3 a4 a5 a6 a7 a8 a9....a15
3684
0
                src_r1_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + 8));              //b0 b1 b2 b3 b4 b5 b6 b7 b8 b9....b15
3685
0
3686
0
                src_r0_sht_16x8b = _mm_srli_si128(src_r0_16x8b, 1);                    //a1 a2 a3 a4 a5 a6 a7 a8 a9....a15 0
3687
0
                src_r1_sht_16x8b = _mm_srli_si128(src_r1_16x8b, 1);                    //b1 b2 b3 b4 b5 b6 b7 b8 b9....b15 0
3688
0
3689
0
                src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);   //a0 a1 a1 a2 a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8
3690
0
                src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);   //b0 b1 b1 b2 b2 b3 b3 b4 b4 b5 b5 b6 b6 b7 b7 b8
3691
0
3692
0
                res_r0_t1_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff0_1_16x8b);   //a0*c0+a1*c1 a1*c0+a2*c1 a2*c0+a3*c1 a3*c0+a4*c1
3693
0
                                                                                        //a4*c0+a5*c1 a5*c0+a6*c1 a6*c0+a7*c1 a7*c0+a8*c1
3694
0
                res_r1_t1_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff0_1_16x8b);   //b0*c0+b1*c1 b1*c0+b2*c1 b2*c0+b3*c1 b3*c0+b4*c1
3695
0
                                                                                        //b4*c0+b5*c1 b5*c0+b6*c1 b6*c0+b7*c1 b7*c0+b8*c1
3696
0
3697
0
                src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 2);                         //a2 a3 a4 a5 a6 a7 a8 a9....a15 0 0
3698
0
                src_r1_16x8b = _mm_srli_si128(src_r1_16x8b, 2);                         //b2 b3 b4 b5 b6 b7 b8 b9....b15 0 0
3699
0
3700
0
                src_r0_sht_16x8b = _mm_srli_si128(src_r0_sht_16x8b, 2);                 //a3 a4 a5 a6 a7 a8 a9....a15 0  0  0
3701
0
                src_r1_sht_16x8b = _mm_srli_si128(src_r1_sht_16x8b, 2);                 //b3 b4 b5 b6 b7 b8 b9....b15 0  0  0
3702
0
3703
0
                src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);    //a2 a3 a3 a4 a4 a5 a5 a6 a6 a7 a7 a8 a8 a9 a9 a10
3704
0
                src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);    //b2 b3 b3 b4 b4 b5 b5 b6 b6 b7 b7 b8 a8 a9 a9 a10
3705
0
3706
0
                res_r0_t2_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff2_3_16x8b);   //a2*c2+a3*c3 a3*c2+a4*c3 a4*c2+a5*c3 a5*c2+a6*c3
3707
0
                                                                                        //a6*c2+a7*c3 a7*c2+a8*c3 a8*c2+a9*c3 a9*c2+a10*c3
3708
0
                res_r1_t2_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff2_3_16x8b);   //b2*c2+b3*c3 b3*c2+b4*c3 b2*c4+b5*c3 b5*c2+b6*c3
3709
0
                                                                                        //b6*c2+b7*c3 b7*c2+b8*c3 b8*c2+b9*c3 b9*c2+b10*c3
3710
0
3711
0
                src_r0_16x8b = _mm_srli_si128(src_r0_16x8b, 2);                         //a4 a5 a6 a7 a8 a9....a15 0  0  0  0
3712
0
                src_r1_16x8b = _mm_srli_si128(src_r1_16x8b, 2);                         //b4 b5 b6 b7 b8 b9....b15 0  0  0  0
3713
0
3714
0
                src_r0_sht_16x8b = _mm_srli_si128(src_r0_sht_16x8b, 2);                 //a5 a6 a7 a8 a9....a15 0  0  0  0  0
3715
0
                src_r1_sht_16x8b = _mm_srli_si128(src_r1_sht_16x8b, 2);                 //b5 b6 b7 b8 b9....b15 0  0  0  0  0
3716
0
3717
0
                src_r0_t1_16x8b = _mm_unpacklo_epi8(src_r0_16x8b, src_r0_sht_16x8b);    //a4 a5 a5 a6 a6 a7 a7 a8 a8 a9 a9 a10 a10 a11 a11 a12
3718
0
                src_r1_t1_16x8b = _mm_unpacklo_epi8(src_r1_16x8b, src_r1_sht_16x8b);    //b4 b5 b5 b6 b6 b7 b7 b8 b8 b9 b9 b10 b10 b11 b11 b12
3719
0
3720
0
                res_r0_t3_8x16b = _mm_maddubs_epi16(src_r0_t1_16x8b, coeff4_5_16x8b);   //a4*c4+a5*c5 a5*c4+a6*c5 a6*c4+a7*c5 a7*c4+a8*c5
3721
0
                                                                                        //a8*c4+a9*c5 a9*c4+a10*c5 a10*c4+a11*c5 a11*c4+a12*c5
3722
0
                res_r1_t3_8x16b = _mm_maddubs_epi16(src_r1_t1_16x8b, coeff4_5_16x8b);   //b4*c4+b5*c5 b5*c4+b6*c5 b6*c4+b7*c5 b7*c4+b8*c5
3723
0
                                                                                        //b8*c4+b9*c5 b9*c4+b10*c5 b10*c4+b11*c5 b11*c4+b12*c5
3724
0
                res_r0_t1_8x16b = _mm_add_epi16(res_r0_t1_8x16b, res_r0_t2_8x16b);
3725
0
                res_r0_t1_8x16b = _mm_add_epi16(res_r0_t1_8x16b, res_r0_t3_8x16b);
3726
0
3727
0
                res_r1_t1_8x16b = _mm_add_epi16(res_r1_t1_8x16b, res_r1_t2_8x16b);
3728
0
                res_r1_t1_8x16b = _mm_add_epi16(res_r1_t1_8x16b, res_r1_t3_8x16b);
3729
0
3730
0
                _mm_storeu_si128((__m128i *)(pi2_temp1), res_r0_t1_8x16b);
3731
0
                _mm_storeu_si128((__m128i *)(pi2_temp1 + 8), res_r1_t1_8x16b);
3732
0
3733
0
                ht_temp--;
3734
0
                pu1_src =  pu1_src + src_strd;
3735
0
                pi2_temp1 =  pi2_temp1 + 16;
3736
0
            }
3737
0
            while(ht_temp > 0);
3738
0
        }
3739
0
        // vertical q-pel
3740
0
        {
3741
0
            __m128i src_r0_8x16b, src_r1_8x16b, src_r2_8x16b, src_r3_8x16b, src_r4_8x16b;
3742
0
            __m128i src_r5_8x16b, src_r6_8x16b;
3743
0
            __m128i src_r0r1_8x16b, src_r2r3_8x16b, src_r4r5_8x16b;
3744
0
            __m128i src_hpel_8x16b, src_hpel_16x8b;
3745
0
3746
0
            __m128i res_t0_4x32b, res_t1_4x32b, res_t2_4x32b, res_t3_4x32b;
3747
0
            __m128i res_8x16b, res_16x8b;
3748
0
3749
0
            __m128i coeff0_1_8x16b, coeff2_3_8x16b, coeff4_5_8x16b;
3750
0
            __m128i const_val512_4x32b, const_val16_8x16b;
3751
0
3752
0
            coeff0_1_8x16b = _mm_set1_epi32(0xFFFB0001);
3753
0
            coeff2_3_8x16b = _mm_set1_epi32(0x00140014);
3754
0
            coeff4_5_8x16b = _mm_set1_epi32(0x0001FFFB);
3755
0
3756
0
            const_val512_4x32b = _mm_set1_epi32(512);
3757
0
            const_val16_8x16b = _mm_set1_epi16(16);
3758
0
3759
0
            /**********************************************************/
3760
0
            /*     Do first height x 8 block                          */
3761
0
            /**********************************************************/
3762
0
            src_r0_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2));
3763
0
            src_r1_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2 + 16));
3764
0
            src_r2_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2 + 32));
3765
0
            src_r3_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2 + 48));
3766
0
            src_r4_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2 + 64));
3767
0
            pi2_temp2 += 80;
3768
0
3769
0
            ht_temp = ht;
3770
0
            do
3771
0
            {
3772
0
                src_r5_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2));
3773
0
                src_r6_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp2 + 16));
3774
0
3775
0
                src_r0r1_8x16b = _mm_unpacklo_epi16(src_r0_8x16b, src_r1_8x16b);
3776
0
                src_r2r3_8x16b = _mm_unpacklo_epi16(src_r2_8x16b, src_r3_8x16b);
3777
0
                src_r4r5_8x16b = _mm_unpacklo_epi16(src_r4_8x16b, src_r5_8x16b);
3778
0
3779
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_8x16b, coeff0_1_8x16b);
3780
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_8x16b, coeff2_3_8x16b);
3781
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_8x16b, coeff4_5_8x16b);
3782
0
3783
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
3784
0
                res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
3785
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
3786
0
                res_t0_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
3787
0
3788
0
                src_r0r1_8x16b = _mm_unpackhi_epi16(src_r0_8x16b, src_r1_8x16b);
3789
0
                src_r2r3_8x16b = _mm_unpackhi_epi16(src_r2_8x16b, src_r3_8x16b);
3790
0
                src_r4r5_8x16b = _mm_unpackhi_epi16(src_r4_8x16b, src_r5_8x16b);
3791
0
3792
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_8x16b, coeff0_1_8x16b);
3793
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_8x16b, coeff2_3_8x16b);
3794
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_8x16b, coeff4_5_8x16b);
3795
0
3796
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
3797
0
                res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
3798
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
3799
0
                res_t1_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
3800
0
3801
0
                res_8x16b = _mm_packs_epi32(res_t0_4x32b, res_t1_4x32b);
3802
0
                res_16x8b = _mm_packus_epi16(res_8x16b, res_8x16b);
3803
0
3804
0
                src_hpel_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp3));
3805
0
                src_hpel_8x16b = _mm_add_epi16(src_hpel_8x16b, const_val16_8x16b);
3806
0
                src_hpel_8x16b = _mm_srai_epi16(src_hpel_8x16b, 5); //shifting right by 5 bits.
3807
0
                src_hpel_16x8b = _mm_packus_epi16(src_hpel_8x16b, src_hpel_8x16b);
3808
0
3809
0
                res_16x8b = _mm_avg_epu8(res_16x8b, src_hpel_16x8b);
3810
0
                _mm_storel_epi64((__m128i *)(pu1_dst), res_16x8b);
3811
0
3812
0
                src_r0r1_8x16b = _mm_unpacklo_epi16(src_r1_8x16b, src_r2_8x16b);
3813
0
                src_r2r3_8x16b = _mm_unpacklo_epi16(src_r3_8x16b, src_r4_8x16b);
3814
0
                src_r4r5_8x16b = _mm_unpacklo_epi16(src_r5_8x16b, src_r6_8x16b);
3815
0
3816
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_8x16b, coeff0_1_8x16b);
3817
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_8x16b, coeff2_3_8x16b);
3818
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_8x16b, coeff4_5_8x16b);
3819
0
3820
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
3821
0
                res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
3822
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
3823
0
                res_t0_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
3824
0
3825
0
                src_r0r1_8x16b = _mm_unpackhi_epi16(src_r1_8x16b, src_r2_8x16b);
3826
0
                src_r2r3_8x16b = _mm_unpackhi_epi16(src_r3_8x16b, src_r4_8x16b);
3827
0
                src_r4r5_8x16b = _mm_unpackhi_epi16(src_r5_8x16b, src_r6_8x16b);
3828
0
3829
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_8x16b, coeff0_1_8x16b);
3830
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_8x16b, coeff2_3_8x16b);
3831
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_8x16b, coeff4_5_8x16b);
3832
0
3833
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
3834
0
                res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
3835
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
3836
0
                res_t1_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
3837
0
3838
0
                res_8x16b = _mm_packs_epi32(res_t0_4x32b, res_t1_4x32b);
3839
0
                res_16x8b = _mm_packus_epi16(res_8x16b, res_8x16b);
3840
0
3841
0
                src_hpel_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp3 + 16));
3842
0
                src_hpel_8x16b = _mm_add_epi16(src_hpel_8x16b, const_val16_8x16b);
3843
0
                src_hpel_8x16b = _mm_srai_epi16(src_hpel_8x16b, 5); //shifting right by 5 bits.
3844
0
                src_hpel_16x8b = _mm_packus_epi16(src_hpel_8x16b, src_hpel_8x16b);
3845
0
3846
0
                res_16x8b = _mm_avg_epu8(res_16x8b, src_hpel_16x8b);
3847
0
                _mm_storel_epi64((__m128i *)(pu1_dst + dst_strd), res_16x8b);
3848
0
3849
0
                src_r0_8x16b = src_r2_8x16b;
3850
0
                src_r1_8x16b = src_r3_8x16b;
3851
0
                src_r2_8x16b = src_r4_8x16b;
3852
0
                src_r3_8x16b = src_r5_8x16b;
3853
0
                src_r4_8x16b = src_r6_8x16b;
3854
0
3855
0
                ht_temp -= 2;
3856
0
                pi2_temp3 = pi2_temp3 + (16 << 1);
3857
0
                pi2_temp2 = pi2_temp2 + (16 << 1);
3858
0
                pu1_dst = pu1_dst + (dst_strd << 1);
3859
0
            }
3860
0
            while(ht_temp > 0);
3861
0
3862
0
            /**********************************************************/
3863
0
            /*     Do second height * 8 block                         */
3864
0
            /**********************************************************/
3865
0
            src_r0_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp4));
3866
0
            src_r1_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp4 + 16));
3867
0
            src_r2_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp4 + 32));
3868
0
            src_r3_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp4 + 48));
3869
0
            src_r4_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp4 + 64));
3870
0
            pi2_temp4 += 80;
3871
0
3872
0
            do
3873
0
            {
3874
0
                src_r5_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp4));
3875
0
                src_r6_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp4 + 16));
3876
0
3877
0
                src_r0r1_8x16b = _mm_unpacklo_epi16(src_r0_8x16b, src_r1_8x16b);
3878
0
                src_r2r3_8x16b = _mm_unpacklo_epi16(src_r2_8x16b, src_r3_8x16b);
3879
0
                src_r4r5_8x16b = _mm_unpacklo_epi16(src_r4_8x16b, src_r5_8x16b);
3880
0
3881
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_8x16b, coeff0_1_8x16b);
3882
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_8x16b, coeff2_3_8x16b);
3883
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_8x16b, coeff4_5_8x16b);
3884
0
3885
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
3886
0
                res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
3887
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
3888
0
                res_t0_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
3889
0
3890
0
                src_r0r1_8x16b = _mm_unpackhi_epi16(src_r0_8x16b, src_r1_8x16b);
3891
0
                src_r2r3_8x16b = _mm_unpackhi_epi16(src_r2_8x16b, src_r3_8x16b);
3892
0
                src_r4r5_8x16b = _mm_unpackhi_epi16(src_r4_8x16b, src_r5_8x16b);
3893
0
3894
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_8x16b, coeff0_1_8x16b);
3895
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_8x16b, coeff2_3_8x16b);
3896
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_8x16b, coeff4_5_8x16b);
3897
0
3898
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
3899
0
                res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
3900
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
3901
0
                res_t1_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
3902
0
3903
0
                res_8x16b = _mm_packs_epi32(res_t0_4x32b, res_t1_4x32b);
3904
0
                res_16x8b = _mm_packus_epi16(res_8x16b, res_8x16b);
3905
0
3906
0
                src_hpel_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp5));
3907
0
                src_hpel_8x16b = _mm_add_epi16(src_hpel_8x16b, const_val16_8x16b);
3908
0
                src_hpel_8x16b = _mm_srai_epi16(src_hpel_8x16b, 5); //shifting right by 5 bits.
3909
0
                src_hpel_16x8b = _mm_packus_epi16(src_hpel_8x16b, src_hpel_8x16b);
3910
0
3911
0
                res_16x8b = _mm_avg_epu8(res_16x8b, src_hpel_16x8b);
3912
0
                _mm_storel_epi64((__m128i *)(pu1_dst1), res_16x8b);
3913
0
3914
0
                src_r0r1_8x16b = _mm_unpacklo_epi16(src_r1_8x16b, src_r2_8x16b);
3915
0
                src_r2r3_8x16b = _mm_unpacklo_epi16(src_r3_8x16b, src_r4_8x16b);
3916
0
                src_r4r5_8x16b = _mm_unpacklo_epi16(src_r5_8x16b, src_r6_8x16b);
3917
0
3918
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_8x16b, coeff0_1_8x16b);
3919
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_8x16b, coeff2_3_8x16b);
3920
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_8x16b, coeff4_5_8x16b);
3921
0
3922
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
3923
0
                res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
3924
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
3925
0
                res_t0_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
3926
0
3927
0
                src_r0r1_8x16b = _mm_unpackhi_epi16(src_r1_8x16b, src_r2_8x16b);
3928
0
                src_r2r3_8x16b = _mm_unpackhi_epi16(src_r3_8x16b, src_r4_8x16b);
3929
0
                src_r4r5_8x16b = _mm_unpackhi_epi16(src_r5_8x16b, src_r6_8x16b);
3930
0
3931
0
                res_t1_4x32b = _mm_madd_epi16(src_r0r1_8x16b, coeff0_1_8x16b);
3932
0
                res_t2_4x32b = _mm_madd_epi16(src_r2r3_8x16b, coeff2_3_8x16b);
3933
0
                res_t3_4x32b = _mm_madd_epi16(src_r4r5_8x16b, coeff4_5_8x16b);
3934
0
3935
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t2_4x32b);
3936
0
                res_t3_4x32b = _mm_add_epi32(res_t3_4x32b, const_val512_4x32b);
3937
0
                res_t1_4x32b = _mm_add_epi32(res_t1_4x32b, res_t3_4x32b);
3938
0
                res_t1_4x32b = _mm_srai_epi32(res_t1_4x32b, 10);
3939
0
3940
0
                res_8x16b = _mm_packs_epi32(res_t0_4x32b, res_t1_4x32b);
3941
0
                res_16x8b = _mm_packus_epi16(res_8x16b, res_8x16b);
3942
0
3943
0
                src_hpel_8x16b = _mm_loadu_si128((__m128i *)(pi2_temp5 + 16));
3944
0
                src_hpel_8x16b = _mm_add_epi16(src_hpel_8x16b, const_val16_8x16b);
3945
0
                src_hpel_8x16b = _mm_srai_epi16(src_hpel_8x16b, 5); //shifting right by 5 bits.
3946
0
                src_hpel_16x8b = _mm_packus_epi16(src_hpel_8x16b, src_hpel_8x16b);
3947
0
3948
0
                res_16x8b = _mm_avg_epu8(res_16x8b, src_hpel_16x8b);
3949
0
                _mm_storel_epi64((__m128i *)(pu1_dst1 + dst_strd), res_16x8b);
3950
0
3951
0
                src_r0_8x16b = src_r2_8x16b;
3952
0
                src_r1_8x16b = src_r3_8x16b;
3953
0
                src_r2_8x16b = src_r4_8x16b;
3954
0
                src_r3_8x16b = src_r5_8x16b;
3955
0
                src_r4_8x16b = src_r6_8x16b;
3956
0
3957
0
                ht -= 2;
3958
0
                pi2_temp5 = pi2_temp5 + (16 << 1);
3959
0
                pi2_temp4 = pi2_temp4 + (16 << 1);
3960
0
                pu1_dst1 = pu1_dst1 + (dst_strd << 1);
3961
0
            }
3962
0
            while(ht > 0);
3963
0
        }
3964
0
    }
3965
0
}
3966
3967
/*****************************************************************************/
3968
/*                                                                           */
3969
/*  Function Name : ih264_inter_pred_chroma_ssse3                            */
3970
/*                                                                           */
3971
/*  Description   : This function implements a four-tap 2D filter as         */
3972
/*                  mentioned in sec. 8.4.2.2.2 titled "Chroma sample        */
3973
/*                  "interpolation process". (ht,wd) can be (2,2), (4,2),    */
3974
/*                  (2,4), (4,4), (8,4), (4,8) or (8,8).                     */
3975
/*                                                                           */
3976
/*  Inputs        : puc_src  - pointer to source                             */
3977
/*                  puc_dst  - pointer to destination                        */
3978
/*                  src_strd - stride for source                             */
3979
/*                  dst_strd - stride for destination                        */
3980
/*                  dx       - x position of destination value               */
3981
/*                  dy       - y position of destination value               */
3982
/*                  ht       - height of the block                           */
3983
/*                  wd       - width of the block                            */
3984
/*                                                                           */
3985
/*  Issues        : None                                                     */
3986
/*                                                                           */
3987
/*  Revision History:                                                        */
3988
/*                                                                           */
3989
/*         DD MM YYYY   Author(s)       Changes                              */
3990
/*         13 02 2015   Kaushik         Initial Version                      */
3991
/*                      Senthoor                                             */
3992
/*                                                                           */
3993
/*****************************************************************************/
3994
void ih264_inter_pred_chroma_ssse3(UWORD8 *pu1_src,
3995
                                   UWORD8 *pu1_dst,
3996
                                   WORD32 src_strd,
3997
                                   WORD32 dst_strd,
3998
                                   WORD32 dx,
3999
                                   WORD32 dy,
4000
                                   WORD32 ht,
4001
                                   WORD32 wd)
4002
0
{
4003
0
    WORD32 i, j, A, B, C, D;
4004
0
4005
0
    i = 8 - dx;
4006
0
    j = 8 - dy;
4007
0
4008
0
    A = i * j;
4009
0
    B = dx * j;
4010
0
    C = i * dy;
4011
0
    D = dx * dy;
4012
0
4013
0
    if(wd == 2)
4014
0
    {
4015
0
        WORD32 tmp1, tmp2, tmp3, tmp4;
4016
0
4017
0
        do
4018
0
        {
4019
0
            //U
4020
0
            tmp1 = A * pu1_src[0] + B * pu1_src[2] + C * pu1_src[src_strd] + D * pu1_src[src_strd + 2];
4021
0
            tmp2 = A * pu1_src[2] + B * pu1_src[4] + C * pu1_src[src_strd + 2] + D * pu1_src[src_strd + 4];
4022
0
            //V
4023
0
            tmp3 = A * pu1_src[1] + B * pu1_src[3] + C * pu1_src[src_strd + 1] + D * pu1_src[src_strd + 3];
4024
0
            tmp4 = A * pu1_src[3] + B * pu1_src[5] + C * pu1_src[src_strd + 3] + D * pu1_src[src_strd + 5];
4025
0
4026
0
            tmp1 = (tmp1 + 32) >> 6;
4027
0
            tmp2 = (tmp2 + 32) >> 6;
4028
0
            tmp3 = (tmp3 + 32) >> 6;
4029
0
            tmp4 = (tmp4 + 32) >> 6;
4030
0
4031
0
            pu1_dst[0] = CLIP_U8(tmp1);
4032
0
            pu1_dst[2] = CLIP_U8(tmp2);
4033
0
            pu1_dst[1] = CLIP_U8(tmp3);
4034
0
            pu1_dst[3] = CLIP_U8(tmp4);
4035
0
4036
0
            pu1_src += src_strd;
4037
0
            pu1_dst += dst_strd;
4038
0
4039
0
            tmp1 = A * pu1_src[0] + B * pu1_src[2] + C * pu1_src[src_strd] + D * pu1_src[src_strd + 2];
4040
0
            tmp2 = A * pu1_src[2] + B * pu1_src[4] + C * pu1_src[src_strd + 2] + D * pu1_src[src_strd + 4];
4041
0
            tmp3 = A * pu1_src[1] + B * pu1_src[3] + C * pu1_src[src_strd + 1] + D * pu1_src[src_strd + 3];
4042
0
            tmp4 = A * pu1_src[3] + B * pu1_src[5] + C * pu1_src[src_strd + 3] + D * pu1_src[src_strd + 5];
4043
0
4044
0
            tmp1 = (tmp1 + 32) >> 6;
4045
0
            tmp2 = (tmp2 + 32) >> 6;
4046
0
            tmp3 = (tmp3 + 32) >> 6;
4047
0
            tmp4 = (tmp4 + 32) >> 6;
4048
0
4049
0
            pu1_dst[0] = CLIP_U8(tmp1);
4050
0
            pu1_dst[2] = CLIP_U8(tmp2);
4051
0
            pu1_dst[1] = CLIP_U8(tmp3);
4052
0
            pu1_dst[3] = CLIP_U8(tmp4);
4053
0
4054
0
            ht -= 2;
4055
0
            pu1_src += src_strd;
4056
0
            pu1_dst += dst_strd;
4057
0
        }
4058
0
        while(ht > 0);
4059
0
4060
0
    }
4061
0
    else if(wd == 4)
4062
0
    {
4063
0
        WORD32 AB, CD;
4064
0
4065
0
        __m128i src_r1_16x8b, src_r2_16x8b, src_r3_16x8b;
4066
0
        __m128i res1_AB_8x16b, res1_CD_8x16b, res1_8x16b, res1_16x8b;
4067
0
        __m128i res2_AB_8x16b, res2_CD_8x16b, res2_8x16b, res2_16x8b;
4068
0
4069
0
        __m128i coeffAB_16x8b, coeffCD_16x8b, round_add32_8x16b;
4070
0
        __m128i const_shuff_16x8b;
4071
0
4072
0
        AB = (B << 8) + A;
4073
0
        CD = (D << 8) + C;
4074
0
4075
0
        coeffAB_16x8b = _mm_set1_epi16(AB);
4076
0
        coeffCD_16x8b = _mm_set1_epi16(CD);
4077
0
4078
0
        round_add32_8x16b = _mm_set1_epi16(32);
4079
0
4080
0
        const_shuff_16x8b = _mm_setr_epi32(0x03010200, 0x05030402, 0x07050604, 0x09070806);
4081
0
4082
0
        src_r1_16x8b = _mm_loadu_si128((__m128i *)pu1_src);
4083
0
        src_r1_16x8b = _mm_shuffle_epi8(src_r1_16x8b, const_shuff_16x8b);
4084
0
        pu1_src += src_strd;
4085
0
4086
0
        do
4087
0
        {
4088
0
            src_r2_16x8b = _mm_loadu_si128((__m128i *)pu1_src);
4089
0
            src_r3_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + src_strd));
4090
0
4091
0
            src_r2_16x8b = _mm_shuffle_epi8(src_r2_16x8b, const_shuff_16x8b);
4092
0
            src_r3_16x8b = _mm_shuffle_epi8(src_r3_16x8b, const_shuff_16x8b);
4093
0
4094
0
            res1_AB_8x16b = _mm_maddubs_epi16(src_r1_16x8b, coeffAB_16x8b);
4095
0
            res1_CD_8x16b = _mm_maddubs_epi16(src_r2_16x8b, coeffCD_16x8b);
4096
0
            res2_AB_8x16b = _mm_maddubs_epi16(src_r2_16x8b, coeffAB_16x8b);
4097
0
            res2_CD_8x16b = _mm_maddubs_epi16(src_r3_16x8b, coeffCD_16x8b);
4098
0
4099
0
            res1_8x16b = _mm_add_epi16(res1_AB_8x16b, res1_CD_8x16b);
4100
0
            res2_8x16b = _mm_add_epi16(res2_AB_8x16b, res2_CD_8x16b);
4101
0
            res1_8x16b = _mm_add_epi16(res1_8x16b, round_add32_8x16b);
4102
0
            res2_8x16b = _mm_add_epi16(res2_8x16b, round_add32_8x16b);
4103
0
4104
0
            res1_8x16b = _mm_srai_epi16(res1_8x16b, 6);
4105
0
            res2_8x16b = _mm_srai_epi16(res2_8x16b, 6);
4106
0
4107
0
            res1_16x8b = _mm_packus_epi16(res1_8x16b, res1_8x16b);
4108
0
            res2_16x8b = _mm_packus_epi16(res2_8x16b, res2_8x16b);
4109
0
4110
0
            _mm_storel_epi64((__m128i *)pu1_dst, res1_16x8b);
4111
0
            _mm_storel_epi64((__m128i *)(pu1_dst + dst_strd), res2_16x8b);
4112
0
4113
0
            src_r1_16x8b = src_r3_16x8b;
4114
0
4115
0
            ht -= 2;
4116
0
            pu1_src += src_strd << 1;
4117
0
            pu1_dst += dst_strd << 1;
4118
0
        }
4119
0
        while(ht > 0);
4120
0
    }
4121
0
    else // wd == 8
4122
0
    {
4123
0
        WORD32 AB, CD;
4124
0
4125
0
        __m128i src_r1l_16x8b, src_r2l_16x8b;
4126
0
        __m128i src_r1h_16x8b, src_r2h_16x8b;
4127
0
4128
0
        __m128i res_l_AB_8x16b, res_l_CD_8x16b;
4129
0
        __m128i res_h_AB_8x16b, res_h_CD_8x16b;
4130
0
        __m128i res_l_8x16b, res_h_8x16b, res_16x8b;
4131
0
4132
0
        __m128i coeffAB_16x8b, coeffCD_16x8b, round_add32_8x16b;
4133
0
        __m128i const_shuff_16x8b;
4134
0
4135
0
        AB = (B << 8) + A;
4136
0
        CD = (D << 8) + C;
4137
0
4138
0
        coeffAB_16x8b = _mm_set1_epi16(AB);
4139
0
        coeffCD_16x8b = _mm_set1_epi16(CD);
4140
0
4141
0
        round_add32_8x16b = _mm_set1_epi16(32);
4142
0
4143
0
        const_shuff_16x8b = _mm_setr_epi32(0x03010200, 0x05030402, 0x07050604, 0x09070806);
4144
0
4145
0
        src_r1l_16x8b = _mm_loadu_si128((__m128i *)pu1_src);
4146
0
        src_r1h_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + 8));
4147
0
4148
0
        src_r1l_16x8b = _mm_shuffle_epi8(src_r1l_16x8b, const_shuff_16x8b);
4149
0
        src_r1h_16x8b = _mm_shuffle_epi8(src_r1h_16x8b, const_shuff_16x8b);
4150
0
4151
0
        pu1_src += src_strd;
4152
0
4153
0
        do
4154
0
        {
4155
0
            //row 1
4156
0
            src_r2l_16x8b = _mm_loadu_si128((__m128i *)pu1_src);
4157
0
            src_r2h_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + 8));
4158
0
4159
0
            src_r2l_16x8b = _mm_shuffle_epi8(src_r2l_16x8b, const_shuff_16x8b);
4160
0
            src_r2h_16x8b = _mm_shuffle_epi8(src_r2h_16x8b, const_shuff_16x8b);
4161
0
4162
0
            res_l_AB_8x16b = _mm_maddubs_epi16(src_r1l_16x8b, coeffAB_16x8b);
4163
0
            res_h_AB_8x16b = _mm_maddubs_epi16(src_r1h_16x8b, coeffAB_16x8b);
4164
0
            res_l_CD_8x16b = _mm_maddubs_epi16(src_r2l_16x8b, coeffCD_16x8b);
4165
0
            res_h_CD_8x16b = _mm_maddubs_epi16(src_r2h_16x8b, coeffCD_16x8b);
4166
0
4167
0
            res_l_8x16b = _mm_add_epi16(res_l_AB_8x16b, round_add32_8x16b);
4168
0
            res_h_8x16b = _mm_add_epi16(res_h_AB_8x16b, round_add32_8x16b);
4169
0
            res_l_8x16b = _mm_add_epi16(res_l_8x16b, res_l_CD_8x16b);
4170
0
            res_h_8x16b = _mm_add_epi16(res_h_8x16b, res_h_CD_8x16b);
4171
0
4172
0
            res_l_8x16b = _mm_srai_epi16(res_l_8x16b, 6);
4173
0
            res_h_8x16b = _mm_srai_epi16(res_h_8x16b, 6);
4174
0
4175
0
            res_16x8b = _mm_packus_epi16(res_l_8x16b, res_h_8x16b);
4176
0
4177
0
            _mm_storeu_si128((__m128i *)pu1_dst, res_16x8b);
4178
0
4179
0
            pu1_src += src_strd;
4180
0
            pu1_dst += dst_strd;
4181
0
4182
0
            //row 2
4183
0
            src_r1l_16x8b = _mm_loadu_si128((__m128i *)pu1_src);
4184
0
            src_r1h_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + 8));
4185
0
4186
0
            src_r1l_16x8b = _mm_shuffle_epi8(src_r1l_16x8b, const_shuff_16x8b);
4187
0
            src_r1h_16x8b = _mm_shuffle_epi8(src_r1h_16x8b, const_shuff_16x8b);
4188
0
4189
0
            res_l_AB_8x16b = _mm_maddubs_epi16(src_r2l_16x8b, coeffAB_16x8b);
4190
0
            res_h_AB_8x16b = _mm_maddubs_epi16(src_r2h_16x8b, coeffAB_16x8b);
4191
0
            res_l_CD_8x16b = _mm_maddubs_epi16(src_r1l_16x8b, coeffCD_16x8b);
4192
0
            res_h_CD_8x16b = _mm_maddubs_epi16(src_r1h_16x8b, coeffCD_16x8b);
4193
0
4194
0
            res_l_8x16b = _mm_add_epi16(res_l_AB_8x16b, round_add32_8x16b);
4195
0
            res_h_8x16b = _mm_add_epi16(res_h_AB_8x16b, round_add32_8x16b);
4196
0
            res_l_8x16b = _mm_add_epi16(res_l_8x16b, res_l_CD_8x16b);
4197
0
            res_h_8x16b = _mm_add_epi16(res_h_8x16b, res_h_CD_8x16b);
4198
0
4199
0
            res_l_8x16b = _mm_srai_epi16(res_l_8x16b, 6);
4200
0
            res_h_8x16b = _mm_srai_epi16(res_h_8x16b, 6);
4201
0
4202
0
            res_16x8b = _mm_packus_epi16(res_l_8x16b, res_h_8x16b);
4203
0
4204
0
            _mm_storeu_si128((__m128i *)pu1_dst, res_16x8b);
4205
0
4206
0
            pu1_src += src_strd;
4207
0
            pu1_dst += dst_strd;
4208
0
4209
0
            //row 3
4210
0
            src_r2l_16x8b = _mm_loadu_si128((__m128i *)pu1_src);
4211
0
            src_r2h_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + 8));
4212
0
4213
0
            src_r2l_16x8b = _mm_shuffle_epi8(src_r2l_16x8b, const_shuff_16x8b);
4214
0
            src_r2h_16x8b = _mm_shuffle_epi8(src_r2h_16x8b, const_shuff_16x8b);
4215
0
4216
0
            res_l_AB_8x16b = _mm_maddubs_epi16(src_r1l_16x8b, coeffAB_16x8b);
4217
0
            res_h_AB_8x16b = _mm_maddubs_epi16(src_r1h_16x8b, coeffAB_16x8b);
4218
0
            res_l_CD_8x16b = _mm_maddubs_epi16(src_r2l_16x8b, coeffCD_16x8b);
4219
0
            res_h_CD_8x16b = _mm_maddubs_epi16(src_r2h_16x8b, coeffCD_16x8b);
4220
0
4221
0
            res_l_8x16b = _mm_add_epi16(res_l_AB_8x16b, round_add32_8x16b);
4222
0
            res_h_8x16b = _mm_add_epi16(res_h_AB_8x16b, round_add32_8x16b);
4223
0
            res_l_8x16b = _mm_add_epi16(res_l_8x16b, res_l_CD_8x16b);
4224
0
            res_h_8x16b = _mm_add_epi16(res_h_8x16b, res_h_CD_8x16b);
4225
0
4226
0
            res_l_8x16b = _mm_srai_epi16(res_l_8x16b, 6);
4227
0
            res_h_8x16b = _mm_srai_epi16(res_h_8x16b, 6);
4228
0
4229
0
            res_16x8b = _mm_packus_epi16(res_l_8x16b, res_h_8x16b);
4230
0
4231
0
            _mm_storeu_si128((__m128i *)pu1_dst, res_16x8b);
4232
0
4233
0
            pu1_src += src_strd;
4234
0
            pu1_dst += dst_strd;
4235
0
4236
0
            //row 1
4237
0
            src_r1l_16x8b = _mm_loadu_si128((__m128i *)pu1_src);
4238
0
            src_r1h_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + 8));
4239
0
4240
0
            src_r1l_16x8b = _mm_shuffle_epi8(src_r1l_16x8b, const_shuff_16x8b);
4241
0
            src_r1h_16x8b = _mm_shuffle_epi8(src_r1h_16x8b, const_shuff_16x8b);
4242
0
4243
0
            res_l_AB_8x16b = _mm_maddubs_epi16(src_r2l_16x8b, coeffAB_16x8b);
4244
0
            res_h_AB_8x16b = _mm_maddubs_epi16(src_r2h_16x8b, coeffAB_16x8b);
4245
0
            res_l_CD_8x16b = _mm_maddubs_epi16(src_r1l_16x8b, coeffCD_16x8b);
4246
0
            res_h_CD_8x16b = _mm_maddubs_epi16(src_r1h_16x8b, coeffCD_16x8b);
4247
0
4248
0
            res_l_8x16b = _mm_add_epi16(res_l_AB_8x16b, round_add32_8x16b);
4249
0
            res_h_8x16b = _mm_add_epi16(res_h_AB_8x16b, round_add32_8x16b);
4250
0
            res_l_8x16b = _mm_add_epi16(res_l_8x16b, res_l_CD_8x16b);
4251
0
            res_h_8x16b = _mm_add_epi16(res_h_8x16b, res_h_CD_8x16b);
4252
0
4253
0
            res_l_8x16b = _mm_srai_epi16(res_l_8x16b, 6);
4254
0
            res_h_8x16b = _mm_srai_epi16(res_h_8x16b, 6);
4255
0
4256
0
            res_16x8b = _mm_packus_epi16(res_l_8x16b, res_h_8x16b);
4257
0
4258
0
            _mm_storeu_si128((__m128i *)pu1_dst, res_16x8b);
4259
0
4260
0
            ht -= 4;
4261
0
            pu1_src += src_strd;
4262
0
            pu1_dst += dst_strd;
4263
0
        }
4264
0
        while(ht > 0);
4265
0
    }
4266
0
}
/proc/self/cwd/external/libavc/common/x86/ih264_iquant_itrans_recon_dc_ssse3.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/**
21
 *******************************************************************************
22
 * @file
23
 *  ih264_iquant_itrans_recon_dc_ssse3.c
24
 *
25
 * @brief
26
 *  Contains function definitions for inverse  quantization, inverse
27
 * transform and reconstruction
28
 *
29
 * @author
30
 *  Mohit [100664]
31
 *
32
 * @par List of Functions:
33
 *  - ih264_iquant_itrans_recon_4x4_dc_ssse3()
34
 *  - ih264_iquant_itrans_recon_8x8_dc_ssse3()
35
 *
36
 * @remarks
37
 *  None
38
 *
39
 *******************************************************************************
40
 */
41
/* User include files */
42
#include "ih264_typedefs.h"
43
#include "ih264_defs.h"
44
#include "ih264_trans_macros.h"
45
#include "ih264_macros.h"
46
#include "ih264_platform_macros.h"
47
#include "ih264_trans_data.h"
48
#include "ih264_size_defs.h"
49
#include "ih264_structs.h"
50
#include "ih264_trans_quant_itrans_iquant.h"
51
#include <immintrin.h>
52
53
/*
54
 ********************************************************************************
55
 *
56
 * @brief This function reconstructs a 4x4 sub block from quantized resiude and
57
 * prediction buffer for dc input pattern only, i.e. only the (0,0) element of the input
58
 * 4x4 block is non-zero. For complete function, refer ih264_iquant_itrans_recon_ssse3.c
59
 *
60
 * @par Description:
61
 *  The quantized residue is first inverse quantized, then inverse transformed.
62
 *  This inverse transformed content is added to the prediction buffer to recon-
63
 *  struct the end output
64
 *
65
 * @param[in] pi2_src
66
 *  quantized 4x4 block
67
 *
68
 * @param[in] pu1_pred
69
 *  prediction 4x4 block
70
 *
71
 * @param[out] pu1_out
72
 *  reconstructed 4x4 block
73
 *
74
 * @param[in] src_strd
75
 *  quantization buffer stride
76
 *
77
 * @param[in] pred_strd,
78
 *  Prediction buffer stride
79
 *
80
 * @param[in] out_strd
81
 *  recon buffer Stride
82
 *
83
 * @param[in] pu2_scaling_list
84
 *  pointer to scaling list
85
 *
86
 * @param[in] pu2_norm_adjust
87
 *  pointer to inverse scale matrix
88
 *
89
 * @param[in] u4_qp_div_6
90
 *  Floor (qp/6)
91
 *
92
 * @param[in] pi4_tmp
93
 * temporary buffer of size 1*16
94
 *
95
 * @returns none
96
 *
97
 * @remarks none
98
 *
99
 *******************************************************************************
100
 */
101
void ih264_iquant_itrans_recon_4x4_dc_ssse3(WORD16 *pi2_src,
102
                                   UWORD8 *pu1_pred,
103
                                   UWORD8 *pu1_out,
104
                                   WORD32 pred_strd,
105
                                   WORD32 out_strd,
106
                                   const UWORD16 *pu2_iscal_mat,
107
                                   const UWORD16 *pu2_weigh_mat,
108
                                   UWORD32 u4_qp_div_6,
109
                                   WORD16 *pi2_tmp,
110
                                   WORD32 iq_start_idx,
111
                                   WORD16 *pi2_dc_ld_addr)
112
66
{
113
66
    UWORD32 *pu4_out = (UWORD32 *)pu1_out;
114
66
    WORD32 q0 = pi2_src[0];
115
66
    WORD16 i_macro, rnd_fact = (u4_qp_div_6 < 4) ? 1 << (3 - u4_qp_div_6) : 0;
116
66
117
66
    __m128i predload_r,pred_r0, pred_r1, pred_r2, pred_r3;
118
66
    __m128i sign_reg;
119
66
    __m128i zero_8x16b = _mm_setzero_si128();          // all bits reset to zero
120
66
    __m128i temp4, temp5, temp6, temp7;
121
66
    __m128i value_add;
122
66
123
66
    UNUSED (pi2_tmp);
124
66
125
66
    INV_QUANT(q0, pu2_iscal_mat[0], pu2_weigh_mat[0], u4_qp_div_6, rnd_fact, 4);
126
66
127
66
    if (iq_start_idx != 0 )
128
0
        q0 = pi2_dc_ld_addr[0];     // Restoring dc value for intra case
129
66
130
66
    i_macro = ((q0 + 32) >> 6);
131
66
132
66
    value_add = _mm_set1_epi16(i_macro);
133
66
134
66
    zero_8x16b = _mm_setzero_si128();                  // all bits reset to zero
135
66
    //Load pred buffer
136
66
    predload_r = _mm_loadl_epi64((__m128i *) (&pu1_pred[0])); //p00 p01 p02 p03 0 0 0 0 0 0 0 0 -- all 8 bits
137
66
    pred_r0 = _mm_unpacklo_epi8(predload_r, zero_8x16b); //p00 p01 p02 p03 0 0 0 0 -- all 16 bits
138
66
    predload_r = _mm_loadl_epi64((__m128i *) (&pu1_pred[pred_strd])); //p10 p11 p12 p13 0 0 0 0 0 0 0 0 -- all 8 bits
139
66
    pred_r1 = _mm_unpacklo_epi8(predload_r, zero_8x16b); //p10 p11 p12 p13 0 0 0 0 -- all 16 bits
140
66
    predload_r = _mm_loadl_epi64((__m128i *) (&pu1_pred[2*pred_strd])); //p20 p21 p22 p23 0 0 0 0 0 0 0 0 -- all 8 bits
141
66
    pred_r2 = _mm_unpacklo_epi8(predload_r, zero_8x16b); //p20 p21 p22 p23 0 0 0 0 -- all 16 bits
142
66
    predload_r = _mm_loadl_epi64((__m128i *) (&pu1_pred[3*pred_strd])); //p30 p31 p32 p33 0 0 0 0 0 0 0 0 -- all 8 bits
143
66
    pred_r3 = _mm_unpacklo_epi8(predload_r, zero_8x16b); //p30 p31 p32 p33 0 0 0 0 -- all 16 bits
144
66
145
66
    pred_r0 = _mm_unpacklo_epi64(pred_r0, pred_r1); //p00 p01 p02 p03 p10 p11 p12 p13
146
66
    pred_r2 = _mm_unpacklo_epi64(pred_r2, pred_r3); //p20 p21 p22p p23 p30 p31 p32 p33
147
66
148
66
    temp4 = _mm_add_epi16(value_add, pred_r0);
149
66
    temp5 = _mm_add_epi16(value_add, pred_r2);
150
66
    /*------------------------------------------------------------------*/
151
66
    //Clipping the results to 8 bits
152
66
    sign_reg = _mm_cmpgt_epi16(temp4, zero_8x16b);                 // sign check
153
66
    temp4 = _mm_and_si128(temp4, sign_reg);
154
66
    sign_reg = _mm_cmpgt_epi16(temp5, zero_8x16b);                 // sign check
155
66
    temp5 = _mm_and_si128(temp5, sign_reg);
156
66
157
66
    temp4 = _mm_packus_epi16(temp4,temp5);
158
66
    temp5 = _mm_srli_si128(temp4,4);
159
66
    temp6 = _mm_srli_si128(temp5,4);
160
66
    temp7 = _mm_srli_si128(temp6,4);
161
66
162
66
    *pu4_out = _mm_cvtsi128_si32(temp4);
163
66
    pu1_out += out_strd;
164
66
    pu4_out = (UWORD32 *)(pu1_out);
165
66
    *(pu4_out) = _mm_cvtsi128_si32(temp5);
166
66
    pu1_out += out_strd;
167
66
    pu4_out = (UWORD32 *)(pu1_out);
168
66
    *(pu4_out) = _mm_cvtsi128_si32(temp6);
169
66
    pu1_out += out_strd;
170
66
    pu4_out = (UWORD32 *)(pu1_out);
171
66
    *(pu4_out) = _mm_cvtsi128_si32(temp7);
172
66
}
173
/**
174
 *******************************************************************************
175
 *
176
 * @brief
177
 *  This function performs inverse quant and Inverse transform type Ci4 for 8x8 block
178
 *  for dc input pattern only, i.e. only the (0,0) element of the input 8x8 block is
179
 *  non-zero. For complete function, refer ih264_iquant_itrans_recon_ssse3.c
180
 *
181
 * @par Description:
182
 *  Performs inverse transform Ci8 and adds the residue to get the
183
 *  reconstructed block
184
 *
185
 * @param[in] pi2_src
186
 *  Input 8x8coefficients
187
 *
188
 * @param[in] pu1_pred
189
 *  Prediction 8x8 block
190
 *
191
 * @param[out] pu1_recon
192
 *  Output 8x8 block
193
 *
194
 * @param[in] q_div
195
 *  QP/6
196
 *
197
 * @param[in] q_rem
198
 *  QP%6
199
 *
200
 * @param[in] q_lev
201
 *  Quantizer level
202
 *
203
 * @param[in] u4_src_stride
204
 *  Input stride
205
 *
206
 * @param[in] u4_pred_stride,
207
 *  Prediction stride
208
 *
209
 * @param[in] u4_out_stride
210
 *  Output Stride
211
 *
212
 * @param[in] pi4_tmp
213
 *  temporary buffer of size 1*64
214
 *  the tmp for each block
215
 *
216
 * @param[in] pu4_iquant_mat
217
 *  Pointer to the inverse quantization matrix
218
 *
219
 * @returns  Void
220
 *
221
 * @remarks
222
 *  None
223
 *
224
 *******************************************************************************
225
 */
226
227
void ih264_iquant_itrans_recon_8x8_dc_ssse3 (WORD16 *pi2_src,
228
                                         UWORD8 *pu1_pred,
229
                                         UWORD8 *pu1_out,
230
                                         WORD32 pred_strd,
231
                                         WORD32 out_strd,
232
                                         const UWORD16 *pu2_iscale_mat,
233
                                         const UWORD16 *pu2_weigh_mat,
234
                                         UWORD32 qp_div,
235
                                         WORD16 *pi2_tmp,
236
                                         WORD32 iq_start_idx,
237
                                         WORD16 *pi2_dc_ld_addr)
238
0
{
239
0
    WORD32 q0 = pi2_src[0];
240
0
    WORD16 i_macro, rnd_fact = (qp_div < 6) ? 1 << (5 - qp_div) : 0;
241
0
242
0
    __m128i predload_r,pred_r0, pred_r1, pred_r2, pred_r3,pred_r4,pred_r5,pred_r6,pred_r7;
243
0
    __m128i sign_reg;
244
0
    __m128i zero_8x16b = _mm_setzero_si128();          // all bits reset to zero
245
0
    __m128i temp1,temp2,temp3,temp4, temp5, temp6, temp7,temp8;
246
0
    __m128i value_add;
247
0
248
0
    UNUSED (pi2_tmp);
249
0
    UNUSED (iq_start_idx);
250
0
    UNUSED (pi2_dc_ld_addr);
251
0
252
0
    INV_QUANT(q0, pu2_iscale_mat[0], pu2_weigh_mat[0], qp_div, rnd_fact, 6);
253
0
    i_macro = ((q0 + 32) >> 6);
254
0
255
0
    value_add = _mm_set1_epi16(i_macro);
256
0
257
0
    //Load pred buffer row 0
258
0
    predload_r = _mm_loadl_epi64((__m128i *)(&pu1_pred[0])); //p0 p1 p2 p3 p4 p5 p6 p7 0 0 0 0 0 0 0 0 -- all 8 bits
259
0
    pred_r0 = _mm_unpacklo_epi8(predload_r, zero_8x16b); //p0 p1 p2 p3 p4 p5 p6 p7 -- all 16 bits
260
0
    //Load pred buffer row 1
261
0
    predload_r = _mm_loadl_epi64((__m128i *)(&pu1_pred[pred_strd])); //p0 p1 p2 p3 p4 p5 p6 p7 0 0 0 0 0 0 0 0 -- all 8 bits
262
0
    pred_r1 = _mm_unpacklo_epi8(predload_r, zero_8x16b); //p0 p1 p2 p3 p4 p5 p6 p7 -- all 16 bits
263
0
    //Load pred buffer row 2
264
0
    predload_r = _mm_loadl_epi64(
265
0
                    (__m128i *)(&pu1_pred[2 * pred_strd])); //p0 p1 p2 p3 p4 p5 p6 p7 0 0 0 0 0 0 0 0 -- all 8 bits
266
0
    pred_r2 = _mm_unpacklo_epi8(predload_r, zero_8x16b); //p0 p1 p2 p3 p4 p5 p6 p7 -- all 16 bits
267
0
    //Load pred buffer row 3
268
0
    predload_r = _mm_loadl_epi64(
269
0
                    (__m128i *)(&pu1_pred[3 * pred_strd])); //p0 p1 p2 p3 p4 p5 p6 p7 0 0 0 0 0 0 0 0 -- all 8 bits
270
0
    pred_r3 = _mm_unpacklo_epi8(predload_r, zero_8x16b); //p0 p1 p2 p3 p4 p5 p6 p7 -- all 16 bits
271
0
    //Load pred buffer row 4
272
0
    predload_r = _mm_loadl_epi64(
273
0
                    (__m128i *)(&pu1_pred[4 * pred_strd])); //p0 p1 p2 p3 p4 p5 p6 p7 0 0 0 0 0 0 0 0 -- all 8 bits
274
0
    pred_r4 = _mm_unpacklo_epi8(predload_r, zero_8x16b); //p0 p1 p2 p3 p4 p5 p6 p7 -- all 16 bits
275
0
    //Load pred buffer row 5
276
0
    predload_r = _mm_loadl_epi64(
277
0
                    (__m128i *)(&pu1_pred[5 * pred_strd])); //p0 p1 p2 p3 p4 p5 p6 p7 0 0 0 0 0 0 0 0 -- all 8 bit
278
0
    pred_r5 = _mm_unpacklo_epi8(predload_r, zero_8x16b); //p0 p1 p2 p3 p4 p5 p6 p7 -- all 16 bits
279
0
    //Load pred buffer row 6
280
0
    predload_r = _mm_loadl_epi64(
281
0
                    (__m128i *)(&pu1_pred[6 * pred_strd])); //p0 p1 p2 p3 p4 p5 p6 p7 0 0 0 0 0 0 0 0 -- all 8 bits
282
0
    pred_r6 = _mm_unpacklo_epi8(predload_r, zero_8x16b); //p0 p1 p2 p3 p4 p5 p6 p7 -- all 16 bits
283
0
    //Load pred buffer row 7
284
0
    predload_r = _mm_loadl_epi64(
285
0
                    (__m128i *)(&pu1_pred[7 * pred_strd])); //p0 p1 p2 p3 p4 p5 p6 p7 0 0 0 0 0 0 0 0 -- all 8 bits
286
0
    pred_r7 = _mm_unpacklo_epi8(predload_r, zero_8x16b); //p0 p1 p2 p3 p4 p5 p6 p7 -- all 16 bits
287
0
288
0
    temp1 = _mm_add_epi16(value_add, pred_r0);
289
0
290
0
    temp2 = _mm_add_epi16(value_add, pred_r1);
291
0
292
0
    temp3 = _mm_add_epi16(value_add, pred_r2);
293
0
294
0
    temp4 = _mm_add_epi16(value_add, pred_r3);
295
0
296
0
    temp5 = _mm_add_epi16(value_add, pred_r4);
297
0
298
0
    temp6 = _mm_add_epi16(value_add, pred_r5);
299
0
300
0
    temp7 = _mm_add_epi16(value_add, pred_r6);
301
0
302
0
    temp8 = _mm_add_epi16(value_add, pred_r7);
303
0
    /*------------------------------------------------------------------*/
304
0
    //Clipping the results to 8 bits
305
0
    sign_reg = _mm_cmpgt_epi16(temp1, zero_8x16b); // sign check
306
0
    temp1 = _mm_and_si128(temp1, sign_reg);
307
0
    sign_reg = _mm_cmpgt_epi16(temp2, zero_8x16b); // sign check
308
0
    temp2 = _mm_and_si128(temp2, sign_reg);
309
0
    sign_reg = _mm_cmpgt_epi16(temp3, zero_8x16b); // sign check
310
0
    temp3 = _mm_and_si128(temp3, sign_reg);
311
0
    sign_reg = _mm_cmpgt_epi16(temp4, zero_8x16b); // sign check
312
0
    temp4 = _mm_and_si128(temp4, sign_reg);
313
0
    sign_reg = _mm_cmpgt_epi16(temp5, zero_8x16b); // sign check
314
0
    temp5 = _mm_and_si128(temp5, sign_reg);
315
0
    sign_reg = _mm_cmpgt_epi16(temp6, zero_8x16b); // sign check
316
0
    temp6 = _mm_and_si128(temp6, sign_reg);
317
0
    sign_reg = _mm_cmpgt_epi16(temp7, zero_8x16b); // sign check
318
0
    temp7 = _mm_and_si128(temp7, sign_reg);
319
0
    sign_reg = _mm_cmpgt_epi16(temp8, zero_8x16b); // sign check
320
0
    temp8 = _mm_and_si128(temp8, sign_reg);
321
0
322
0
    temp1 = _mm_packus_epi16(temp1, zero_8x16b);
323
0
    temp2 = _mm_packus_epi16(temp2, zero_8x16b);
324
0
    temp3 = _mm_packus_epi16(temp3, zero_8x16b);
325
0
    temp4 = _mm_packus_epi16(temp4, zero_8x16b);
326
0
    temp5 = _mm_packus_epi16(temp5, zero_8x16b);
327
0
    temp6 = _mm_packus_epi16(temp6, zero_8x16b);
328
0
    temp7 = _mm_packus_epi16(temp7, zero_8x16b);
329
0
    temp8 = _mm_packus_epi16(temp8, zero_8x16b);
330
0
331
0
    _mm_storel_epi64((__m128i *)(&pu1_out[0]), temp1);
332
0
    _mm_storel_epi64((__m128i *)(&pu1_out[out_strd]), temp2);
333
0
    _mm_storel_epi64((__m128i *)(&pu1_out[2 * out_strd]), temp3);
334
0
    _mm_storel_epi64((__m128i *)(&pu1_out[3 * out_strd]), temp4);
335
0
    _mm_storel_epi64((__m128i *)(&pu1_out[4 * out_strd]), temp5);
336
0
    _mm_storel_epi64((__m128i *)(&pu1_out[5 * out_strd]), temp6);
337
0
    _mm_storel_epi64((__m128i *)(&pu1_out[6 * out_strd]), temp7);
338
0
    _mm_storel_epi64((__m128i *)(&pu1_out[7 * out_strd]), temp8);
339
0
}
340
341
/*
342
 ********************************************************************************
343
 *
344
 * @brief This function reconstructs a 4x4 sub block from quantized chroma resiude and
345
 * prediction buffer
346
 *
347
 * @par Description:
348
 *  The quantized residue is first inverse quantized, then inverse transformed.
349
 *  This inverse transformed content is added to the prediction buffer to recon-
350
 *  struct the end output
351
 *
352
 * @param[in] pi2_src
353
 *  quantized 4x4 block
354
 *
355
 * @param[in] pu1_pred
356
 *  prediction 4x4 block
357
 *
358
 * @param[out] pu1_out
359
 *  reconstructed 4x4 block
360
 *
361
 * @param[in] src_strd
362
 *  quantization buffer stride
363
 *
364
 * @param[in] pred_strd,
365
 *  Prediction buffer stride
366
 *
367
 * @param[in] out_strd
368
 *  recon buffer Stride
369
 *
370
 * @param[in] pu2_scaling_list
371
 *  pointer to scaling list
372
 *
373
 * @param[in] pu2_norm_adjust
374
 *  pointer to inverse scale matrix
375
 *
376
 * @param[in] u4_qp_div_6
377
 *  Floor (qp/6)
378
 *
379
 * @param[in] pi4_tmp
380
 * temporary buffer of size 1*16
381
 *
382
 * @returns none
383
 *
384
 * @remarks none
385
 *
386
 *******************************************************************************
387
 */
388
void ih264_iquant_itrans_recon_chroma_4x4_dc_ssse3(WORD16 *pi2_src,
389
                                   UWORD8 *pu1_pred,
390
                                   UWORD8 *pu1_out,
391
                                   WORD32 pred_strd,
392
                                   WORD32 out_strd,
393
                                   const UWORD16 *pu2_iscal_mat,
394
                                   const UWORD16 *pu2_weigh_mat,
395
                                   UWORD32 u4_qp_div_6,
396
                                   WORD16 *pi2_tmp,
397
                                   WORD16 *pi2_dc_src)
398
968
 {
399
968
    WORD16 q0 = pi2_dc_src[0];      // DC value won't be dequantized for chroma inverse transform
400
968
    WORD16 i_macro = ((q0 + 32) >> 6);
401
968
402
968
    __m128i pred_r0, pred_r1, pred_r2, pred_r3, sign_reg;
403
968
    __m128i zero_8x16b = _mm_setzero_si128();          // all bits reset to zero
404
968
    __m128i chroma_mask = _mm_set1_epi16 (0xFF);
405
968
    __m128i value_add = _mm_set1_epi16(i_macro);
406
968
    __m128i out_r0, out_r1, out_r2, out_r3;
407
968
408
968
    UNUSED (pi2_src);
409
968
    UNUSED (pu2_iscal_mat);
410
968
    UNUSED (pu2_weigh_mat);
411
968
    UNUSED (u4_qp_div_6);
412
968
    UNUSED (pi2_tmp);
413
968
414
968
    //Load pred buffer
415
968
    pred_r0 = _mm_loadl_epi64((__m128i *) (&pu1_pred[0])); //p00 p01 p02 p03 0 0 0 0 0 0 0 0 -- all 8 bits
416
968
    pred_r1 = _mm_loadl_epi64((__m128i *) (&pu1_pred[pred_strd])); //p10 p11 p12 p13 0 0 0 0 0 0 0 0 -- all 8 bits
417
968
    pred_r2 = _mm_loadl_epi64((__m128i *) (&pu1_pred[2 * pred_strd])); //p20 p21 p22 p23 0 0 0 0 0 0 0 0 -- all 8 bits
418
968
    pred_r3 = _mm_loadl_epi64((__m128i *) (&pu1_pred[3 * pred_strd])); //p30 p31 p32 p33 0 0 0 0 0 0 0 0 -- all 8 bits
419
968
420
968
    pred_r0 = _mm_and_si128(pred_r0, chroma_mask);
421
968
    pred_r1 = _mm_and_si128(pred_r1, chroma_mask);
422
968
    pred_r2 = _mm_and_si128(pred_r2, chroma_mask);
423
968
    pred_r3 = _mm_and_si128(pred_r3, chroma_mask);
424
968
425
968
    pred_r0 = _mm_unpacklo_epi64(pred_r0, pred_r1); //p00 p01 p02 p03 p10 p11 p12 p13
426
968
    pred_r2 = _mm_unpacklo_epi64(pred_r2, pred_r3); //p20 p21 p22p p23 p30 p31 p32 p33
427
968
428
968
    pred_r0 = _mm_add_epi16(value_add, pred_r0);
429
968
    pred_r2 = _mm_add_epi16(value_add, pred_r2);
430
968
431
968
    /*------------------------------------------------------------------*/
432
968
    //Clipping the results to 8 bits
433
968
    sign_reg = _mm_cmpgt_epi16(pred_r0, zero_8x16b);        // sign check
434
968
    pred_r0 = _mm_and_si128(pred_r0, sign_reg);
435
968
    sign_reg = _mm_cmpgt_epi16(pred_r2, zero_8x16b);
436
968
    pred_r2 = _mm_and_si128(pred_r2, sign_reg);
437
968
438
968
    pred_r0 = _mm_packus_epi16(pred_r0, pred_r2);
439
968
    pred_r1 = _mm_srli_si128(pred_r0, 4);
440
968
    pred_r2 = _mm_srli_si128(pred_r1, 4);
441
968
    pred_r3 = _mm_srli_si128(pred_r2, 4);
442
968
443
968
    pred_r0 = _mm_unpacklo_epi8(pred_r0, zero_8x16b); //p00 p01 p02 p03 -- all 16 bits
444
968
    pred_r1 = _mm_unpacklo_epi8(pred_r1, zero_8x16b); //p10 p11 p12 p13 -- all 16 bits
445
968
    pred_r2 = _mm_unpacklo_epi8(pred_r2, zero_8x16b); //p20 p21 p22 p23 -- all 16 bits
446
968
    pred_r3 = _mm_unpacklo_epi8(pred_r3, zero_8x16b); //p30 p31 p32 p33 -- all 16 bits
447
968
448
968
    chroma_mask = _mm_set1_epi16 (0xFF00);
449
968
    out_r0 = _mm_loadl_epi64((__m128i *) (&pu1_out[0]));
450
968
    out_r1 = _mm_loadl_epi64((__m128i *) (&pu1_out[out_strd]));
451
968
    out_r2 = _mm_loadl_epi64((__m128i *) (&pu1_out[2 * out_strd]));
452
968
    out_r3 = _mm_loadl_epi64((__m128i *) (&pu1_out[3 * out_strd]));
453
968
454
968
    out_r0 = _mm_and_si128(out_r0, chroma_mask);
455
968
    out_r1 = _mm_and_si128(out_r1, chroma_mask);
456
968
    out_r2 = _mm_and_si128(out_r2, chroma_mask);
457
968
    out_r3 = _mm_and_si128(out_r3, chroma_mask);
458
968
459
968
    out_r0 = _mm_add_epi8(out_r0, pred_r0);
460
968
    out_r1 = _mm_add_epi8(out_r1, pred_r1);
461
968
    out_r2 = _mm_add_epi8(out_r2, pred_r2);
462
968
    out_r3 = _mm_add_epi8(out_r3, pred_r3);
463
968
464
968
    _mm_storel_epi64((__m128i *)(&pu1_out[0]), out_r0);
465
968
    _mm_storel_epi64((__m128i *)(&pu1_out[out_strd]), out_r1);
466
968
    _mm_storel_epi64((__m128i *)(&pu1_out[2 * out_strd]), out_r2);
467
968
    _mm_storel_epi64((__m128i *)(&pu1_out[3 * out_strd]), out_r3);
468
968
}
469
470
/proc/self/cwd/external/libavc/common/x86/ih264_iquant_itrans_recon_sse42.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/**
21
 *******************************************************************************
22
 * @file
23
 *  ih264_iquant_itrans_recon_sse42.c
24
 *
25
 * @brief
26
 *  Contains function definitions for inverse  quantization, inverse
27
 * transform and reconstruction
28
 *
29
 * @author
30
 *  Mohit [100664]
31
 *
32
 * @par List of Functions:
33
 *  - ih264_iquant_itrans_recon_4x4_sse42()
34
 *  - ih264_iquant_itrans_recon_chroma_4x4_sse42()
35
 *
36
 * @remarks
37
 *  None
38
 *
39
 *******************************************************************************
40
 */
41
/* User include files */
42
#include "ih264_typedefs.h"
43
#include "ih264_defs.h"
44
#include "ih264_trans_macros.h"
45
#include "ih264_macros.h"
46
#include "ih264_platform_macros.h"
47
#include "ih264_trans_data.h"
48
#include "ih264_size_defs.h"
49
#include "ih264_structs.h"
50
#include "ih264_trans_quant_itrans_iquant.h"
51
#include <immintrin.h>
52
53
/*
54
 ********************************************************************************
55
 *
56
 * @brief This function reconstructs a 4x4 sub block from quantized resiude and
57
 * prediction buffer
58
 *
59
 * @par Description:
60
 *  The quantized residue is first inverse quantized, then inverse transformed.
61
 *  This inverse transformed content is added to the prediction buffer to recon-
62
 *  struct the end output
63
 *
64
 * @param[in] pi2_src
65
 *  quantized 4x4 block
66
 *
67
 * @param[in] pu1_pred
68
 *  prediction 4x4 block
69
 *
70
 * @param[out] pu1_out
71
 *  reconstructed 4x4 block
72
 *
73
 * @param[in] src_strd
74
 *  quantization buffer stride
75
 *
76
 * @param[in] pred_strd,
77
 *  Prediction buffer stride
78
 *
79
 * @param[in] out_strd
80
 *  recon buffer Stride
81
 *
82
 * @param[in] pu2_scaling_list
83
 *  pointer to scaling list
84
 *
85
 * @param[in] pu2_norm_adjust
86
 *  pointer to inverse scale matrix
87
 *
88
 * @param[in] u4_qp_div_6
89
 *  Floor (qp/6)
90
 *
91
 * @param[in] pi4_tmp
92
 * temporary buffer of size 1*16
93
 *
94
 * @returns none
95
 *
96
 * @remarks none
97
 *
98
 *******************************************************************************
99
 */
100
void ih264_iquant_itrans_recon_4x4_sse42(WORD16 *pi2_src,
101
                                   UWORD8 *pu1_pred,
102
                                   UWORD8 *pu1_out,
103
                                   WORD32 pred_strd,
104
                                   WORD32 out_strd,
105
                                   const UWORD16 *pu2_iscal_mat,
106
                                   const UWORD16 *pu2_weigh_mat,
107
                                   UWORD32 u4_qp_div_6,
108
                                   WORD16 *pi2_tmp,
109
                                   WORD32 iq_start_idx,
110
                                   WORD16 *pi2_dc_ld_addr)
111
15.0k
 {
112
15.0k
    UWORD32 *pu4_out = (UWORD32 *) pu1_out;
113
15.0k
    __m128i src_r0_r1, src_r2_r3;
114
15.0k
    __m128i src_r0, src_r1, src_r2, src_r3;
115
15.0k
    __m128i scalemat_r0_r1, scalemat_r2_r3;
116
15.0k
    __m128i pred_r0, pred_r1, pred_r2, pred_r3;
117
15.0k
    __m128i sign_reg, dequant_r0_r1, dequant_r2_r3;
118
15.0k
    __m128i zero_8x16b = _mm_setzero_si128();          // all bits reset to zero
119
15.0k
    __m128i temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7;
120
15.0k
    __m128i resq_r0, resq_r1, resq_r2, resq_r3;
121
15.0k
    __m128i add_rshift = _mm_set1_epi32((1 << (3 - u4_qp_div_6)));
122
15.0k
    __m128i value_32 = _mm_set1_epi32(32);
123
15.0k
    UNUSED (pi2_tmp);
124
15.0k
125
15.0k
    /*************************************************************/
126
15.0k
    /* Dequantization of coefficients. Will be replaced by SIMD  */
127
15.0k
    /* operations on platform                                    */
128
15.0k
    /*************************************************************/
129
15.0k
    src_r0_r1 = _mm_loadu_si128((__m128i *) (pi2_src)); //a00 a01 a02 a03 a10 a11 a12 a13 -- the source matrix 0th,1st row
130
15.0k
    src_r2_r3 = _mm_loadu_si128((__m128i *) (pi2_src + 8)); //a20 a21 a22 a23 a30 a31 a32 a33 -- the source matrix 2nd,3rd row
131
15.0k
    scalemat_r0_r1 = _mm_loadu_si128((__m128i *) (pu2_iscal_mat)); //b00 b01 b02 b03 b10 b11 b12 b13 -- the scaling matrix 0th,1st row
132
15.0k
    scalemat_r2_r3 = _mm_loadu_si128((__m128i *) (pu2_iscal_mat + 8)); //b20 b21 b22 b23 b30 b31 b32 b33 -- the scaling matrix 2nd,3rd row
133
15.0k
    dequant_r0_r1 = _mm_loadu_si128((__m128i *) (pu2_weigh_mat)); //q00 q01 q02 q03 q10 q11 q12 q13 -- all 16 bits
134
15.0k
    dequant_r2_r3 = _mm_loadu_si128((__m128i *) (pu2_weigh_mat + 8)); //q20 q21 q22 q23 q30 q31 q32 q33 -- all 16 bits
135
15.0k
136
15.0k
    temp0 = _mm_mullo_epi16(scalemat_r0_r1, dequant_r0_r1); //b00*q00 b01*q01 b02*q02 b03*q03 b10*q10 b11*q11 b12*q12 b13*q13 -- 16 bit result
137
15.0k
    temp1 = _mm_mullo_epi16(scalemat_r2_r3, dequant_r2_r3); //b00*q00 b01*q01 b02*q02 b03*q03 b10*q10 b11*q11 b12*q12 b13*q13 -- 16 bit result
138
15.0k
139
15.0k
    temp4 = _mm_unpacklo_epi16(temp0, zero_8x16b); // b00*q00 0 b01*q01 0 b02*q02 0 b03*q03 0 -- 16 bit long
140
15.0k
    temp5 = _mm_unpackhi_epi16(temp0, zero_8x16b); // b10*q10 0 b11*q11 0 b12*q12 0 b13*q13 0 -- 16 bit long
141
15.0k
    temp6 = _mm_unpacklo_epi16(temp1, zero_8x16b); // b00*q00 0 b01*q01 0 b02*q02 0 b03*q03 0 -- 16 bit long
142
15.0k
    temp7 = _mm_unpackhi_epi16(temp1, zero_8x16b); // b10*q10 0 b11*q11 0 b12*q12 0 b13*q13 0 -- 16 bit long
143
15.0k
144
15.0k
    src_r0 = _mm_unpacklo_epi16(src_r0_r1, zero_8x16b); // a00 0 a01 0 a02 0 a03 0 -- 16 bit long
145
15.0k
    src_r1 = _mm_unpackhi_epi16(src_r0_r1, zero_8x16b); // a10 0 a11 0 a12 0 a13 0 -- 16 bit long
146
15.0k
    src_r2 = _mm_unpacklo_epi16(src_r2_r3, zero_8x16b); // a20 0 a21 0 a22 0 a23 0 -- 16 bit long
147
15.0k
    src_r3 = _mm_unpackhi_epi16(src_r2_r3, zero_8x16b); // a30 0 a31 0 a32 0 a33 0 -- 16 bit long
148
15.0k
149
15.0k
    temp4 = _mm_madd_epi16(src_r0, temp4); //a00*b00*q00 a10*b10*q10 a20*b20*q20 a30*b30 q30 -- 32 bits long
150
15.0k
    temp5 = _mm_madd_epi16(src_r1, temp5);
151
15.0k
    temp6 = _mm_madd_epi16(src_r2, temp6);
152
15.0k
    temp7 = _mm_madd_epi16(src_r3, temp7);
153
15.0k
154
15.0k
    if (u4_qp_div_6 >= 4) {
155
0
        resq_r0 = _mm_slli_epi32(temp4, u4_qp_div_6 - 4);
156
0
        resq_r1 = _mm_slli_epi32(temp5, u4_qp_div_6 - 4);
157
0
        resq_r2 = _mm_slli_epi32(temp6, u4_qp_div_6 - 4);
158
0
        resq_r3 = _mm_slli_epi32(temp7, u4_qp_div_6 - 4);
159
15.0k
    } else {
160
15.0k
        temp4 = _mm_add_epi32(temp4, add_rshift);
161
15.0k
        temp5 = _mm_add_epi32(temp5, add_rshift);
162
15.0k
        temp6 = _mm_add_epi32(temp6, add_rshift);
163
15.0k
        temp7 = _mm_add_epi32(temp7, add_rshift);
164
15.0k
        resq_r0 = _mm_srai_epi32(temp4, 4 - u4_qp_div_6);
165
15.0k
        resq_r1 = _mm_srai_epi32(temp5, 4 - u4_qp_div_6);
166
15.0k
        resq_r2 = _mm_srai_epi32(temp6, 4 - u4_qp_div_6);
167
15.0k
        resq_r3 = _mm_srai_epi32(temp7, 4 - u4_qp_div_6);
168
15.0k
    }
169
15.0k
170
15.0k
    if (iq_start_idx == 1)
171
121
        resq_r0 = _mm_insert_epi32(resq_r0,(WORD32)pi2_dc_ld_addr[0],0);
172
15.0k
    /* Perform Inverse transform */
173
15.0k
    /*-------------------------------------------------------------*/
174
15.0k
    /* IDCT [ Horizontal transformation ]                          */
175
15.0k
    /*-------------------------------------------------------------*/
176
15.0k
    // Matrix transpose
177
15.0k
    /*
178
15.0k
     *  a0 a1 a2 a3
179
15.0k
     *  b0 b1 b2 b3
180
15.0k
     *  c0 c1 c2 c3
181
15.0k
     *  d0 d1 d2 d3
182
15.0k
     */
183
15.0k
    temp1 = _mm_unpacklo_epi32(resq_r0, resq_r1);                  //a0 b0 a1 b1
184
15.0k
    temp3 = _mm_unpacklo_epi32(resq_r2, resq_r3);                  //c0 d0 c1 d1
185
15.0k
    temp2 = _mm_unpackhi_epi32(resq_r0, resq_r1);                  //a2 b2 a3 b3
186
15.0k
    temp4 = _mm_unpackhi_epi32(resq_r2, resq_r3);                  //c2 d2 c3 d3
187
15.0k
    resq_r0 = _mm_unpacklo_epi64(temp1, temp3);                    //a0 b0 c0 d0
188
15.0k
    resq_r1 = _mm_unpackhi_epi64(temp1, temp3);                    //a1 b1 c1 d1
189
15.0k
    resq_r2 = _mm_unpacklo_epi64(temp2, temp4);                    //a2 b2 c2 d2
190
15.0k
    resq_r3 = _mm_unpackhi_epi64(temp2, temp4);                    //a3 b3 c3 d3
191
15.0k
    //Transform starts -- horizontal transform
192
15.0k
    /*------------------------------------------------------------------*/
193
15.0k
    /* z0 = w0 + w2                                             */
194
15.0k
    temp0 = _mm_add_epi32(resq_r0, resq_r2);
195
15.0k
    /* z1 = w0 - w2                                             */
196
15.0k
    temp1 = _mm_sub_epi32(resq_r0, resq_r2);
197
15.0k
    /* z2 = (w1 >> 1) - w3                                      */
198
15.0k
    temp2 = _mm_srai_epi32(resq_r1, 1);                         //(w1>>1)
199
15.0k
    temp2 = _mm_sub_epi32(temp2, resq_r3);                      //(w1>>1) - w3
200
15.0k
    /* z3 = w1 + (w3 >> 1)                                      */
201
15.0k
    temp3 = _mm_srai_epi32(resq_r3, 1);                         //(w3>>1) + w1
202
15.0k
    temp3 = _mm_add_epi32(temp3, resq_r1);
203
15.0k
    /*----------------------------------------------------------*/
204
15.0k
    /* x0 = z0 + z3                                             */
205
15.0k
    resq_r0 = _mm_add_epi32(temp0, temp3);
206
15.0k
    /* x1 = z1 + z2                                             */
207
15.0k
    resq_r1 = _mm_add_epi32(temp1, temp2);
208
15.0k
    /* x2 = z1 - z2                                             */
209
15.0k
    resq_r2 = _mm_sub_epi32(temp1, temp2);
210
15.0k
    /* x3 = z0 - z3                                             */
211
15.0k
    resq_r3 = _mm_sub_epi32(temp0, temp3);
212
15.0k
    // Matrix transpose
213
15.0k
    /*
214
15.0k
     *  a0 b0 c0 d0
215
15.0k
     *  a1 b1 c1 d1
216
15.0k
     *  a2 b2 c2 d2
217
15.0k
     *  a3 b3 c3 d3
218
15.0k
     */
219
15.0k
    temp1 = _mm_unpacklo_epi32(resq_r0, resq_r1);                  //a0 a1 b0 b1
220
15.0k
    temp3 = _mm_unpacklo_epi32(resq_r2, resq_r3);                  //a2 a3 b2 b3
221
15.0k
    temp2 = _mm_unpackhi_epi32(resq_r0, resq_r1);                  //c0 c1 d0 d1
222
15.0k
    temp4 = _mm_unpackhi_epi32(resq_r2, resq_r3);                  //c2 c3 d2 d3
223
15.0k
    resq_r0 = _mm_unpacklo_epi64(temp1, temp3);                    //a0 a1 a2 a3
224
15.0k
    resq_r1 = _mm_unpackhi_epi64(temp1, temp3);                    //b0 b1 b2 b3
225
15.0k
    resq_r2 = _mm_unpacklo_epi64(temp2, temp4);                    //c0 c1 c2 c3
226
15.0k
    resq_r3 = _mm_unpackhi_epi64(temp2, temp4);                    //d0 d1 d2 d3
227
15.0k
    //Transform ends -- horizontal transform
228
15.0k
229
15.0k
    //Load pred buffer
230
15.0k
    pred_r0 = _mm_loadl_epi64((__m128i *) (&pu1_pred[0])); //p00 p01 p02 p03 0 0 0 0 0 0 0 0 -- all 8 bits
231
15.0k
    pred_r1 = _mm_loadl_epi64((__m128i *) (&pu1_pred[pred_strd])); //p10 p11 p12 p13 0 0 0 0 0 0 0 0 -- all 8 bits
232
15.0k
    pred_r2 = _mm_loadl_epi64((__m128i *) (&pu1_pred[2 * pred_strd])); //p20 p21 p22 p23 0 0 0 0 0 0 0 0 -- all 8 bits
233
15.0k
    pred_r3 = _mm_loadl_epi64((__m128i *) (&pu1_pred[3 * pred_strd])); //p30 p31 p32 p33 0 0 0 0 0 0 0 0 -- all 8 bits
234
15.0k
235
15.0k
    pred_r0 = _mm_cvtepu8_epi32(pred_r0); //p00 p01 p02 p03 -- all 32 bits
236
15.0k
    pred_r1 = _mm_cvtepu8_epi32(pred_r1); //p10 p11 p12 p13 -- all 32 bits
237
15.0k
    pred_r2 = _mm_cvtepu8_epi32(pred_r2); //p20 p21 p22 p23 -- all 32 bits
238
15.0k
    pred_r3 = _mm_cvtepu8_epi32(pred_r3); //p30 p31 p32 p33 -- all 32 bits
239
15.0k
240
15.0k
    /*--------------------------------------------------------------*/
241
15.0k
    /* IDCT [ Vertical transformation] and Xij = (xij + 32)>>6      */
242
15.0k
    /*                                                              */
243
15.0k
    /* Add the prediction and store it back to same buffer          */
244
15.0k
    /*--------------------------------------------------------------*/
245
15.0k
    /* z0j = y0j + y2j                                                        */
246
15.0k
    temp0 = _mm_add_epi32(resq_r0, resq_r2);
247
15.0k
    /* z1j = y0j - y2j                                                        */
248
15.0k
    temp1 = _mm_sub_epi32(resq_r0, resq_r2);
249
15.0k
    /* z2j = (y1j>>1) - y3j                                                        */
250
15.0k
    temp2 = _mm_srai_epi32(resq_r1, 1);                             //(y1j>>1)
251
15.0k
    temp2 = _mm_sub_epi32(temp2, resq_r3);
252
15.0k
    /* z3j = y1j + (y3j>>1)                                                        */
253
15.0k
    temp3 = _mm_srai_epi32(resq_r3, 1);                             //(y3j>>1)
254
15.0k
    temp3 = _mm_add_epi32(temp3, resq_r1);
255
15.0k
256
15.0k
    /* x0j = z0j + z3j                                                        */
257
15.0k
    temp4 = _mm_add_epi32(temp0, temp3);
258
15.0k
    temp4 = _mm_add_epi32(temp4, value_32);
259
15.0k
    temp4 = _mm_srai_epi32(temp4, 6);
260
15.0k
    temp4 = _mm_add_epi32(temp4, pred_r0);
261
15.0k
    /* x1j = z1j + z2j                                                        */
262
15.0k
    temp5 = _mm_add_epi32(temp1, temp2);
263
15.0k
    temp5 = _mm_add_epi32(temp5, value_32);
264
15.0k
    temp5 = _mm_srai_epi32(temp5, 6);
265
15.0k
    temp5 = _mm_add_epi32(temp5, pred_r1);
266
15.0k
    /* x2j = z1j - z2j                                                        */
267
15.0k
    temp6 = _mm_sub_epi32(temp1, temp2);
268
15.0k
    temp6 = _mm_add_epi32(temp6, value_32);
269
15.0k
    temp6 = _mm_srai_epi32(temp6, 6);
270
15.0k
    temp6 = _mm_add_epi32(temp6, pred_r2);
271
15.0k
    /* x3j = z0j - z3j                                                        */
272
15.0k
    temp7 = _mm_sub_epi32(temp0, temp3);
273
15.0k
    temp7 = _mm_add_epi32(temp7, value_32);
274
15.0k
    temp7 = _mm_srai_epi32(temp7, 6);
275
15.0k
    temp7 = _mm_add_epi32(temp7, pred_r3);
276
15.0k
277
15.0k
    // 32-bit to 16-bit conversion
278
15.0k
    temp0 = _mm_packs_epi32(temp4, temp5);
279
15.0k
    temp1 = _mm_packs_epi32(temp6, temp7);
280
15.0k
    /*------------------------------------------------------------------*/
281
15.0k
    //Clipping the results to 8 bits
282
15.0k
    sign_reg = _mm_cmpgt_epi16(temp0, zero_8x16b);      // sign check
283
15.0k
    temp0 = _mm_and_si128(temp0, sign_reg);
284
15.0k
    sign_reg = _mm_cmpgt_epi16(temp1, zero_8x16b);
285
15.0k
    temp1 = _mm_and_si128(temp1, sign_reg);
286
15.0k
287
15.0k
    resq_r0 = _mm_packus_epi16(temp0, temp1);
288
15.0k
    resq_r1 = _mm_srli_si128(resq_r0, 4);
289
15.0k
    resq_r2 = _mm_srli_si128(resq_r1, 4);
290
15.0k
    resq_r3 = _mm_srli_si128(resq_r2, 4);
291
15.0k
292
15.0k
    *pu4_out = _mm_cvtsi128_si32(resq_r0);
293
15.0k
    pu1_out += out_strd;
294
15.0k
    pu4_out = (UWORD32 *) (pu1_out);
295
15.0k
    *(pu4_out) = _mm_cvtsi128_si32(resq_r1);
296
15.0k
    pu1_out += out_strd;
297
15.0k
    pu4_out = (UWORD32 *) (pu1_out);
298
15.0k
    *(pu4_out) = _mm_cvtsi128_si32(resq_r2);
299
15.0k
    pu1_out += out_strd;
300
15.0k
    pu4_out = (UWORD32 *) (pu1_out);
301
15.0k
    *(pu4_out) = _mm_cvtsi128_si32(resq_r3);
302
15.0k
}
303
304
/*
305
 ********************************************************************************
306
 *
307
 * @brief This function reconstructs a 4x4 sub block from quantized chroma resiude and
308
 * prediction buffer
309
 *
310
 * @par Description:
311
 *  The quantized residue is first inverse quantized, then inverse transformed.
312
 *  This inverse transformed content is added to the prediction buffer to recon-
313
 *  struct the end output
314
 *
315
 * @param[in] pi2_src
316
 *  quantized 4x4 block
317
 *
318
 * @param[in] pu1_pred
319
 *  prediction 4x4 block
320
 *
321
 * @param[out] pu1_out
322
 *  reconstructed 4x4 block
323
 *
324
 * @param[in] src_strd
325
 *  quantization buffer stride
326
 *
327
 * @param[in] pred_strd,
328
 *  Prediction buffer stride
329
 *
330
 * @param[in] out_strd
331
 *  recon buffer Stride
332
 *
333
 * @param[in] pu2_scaling_list
334
 *  pointer to scaling list
335
 *
336
 * @param[in] pu2_norm_adjust
337
 *  pointer to inverse scale matrix
338
 *
339
 * @param[in] u4_qp_div_6
340
 *  Floor (qp/6)
341
 *
342
 * @param[in] pi4_tmp
343
 * temporary buffer of size 1*16
344
 *
345
 * @returns none
346
 *
347
 * @remarks none
348
 *
349
 *******************************************************************************
350
 */
351
void ih264_iquant_itrans_recon_chroma_4x4_sse42(WORD16 *pi2_src,
352
                                   UWORD8 *pu1_pred,
353
                                   UWORD8 *pu1_out,
354
                                   WORD32 pred_strd,
355
                                   WORD32 out_strd,
356
                                   const UWORD16 *pu2_iscal_mat,
357
                                   const UWORD16 *pu2_weigh_mat,
358
                                   UWORD32 u4_qp_div_6,
359
                                   WORD16 *pi2_tmp,
360
                                   WORD16 *pi2_dc_ld_addr)
361
8.88k
 {
362
8.88k
    __m128i src_r0_r1, src_r2_r3;
363
8.88k
    __m128i src_r0, src_r1, src_r2, src_r3;
364
8.88k
    __m128i scalemat_r0_r1, scalemat_r2_r3;
365
8.88k
    __m128i pred_r0, pred_r1, pred_r2, pred_r3;
366
8.88k
    __m128i sign_reg, dequant_r0_r1, dequant_r2_r3;
367
8.88k
    __m128i zero_8x16b = _mm_setzero_si128();          // all bits reset to zero
368
8.88k
    __m128i temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7;
369
8.88k
    __m128i resq_r0, resq_r1, resq_r2, resq_r3;
370
8.88k
    __m128i add_rshift = _mm_set1_epi32((1 << (3 - u4_qp_div_6)));
371
8.88k
    __m128i value_32 = _mm_set1_epi32(32);
372
8.88k
    __m128i chroma_mask = _mm_set1_epi16 (0xFF);
373
8.88k
    __m128i out_r0, out_r1, out_r2, out_r3;
374
8.88k
    UNUSED (pi2_tmp);
375
8.88k
376
8.88k
    /*************************************************************/
377
8.88k
    /* Dequantization of coefficients. Will be replaced by SIMD  */
378
8.88k
    /* operations on platform                                    */
379
8.88k
    /*************************************************************/
380
8.88k
    src_r0_r1 = _mm_loadu_si128((__m128i *) (pi2_src)); //a00 a01 a02 a03 a10 a11 a12 a13 -- the source matrix 0th,1st row
381
8.88k
    src_r2_r3 = _mm_loadu_si128((__m128i *) (pi2_src + 8)); //a20 a21 a22 a23 a30 a31 a32 a33 -- the source matrix 2nd,3rd row
382
8.88k
    scalemat_r0_r1 = _mm_loadu_si128((__m128i *) (pu2_iscal_mat)); //b00 b01 b02 b03 b10 b11 b12 b13 -- the scaling matrix 0th,1st row
383
8.88k
    scalemat_r2_r3 = _mm_loadu_si128((__m128i *) (pu2_iscal_mat + 8)); //b20 b21 b22 b23 b30 b31 b32 b33 -- the scaling matrix 2nd,3rd row
384
8.88k
    dequant_r0_r1 = _mm_loadu_si128((__m128i *) (pu2_weigh_mat)); //q00 q01 q02 q03 q10 q11 q12 q13 -- all 16 bits
385
8.88k
    dequant_r2_r3 = _mm_loadu_si128((__m128i *) (pu2_weigh_mat + 8)); //q20 q21 q22 q23 q30 q31 q32 q33 -- all 16 bits
386
8.88k
387
8.88k
    temp0 = _mm_mullo_epi16(scalemat_r0_r1, dequant_r0_r1); //b00*q00 b01*q01 b02*q02 b03*q03 b10*q10 b11*q11 b12*q12 b13*q13 -- 16 bit result
388
8.88k
    temp1 = _mm_mullo_epi16(scalemat_r2_r3, dequant_r2_r3); //b00*q00 b01*q01 b02*q02 b03*q03 b10*q10 b11*q11 b12*q12 b13*q13 -- 16 bit result
389
8.88k
390
8.88k
    temp4 = _mm_unpacklo_epi16(temp0, zero_8x16b); // b00*q00 0 b01*q01 0 b02*q02 0 b03*q03 0 -- 16 bit long
391
8.88k
    temp5 = _mm_unpackhi_epi16(temp0, zero_8x16b); // b10*q10 0 b11*q11 0 b12*q12 0 b13*q13 0 -- 16 bit long
392
8.88k
    temp6 = _mm_unpacklo_epi16(temp1, zero_8x16b); // b00*q00 0 b01*q01 0 b02*q02 0 b03*q03 0 -- 16 bit long
393
8.88k
    temp7 = _mm_unpackhi_epi16(temp1, zero_8x16b); // b10*q10 0 b11*q11 0 b12*q12 0 b13*q13 0 -- 16 bit long
394
8.88k
395
8.88k
    src_r0 = _mm_unpacklo_epi16(src_r0_r1, zero_8x16b); // a00 0 a01 0 a02 0 a03 0 -- 16 bit long
396
8.88k
    src_r1 = _mm_unpackhi_epi16(src_r0_r1, zero_8x16b); // a10 0 a11 0 a12 0 a13 0 -- 16 bit long
397
8.88k
    src_r2 = _mm_unpacklo_epi16(src_r2_r3, zero_8x16b); // a20 0 a21 0 a22 0 a23 0 -- 16 bit long
398
8.88k
    src_r3 = _mm_unpackhi_epi16(src_r2_r3, zero_8x16b); // a30 0 a31 0 a32 0 a33 0 -- 16 bit long
399
8.88k
400
8.88k
    temp4 = _mm_madd_epi16(src_r0, temp4); //a00*b00*q00 a10*b10*q10 a20*b20*q20 a30*b30 q30 -- 32 bits long
401
8.88k
    temp5 = _mm_madd_epi16(src_r1, temp5);
402
8.88k
    temp6 = _mm_madd_epi16(src_r2, temp6);
403
8.88k
    temp7 = _mm_madd_epi16(src_r3, temp7);
404
8.88k
405
8.88k
    if (u4_qp_div_6 >= 4) {
406
0
        resq_r0 = _mm_slli_epi32(temp4, u4_qp_div_6 - 4);
407
0
        resq_r1 = _mm_slli_epi32(temp5, u4_qp_div_6 - 4);
408
0
        resq_r2 = _mm_slli_epi32(temp6, u4_qp_div_6 - 4);
409
0
        resq_r3 = _mm_slli_epi32(temp7, u4_qp_div_6 - 4);
410
8.88k
    } else {
411
8.88k
        temp4 = _mm_add_epi32(temp4, add_rshift);
412
8.88k
        temp5 = _mm_add_epi32(temp5, add_rshift);
413
8.88k
        temp6 = _mm_add_epi32(temp6, add_rshift);
414
8.88k
        temp7 = _mm_add_epi32(temp7, add_rshift);
415
8.88k
        resq_r0 = _mm_srai_epi32(temp4, 4 - u4_qp_div_6);
416
8.88k
        resq_r1 = _mm_srai_epi32(temp5, 4 - u4_qp_div_6);
417
8.88k
        resq_r2 = _mm_srai_epi32(temp6, 4 - u4_qp_div_6);
418
8.88k
        resq_r3 = _mm_srai_epi32(temp7, 4 - u4_qp_div_6);
419
8.88k
    }
420
8.88k
421
8.88k
    resq_r0 = _mm_insert_epi32(resq_r0,(WORD32)pi2_dc_ld_addr[0],0);
422
8.88k
    /* Perform Inverse transform */
423
8.88k
    /*-------------------------------------------------------------*/
424
8.88k
    /* IDCT [ Horizontal transformation ]                          */
425
8.88k
    /*-------------------------------------------------------------*/
426
8.88k
    // Matrix transpose
427
8.88k
    /*
428
8.88k
     *  a0 a1 a2 a3
429
8.88k
     *  b0 b1 b2 b3
430
8.88k
     *  c0 c1 c2 c3
431
8.88k
     *  d0 d1 d2 d3
432
8.88k
     */
433
8.88k
    temp1 = _mm_unpacklo_epi32(resq_r0, resq_r1);                  //a0 b0 a1 b1
434
8.88k
    temp3 = _mm_unpacklo_epi32(resq_r2, resq_r3);                  //c0 d0 c1 d1
435
8.88k
    temp2 = _mm_unpackhi_epi32(resq_r0, resq_r1);                  //a2 b2 a3 b3
436
8.88k
    temp4 = _mm_unpackhi_epi32(resq_r2, resq_r3);                  //c2 d2 c3 d3
437
8.88k
    resq_r0 = _mm_unpacklo_epi64(temp1, temp3);                    //a0 b0 c0 d0
438
8.88k
    resq_r1 = _mm_unpackhi_epi64(temp1, temp3);                    //a1 b1 c1 d1
439
8.88k
    resq_r2 = _mm_unpacklo_epi64(temp2, temp4);                    //a2 b2 c2 d2
440
8.88k
    resq_r3 = _mm_unpackhi_epi64(temp2, temp4);                    //a3 b3 c3 d3
441
8.88k
    //Transform starts -- horizontal transform
442
8.88k
    /*------------------------------------------------------------------*/
443
8.88k
    /* z0 = w0 + w2                                             */
444
8.88k
    temp0 = _mm_add_epi32(resq_r0, resq_r2);
445
8.88k
    /* z1 = w0 - w2                                             */
446
8.88k
    temp1 = _mm_sub_epi32(resq_r0, resq_r2);
447
8.88k
    /* z2 = (w1 >> 1) - w3                                      */
448
8.88k
    temp2 = _mm_srai_epi32(resq_r1, 1);                         //(w1>>1)
449
8.88k
    temp2 = _mm_sub_epi32(temp2, resq_r3);                      //(w1>>1) - w3
450
8.88k
    /* z3 = w1 + (w3 >> 1)                                      */
451
8.88k
    temp3 = _mm_srai_epi32(resq_r3, 1);                         //(w3>>1) + w1
452
8.88k
    temp3 = _mm_add_epi32(temp3, resq_r1);
453
8.88k
    /*----------------------------------------------------------*/
454
8.88k
    /* x0 = z0 + z3                                             */
455
8.88k
    resq_r0 = _mm_add_epi32(temp0, temp3);
456
8.88k
    /* x1 = z1 + z2                                             */
457
8.88k
    resq_r1 = _mm_add_epi32(temp1, temp2);
458
8.88k
    /* x2 = z1 - z2                                             */
459
8.88k
    resq_r2 = _mm_sub_epi32(temp1, temp2);
460
8.88k
    /* x3 = z0 - z3                                             */
461
8.88k
    resq_r3 = _mm_sub_epi32(temp0, temp3);
462
8.88k
    // Matrix transpose
463
8.88k
    /*
464
8.88k
     *  a0 b0 c0 d0
465
8.88k
     *  a1 b1 c1 d1
466
8.88k
     *  a2 b2 c2 d2
467
8.88k
     *  a3 b3 c3 d3
468
8.88k
     */
469
8.88k
    temp1 = _mm_unpacklo_epi32(resq_r0, resq_r1);                  //a0 a1 b0 b1
470
8.88k
    temp3 = _mm_unpacklo_epi32(resq_r2, resq_r3);                  //a2 a3 b2 b3
471
8.88k
    temp2 = _mm_unpackhi_epi32(resq_r0, resq_r1);                  //c0 c1 d0 d1
472
8.88k
    temp4 = _mm_unpackhi_epi32(resq_r2, resq_r3);                  //c2 c3 d2 d3
473
8.88k
    resq_r0 = _mm_unpacklo_epi64(temp1, temp3);                    //a0 a1 a2 a3
474
8.88k
    resq_r1 = _mm_unpackhi_epi64(temp1, temp3);                    //b0 b1 b2 b3
475
8.88k
    resq_r2 = _mm_unpacklo_epi64(temp2, temp4);                    //c0 c1 c2 c3
476
8.88k
    resq_r3 = _mm_unpackhi_epi64(temp2, temp4);                    //d0 d1 d2 d3
477
8.88k
    //Transform ends -- horizontal transform
478
8.88k
479
8.88k
    //Load pred buffer
480
8.88k
    pred_r0 = _mm_loadl_epi64((__m128i *) (&pu1_pred[0])); //p00 p01 p02 p03 0 0 0 0 0 0 0 0 -- all 8 bits
481
8.88k
    pred_r1 = _mm_loadl_epi64((__m128i *) (&pu1_pred[pred_strd])); //p10 p11 p12 p13 0 0 0 0 0 0 0 0 -- all 8 bits
482
8.88k
    pred_r2 = _mm_loadl_epi64((__m128i *) (&pu1_pred[2 * pred_strd])); //p20 p21 p22 p23 0 0 0 0 0 0 0 0 -- all 8 bits
483
8.88k
    pred_r3 = _mm_loadl_epi64((__m128i *) (&pu1_pred[3 * pred_strd])); //p30 p31 p32 p33 0 0 0 0 0 0 0 0 -- all 8 bits
484
8.88k
485
8.88k
    pred_r0 = _mm_and_si128(pred_r0, chroma_mask);
486
8.88k
    pred_r1 = _mm_and_si128(pred_r1, chroma_mask);
487
8.88k
    pred_r2 = _mm_and_si128(pred_r2, chroma_mask);
488
8.88k
    pred_r3 = _mm_and_si128(pred_r3, chroma_mask);
489
8.88k
490
8.88k
    pred_r0 = _mm_cvtepu16_epi32(pred_r0); //p00 p01 p02 p03 -- all 32 bits
491
8.88k
    pred_r1 = _mm_cvtepu16_epi32(pred_r1); //p10 p11 p12 p13 -- all 32 bits
492
8.88k
    pred_r2 = _mm_cvtepu16_epi32(pred_r2); //p20 p21 p22 p23 -- all 32 bits
493
8.88k
    pred_r3 = _mm_cvtepu16_epi32(pred_r3); //p30 p31 p32 p33 -- all 32 bits
494
8.88k
495
8.88k
    /*--------------------------------------------------------------*/
496
8.88k
    /* IDCT [ Vertical transformation] and Xij = (xij + 32)>>6      */
497
8.88k
    /*                                                              */
498
8.88k
    /* Add the prediction and store it back to same buffer          */
499
8.88k
    /*--------------------------------------------------------------*/
500
8.88k
    /* z0j = y0j + y2j                                                        */
501
8.88k
    temp0 = _mm_add_epi32(resq_r0, resq_r2);
502
8.88k
    /* z1j = y0j - y2j                                                        */
503
8.88k
    temp1 = _mm_sub_epi32(resq_r0, resq_r2);
504
8.88k
    /* z2j = (y1j>>1) - y3j                                                        */
505
8.88k
    temp2 = _mm_srai_epi32(resq_r1, 1);                             //(y1j>>1)
506
8.88k
    temp2 = _mm_sub_epi32(temp2, resq_r3);
507
8.88k
    /* z3j = y1j + (y3j>>1)                                                        */
508
8.88k
    temp3 = _mm_srai_epi32(resq_r3, 1);                             //(y3j>>1)
509
8.88k
    temp3 = _mm_add_epi32(temp3, resq_r1);
510
8.88k
511
8.88k
    /* x0j = z0j + z3j                                                        */
512
8.88k
    temp4 = _mm_add_epi32(temp0, temp3);
513
8.88k
    temp4 = _mm_add_epi32(temp4, value_32);
514
8.88k
    temp4 = _mm_srai_epi32(temp4, 6);
515
8.88k
    temp4 = _mm_add_epi32(temp4, pred_r0);
516
8.88k
    /* x1j = z1j + z2j                                                        */
517
8.88k
    temp5 = _mm_add_epi32(temp1, temp2);
518
8.88k
    temp5 = _mm_add_epi32(temp5, value_32);
519
8.88k
    temp5 = _mm_srai_epi32(temp5, 6);
520
8.88k
    temp5 = _mm_add_epi32(temp5, pred_r1);
521
8.88k
    /* x2j = z1j - z2j                                                        */
522
8.88k
    temp6 = _mm_sub_epi32(temp1, temp2);
523
8.88k
    temp6 = _mm_add_epi32(temp6, value_32);
524
8.88k
    temp6 = _mm_srai_epi32(temp6, 6);
525
8.88k
    temp6 = _mm_add_epi32(temp6, pred_r2);
526
8.88k
    /* x3j = z0j - z3j                                                        */
527
8.88k
    temp7 = _mm_sub_epi32(temp0, temp3);
528
8.88k
    temp7 = _mm_add_epi32(temp7, value_32);
529
8.88k
    temp7 = _mm_srai_epi32(temp7, 6);
530
8.88k
    temp7 = _mm_add_epi32(temp7, pred_r3);
531
8.88k
532
8.88k
    // 32-bit to 16-bit conversion
533
8.88k
    temp0 = _mm_packs_epi32(temp4, temp5);
534
8.88k
    temp1 = _mm_packs_epi32(temp6, temp7);
535
8.88k
    /*------------------------------------------------------------------*/
536
8.88k
    //Clipping the results to 8 bits
537
8.88k
    sign_reg = _mm_cmpgt_epi16(temp0, zero_8x16b);      // sign check
538
8.88k
    temp0 = _mm_and_si128(temp0, sign_reg);
539
8.88k
    sign_reg = _mm_cmpgt_epi16(temp1, zero_8x16b);
540
8.88k
    temp1 = _mm_and_si128(temp1, sign_reg);
541
8.88k
542
8.88k
    resq_r0 = _mm_packus_epi16(temp0, temp1);
543
8.88k
    resq_r1 = _mm_srli_si128(resq_r0, 4);
544
8.88k
    resq_r2 = _mm_srli_si128(resq_r1, 4);
545
8.88k
    resq_r3 = _mm_srli_si128(resq_r2, 4);
546
8.88k
547
8.88k
    resq_r0 = _mm_cvtepu8_epi16(resq_r0); //p00 p01 p02 p03 -- all 16 bits
548
8.88k
    resq_r1 = _mm_cvtepu8_epi16(resq_r1); //p10 p11 p12 p13 -- all 16 bits
549
8.88k
    resq_r2 = _mm_cvtepu8_epi16(resq_r2); //p20 p21 p22 p23 -- all 16 bits
550
8.88k
    resq_r3 = _mm_cvtepu8_epi16(resq_r3); //p30 p31 p32 p33 -- all 16 bits
551
8.88k
552
8.88k
    chroma_mask = _mm_set1_epi16 (0xFF00);
553
8.88k
    out_r0 = _mm_loadl_epi64((__m128i *) (&pu1_out[0]));
554
8.88k
    out_r1 = _mm_loadl_epi64((__m128i *) (&pu1_out[out_strd]));
555
8.88k
    out_r2 = _mm_loadl_epi64((__m128i *) (&pu1_out[2 * out_strd]));
556
8.88k
    out_r3 = _mm_loadl_epi64((__m128i *) (&pu1_out[3 * out_strd]));
557
8.88k
558
8.88k
    out_r0 = _mm_and_si128(out_r0, chroma_mask);
559
8.88k
    out_r1 = _mm_and_si128(out_r1, chroma_mask);
560
8.88k
    out_r2 = _mm_and_si128(out_r2, chroma_mask);
561
8.88k
    out_r3 = _mm_and_si128(out_r3, chroma_mask);
562
8.88k
563
8.88k
    out_r0 = _mm_add_epi8(out_r0, resq_r0);
564
8.88k
    out_r1 = _mm_add_epi8(out_r1, resq_r1);
565
8.88k
    out_r2 = _mm_add_epi8(out_r2, resq_r2);
566
8.88k
    out_r3 = _mm_add_epi8(out_r3, resq_r3);
567
8.88k
568
8.88k
    _mm_storel_epi64((__m128i *)(&pu1_out[0]), out_r0);
569
8.88k
    _mm_storel_epi64((__m128i *)(&pu1_out[out_strd]), out_r1);
570
8.88k
    _mm_storel_epi64((__m128i *)(&pu1_out[2 * out_strd]), out_r2);
571
8.88k
    _mm_storel_epi64((__m128i *)(&pu1_out[3 * out_strd]), out_r3);
572
8.88k
}
/proc/self/cwd/external/libavc/common/x86/ih264_iquant_itrans_recon_ssse3.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/**
21
 *******************************************************************************
22
 * @file
23
 *  ih264_iquant_itrans_recon_ssse3.c
24
 *
25
 * @brief
26
 *  Contains function definitions for inverse  quantization, inverse
27
 * transform and reconstruction
28
 *
29
 * @author
30
 *  Mohit [100664]
31
 *
32
 * @par List of Functions:
33
 *  - ih264_iquant_itrans_recon_4x4_ssse3()
34
 *  - ih264_iquant_itrans_recon_8x8_ssse3()
35
 *
36
 * @remarks
37
 *  None
38
 *
39
 *******************************************************************************
40
 */
41
/* User include files */
42
#include "ih264_typedefs.h"
43
#include "ih264_defs.h"
44
#include "ih264_trans_macros.h"
45
#include "ih264_macros.h"
46
#include "ih264_platform_macros.h"
47
#include "ih264_trans_data.h"
48
#include "ih264_size_defs.h"
49
#include "ih264_structs.h"
50
#include "ih264_trans_quant_itrans_iquant.h"
51
#include <immintrin.h>
52
53
/*
54
 ********************************************************************************
55
 *
56
 * @brief This function reconstructs a 4x4 sub block from quantized resiude and
57
 * prediction buffer
58
 *
59
 * @par Description:
60
 *  The quantized residue is first inverse quantized, then inverse transformed.
61
 *  This inverse transformed content is added to the prediction buffer to recon-
62
 *  struct the end output
63
 *
64
 * @param[in] pi2_src
65
 *  quantized 4x4 block
66
 *
67
 * @param[in] pu1_pred
68
 *  prediction 4x4 block
69
 *
70
 * @param[out] pu1_out
71
 *  reconstructed 4x4 block
72
 *
73
 * @param[in] src_strd
74
 *  quantization buffer stride
75
 *
76
 * @param[in] pred_strd,
77
 *  Prediction buffer stride
78
 *
79
 * @param[in] out_strd
80
 *  recon buffer Stride
81
 *
82
 * @param[in] pu2_scaling_list
83
 *  pointer to scaling list
84
 *
85
 * @param[in] pu2_norm_adjust
86
 *  pointer to inverse scale matrix
87
 *
88
 * @param[in] u4_qp_div_6
89
 *  Floor (qp/6)
90
 *
91
 * @param[in] pi4_tmp
92
 * temporary buffer of size 1*16
93
 *
94
 * @returns none
95
 *
96
 * @remarks none
97
 *
98
 *******************************************************************************
99
 */
100
void ih264_iquant_itrans_recon_4x4_ssse3(WORD16 *pi2_src,
101
                                         UWORD8 *pu1_pred,
102
                                         UWORD8 *pu1_out,
103
                                         WORD32 pred_strd,
104
                                         WORD32 out_strd,
105
                                         const UWORD16 *pu2_iscal_mat,
106
                                         const UWORD16 *pu2_weigh_mat,
107
                                         UWORD32 u4_qp_div_6,
108
                                         WORD16 *pi2_tmp,
109
                                         WORD32 iq_start_idx,
110
                                         WORD16 *pi2_dc_ld_addr)
111
0
{
112
0
    UWORD32 *pu4_out = (UWORD32 *) pu1_out;
113
0
    __m128i src_r0_r1, src_r2_r3;
114
0
    __m128i src_r0, src_r1, src_r2, src_r3;
115
0
    __m128i scalemat_r0_r1, scalemat_r2_r3, predload_r;
116
0
    __m128i pred_r0, pred_r1, pred_r2, pred_r3;
117
0
    __m128i sign_reg, dequant_r0_r1, dequant_r2_r3;
118
0
    __m128i zero_8x16b = _mm_setzero_si128();          // all bits reset to zero
119
0
    __m128i temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7;
120
0
    __m128i resq_r0, resq_r1, resq_r2, resq_r3;
121
0
    __m128i add_rshift = _mm_set1_epi32((1 << (3 - u4_qp_div_6)));
122
0
    __m128i value_32 = _mm_set1_epi32(32);
123
0
    UNUSED (pi2_tmp);
124
0
    UNUSED (pi2_dc_ld_addr);
125
0
126
0
    /*************************************************************/
127
0
    /* Dequantization of coefficients. Will be replaced by SIMD  */
128
0
    /* operations on platform                                    */
129
0
    /*************************************************************/
130
0
    src_r0_r1 = _mm_loadu_si128((__m128i *) (pi2_src)); //a00 a01 a02 a03 a10 a11 a12 a13 -- the source matrix 0th,1st row
131
0
    src_r2_r3 = _mm_loadu_si128((__m128i *) (pi2_src + 8)); //a20 a21 a22 a23 a30 a31 a32 a33 -- the source matrix 2nd,3rd row
132
0
    scalemat_r0_r1 = _mm_loadu_si128((__m128i *) (pu2_iscal_mat)); //b00 b01 b02 b03 b10 b11 b12 b13 -- the scaling matrix 0th,1st row
133
0
    scalemat_r2_r3 = _mm_loadu_si128((__m128i *) (pu2_iscal_mat + 8)); //b20 b21 b22 b23 b30 b31 b32 b33 -- the scaling matrix 2nd,3rd row
134
0
    dequant_r0_r1 = _mm_loadu_si128((__m128i *) (pu2_weigh_mat)); //q00 q01 q02 q03 q10 q11 q12 q13 -- all 16 bits
135
0
    dequant_r2_r3 = _mm_loadu_si128((__m128i *) (pu2_weigh_mat + 8)); //q20 q21 q22 q23 q30 q31 q32 q33 -- all 16 bits
136
0
137
0
    temp0 = _mm_mullo_epi16(scalemat_r0_r1, dequant_r0_r1); //b00*q00 b01*q01 b02*q02 b03*q03 b10*q10 b11*q11 b12*q12 b13*q13 -- 16 bit result
138
0
    temp1 = _mm_mullo_epi16(scalemat_r2_r3, dequant_r2_r3); //b00*q00 b01*q01 b02*q02 b03*q03 b10*q10 b11*q11 b12*q12 b13*q13 -- 16 bit result
139
0
140
0
    temp4 = _mm_unpacklo_epi16(temp0, zero_8x16b); // b00*q00 0 b01*q01 0 b02*q02 0 b03*q03 0 -- 16 bit long
141
0
    temp5 = _mm_unpackhi_epi16(temp0, zero_8x16b); // b10*q10 0 b11*q11 0 b12*q12 0 b13*q13 0 -- 16 bit long
142
0
    temp6 = _mm_unpacklo_epi16(temp1, zero_8x16b); // b00*q00 0 b01*q01 0 b02*q02 0 b03*q03 0 -- 16 bit long
143
0
    temp7 = _mm_unpackhi_epi16(temp1, zero_8x16b); // b10*q10 0 b11*q11 0 b12*q12 0 b13*q13 0 -- 16 bit long
144
0
145
0
    src_r0 = _mm_unpacklo_epi16(src_r0_r1, zero_8x16b); // a00 0 a01 0 a02 0 a03 0 -- 16 bit long
146
0
    src_r1 = _mm_unpackhi_epi16(src_r0_r1, zero_8x16b); // a10 0 a11 0 a12 0 a13 0 -- 16 bit long
147
0
    src_r2 = _mm_unpacklo_epi16(src_r2_r3, zero_8x16b); // a20 0 a21 0 a22 0 a23 0 -- 16 bit long
148
0
    src_r3 = _mm_unpackhi_epi16(src_r2_r3, zero_8x16b); // a30 0 a31 0 a32 0 a33 0 -- 16 bit long
149
0
150
0
    temp4 = _mm_madd_epi16(src_r0, temp4); //a00*b00*q00 a10*b10*q10 a20*b20*q20 a30*b30 q30 -- 32 bits long
151
0
    temp5 = _mm_madd_epi16(src_r1, temp5);
152
0
    temp6 = _mm_madd_epi16(src_r2, temp6);
153
0
    temp7 = _mm_madd_epi16(src_r3, temp7);
154
0
155
0
    if (u4_qp_div_6 >= 4) {
156
0
        resq_r0 = _mm_slli_epi32(temp4, u4_qp_div_6 - 4);
157
0
        resq_r1 = _mm_slli_epi32(temp5, u4_qp_div_6 - 4);
158
0
        resq_r2 = _mm_slli_epi32(temp6, u4_qp_div_6 - 4);
159
0
        resq_r3 = _mm_slli_epi32(temp7, u4_qp_div_6 - 4);
160
0
    } else {
161
0
        temp4 = _mm_add_epi32(temp4, add_rshift);
162
0
        temp5 = _mm_add_epi32(temp5, add_rshift);
163
0
        temp6 = _mm_add_epi32(temp6, add_rshift);
164
0
        temp7 = _mm_add_epi32(temp7, add_rshift);
165
0
        resq_r0 = _mm_srai_epi32(temp4, 4 - u4_qp_div_6);
166
0
        resq_r1 = _mm_srai_epi32(temp5, 4 - u4_qp_div_6);
167
0
        resq_r2 = _mm_srai_epi32(temp6, 4 - u4_qp_div_6);
168
0
        resq_r3 = _mm_srai_epi32(temp7, 4 - u4_qp_div_6);
169
0
    }
170
0
171
0
    if (iq_start_idx == 1)
172
0
    {
173
0
        resq_r0 = _mm_insert_epi16(resq_r0,(WORD32)pi2_src[0],0);
174
0
        if (pi2_src[0] >= 0)
175
0
            resq_r0 = _mm_insert_epi16(resq_r0,0,1);
176
0
        else
177
0
            resq_r0 = _mm_insert_epi16(resq_r0,-1,1);
178
0
    }
179
0
    /* Perform Inverse transform */
180
0
    /*-------------------------------------------------------------*/
181
0
    /* IDCT [ Horizontal transformation ]                          */
182
0
    /*-------------------------------------------------------------*/
183
0
    // Matrix transpose
184
0
    /*
185
0
     *  a0 a1 a2 a3
186
0
     *  b0 b1 b2 b3
187
0
     *  c0 c1 c2 c3
188
0
     *  d0 d1 d2 d3
189
0
     */
190
0
    temp1 = _mm_unpacklo_epi32(resq_r0, resq_r1);                  //a0 b0 a1 b1
191
0
    temp3 = _mm_unpacklo_epi32(resq_r2, resq_r3);                  //c0 d0 c1 d1
192
0
    temp2 = _mm_unpackhi_epi32(resq_r0, resq_r1);                  //a2 b2 a3 b3
193
0
    temp4 = _mm_unpackhi_epi32(resq_r2, resq_r3);                  //c2 d2 c3 d3
194
0
    resq_r0 = _mm_unpacklo_epi64(temp1, temp3);                    //a0 b0 c0 d0
195
0
    resq_r1 = _mm_unpackhi_epi64(temp1, temp3);                    //a1 b1 c1 d1
196
0
    resq_r2 = _mm_unpacklo_epi64(temp2, temp4);                    //a2 b2 c2 d2
197
0
    resq_r3 = _mm_unpackhi_epi64(temp2, temp4);                    //a3 b3 c3 d3
198
0
    //Transform starts -- horizontal transform
199
0
    /*------------------------------------------------------------------*/
200
0
    /* z0 = w0 + w2                                             */
201
0
    temp0 = _mm_add_epi32(resq_r0, resq_r2);
202
0
    /* z1 = w0 - w2                                             */
203
0
    temp1 = _mm_sub_epi32(resq_r0, resq_r2);
204
0
    /* z2 = (w1 >> 1) - w3                                      */
205
0
    temp2 = _mm_srai_epi32(resq_r1, 1);                         //(w1>>1)
206
0
    temp2 = _mm_sub_epi32(temp2, resq_r3);                      //(w1>>1) - w3
207
0
    /* z3 = w1 + (w3 >> 1)                                      */
208
0
    temp3 = _mm_srai_epi32(resq_r3, 1);                         //(w3>>1) + w1
209
0
    temp3 = _mm_add_epi32(temp3, resq_r1);
210
0
    /*----------------------------------------------------------*/
211
0
    /* x0 = z0 + z3                                             */
212
0
    resq_r0 = _mm_add_epi32(temp0, temp3);
213
0
    /* x1 = z1 + z2                                             */
214
0
    resq_r1 = _mm_add_epi32(temp1, temp2);
215
0
    /* x2 = z1 - z2                                             */
216
0
    resq_r2 = _mm_sub_epi32(temp1, temp2);
217
0
    /* x3 = z0 - z3                                             */
218
0
    resq_r3 = _mm_sub_epi32(temp0, temp3);
219
0
    // Matrix transpose
220
0
    /*
221
0
     *  a0 b0 c0 d0
222
0
     *  a1 b1 c1 d1
223
0
     *  a2 b2 c2 d2
224
0
     *  a3 b3 c3 d3
225
0
     */
226
0
    temp1 = _mm_unpacklo_epi32(resq_r0, resq_r1);                  //a0 a1 b0 b1
227
0
    temp3 = _mm_unpacklo_epi32(resq_r2, resq_r3);                  //a2 a3 b2 b3
228
0
    temp2 = _mm_unpackhi_epi32(resq_r0, resq_r1);                  //c0 c1 d0 d1
229
0
    temp4 = _mm_unpackhi_epi32(resq_r2, resq_r3);                  //c2 c3 d2 d3
230
0
    resq_r0 = _mm_unpacklo_epi64(temp1, temp3);                    //a0 a1 a2 a3
231
0
    resq_r1 = _mm_unpackhi_epi64(temp1, temp3);                    //b0 b1 b2 b3
232
0
    resq_r2 = _mm_unpacklo_epi64(temp2, temp4);                    //c0 c1 c2 c3
233
0
    resq_r3 = _mm_unpackhi_epi64(temp2, temp4);                    //d0 d1 d2 d3
234
0
    //Transform ends -- horizontal transform
235
0
236
0
    zero_8x16b = _mm_setzero_si128();                  // all bits reset to zero
237
0
    //Load pred buffer
238
0
    predload_r = _mm_loadl_epi64((__m128i *) (&pu1_pred[0])); //p00 p01 p02 p03 0 0 0 0 0 0 0 0 -- all 8 bits
239
0
    pred_r0 = _mm_unpacklo_epi8(predload_r, zero_8x16b); //p00 p01 p02 p03 0 0 0 0 -- all 16 bits
240
0
241
0
    predload_r = _mm_loadl_epi64((__m128i *) (&pu1_pred[pred_strd])); //p10 p11 p12 p13 0 0 0 0 0 0 0 0 -- all 8 bits
242
0
    pred_r1 = _mm_unpacklo_epi8(predload_r, zero_8x16b); //p10 p11 p12 p13 0 0 0 0 -- all 16 bits
243
0
244
0
    predload_r = _mm_loadl_epi64((__m128i *) (&pu1_pred[2 * pred_strd])); //p20 p21 p22 p23 0 0 0 0 0 0 0 0 -- all 8 bits
245
0
    pred_r2 = _mm_unpacklo_epi8(predload_r, zero_8x16b); //p20 p21 p22 p23 0 0 0 0 -- all 16 bits
246
0
247
0
    predload_r = _mm_loadl_epi64((__m128i *) (&pu1_pred[3 * pred_strd])); //p30 p31 p32 p33 0 0 0 0 0 0 0 0 -- all 8 bits
248
0
    pred_r3 = _mm_unpacklo_epi8(predload_r, zero_8x16b); //p30 p31 p32 p33 0 0 0 0 -- all 16 bits
249
0
    pred_r0 = _mm_unpacklo_epi16(pred_r0, zero_8x16b); //p00 p01 p02 p03 -- 32 bits sign extended
250
0
    pred_r1 = _mm_unpacklo_epi16(pred_r1, zero_8x16b); //p10 p11 p12 p13 -- 32 bits sign extended
251
0
    pred_r2 = _mm_unpacklo_epi16(pred_r2, zero_8x16b); //p20 p21 p22 p23 -- 32 bits sign extended
252
0
    pred_r3 = _mm_unpacklo_epi16(pred_r3, zero_8x16b); //p30 p31 p32 p33 -- 32 bits sign extended
253
0
254
0
    /*--------------------------------------------------------------*/
255
0
    /* IDCT [ Vertical transformation] and Xij = (xij + 32)>>6      */
256
0
    /*                                                              */
257
0
    /* Add the prediction and store it back to same buffer          */
258
0
    /*--------------------------------------------------------------*/
259
0
    /* z0j = y0j + y2j                                                        */
260
0
    temp0 = _mm_add_epi32(resq_r0, resq_r2);
261
0
    /* z1j = y0j - y2j                                                        */
262
0
    temp1 = _mm_sub_epi32(resq_r0, resq_r2);
263
0
    /* z2j = (y1j>>1) - y3j                                                        */
264
0
    temp2 = _mm_srai_epi32(resq_r1, 1);                             //(y1j>>1)
265
0
    temp2 = _mm_sub_epi32(temp2, resq_r3);
266
0
    /* z3j = y1j + (y3j>>1)                                                        */
267
0
    temp3 = _mm_srai_epi32(resq_r3, 1);                             //(y3j>>1)
268
0
    temp3 = _mm_add_epi32(temp3, resq_r1);
269
0
270
0
    /* x0j = z0j + z3j                                                        */
271
0
    temp4 = _mm_add_epi32(temp0, temp3);
272
0
    temp4 = _mm_add_epi32(temp4, value_32);
273
0
    temp4 = _mm_srai_epi32(temp4, 6);
274
0
    temp4 = _mm_add_epi32(temp4, pred_r0);
275
0
    /* x1j = z1j + z2j                                                        */
276
0
    temp5 = _mm_add_epi32(temp1, temp2);
277
0
    temp5 = _mm_add_epi32(temp5, value_32);
278
0
    temp5 = _mm_srai_epi32(temp5, 6);
279
0
    temp5 = _mm_add_epi32(temp5, pred_r1);
280
0
    /* x2j = z1j - z2j                                                        */
281
0
    temp6 = _mm_sub_epi32(temp1, temp2);
282
0
    temp6 = _mm_add_epi32(temp6, value_32);
283
0
    temp6 = _mm_srai_epi32(temp6, 6);
284
0
    temp6 = _mm_add_epi32(temp6, pred_r2);
285
0
    /* x3j = z0j - z3j                                                        */
286
0
    temp7 = _mm_sub_epi32(temp0, temp3);
287
0
    temp7 = _mm_add_epi32(temp7, value_32);
288
0
    temp7 = _mm_srai_epi32(temp7, 6);
289
0
    temp7 = _mm_add_epi32(temp7, pred_r3);
290
0
291
0
    // 32-bit to 16-bit conversion
292
0
    temp0 = _mm_packs_epi32(temp4, temp5);
293
0
    temp1 = _mm_packs_epi32(temp6, temp7);
294
0
    /*------------------------------------------------------------------*/
295
0
    //Clipping the results to 8 bits
296
0
    sign_reg = _mm_cmpgt_epi16(temp0, zero_8x16b);      // sign check
297
0
    temp0 = _mm_and_si128(temp0, sign_reg);
298
0
    sign_reg = _mm_cmpgt_epi16(temp1, zero_8x16b);
299
0
    temp1 = _mm_and_si128(temp1, sign_reg);
300
0
301
0
    resq_r0 = _mm_packus_epi16(temp0, temp1);
302
0
    resq_r1 = _mm_srli_si128(resq_r0, 4);
303
0
    resq_r2 = _mm_srli_si128(resq_r1, 4);
304
0
    resq_r3 = _mm_srli_si128(resq_r2, 4);
305
0
306
0
    *pu4_out = _mm_cvtsi128_si32(resq_r0);
307
0
    pu1_out += out_strd;
308
0
    pu4_out = (UWORD32 *) (pu1_out);
309
0
    *(pu4_out) = _mm_cvtsi128_si32(resq_r1);
310
0
    pu1_out += out_strd;
311
0
    pu4_out = (UWORD32 *) (pu1_out);
312
0
    *(pu4_out) = _mm_cvtsi128_si32(resq_r2);
313
0
    pu1_out += out_strd;
314
0
    pu4_out = (UWORD32 *) (pu1_out);
315
0
    *(pu4_out) = _mm_cvtsi128_si32(resq_r3);
316
0
}
317
/**
318
 *******************************************************************************
319
 *
320
 * @brief
321
 *  This function performs inverse quant and Inverse transform type Ci4 for 8x8 block
322
 *
323
 * @par Description:
324
 *  Performs inverse transform Ci8 and adds the residue to get the
325
 *  reconstructed block
326
 *
327
 * @param[in] pi2_src
328
 *  Input 8x8coefficients
329
 *
330
 * @param[in] pu1_pred
331
 *  Prediction 8x8 block
332
 *
333
 * @param[out] pu1_recon
334
 *  Output 8x8 block
335
 *
336
 * @param[in] q_div
337
 *  QP/6
338
 *
339
 * @param[in] q_rem
340
 *  QP%6
341
 *
342
 * @param[in] q_lev
343
 *  Quantizer level
344
 *
345
 * @param[in] u4_src_stride
346
 *  Input stride
347
 *
348
 * @param[in] u4_pred_stride,
349
 *  Prediction stride
350
 *
351
 * @param[in] u4_out_stride
352
 *  Output Stride
353
 *
354
 * @param[in] pi4_tmp
355
 *  temporary buffer of size 1*64
356
 *  the tmp for each block
357
 *
358
 * @param[in] pu4_iquant_mat
359
 *  Pointer to the inverse quantization matrix
360
 *
361
 * @returns  Void
362
 *
363
 * @remarks
364
 *  None
365
 *
366
 *******************************************************************************
367
 */
368
369
void ih264_iquant_itrans_recon_8x8_ssse3(WORD16 *pi2_src,
370
                                         UWORD8 *pu1_pred,
371
                                         UWORD8 *pu1_out,
372
                                         WORD32 pred_strd,
373
                                         WORD32 out_strd,
374
                                         const UWORD16 *pu2_iscale_mat,
375
                                         const UWORD16 *pu2_weigh_mat,
376
                                         UWORD32 qp_div,
377
                                         WORD16 *pi2_tmp,
378
                                         WORD32 iq_start_idx,
379
                                         WORD16 *pi2_dc_ld_addr)
380
0
{
381
0
    __m128i src_r0;
382
0
    __m128i scalemat_r0;
383
0
    __m128i zero_8x16b = _mm_setzero_si128(); // all bits reset to zero
384
0
    // __m128i one_8x16b = _mm_set1_epi8(255); // all bits set to 1
385
0
    // __m128i one_zero_mask = _mm_unpacklo_epi16(one_8x16b, zero_8x16b); // 1 0 1 0 1 0 1 0 --- 16 bits size
386
0
    __m128i value_32 = _mm_set1_epi32(32);
387
0
    __m128i add_rshift = _mm_set1_epi32((1 << (5 - qp_div)));
388
0
    __m128i dequant_r0;
389
0
    __m128i predload_r;
390
0
    __m128i pred_r0_1, pred_r1_1, pred_r2_1, pred_r3_1, pred_r4_1, pred_r5_1,
391
0
            pred_r6_1, pred_r7_1;
392
0
    __m128i sign_reg;
393
0
    __m128i src_r0_1, src_r0_2;
394
0
    __m128i scalemat_r0_1, scalemat_r0_2;
395
0
    __m128i temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8;
396
0
    __m128i temp10, temp11, temp12, temp13, temp14, temp15, temp16, temp17,
397
0
            temp18, temp19, temp20;
398
0
    // To store dequantization results
399
0
    __m128i resq_r0_1, resq_r0_2, resq_r1_1, resq_r1_2, resq_r2_1, resq_r2_2,
400
0
            resq_r3_1, resq_r3_2, resq_r4_1, resq_r4_2, resq_r5_1, resq_r5_2,
401
0
            resq_r6_1, resq_r6_2, resq_r7_1, resq_r7_2;
402
0
    UNUSED (pi2_tmp);
403
0
    UNUSED (iq_start_idx);
404
0
    UNUSED (pi2_dc_ld_addr);
405
0
406
0
    /*************************************************************/
407
0
    /* Dequantization of coefficients. Will be replaced by SIMD  */
408
0
    /* operations on platform. Note : DC coeff is not scaled     */
409
0
    /*************************************************************/
410
0
411
0
    // Row 0 processing
412
0
    src_r0 = _mm_loadu_si128((__m128i *) (pi2_src)); //a00 a01 a02 a03 a04 a05 a06 a07 -- the source matrix 0th row
413
0
    scalemat_r0 = _mm_loadu_si128((__m128i *) (pu2_iscale_mat)); //b00 b01 b02 b03 b04 b05 b06 b07 -- the scaling matrix 0th row
414
0
    dequant_r0 = _mm_loadu_si128((__m128i *) (&pu2_weigh_mat[0])); //q0 q1 q2 q3 q4 q5 q6 q7 -- all 16 bits
415
0
    src_r0_1 = _mm_unpacklo_epi16(src_r0, zero_8x16b); //a00 0 a01 0 a02 0 a03 0 -- 16 bit long
416
0
    src_r0_2 = _mm_unpackhi_epi16(src_r0, zero_8x16b); // a04 0 a05 0 a06 0 a07 0 -- 16 bit long
417
0
    temp10 = _mm_mullo_epi16(scalemat_r0, dequant_r0); //b00*q0 b01*q1 b02*q2 b03*q3 b04*q4 b05*q5 b06*q6 b07*q7 -- 16 bit result
418
0
    scalemat_r0_1 = _mm_unpacklo_epi16(temp10, zero_8x16b); // b00*q0 0 b01*q1 0 b02*q2 0 b03*q3 0 -- 16 bit long
419
0
    scalemat_r0_2 = _mm_unpackhi_epi16(temp10, zero_8x16b); // b04*q4 0 b05*q5 0 b06*q6 0 b07*q7 0 -- 16 bit long
420
0
421
0
    temp5 = _mm_madd_epi16(src_r0_1, scalemat_r0_1); // a00*b00*q0 a01*b01*q1 a02*b02*q2 a03*b03*q3 -- 32 bits long
422
0
    temp7 = _mm_madd_epi16(src_r0_2, scalemat_r0_2); // a04*b04*q4 a05*b05*q5 a06*b06*q6 a07*b07*q7 -- 32 bits long
423
0
424
0
    if (qp_div >= 6) {
425
0
        resq_r0_1 = _mm_slli_epi32(temp5, qp_div - 6);
426
0
        resq_r0_2 = _mm_slli_epi32(temp7, qp_div - 6);
427
0
    } else {
428
0
        temp5 = _mm_add_epi32(temp5, add_rshift);
429
0
        temp7 = _mm_add_epi32(temp7, add_rshift);
430
0
        resq_r0_1 = _mm_srai_epi32(temp5, 6 - qp_div);
431
0
        resq_r0_2 = _mm_srai_epi32(temp7, 6 - qp_div);
432
0
    }
433
0
    resq_r0_1 = _mm_packs_epi32(resq_r0_1, resq_r0_2); //a00*b00*q0 a01*b01*q1 a02*b02*q2 a03*b03*q3 a04*b04*q4 a05*b05*q5 a06*b06*q6 a07*b07*q7 -- 16 bit long
434
0
    // Row 1 processing
435
0
    src_r0 = _mm_loadu_si128((__m128i *) (pi2_src + 8)); //a00 a01 a02 a03 a04 a05 a06 a07 a08 -- the source matrix 1st row
436
0
    scalemat_r0 = _mm_loadu_si128((__m128i *) (pu2_iscale_mat + 8)); //b00 b01 b02 b03 b04 b05 b06 b07 b08 -- the scaling matrix 1st row
437
0
    dequant_r0 = _mm_loadu_si128((__m128i *) (&pu2_weigh_mat[8])); //q0 q1 q2 q3 q4 q5 q6 q7 -- all 16 bits
438
0
    src_r0_1 = _mm_unpacklo_epi16(src_r0, zero_8x16b); //a00 0 a01 0 a02 0 a03 0 -- 16 bit long
439
0
    src_r0_2 = _mm_unpackhi_epi16(src_r0, zero_8x16b); // a04 0 a05 0 a06 0 a07 0 -- 16 bit long
440
0
    temp10 = _mm_mullo_epi16(scalemat_r0, dequant_r0); //b00*q0 b01*q1 b02*q2 b03*q3 b04*q4 b05*q5 b06*q6 b07*q7 -- 16 bit result
441
0
    scalemat_r0_1 = _mm_unpacklo_epi16(temp10, zero_8x16b); // b00*q0 0 b01*q1 0 b02*q2 0 b03*q3 0 -- 16 bit long
442
0
    scalemat_r0_2 = _mm_unpackhi_epi16(temp10, zero_8x16b); // b04*q4 0 b05*q5 0 b06*q6 0 b07*q7 0 -- 16 bit long
443
0
    temp5 = _mm_madd_epi16(src_r0_1, scalemat_r0_1); // a00*b00*q0 a01*b01*q1 a02*b02*q2 a03*b03*q3 -- 32 bits long
444
0
    temp7 = _mm_madd_epi16(src_r0_2, scalemat_r0_2); // a04*b04*q4 a05*b05*q5 a06*b06*q6 a07*b07*q7 -- 32 bits long
445
0
    if (qp_div >= 6) {
446
0
        resq_r1_1 = _mm_slli_epi32(temp5, qp_div - 6);
447
0
        resq_r1_2 = _mm_slli_epi32(temp7, qp_div - 6);
448
0
    } else {
449
0
        temp5 = _mm_add_epi32(temp5, add_rshift);
450
0
        temp7 = _mm_add_epi32(temp7, add_rshift);
451
0
        resq_r1_1 = _mm_srai_epi32(temp5, 6 - qp_div);
452
0
        resq_r1_2 = _mm_srai_epi32(temp7, 6 - qp_div);
453
0
    }
454
0
    resq_r1_1 = _mm_packs_epi32(resq_r1_1, resq_r1_2); //a00*b00*q0 a01*b01*q1 a02*b02*q2 a03*b03*q3 a04*b04*q4 a05*b05*q5 a06*b06*q6 a07*b07*q7 -- 16 bit long
455
0
    // Row 2 processing
456
0
    src_r0 = _mm_loadu_si128((__m128i *) (pi2_src + 16)); //a00 a01 a02 a03 a04 a05 a06 a07 a08 -- the source matrix 2nd row
457
0
    scalemat_r0 = _mm_loadu_si128((__m128i *) (pu2_iscale_mat + 16)); //b00 b01 b02 b03 b04 b05 b06 b07 b08 -- the scaling matrix 2nd row
458
0
    dequant_r0 = _mm_loadu_si128((__m128i *) (&pu2_weigh_mat[16])); //q0 q1 q2 q3 q4 q5 q6 q7 -- all 16 bits
459
0
    src_r0_1 = _mm_unpacklo_epi16(src_r0, zero_8x16b); //a00 0 a01 0 a02 0 a03 0 -- 16 bit long
460
0
    src_r0_2 = _mm_unpackhi_epi16(src_r0, zero_8x16b); // a04 0 a05 0 a06 0 a07 0 -- 16 bit long
461
0
    temp10 = _mm_mullo_epi16(scalemat_r0, dequant_r0); //b00*q0 b01*q1 b02*q2 b03*q3 b04*q4 b05*q5 b06*q6 b07*q7 -- 16 bit result
462
0
    scalemat_r0_1 = _mm_unpacklo_epi16(temp10, zero_8x16b); // b00*q0 0 b01*q1 0 b02*q2 0 b03*q3 0 -- 16 bit long
463
0
    scalemat_r0_2 = _mm_unpackhi_epi16(temp10, zero_8x16b); // b04*q4 0 b05*q5 0 b06*q6 0 b07*q7 0 -- 16 bit long
464
0
    temp5 = _mm_madd_epi16(src_r0_1, scalemat_r0_1); // a00*b00*q0 a01*b01*q1 a02*b02*q2 a03*b03*q3 -- 32 bits long
465
0
    temp7 = _mm_madd_epi16(src_r0_2, scalemat_r0_2); // a04*b04*q4 a05*b05*q5 a06*b06*q6 a07*b07*q7 -- 32 bits long
466
0
    if (qp_div >= 6) {
467
0
        resq_r2_1 = _mm_slli_epi32(temp5, qp_div - 6);
468
0
        resq_r2_2 = _mm_slli_epi32(temp7, qp_div - 6);
469
0
    } else {
470
0
        temp5 = _mm_add_epi32(temp5, add_rshift);
471
0
        temp7 = _mm_add_epi32(temp7, add_rshift);
472
0
        resq_r2_1 = _mm_srai_epi32(temp5, 6 - qp_div);
473
0
        resq_r2_2 = _mm_srai_epi32(temp7, 6 - qp_div);
474
0
    }
475
0
    resq_r2_1 = _mm_packs_epi32(resq_r2_1, resq_r2_2); //a00*b00*q0 a01*b01*q1 a02*b02*q2 a03*b03*q3 a04*b04*q4 a05*b05*q5 a06*b06*q6 a07*b07*q7 -- 16 bit long
476
0
    // Row 3 processing
477
0
    src_r0 = _mm_loadu_si128((__m128i *) (pi2_src + 24)); //a00 a01 a02 a03 a04 a05 a06 a07 a08 -- the source matrix 3rd row
478
0
    scalemat_r0 = _mm_loadu_si128((__m128i *) (pu2_iscale_mat + 24)); //b00 b01 b02 b03 b04 b05 b06 b07 b08 -- the scaling matrix 3rd row
479
0
    dequant_r0 = _mm_loadu_si128((__m128i *) (&pu2_weigh_mat[24])); //q0 q1 q2 q3 q4 q5 q6 q7 -- all 16 bits
480
0
    src_r0_1 = _mm_unpacklo_epi16(src_r0, zero_8x16b); //a00 0 a01 0 a02 0 a03 0 -- 16 bit long
481
0
    src_r0_2 = _mm_unpackhi_epi16(src_r0, zero_8x16b); // a04 0 a05 0 a06 0 a07 0 -- 16 bit long
482
0
    temp10 = _mm_mullo_epi16(scalemat_r0, dequant_r0); //b00*q0 b01*q1 b02*q2 b03*q3 b04*q4 b05*q5 b06*q6 b07*q7 -- 16 bit result
483
0
    scalemat_r0_1 = _mm_unpacklo_epi16(temp10, zero_8x16b); // b00*q0 0 b01*q1 0 b02*q2 0 b03*q3 0 -- 16 bit long
484
0
    scalemat_r0_2 = _mm_unpackhi_epi16(temp10, zero_8x16b); // b04*q4 0 b05*q5 0 b06*q6 0 b07*q7 0 -- 16 bit long
485
0
    temp5 = _mm_madd_epi16(src_r0_1, scalemat_r0_1); // a00*b00*q0 a01*b01*q1 a02*b02*q2 a03*b03*q3 - 32 bits long
486
0
    temp7 = _mm_madd_epi16(src_r0_2, scalemat_r0_2); // a04*b04*q4 a05*b05*q5 a06*b06*q6 a07*b07*q7 -- 32 bits long
487
0
    if (qp_div >= 6) {
488
0
        resq_r3_1 = _mm_slli_epi32(temp5, qp_div - 6);
489
0
        resq_r3_2 = _mm_slli_epi32(temp7, qp_div - 6);
490
0
    } else {
491
0
        temp5 = _mm_add_epi32(temp5, add_rshift);
492
0
        temp7 = _mm_add_epi32(temp7, add_rshift);
493
0
        resq_r3_1 = _mm_srai_epi32(temp5, 6 - qp_div);
494
0
        resq_r3_2 = _mm_srai_epi32(temp7, 6 - qp_div);
495
0
    }
496
0
    resq_r3_1 = _mm_packs_epi32(resq_r3_1, resq_r3_2); //a00*b00*q0 a01*b01*q1 a02*b02*q2 a03*b03*q3 a04*b04*q4 a05*b05*q5 a06*b06*q6 a07*b07*q7 -- 16 bit long
497
0
    // Row 4 processing
498
0
    src_r0 = _mm_loadu_si128((__m128i *) (pi2_src + 32)); //a00 a01 a02 a03 a04 a05 a06 a07 a08 -- the source matrix 4th row
499
0
    scalemat_r0 = _mm_loadu_si128((__m128i *) (pu2_iscale_mat + 32)); //b00 b01 b02 b03 b04 b05 b06 b07 b08 -- the scaling matrix 4th row
500
0
    dequant_r0 = _mm_loadu_si128((__m128i *) (&pu2_weigh_mat[32])); //q0 q1 q2 q3 q4 q5 q6 q7 -- all 16 bits
501
0
    src_r0_1 = _mm_unpacklo_epi16(src_r0, zero_8x16b); //a00 0 a01 0 a02 0 a03 0 -- 16 bit long
502
0
    src_r0_2 = _mm_unpackhi_epi16(src_r0, zero_8x16b); // a04 0 a05 0 a06 0 a07 0 -- 16 bit long
503
0
    temp10 = _mm_mullo_epi16(scalemat_r0, dequant_r0); //b00*q0 b01*q1 b02*q2 b03*q3 b04*q4 b05*q5 b06*q6 b07*q7 -- 16 bit result
504
0
    scalemat_r0_1 = _mm_unpacklo_epi16(temp10, zero_8x16b); // b00*q0 0 b01*q1 0 b02*q2 0 b03*q3 0 -- 16 bit long
505
0
    scalemat_r0_2 = _mm_unpackhi_epi16(temp10, zero_8x16b); // b04*q4 0 b05*q5 0 b06*q6 0 b07*q7 0 -- 16 bit long
506
0
    temp5 = _mm_madd_epi16(src_r0_1, scalemat_r0_1); // a00*b00*q0 a01*b01*q1 a02*b02*q2 a03*b03*q3 -- 32 bits long
507
0
    temp7 = _mm_madd_epi16(src_r0_2, scalemat_r0_2); // a04*b04*q4 a05*b05*q5 a06*b06*q6 a07*b07*q7 -- 32 bits long
508
0
    if (qp_div >= 6) {
509
0
        resq_r4_1 = _mm_slli_epi32(temp5, qp_div - 6);
510
0
        resq_r4_2 = _mm_slli_epi32(temp7, qp_div - 6);
511
0
512
0
    } else {
513
0
        temp5 = _mm_add_epi32(temp5, add_rshift);
514
0
        temp7 = _mm_add_epi32(temp7, add_rshift);
515
0
        resq_r4_1 = _mm_srai_epi32(temp5, 6 - qp_div);
516
0
        resq_r4_2 = _mm_srai_epi32(temp7, 6 - qp_div);
517
0
    }
518
0
    resq_r4_1 = _mm_packs_epi32(resq_r4_1, resq_r4_2); //a00*b00*q0 a01*b01*q1 a02*b02*q2 a03*b03*q3 a04*b04*q4 a05*b05*q5 a06*b06*q6 a07*b07*q7 -- 16 bit long
519
0
    // Row 5 processing
520
0
    src_r0 = _mm_loadu_si128((__m128i *) (pi2_src + 40)); //a00 a01 a02 a03 a04 a05 a06 a07 a08 -- the source matrix 5th row
521
0
    scalemat_r0 = _mm_loadu_si128((__m128i *) (pu2_iscale_mat + 40)); //b00 b01 b02 b03 b04 b05 b06 b07 b08 -- the scaling matrix 5th row
522
0
    dequant_r0 = _mm_loadu_si128((__m128i *) (&pu2_weigh_mat[40])); //q0 q1 q2 q3 q4 q5 q6 q7 -- all 16 bits
523
0
    src_r0_1 = _mm_unpacklo_epi16(src_r0, zero_8x16b); //a00 0 a01 0 a02 0 a03 0 -- 16 bit long
524
0
    src_r0_2 = _mm_unpackhi_epi16(src_r0, zero_8x16b); // a04 0 a05 0 a06 0 a07 0 -- 16 bit long
525
0
    temp10 = _mm_mullo_epi16(scalemat_r0, dequant_r0); //b00*q0 b01*q1 b02*q2 b03*q3 b04*q4 b05*q5 b06*q6 b07*q7 -- 16 bit result
526
0
    scalemat_r0_1 = _mm_unpacklo_epi16(temp10, zero_8x16b); // b00*q0 0 b01*q1 0 b02*q2 0 b03*q3 0 -- 16 bit long
527
0
    scalemat_r0_2 = _mm_unpackhi_epi16(temp10, zero_8x16b); // b04*q4 0 b05*q5 0 b06*q6 0 b07*q7 0 -- 16 bit long
528
0
    temp5 = _mm_madd_epi16(src_r0_1, scalemat_r0_1); // a00*b00*q0 a01*b01*q1 a02*b02*q2 a03*b03*q3 -- 32 bits long
529
0
    temp7 = _mm_madd_epi16(src_r0_2, scalemat_r0_2); // a04*b04*q4 a05*b05*q5 a06*b06*q6 a07*b07*q7 -- 32 bits long
530
0
    if (qp_div >= 6) {
531
0
        resq_r5_1 = _mm_slli_epi32(temp5, qp_div - 6);
532
0
        resq_r5_2 = _mm_slli_epi32(temp7, qp_div - 6);
533
0
        //resq_r5_1 = _mm_and_si128(resq_r5_1,one_zero_mask);
534
0
        //resq_r5_2 = _mm_and_si128(resq_r5_2,one_zero_mask);
535
0
    } else {
536
0
        temp5 = _mm_add_epi32(temp5, add_rshift);
537
0
        temp7 = _mm_add_epi32(temp7, add_rshift);
538
0
        resq_r5_1 = _mm_srai_epi32(temp5, 6 - qp_div);
539
0
        resq_r5_2 = _mm_srai_epi32(temp7, 6 - qp_div);
540
0
    }
541
0
    resq_r5_1 = _mm_packs_epi32(resq_r5_1, resq_r5_2); //a00*b00*q0 a01*b01*q1 a02*b02*q2 a03*b03*q3 a04*b04*q4 a05*b05*q5 a06*b06*q6 a07*b07*q7 -- 16 bit long
542
0
    // Row 6 processing
543
0
    src_r0 = _mm_loadu_si128((__m128i *) (pi2_src + 48)); //a00 a01 a02 a03 a04 a05 a06 a07 a08 -- the source matrix 6th row
544
0
    scalemat_r0 = _mm_loadu_si128((__m128i *) (pu2_iscale_mat + 48)); //b00 b01 b02 b03 b04 b05 b06 b07 b08 -- the scaling matrix 6th row
545
0
    dequant_r0 = _mm_loadu_si128((__m128i *) (&pu2_weigh_mat[48])); //q0 q1 q2 q3 q4 q5 q6 q7 -- all 16 bits
546
0
    src_r0_1 = _mm_unpacklo_epi16(src_r0, zero_8x16b); //a00 0 a01 0 a02 0 a03 0 -- 16 bit long
547
0
    src_r0_2 = _mm_unpackhi_epi16(src_r0, zero_8x16b); // a04 0 a05 0 a06 0 a07 0 -- 16 bit long
548
0
    temp10 = _mm_mullo_epi16(scalemat_r0, dequant_r0); //b00*q0 b01*q1 b02*q2 b03*q3 b04*q4 b05*q5 b06*q6 b07*q7 -- 16 bit result
549
0
    scalemat_r0_1 = _mm_unpacklo_epi16(temp10, zero_8x16b); // b00*q0 0 b01*q1 0 b02*q2 0 b03*q3 0 -- 16 bit long
550
0
    scalemat_r0_2 = _mm_unpackhi_epi16(temp10, zero_8x16b); // b04*q4 0 b05*q5 0 b06*q6 0 b07*q7 0 -- 16 bit long
551
0
    temp5 = _mm_madd_epi16(src_r0_1, scalemat_r0_1); // a00*b00*q0 a01*b01*q1 a02*b02*q2 a03*b03*q3 -- 32 bits long
552
0
    temp7 = _mm_madd_epi16(src_r0_2, scalemat_r0_2); // a04*b04*q4 a05*b05*q5 a06*b06*q6 a07*b07*q7 -- 32 bits long
553
0
    if (qp_div >= 6) {
554
0
        resq_r6_1 = _mm_slli_epi32(temp5, qp_div - 6);
555
0
        resq_r6_2 = _mm_slli_epi32(temp7, qp_div - 6);
556
0
        //resq_r6_1 = _mm_and_si128(resq_r6_1,one_zero_mask);
557
0
        //resq_r6_2 = _mm_and_si128(resq_r6_2,one_zero_mask);
558
0
    } else {
559
0
        temp5 = _mm_add_epi32(temp5, add_rshift);
560
0
        temp7 = _mm_add_epi32(temp7, add_rshift);
561
0
        resq_r6_1 = _mm_srai_epi32(temp5, 6 - qp_div);
562
0
        resq_r6_2 = _mm_srai_epi32(temp7, 6 - qp_div);
563
0
        //resq_r6_1 = _mm_and_si128(resq_r6_1,one_zero_mask);
564
0
        //resq_r6_2 = _mm_and_si128(resq_r6_2,one_zero_mask);
565
0
    }
566
0
    resq_r6_1 = _mm_packs_epi32(resq_r6_1, resq_r6_2); //a00*b00*q0 a01*b01*q1 a02*b02*q2 a03*b03*q3 a04*b04*q4 a05*b05*q5 a06*b06*q6 a07*b07*q7 -- 16 bit long
567
0
    // Row 7 processing
568
0
    src_r0 = _mm_loadu_si128((__m128i *) (pi2_src + 56)); //a00 a01 a02 a03 a04 a05 a06 a07 a08 -- the source matrix 7th row
569
0
    scalemat_r0 = _mm_loadu_si128((__m128i *) (pu2_iscale_mat + 56)); //b00 b01 b02 b03 b04 b05 b06 b07 b08 -- the scaling matrix 7th row
570
0
    dequant_r0 = _mm_loadu_si128((__m128i *) (&pu2_weigh_mat[56])); //q0 q1 q2 q3 q4 q5 q6 q7 -- all 16 bits
571
0
    src_r0_1 = _mm_unpacklo_epi16(src_r0, zero_8x16b); //a00 0 a01 0 a02 0 a03 0 -- 16 bit long
572
0
    src_r0_2 = _mm_unpackhi_epi16(src_r0, zero_8x16b); // a04 0 a05 0 a06 0 a07 0 -- 16 bit long
573
0
    temp10 = _mm_mullo_epi16(scalemat_r0, dequant_r0); //b00*q0 b01*q1 b02*q2 b03*q3 b04*q4 b05*q5 b06*q6 b07*q7 -- 16 bit result
574
0
    scalemat_r0_1 = _mm_unpacklo_epi16(temp10, zero_8x16b); // b00*q0 0 b01*q1 0 b02*q2 0 b03*q3 0 -- 16 bit long
575
0
    scalemat_r0_2 = _mm_unpackhi_epi16(temp10, zero_8x16b); // b04*q4 0 b05*q5 0 b06*q6 0 b07*q7 0 -- 16 bit long
576
0
    temp5 = _mm_madd_epi16(src_r0_1, scalemat_r0_1); // a00*b00*q0 a01*b01*q1 a02*b02*q2 a03*b03*q3 -- 32 bits long
577
0
    temp7 = _mm_madd_epi16(src_r0_2, scalemat_r0_2); // a04*b04*q4 a05*b05*q5 a06*b06*q6 a07*b07*q7 -- 32 bits long
578
0
    if (qp_div >= 6) {
579
0
        resq_r7_1 = _mm_slli_epi32(temp5, qp_div - 6);
580
0
        resq_r7_2 = _mm_slli_epi32(temp7, qp_div - 6);
581
0
    } else {
582
0
        temp5 = _mm_add_epi32(temp5, add_rshift);
583
0
        temp7 = _mm_add_epi32(temp7, add_rshift);
584
0
        resq_r7_1 = _mm_srai_epi32(temp5, 6 - qp_div);
585
0
        resq_r7_2 = _mm_srai_epi32(temp7, 6 - qp_div);
586
0
    }
587
0
    resq_r7_1 = _mm_packs_epi32(resq_r7_1, resq_r7_2); //a00*b00*q0 a01*b01*q1 a02*b02*q2 a03*b03*q3 a04*b04*q4 a05*b05*q5 a06*b06*q6 a07*b07*q7 -- 16 bit long
588
0
    /* Perform Inverse transform */
589
0
    /*--------------------------------------------------------------------*/
590
0
    /* IDCT [ Horizontal transformation ]                                 */
591
0
    /*--------------------------------------------------------------------*/
592
0
    // Matrix transpose
593
0
    /*
594
0
     *  a0 a1 a2 a3 a4 a5 a6 a7
595
0
     *  b0 b1 b2 b3 b4 b5 b6 b7
596
0
     *  c0 c1 c2 c3 c4 c5 c6 c7
597
0
     *  d0 d1 d2 d3 d4 d5 d6 d7
598
0
     */
599
0
    temp1 = _mm_unpacklo_epi16(resq_r0_1, resq_r1_1); //a0 b0 a1 b1 a2 b2 a3 b3
600
0
    temp3 = _mm_unpacklo_epi16(resq_r2_1, resq_r3_1); //c0 d0 c1 d1 c2 d2 c3 d3
601
0
    temp2 = _mm_unpackhi_epi16(resq_r0_1, resq_r1_1); //a4 b4 a5 b5 a6 b6 a7 b7
602
0
    temp4 = _mm_unpackhi_epi16(resq_r2_1, resq_r3_1); //c4 d4 c5 d5 c6 d6 c7 d7
603
0
    resq_r0_1 = _mm_unpacklo_epi32(temp1, temp3); //a0 b0 c0 d0 a1 b1 c1 d1
604
0
    resq_r1_1 = _mm_unpackhi_epi32(temp1, temp3); //a2 b2 c2 d2 a3 b3 c3 d3
605
0
    resq_r2_1 = _mm_unpacklo_epi32(temp2, temp4); //a4 b4 c4 d4 a5 b5 c5 d5
606
0
    resq_r3_1 = _mm_unpackhi_epi32(temp2, temp4); //a6 b6 c6 d6 a7 b7 c7 d7
607
0
    /*
608
0
     * e0 e1 e2 e3 e4 e5 e6 e7
609
0
     * f0 f1 f2 f3 f4 f5 f6 f7
610
0
     * g0 g1 g2 g3 g4 g5 g6 g7
611
0
     * h0 h1 h2 h3 h4 h5 h6 h7
612
0
     */
613
0
    temp1 = _mm_unpacklo_epi16(resq_r4_1, resq_r5_1); //e0 f0 e1 f1 e2 f2 e2 f3
614
0
    temp3 = _mm_unpacklo_epi16(resq_r6_1, resq_r7_1); //g0 h0 g1 h1 g2 h2 g3 h3
615
0
    temp2 = _mm_unpackhi_epi16(resq_r4_1, resq_r5_1); //e4 f4 e5 f5 e6 f6 e7 f7
616
0
    temp4 = _mm_unpackhi_epi16(resq_r6_1, resq_r7_1); //g4 h4 g5 h5 g6 h6 g7 h7
617
0
    resq_r4_1 = _mm_unpacklo_epi32(temp1, temp3); //e0 f0 g0 h0 e1 f1 g1 h1
618
0
    resq_r5_1 = _mm_unpackhi_epi32(temp1, temp3); //e2 f2 g2 h2 e3 f3 g3 h3
619
0
    resq_r6_1 = _mm_unpacklo_epi32(temp2, temp4); //e4 f4 g4 h4 e5 f5 g5 h5
620
0
    resq_r7_1 = _mm_unpackhi_epi32(temp2, temp4); //e6 f6 g6 h6 e7 f7 g7 h7
621
0
    /*
622
0
     * a0 b0 c0 d0 a1 b1 c1 d1
623
0
     * a2 b2 c2 d2 a3 b3 c3 d3
624
0
     * a4 b4 c4 d4 a5 b5 c5 d5
625
0
     * a6 b6 c6 d6 a7 b7 c7 d7
626
0
     * e0 f0 g0 h0 e1 f1 g1 h1
627
0
     * e2 f2 g2 h2 e3 f3 g3 h3
628
0
     * e4 f4 g4 h4 e5 f5 g5 h5
629
0
     * e6 f6 g6 h6 e7 f7 g7 h7
630
0
     */
631
0
    resq_r0_2 = _mm_unpacklo_epi64(resq_r0_1, resq_r4_1); //a0 b0 c0 d0 e0 f0 g0 h0
632
0
    resq_r1_2 = _mm_unpackhi_epi64(resq_r0_1, resq_r4_1); //a1 b1 c1 d1 e1 f1 g1 h1
633
0
    resq_r2_2 = _mm_unpacklo_epi64(resq_r1_1, resq_r5_1); //a2 b2 c2 d2 e2 f2 g2 h2
634
0
    resq_r3_2 = _mm_unpackhi_epi64(resq_r1_1, resq_r5_1); //a3 b3 c3 d3 e3 f3 g3 h3
635
0
    resq_r4_2 = _mm_unpacklo_epi64(resq_r2_1, resq_r6_1); //a4 b4 c4 d4 e4 f4 g4 h4
636
0
    resq_r5_2 = _mm_unpackhi_epi64(resq_r2_1, resq_r6_1); //a5 b5 c5 d5 e5 f5 g5 h5
637
0
    resq_r6_2 = _mm_unpacklo_epi64(resq_r3_1, resq_r7_1); //a6 b6 c6 d6 e6 f6 g6 h6
638
0
    resq_r7_2 = _mm_unpackhi_epi64(resq_r3_1, resq_r7_1); //a7 b7 c7 d7 e7 f7 g7 h7
639
0
640
0
    sign_reg = _mm_cmpgt_epi16(zero_8x16b, resq_r1_2);
641
0
    resq_r1_1 = _mm_unpacklo_epi16(resq_r1_2, sign_reg); //a1 b1 c1 d1 -- 32 bit
642
0
    resq_r1_2 = _mm_unpackhi_epi16(resq_r1_2, sign_reg); //e1 f1 g1 h1 -- 32 bit
643
0
    sign_reg = _mm_cmpgt_epi16(zero_8x16b, resq_r3_2);
644
0
    resq_r3_1 = _mm_unpacklo_epi16(resq_r3_2, sign_reg); //a3 b3 c3 d3 -- 32 bit
645
0
    resq_r3_2 = _mm_unpackhi_epi16(resq_r3_2, sign_reg); //e3 f3 g3 h3 -- 32 bit
646
0
    sign_reg = _mm_cmpgt_epi16(zero_8x16b, resq_r5_2);
647
0
    resq_r5_1 = _mm_unpacklo_epi16(resq_r5_2, sign_reg); //a5 b5 c5 d5 -- 32 bit
648
0
    resq_r5_2 = _mm_unpackhi_epi16(resq_r5_2, sign_reg); //e5 f5 g5 h5 -- 32 bit
649
0
    sign_reg = _mm_cmpgt_epi16(zero_8x16b, resq_r7_2);
650
0
    resq_r7_1 = _mm_unpacklo_epi16(resq_r7_2, sign_reg); //a7 b7 c7 d7 -- 32 bit
651
0
    resq_r7_2 = _mm_unpackhi_epi16(resq_r7_2, sign_reg); //e7 f7 g7 h7 -- 32 bit
652
0
    //Transform starts -- horizontal transform
653
0
    /*------------------------------------------------------------------*/
654
0
    /* y0 = w0 + w4                                                     */
655
0
    temp1 = _mm_add_epi16(resq_r0_2, resq_r4_2);
656
0
    /* y2 = w0 - w4                                                      */
657
0
    temp3 = _mm_sub_epi16(resq_r0_2, resq_r4_2);
658
0
    /* y1 = -w3 + w5 - w7 - (w7 >> 1)                                   */
659
0
    temp2 = _mm_sub_epi32(resq_r5_1, resq_r3_1); //-w3+w5
660
0
    temp10 = _mm_sub_epi32(resq_r5_2, resq_r3_2);
661
0
    temp4 = _mm_sub_epi32(temp2, resq_r7_1); //-w3+w5-w7
662
0
    temp12 = _mm_sub_epi32(temp10, resq_r7_2);
663
0
    temp5 = _mm_srai_epi32(resq_r7_1, 1); //w7>>1
664
0
    temp13 = _mm_srai_epi32(resq_r7_2, 1);
665
0
    temp2 = _mm_sub_epi32(temp4, temp5); //-w3+w5-w7 -(w7>>1)
666
0
    temp10 = _mm_sub_epi32(temp12, temp13);
667
0
    temp2 = _mm_packs_epi32(temp2, temp10);
668
0
    /* y3 = w1 + w7 - w3 - (w3 >> 1)                                    */
669
0
    temp4 = _mm_add_epi32(resq_r1_1, resq_r7_1); //w1+w7
670
0
    temp12 = _mm_add_epi32(resq_r1_2, resq_r7_2);
671
0
    temp4 = _mm_sub_epi32(temp4, resq_r3_1); //w1+w7-w3
672
0
    temp12 = _mm_sub_epi32(temp12, resq_r3_2);
673
0
    temp5 = _mm_srai_epi32(resq_r3_1, 1); //w3>>1
674
0
    temp13 = _mm_srai_epi32(resq_r3_2, 1);
675
0
    temp4 = _mm_sub_epi32(temp4, temp5); //w1+w7-w3-(w3>>1)
676
0
    temp12 = _mm_sub_epi32(temp12, temp13);
677
0
    temp4 = _mm_packs_epi32(temp4, temp12);
678
0
    /* y4 = (w2 >> 1) - w6                                              */
679
0
    temp5 = _mm_srai_epi16(resq_r2_2, 1); //w2>>1
680
0
    temp5 = _mm_sub_epi16(temp5, resq_r6_2); //(w2>>1)-w6
681
0
    /* y5 = -w1 + w7 + w5 + (w5 >> 1)                                   */
682
0
    temp6 = _mm_sub_epi32(resq_r7_1, resq_r1_1); //w7-w1
683
0
    temp14 = _mm_sub_epi32(resq_r7_2, resq_r1_2);
684
0
    temp6 = _mm_add_epi32(temp6, resq_r5_1); //w7-w1+w5
685
0
    temp14 = _mm_add_epi32(temp14, resq_r5_2);
686
0
    temp7 = _mm_srai_epi32(resq_r5_1, 1); //w5>>1
687
0
    temp15 = _mm_srai_epi32(resq_r5_2, 1);
688
0
    temp6 = _mm_add_epi32(temp6, temp7); //w7-w1_w5+(w5>>1)
689
0
    temp14 = _mm_add_epi32(temp14, temp15);
690
0
    temp6 = _mm_packs_epi32(temp6, temp14);
691
0
    /* y6 = w2 + (w6 >> 1)                                              */
692
0
    temp7 = _mm_srai_epi16(resq_r6_2, 1); //w6>>1
693
0
    temp7 = _mm_add_epi16(temp7, resq_r2_2); //(w6>>1)+w2
694
0
    /* y7 = w3 + w5 + w1 + (w1 >> 1)                                    */
695
0
    temp8 = _mm_add_epi32(resq_r3_1, resq_r5_1); //w3+w5
696
0
    temp16 = _mm_add_epi32(resq_r3_2, resq_r5_2);
697
0
    temp8 = _mm_add_epi32(temp8, resq_r1_1); //w3+w5+w1
698
0
    temp16 = _mm_add_epi32(temp16, resq_r1_2);
699
0
    temp17 = _mm_srai_epi32(resq_r1_1, 1); //w1>>1
700
0
    temp18 = _mm_srai_epi32(resq_r1_2, 1);
701
0
    temp8 = _mm_add_epi32(temp8, temp17); //w3+w5+w1+(w1>>1)
702
0
    temp16 = _mm_add_epi32(temp16, temp18);
703
0
    temp8 = _mm_packs_epi32(temp8, temp16);
704
0
    /*------------------------------------------------------------------*/
705
0
    /*------------------------------------------------------------------*/
706
0
    /* z0 = y0 + y6                                                        */
707
0
    resq_r0_1 = _mm_add_epi16(temp1, temp7);
708
0
    /* z1 = y1 + (y7 >> 2)                                                */
709
0
    resq_r1_1 = _mm_srai_epi16(temp8, 2);
710
0
    resq_r1_1 = _mm_add_epi16(resq_r1_1, temp2);
711
0
    /* z2 = y2 + y4                                                        */
712
0
    resq_r2_1 = _mm_add_epi16(temp3, temp5);
713
0
    /* z3 = y3 + (y5 >> 2)                                                */
714
0
    resq_r3_1 = _mm_srai_epi16(temp6, 2);
715
0
    resq_r3_1 = _mm_add_epi16(resq_r3_1, temp4);
716
0
    /* z4 = y2 - y4                                                        */
717
0
    resq_r4_1 = _mm_sub_epi16(temp3, temp5);
718
0
    /* z5 = (y3 >> 2) - y5                                                 */
719
0
    resq_r5_1 = _mm_srai_epi16(temp4, 2);
720
0
    resq_r5_1 = _mm_sub_epi16(resq_r5_1, temp6);
721
0
    /* z6 = y0 - y6                                                     */
722
0
    resq_r6_1 = _mm_sub_epi16(temp1, temp7);
723
0
    /* z7 = y7 - (y1 >> 2)                                                 */
724
0
    resq_r7_1 = _mm_srai_epi16(temp2, 2);
725
0
    resq_r7_1 = _mm_sub_epi16(temp8, resq_r7_1);
726
0
    /*------------------------------------------------------------------*/
727
0
    /*------------------------------------------------------------------*/
728
0
    /* x0 = z0 + z7                                                        */
729
0
    temp1 = _mm_add_epi16(resq_r0_1, resq_r7_1);
730
0
    /* x1 = z2 + z5                                                        */
731
0
    temp2 = _mm_add_epi16(resq_r2_1, resq_r5_1);
732
0
    /* x2 = z4 + z3                                                        */
733
0
    temp3 = _mm_add_epi16(resq_r4_1, resq_r3_1);
734
0
    /* x3 = z6 + z1                                                        */
735
0
    temp4 = _mm_add_epi16(resq_r6_1, resq_r1_1);
736
0
    /* x4 = z6 - z1                                                        */
737
0
    temp5 = _mm_sub_epi16(resq_r6_1, resq_r1_1);
738
0
    /* x5 = z4 - z3                                                        */
739
0
    temp6 = _mm_sub_epi16(resq_r4_1, resq_r3_1);
740
0
    /* x6 = z2 - z5                                                        */
741
0
    temp7 = _mm_sub_epi16(resq_r2_1, resq_r5_1);
742
0
    /* x7 = z0 - z7                                                        */
743
0
    temp8 = _mm_sub_epi16(resq_r0_1, resq_r7_1);
744
0
    /*------------------------------------------------------------------*/
745
0
    // Matrix transpose
746
0
    /*
747
0
     *  a0 b0 c0 d0 e0 f0 g0 h0
748
0
     *  a1 b1 c1 d1 e1 f1 g1 h1
749
0
     *  a2 b2 c2 d2 e2 f2 g2 h2
750
0
     *  a3 b3 c3 d3 e3 f3 g3 h3
751
0
     */
752
0
    temp17 = _mm_unpacklo_epi16(temp1, temp2); //a0 a1 b0 b1 c0 c1 d0 d1
753
0
    temp19 = _mm_unpacklo_epi16(temp3, temp4); //a2 a3 b2 b3 c2 c3 d2 d3
754
0
    temp18 = _mm_unpackhi_epi16(temp1, temp2); //e0 e1 f0 f1 g0 g1 h0 h1
755
0
    temp20 = _mm_unpackhi_epi16(temp3, temp4); //e2 e3 f2 f3 g2 g3 h2 h3
756
0
757
0
    resq_r0_1 = _mm_unpacklo_epi32(temp17, temp19); //a0 a1 a2 a3 b0 b1 b2 b3
758
0
    resq_r1_1 = _mm_unpackhi_epi32(temp17, temp19); //c0 c1 c2 c3 d0 d1 d2 d3
759
0
    resq_r2_1 = _mm_unpacklo_epi32(temp18, temp20); //e0 e1 e2 e3 f0 f1 f2 f3
760
0
    resq_r3_1 = _mm_unpackhi_epi32(temp18, temp20); //g0 g2 g2 g3 h0 h1 h2 h3
761
0
    /*
762
0
     *  a4 b4 c4 d4 e4 f4 g4 h4
763
0
     *  a5 b5 c5 d5 e5 f5 g5 h5
764
0
     *  a6 b6 c6 d6 e6 f6 g6 h6
765
0
     *  a7 b7 c7 d7 e7 f7 g7 h7
766
0
     */
767
0
    temp17 = _mm_unpacklo_epi16(temp5, temp6); //a4 a5 b4 b5 c4 c5 d4 d5
768
0
    temp19 = _mm_unpacklo_epi16(temp7, temp8); //a6 a7 b6 b7 c6 c7 d6 d7
769
0
    temp18 = _mm_unpackhi_epi16(temp5, temp6); //e4 e5 f4 f5 g4 g5 h4 h5
770
0
    temp20 = _mm_unpackhi_epi16(temp7, temp8); //e6 e7 f6 f7 g6 g7 h6 h7
771
0
772
0
    resq_r4_1 = _mm_unpacklo_epi32(temp17, temp19); //a4 a5 a6 a7 b4 b5 b6 b7
773
0
    resq_r5_1 = _mm_unpackhi_epi32(temp17, temp19); //c4 c5 c6 c7 d4 d5 d6 d7
774
0
    resq_r6_1 = _mm_unpacklo_epi32(temp18, temp20); //e4 e5 e6 e7 f4 f5 f6 f7
775
0
    resq_r7_1 = _mm_unpackhi_epi32(temp18, temp20); //g4 g5 g6 g7 h4 h5 h6 h7
776
0
    /*  a0 a1 a2 a3 b0 b1 b2 b3
777
0
     *  c0 c1 c2 c3 d0 d1 d2 d3
778
0
     *  e0 e1 e2 e3 f0 f1 f2 f3
779
0
     *  g0 g2 g2 g3 h0 h1 h2 h3
780
0
     *  a4 a5 a6 a7 b4 b5 b6 b7
781
0
     *  c4 c5 c6 c7 d4 d5 d6 d7
782
0
     *  e4 e5 e6 e7 f4 f5 f6 f7
783
0
     *  g4 g5 g6 g7 h4 h5 h6 h7
784
0
     */
785
0
    resq_r0_2 = _mm_unpacklo_epi64(resq_r0_1, resq_r4_1); //a0 a1 a2 a3 a4 a5 a6 a7
786
0
    resq_r1_2 = _mm_unpackhi_epi64(resq_r0_1, resq_r4_1); //b0 b1 b2 b3 b4 b5 b6 b7
787
0
    resq_r2_2 = _mm_unpacklo_epi64(resq_r1_1, resq_r5_1); //c0 c1 c2 c3 c4 c5 c6 c7
788
0
    resq_r3_2 = _mm_unpackhi_epi64(resq_r1_1, resq_r5_1); //d0 d1 d2 d3 d4 d5 d6 d7
789
0
    resq_r4_2 = _mm_unpacklo_epi64(resq_r2_1, resq_r6_1); //e0 e1 e2 e3 e4 e5 e6 e7
790
0
    resq_r5_2 = _mm_unpackhi_epi64(resq_r2_1, resq_r6_1); //f0 f1 f2 f3 f4 f5 f6 f7
791
0
    resq_r6_2 = _mm_unpacklo_epi64(resq_r3_1, resq_r7_1); //g0 g1 g2 g3 g4 g5 g6 g7
792
0
    resq_r7_2 = _mm_unpackhi_epi64(resq_r3_1, resq_r7_1); //h0 h1 h2 h3 h4 h5 h6 h7
793
0
794
0
    sign_reg = _mm_cmpgt_epi16(zero_8x16b, resq_r1_2);
795
0
    resq_r1_1 = _mm_unpacklo_epi16(resq_r1_2, sign_reg); //a1 b1 c1 d1 -- 32 bit
796
0
    resq_r1_2 = _mm_unpackhi_epi16(resq_r1_2, sign_reg); //e1 f1 g1 h1 -- 32 bit
797
0
    sign_reg = _mm_cmpgt_epi16(zero_8x16b, resq_r3_2);
798
0
    resq_r3_1 = _mm_unpacklo_epi16(resq_r3_2, sign_reg); //a3 b3 c3 d3 -- 32 bit
799
0
    resq_r3_2 = _mm_unpackhi_epi16(resq_r3_2, sign_reg); //e3 f3 g3 h3 -- 32 bit
800
0
    sign_reg = _mm_cmpgt_epi16(zero_8x16b, resq_r5_2);
801
0
    resq_r5_1 = _mm_unpacklo_epi16(resq_r5_2, sign_reg); //a5 b5 c5 d5 -- 32 bit
802
0
    resq_r5_2 = _mm_unpackhi_epi16(resq_r5_2, sign_reg); //e5 f5 g5 h5 -- 32 bit
803
0
    sign_reg = _mm_cmpgt_epi16(zero_8x16b, resq_r7_2);
804
0
    resq_r7_1 = _mm_unpacklo_epi16(resq_r7_2, sign_reg); //a7 b7 c7 d7 -- 32 bit
805
0
    resq_r7_2 = _mm_unpackhi_epi16(resq_r7_2, sign_reg); //e7 f7 g7 h7 -- 32 bit
806
0
807
0
    zero_8x16b = _mm_setzero_si128(); // all bits reset to zero
808
0
    //Load pred buffer row 0
809
0
    predload_r = _mm_loadl_epi64((__m128i *) (&pu1_pred[0])); //p0 p1 p2 p3 p4 p5 p6 p7 0 0 0 0 0 0 0 0 -- all 8 bits
810
0
    pred_r0_1 = _mm_unpacklo_epi8(predload_r, zero_8x16b); //p0 p1 p2 p3 p4 p5 p6 p7 -- all 16 bits
811
0
    //Load pred buffer row 1
812
0
    predload_r = _mm_loadl_epi64((__m128i *) (&pu1_pred[pred_strd])); //p0 p1 p2 p3 p4 p5 p6 p7 0 0 0 0 0 0 0 0 -- all 8 bits
813
0
    pred_r1_1 = _mm_unpacklo_epi8(predload_r, zero_8x16b); //p0 p1 p2 p3 p4 p5 p6 p7 -- all 16 bits
814
0
    //Load pred buffer row 2
815
0
    predload_r = _mm_loadl_epi64((__m128i *) (&pu1_pred[2 * pred_strd])); //p0 p1 p2 p3 p4 p5 p6 p7 0 0 0 0 0 0 0 0 -- all 8 bits
816
0
    pred_r2_1 = _mm_unpacklo_epi8(predload_r, zero_8x16b); //p0 p1 p2 p3 p4 p5 p6 p7 -- all 16 bits
817
0
    //Load pred buffer row 3
818
0
    predload_r = _mm_loadl_epi64((__m128i *) (&pu1_pred[3 * pred_strd])); //p0 p1 p2 p3 p4 p5 p6 p7 0 0 0 0 0 0 0 0 -- all 8 bits
819
0
    pred_r3_1 = _mm_unpacklo_epi8(predload_r, zero_8x16b); //p0 p1 p2 p3 p4 p5 p6 p7 -- all 16 bits
820
0
    //Load pred buffer row 4
821
0
    predload_r = _mm_loadl_epi64((__m128i *) (&pu1_pred[4 * pred_strd])); //p0 p1 p2 p3 p4 p5 p6 p7 0 0 0 0 0 0 0 0 -- all 8 bits
822
0
    pred_r4_1 = _mm_unpacklo_epi8(predload_r, zero_8x16b); //p0 p1 p2 p3 p4 p5 p6 p7 -- all 16 bits
823
0
    //Load pred buffer row 5
824
0
    predload_r = _mm_loadl_epi64((__m128i *) (&pu1_pred[5 * pred_strd])); //p0 p1 p2 p3 p4 p5 p6 p7 0 0 0 0 0 0 0 0 -- all 8 bit
825
0
    pred_r5_1 = _mm_unpacklo_epi8(predload_r, zero_8x16b); //p0 p1 p2 p3 p4 p5 p6 p7 -- all 16 bits
826
0
    //Load pred buffer row 6
827
0
    predload_r = _mm_loadl_epi64((__m128i *) (&pu1_pred[6 * pred_strd])); //p0 p1 p2 p3 p4 p5 p6 p7 0 0 0 0 0 0 0 0 -- all 8 bits
828
0
    pred_r6_1 = _mm_unpacklo_epi8(predload_r, zero_8x16b); //p0 p1 p2 p3 p4 p5 p6 p7 -- all 16 bits
829
0
    //Load pred buffer row 7
830
0
    predload_r = _mm_loadl_epi64((__m128i *) (&pu1_pred[7 * pred_strd])); //p0 p1 p2 p3 p4 p5 p6 p7 0 0 0 0 0 0 0 0 -- all 8 bits
831
0
    pred_r7_1 = _mm_unpacklo_epi8(predload_r, zero_8x16b); //p0 p1 p2 p3 p4 p5 p6 p7 -- all 16 bits
832
0
833
0
    /*--------------------------------------------------------------------*/
834
0
    /* IDCT [ Vertical transformation] and Xij = (xij + 32)>>6            */
835
0
    /*                                                                    */
836
0
    /* Add the prediction and store it back to reconstructed frame buffer */
837
0
    /* [Prediction buffer itself in this case]                            */
838
0
    /*--------------------------------------------------------------------*/
839
0
840
0
    /* y0j = w0j + w4j                                                     */
841
0
    temp1 = _mm_add_epi16(resq_r0_2, resq_r4_2);
842
0
    /* y2j = w0j - w4j                                                      */
843
0
    temp3 = _mm_sub_epi16(resq_r0_2, resq_r4_2);
844
0
    /* y1j = -w3j + w5j - w7j - (w7j >> 1)                                   */
845
0
    temp2 = _mm_sub_epi32(resq_r5_1, resq_r3_1); //-w3+w5
846
0
    temp10 = _mm_sub_epi32(resq_r5_2, resq_r3_2);
847
0
    temp4 = _mm_sub_epi32(temp2, resq_r7_1); //-w3+w5-w7
848
0
    temp12 = _mm_sub_epi32(temp10, resq_r7_2);
849
0
    temp5 = _mm_srai_epi32(resq_r7_1, 1); //w7>>1
850
0
    temp13 = _mm_srai_epi32(resq_r7_2, 1);
851
0
    temp2 = _mm_sub_epi32(temp4, temp5); //-w3+w5-w7 -(w7>>1)
852
0
    temp10 = _mm_sub_epi32(temp12, temp13);
853
0
    temp2 = _mm_packs_epi32(temp2, temp10);
854
0
    /* y3j = w1j + w7j - w3j - (w3j >> 1)                                    */
855
0
    temp4 = _mm_add_epi32(resq_r1_1, resq_r7_1); //w1+w7
856
0
    temp12 = _mm_add_epi32(resq_r1_2, resq_r7_2);
857
0
    temp4 = _mm_sub_epi32(temp4, resq_r3_1); //w1+w7-w3
858
0
    temp12 = _mm_sub_epi32(temp12, resq_r3_2);
859
0
    temp5 = _mm_srai_epi32(resq_r3_1, 1); //w3>>1
860
0
    temp13 = _mm_srai_epi32(resq_r3_2, 1);
861
0
    temp4 = _mm_sub_epi32(temp4, temp5); //w1+w7-w3-(w3>>1)
862
0
    temp12 = _mm_sub_epi32(temp12, temp13);
863
0
    temp4 = _mm_packs_epi32(temp4, temp12);
864
0
    /* y4j = (w2j >> 1) - w6j                                              */
865
0
    temp5 = _mm_srai_epi16(resq_r2_2, 1); //w2>>1
866
0
    temp5 = _mm_sub_epi16(temp5, resq_r6_2); //(w2>>1)-w6
867
0
    /* y5j = -w1j + w7j + w5j + (w5j >> 1)                                   */
868
0
    temp6 = _mm_sub_epi32(resq_r7_1, resq_r1_1); //w7-w1
869
0
    temp14 = _mm_sub_epi32(resq_r7_2, resq_r1_2);
870
0
    temp6 = _mm_add_epi32(temp6, resq_r5_1); //w7-w1+w5
871
0
    temp14 = _mm_add_epi32(temp14, resq_r5_2);
872
0
    temp7 = _mm_srai_epi32(resq_r5_1, 1); //w5>>1
873
0
    temp15 = _mm_srai_epi32(resq_r5_2, 1);
874
0
    temp6 = _mm_add_epi32(temp6, temp7); //w7-w1_w5+(w5>>1)
875
0
    temp14 = _mm_add_epi32(temp14, temp15);
876
0
    temp6 = _mm_packs_epi32(temp6, temp14);
877
0
    /* y6j = w2j + (w6j >> 1)                                              */
878
0
    temp7 = _mm_srai_epi16(resq_r6_2, 1); //w6>>1
879
0
    temp7 = _mm_add_epi16(temp7, resq_r2_2); //(w6>>1)+w2
880
0
    /* y7j = w3j + w5j + w1j + (w1j >> 1)                                    */
881
0
    temp8 = _mm_add_epi32(resq_r3_1, resq_r5_1); //w3+w5
882
0
    temp16 = _mm_add_epi32(resq_r3_2, resq_r5_2);
883
0
    temp8 = _mm_add_epi32(temp8, resq_r1_1); //w3+w5+w1
884
0
    temp16 = _mm_add_epi32(temp16, resq_r1_2);
885
0
    temp17 = _mm_srai_epi32(resq_r1_1, 1); //w1>>1
886
0
    temp18 = _mm_srai_epi32(resq_r1_2, 1);
887
0
    temp8 = _mm_add_epi32(temp8, temp17); //w3+w5+w1+(w1>>1)
888
0
    temp16 = _mm_add_epi32(temp16, temp18);
889
0
    temp8 = _mm_packs_epi32(temp8, temp16);
890
0
    /*------------------------------------------------------------------*/
891
0
    /*------------------------------------------------------------------*/
892
0
    /* z0j = y0j + y6j                                                        */
893
0
    resq_r0_1 = _mm_add_epi16(temp1, temp7);
894
0
    /* z1j = y1j + (y7j >> 2)                                                */
895
0
    resq_r1_1 = _mm_srai_epi16(temp8, 2);
896
0
    resq_r1_1 = _mm_add_epi16(resq_r1_1, temp2);
897
0
    /* z2j = y2j + y4j                                                        */
898
0
    resq_r2_1 = _mm_add_epi16(temp3, temp5);
899
0
    /* z3j = y3j + (y5j >> 2)                                                */
900
0
    resq_r3_1 = _mm_srai_epi16(temp6, 2);
901
0
    resq_r3_1 = _mm_add_epi16(resq_r3_1, temp4);
902
0
    /* z4j = y2j - y4j                                                        */
903
0
    resq_r4_1 = _mm_sub_epi16(temp3, temp5);
904
0
    /* z5j = (y3j >> 2) - y5j                                                 */
905
0
    resq_r5_1 = _mm_srai_epi16(temp4, 2);
906
0
    resq_r5_1 = _mm_sub_epi16(resq_r5_1, temp6);
907
0
    /* z6j = y0j - y6j                                                     */
908
0
    resq_r6_1 = _mm_sub_epi16(temp1, temp7);
909
0
    /* z7j = y7j - (y1j >> 2)                                                 */
910
0
    resq_r7_1 = _mm_srai_epi16(temp2, 2);
911
0
    resq_r7_1 = _mm_sub_epi16(temp8, resq_r7_1);
912
0
    /*------------------------------------------------------------------*/
913
0
914
0
    /*------------------------------------------------------------------*/
915
0
    /* x0j = z0j + z7j                                                        */
916
0
    temp1 = _mm_add_epi16(resq_r0_1, resq_r7_1);
917
0
    sign_reg = _mm_cmpgt_epi16(zero_8x16b, temp1);
918
0
    temp10 = _mm_unpacklo_epi16(temp1, sign_reg);
919
0
    temp11 = _mm_unpackhi_epi16(temp1, sign_reg);
920
0
    temp10 = _mm_add_epi32(temp10, value_32);
921
0
    temp11 = _mm_add_epi32(temp11, value_32);
922
0
    temp10 = _mm_srai_epi32(temp10, 6);
923
0
    temp11 = _mm_srai_epi32(temp11, 6);
924
0
    temp10 = _mm_packs_epi32(temp10, temp11);
925
0
    temp1 = _mm_add_epi16(temp10, pred_r0_1);
926
0
    /* x1j = z2j + z5j                                                        */
927
0
    temp2 = _mm_add_epi16(resq_r2_1, resq_r5_1);
928
0
    sign_reg = _mm_cmpgt_epi16(zero_8x16b, temp2);
929
0
    temp10 = _mm_unpacklo_epi16(temp2, sign_reg);
930
0
    temp11 = _mm_unpackhi_epi16(temp2, sign_reg);
931
0
    temp10 = _mm_add_epi32(temp10, value_32);
932
0
    temp11 = _mm_add_epi32(temp11, value_32);
933
0
    temp10 = _mm_srai_epi32(temp10, 6);
934
0
    temp11 = _mm_srai_epi32(temp11, 6);
935
0
    temp10 = _mm_packs_epi32(temp10, temp11);
936
0
    temp2 = _mm_add_epi16(temp10, pred_r1_1);
937
0
    /* x2j = z4j + z3j                                                        */
938
0
    temp3 = _mm_add_epi16(resq_r4_1, resq_r3_1);
939
0
    sign_reg = _mm_cmpgt_epi16(zero_8x16b, temp3);
940
0
    temp10 = _mm_unpacklo_epi16(temp3, sign_reg);
941
0
    temp11 = _mm_unpackhi_epi16(temp3, sign_reg);
942
0
    temp10 = _mm_add_epi32(temp10, value_32);
943
0
    temp11 = _mm_add_epi32(temp11, value_32);
944
0
    temp10 = _mm_srai_epi32(temp10, 6);
945
0
    temp11 = _mm_srai_epi32(temp11, 6);
946
0
    temp10 = _mm_packs_epi32(temp10, temp11);
947
0
    temp3 = _mm_add_epi16(temp10, pred_r2_1);
948
0
    /* x3j = z6j + z1j                                                        */
949
0
    temp4 = _mm_add_epi16(resq_r6_1, resq_r1_1);
950
0
    sign_reg = _mm_cmpgt_epi16(zero_8x16b, temp4);
951
0
    temp10 = _mm_unpacklo_epi16(temp4, sign_reg);
952
0
    temp11 = _mm_unpackhi_epi16(temp4, sign_reg);
953
0
    temp10 = _mm_add_epi32(temp10, value_32);
954
0
    temp11 = _mm_add_epi32(temp11, value_32);
955
0
    temp10 = _mm_srai_epi32(temp10, 6);
956
0
    temp11 = _mm_srai_epi32(temp11, 6);
957
0
    temp10 = _mm_packs_epi32(temp10, temp11);
958
0
    temp4 = _mm_add_epi16(temp10, pred_r3_1);
959
0
    /* x4j = z6j - z1j                                                        */
960
0
    temp5 = _mm_sub_epi16(resq_r6_1, resq_r1_1);
961
0
    sign_reg = _mm_cmpgt_epi16(zero_8x16b, temp5);
962
0
    temp10 = _mm_unpacklo_epi16(temp5, sign_reg);
963
0
    temp11 = _mm_unpackhi_epi16(temp5, sign_reg);
964
0
    temp10 = _mm_add_epi32(temp10, value_32);
965
0
    temp11 = _mm_add_epi32(temp11, value_32);
966
0
    temp10 = _mm_srai_epi32(temp10, 6);
967
0
    temp11 = _mm_srai_epi32(temp11, 6);
968
0
    temp10 = _mm_packs_epi32(temp10, temp11);
969
0
    temp5 = _mm_add_epi16(temp10, pred_r4_1);
970
0
    /* x5j = z4j - z3j                                                        */
971
0
    temp6 = _mm_sub_epi16(resq_r4_1, resq_r3_1);
972
0
    sign_reg = _mm_cmpgt_epi16(zero_8x16b, temp6);
973
0
    temp10 = _mm_unpacklo_epi16(temp6, sign_reg);
974
0
    temp11 = _mm_unpackhi_epi16(temp6, sign_reg);
975
0
    temp10 = _mm_add_epi32(temp10, value_32);
976
0
    temp11 = _mm_add_epi32(temp11, value_32);
977
0
    temp10 = _mm_srai_epi32(temp10, 6);
978
0
    temp11 = _mm_srai_epi32(temp11, 6);
979
0
    temp10 = _mm_packs_epi32(temp10, temp11);
980
0
    temp6 = _mm_add_epi16(temp10, pred_r5_1);
981
0
    /* x6j = z2j - z5j                                                        */
982
0
    temp7 = _mm_sub_epi16(resq_r2_1, resq_r5_1);
983
0
    sign_reg = _mm_cmpgt_epi16(zero_8x16b, temp7);
984
0
    temp10 = _mm_unpacklo_epi16(temp7, sign_reg);
985
0
    temp11 = _mm_unpackhi_epi16(temp7, sign_reg);
986
0
    temp10 = _mm_add_epi32(temp10, value_32);
987
0
    temp11 = _mm_add_epi32(temp11, value_32);
988
0
    temp10 = _mm_srai_epi32(temp10, 6);
989
0
    temp11 = _mm_srai_epi32(temp11, 6);
990
0
    temp10 = _mm_packs_epi32(temp10, temp11);
991
0
    temp7 = _mm_add_epi16(temp10, pred_r6_1);
992
0
    /* x7j = z0j - z7j                                                        */
993
0
    temp8 = _mm_sub_epi16(resq_r0_1, resq_r7_1);
994
0
    sign_reg = _mm_cmpgt_epi16(zero_8x16b, temp8);
995
0
    temp10 = _mm_unpacklo_epi16(temp8, sign_reg);
996
0
    temp11 = _mm_unpackhi_epi16(temp8, sign_reg);
997
0
    temp10 = _mm_add_epi32(temp10, value_32);
998
0
    temp11 = _mm_add_epi32(temp11, value_32);
999
0
    temp10 = _mm_srai_epi32(temp10, 6);
1000
0
    temp11 = _mm_srai_epi32(temp11, 6);
1001
0
    temp10 = _mm_packs_epi32(temp10, temp11);
1002
0
    temp8 = _mm_add_epi16(temp10, pred_r7_1);
1003
0
    /*------------------------------------------------------------------*/
1004
0
    //Clipping the results to 8 bits
1005
0
    sign_reg = _mm_cmpgt_epi16(temp1, zero_8x16b); // sign check
1006
0
    temp1 = _mm_and_si128(temp1, sign_reg);
1007
0
    sign_reg = _mm_cmpgt_epi16(temp2, zero_8x16b); // sign check
1008
0
    temp2 = _mm_and_si128(temp2, sign_reg);
1009
0
    sign_reg = _mm_cmpgt_epi16(temp3, zero_8x16b); // sign check
1010
0
    temp3 = _mm_and_si128(temp3, sign_reg);
1011
0
    sign_reg = _mm_cmpgt_epi16(temp4, zero_8x16b); // sign check
1012
0
    temp4 = _mm_and_si128(temp4, sign_reg);
1013
0
    sign_reg = _mm_cmpgt_epi16(temp5, zero_8x16b); // sign check
1014
0
    temp5 = _mm_and_si128(temp5, sign_reg);
1015
0
    sign_reg = _mm_cmpgt_epi16(temp6, zero_8x16b); // sign check
1016
0
    temp6 = _mm_and_si128(temp6, sign_reg);
1017
0
    sign_reg = _mm_cmpgt_epi16(temp7, zero_8x16b); // sign check
1018
0
    temp7 = _mm_and_si128(temp7, sign_reg);
1019
0
    sign_reg = _mm_cmpgt_epi16(temp8, zero_8x16b); // sign check
1020
0
    temp8 = _mm_and_si128(temp8, sign_reg);
1021
0
1022
0
    resq_r0_2 = _mm_packus_epi16(temp1, zero_8x16b);
1023
0
    resq_r1_2 = _mm_packus_epi16(temp2, zero_8x16b);
1024
0
    resq_r2_2 = _mm_packus_epi16(temp3, zero_8x16b);
1025
0
    resq_r3_2 = _mm_packus_epi16(temp4, zero_8x16b);
1026
0
    resq_r4_2 = _mm_packus_epi16(temp5, zero_8x16b);
1027
0
    resq_r5_2 = _mm_packus_epi16(temp6, zero_8x16b);
1028
0
    resq_r6_2 = _mm_packus_epi16(temp7, zero_8x16b);
1029
0
    resq_r7_2 = _mm_packus_epi16(temp8, zero_8x16b);
1030
0
1031
0
    _mm_storel_epi64((__m128i *) (&pu1_out[0]), resq_r0_2);
1032
0
    _mm_storel_epi64((__m128i *) (&pu1_out[out_strd]), resq_r1_2);
1033
0
    _mm_storel_epi64((__m128i *) (&pu1_out[2 * out_strd]), resq_r2_2);
1034
0
    _mm_storel_epi64((__m128i *) (&pu1_out[3 * out_strd]), resq_r3_2);
1035
0
    _mm_storel_epi64((__m128i *) (&pu1_out[4 * out_strd]), resq_r4_2);
1036
0
    _mm_storel_epi64((__m128i *) (&pu1_out[5 * out_strd]), resq_r5_2);
1037
0
    _mm_storel_epi64((__m128i *) (&pu1_out[6 * out_strd]), resq_r6_2);
1038
0
    _mm_storel_epi64((__m128i *) (&pu1_out[7 * out_strd]), resq_r7_2);
1039
0
}
1040
/proc/self/cwd/external/libavc/common/x86/ih264_luma_intra_pred_filters_ssse3.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/**
21
 *******************************************************************************
22
 * @file
23
 *  ih264_luma_intra_pred_filters_ssse3.c
24
 *
25
 * @brief
26
 *  Contains function definitions for luma intra prediction filters in x86
27
 *  intrinsics
28
 *
29
 * @author
30
 *  Ittiam
31
 *
32
 * @par List of Functions:
33
 *  - ih264_intra_pred_luma_4x4_mode_vert_ssse3
34
 *  - ih264_intra_pred_luma_4x4_mode_horz_ssse3
35
 *  - ih264_intra_pred_luma_4x4_mode_dc_ssse3
36
 *  - ih264_intra_pred_luma_4x4_mode_diag_dl_ssse3
37
 *  - ih264_intra_pred_luma_4x4_mode_diag_dr_ssse3
38
 *  - ih264_intra_pred_luma_4x4_mode_vert_r_ssse3
39
 *  - ih264_intra_pred_luma_4x4_mode_horz_d_ssse3
40
 *  - ih264_intra_pred_luma_4x4_mode_vert_l_ssse3
41
 *  - ih264_intra_pred_luma_4x4_mode_horz_u_ssse3
42
 *  - ih264_intra_pred_luma_8x8_mode_vert_ssse3
43
 *  - ih264_intra_pred_luma_8x8_mode_horz_ssse3
44
 *  - ih264_intra_pred_luma_8x8_mode_dc_ssse3
45
 *  - ih264_intra_pred_luma_8x8_mode_diag_dl_ssse3
46
 *  - ih264_intra_pred_luma_8x8_mode_diag_dr_ssse3
47
 *  - ih264_intra_pred_luma_8x8_mode_vert_r_ssse3
48
 *  - ih264_intra_pred_luma_8x8_mode_horz_d_ssse3
49
 *  - ih264_intra_pred_luma_8x8_mode_vert_l_ssse3
50
 *  - ih264_intra_pred_luma_8x8_mode_horz_u_ssse3
51
 *  - ih264_intra_pred_luma_16x16_mode_vert_ssse3
52
 *  - ih264_intra_pred_luma_16x16_mode_horz_ssse3
53
 *  - ih264_intra_pred_luma_16x16_mode_dc_ssse3
54
 *  - ih264_intra_pred_luma_16x16_mode_plane_ssse3
55
 *
56
 * @remarks
57
 *  None
58
 *
59
 ******************************************************************************
60
 */
61
62
/*****************************************************************************/
63
/* File Includes                                                             */
64
/*****************************************************************************/
65
/* System include files */
66
#include <stdio.h>
67
#include <stddef.h>
68
#include <string.h>
69
#include <immintrin.h>
70
71
/* User include files */
72
#include "ih264_defs.h"
73
#include "ih264_typedefs.h"
74
#include "ih264_macros.h"
75
#include "ih264_platform_macros.h"
76
#include "ih264_intra_pred_filters.h"
77
78
79
80
/*******************    LUMA INTRAPREDICTION    *******************/
81
82
/*******************    4x4 Modes    *******************/
83
84
/**
85
 *******************************************************************************
86
 *
87
 * ih264_intra_pred_luma_4x4_mode_vert_ssse3
88
 *
89
 * @brief
90
 *  Perform Intra prediction for luma_4x4 mode:vertical
91
 *
92
 * @par Description:
93
 *  Perform Intra prediction for luma_4x4 mode:vertical ,described in sec 8.3.1.2.1
94
 *
95
 * @param[in] pu1_src
96
 *  UWORD8 pointer to the source
97
 *
98
 * @param[out] pu1_dst
99
 *  UWORD8 pointer to the destination
100
 *
101
 * @param[in] src_strd
102
 *  integer source stride
103
 *
104
 * @param[in] dst_strd
105
 *  integer destination stride
106
 *
107
 * @param[in] ngbr_avail
108
 * availability of neighbouring pixels(Not used in this function)
109
 *
110
 * @returns
111
 *
112
 * @remarks
113
 *  None
114
 *
115
 *******************************************************************************
116
 */
117
void ih264_intra_pred_luma_4x4_mode_vert_ssse3(UWORD8 *pu1_src,
118
                                               UWORD8 *pu1_dst,
119
                                               WORD32 src_strd,
120
                                               WORD32 dst_strd,
121
                                               WORD32 ngbr_avail)
122
13.2k
{
123
13.2k
    UWORD8 *pu1_top;
124
13.2k
    WORD32 dst_strd2, dst_strd3;
125
13.2k
    WORD32 i4_top;
126
13.2k
127
13.2k
    UNUSED(src_strd);
128
13.2k
    UNUSED(ngbr_avail);
129
13.2k
130
13.2k
    pu1_top = pu1_src + BLK_SIZE + 1;
131
13.2k
132
13.2k
    i4_top = *((WORD32 *)pu1_top);
133
13.2k
134
13.2k
    dst_strd2 = dst_strd << 1;
135
13.2k
    dst_strd3 = dst_strd + dst_strd2;
136
13.2k
137
13.2k
    *((WORD32 *)(pu1_dst)) = i4_top;
138
13.2k
    *((WORD32 *)(pu1_dst + dst_strd)) = i4_top;
139
13.2k
    *((WORD32 *)(pu1_dst + dst_strd2)) = i4_top;
140
13.2k
    *((WORD32 *)(pu1_dst + dst_strd3)) = i4_top;
141
13.2k
}
142
143
/**
144
 *******************************************************************************
145
 *
146
 *ih264_intra_pred_luma_4x4_mode_horz_ssse3
147
 *
148
 * @brief
149
 *  Perform Intra prediction for luma_4x4 mode:horizontal
150
 *
151
 * @par Description:
152
 *  Perform Intra prediction for luma_4x4 mode:horizontal ,described in sec 8.3.1.2.2
153
 *
154
 * @param[in] pu1_src
155
 *  UWORD8 pointer to the source
156
 *
157
 * @param[out] pu1_dst
158
 *  UWORD8 pointer to the destination
159
 *
160
 * @param[in] src_strd
161
 *  integer source stride
162
 *
163
 * @param[in] dst_strd
164
 *  integer destination stride
165
 *
166
 * @param[in] ngbr_avail
167
 * availability of neighbouring pixels(Not used in this function)
168
 *
169
 * @returns
170
 *
171
 * @remarks
172
 *  None
173
 *
174
 *******************************************************************************
175
 */
176
void ih264_intra_pred_luma_4x4_mode_horz_ssse3(UWORD8 *pu1_src,
177
                                               UWORD8 *pu1_dst,
178
                                               WORD32 src_strd,
179
                                               WORD32 dst_strd,
180
                                               WORD32 ngbr_avail)
181
11.6k
{
182
11.6k
    UWORD8 *pu1_left = NULL; /* Pointer to start of left predictors */
183
11.6k
    WORD32 row1,row2,row3,row4;
184
11.6k
    UWORD8 val;
185
11.6k
    WORD32 dst_strd2, dst_strd3;
186
11.6k
187
11.6k
    UNUSED(src_strd);
188
11.6k
    UNUSED(ngbr_avail);
189
11.6k
    pu1_left = pu1_src + BLK_SIZE - 1;
190
11.6k
191
11.6k
    val  = *pu1_left;
192
11.6k
    row1 = val + (val << 8) + (val << 16) + (val << 24);
193
11.6k
    val  = *(pu1_left - 1);
194
11.6k
    row2 = val + (val << 8) + (val << 16) + (val << 24);
195
11.6k
    val  = *(pu1_left - 2);
196
11.6k
    row3 = val + (val << 8) + (val << 16) + (val << 24);
197
11.6k
    val  = *(pu1_left - 3);
198
11.6k
    row4 = val + (val << 8) + (val << 16) + (val << 24);
199
11.6k
200
11.6k
    dst_strd2 = dst_strd << 1;
201
11.6k
    dst_strd3 = dst_strd + dst_strd2;
202
11.6k
203
11.6k
    *((WORD32 *)(pu1_dst)) = row1;
204
11.6k
    *((WORD32 *)(pu1_dst + dst_strd)) = row2;
205
11.6k
    *((WORD32 *)(pu1_dst + dst_strd2)) = row3;
206
11.6k
    *((WORD32 *)(pu1_dst + dst_strd3)) = row4;
207
11.6k
}
208
209
/**
210
 *******************************************************************************
211
 *
212
 * ih264_intra_pred_luma_4x4_mode_dc_ssse3
213
 *
214
 * @brief
215
 *  Perform Intra prediction for luma_4x4 mode:DC
216
 *
217
 * @par Description:
218
 *  Perform Intra prediction for luma_4x4 mode:DC ,described in sec 8.3.1.2.3
219
 *
220
 * @param[in] pu1_src
221
 *  UWORD8 pointer to the source
222
 *
223
 * @param[out] pu1_dst
224
 *  UWORD8 pointer to the destination
225
 *
226
 * @param[in] src_strd
227
 *  integer source stride
228
 *
229
 * @param[in] dst_strd
230
 *  integer destination stride
231
 *
232
 * @param[in] ngbr_avail
233
 *  availability of neighbouring pixels
234
 *
235
 * @returns
236
 *
237
 * @remarks
238
 *  None
239
 *
240
 *******************************************************************************/
241
void ih264_intra_pred_luma_4x4_mode_dc_ssse3(UWORD8 *pu1_src,
242
                                             UWORD8 *pu1_dst,
243
                                             WORD32 src_strd,
244
                                             WORD32 dst_strd,
245
                                             WORD32 ngbr_avail)
246
9.04k
{
247
9.04k
    UWORD8 u1_useleft; /* availability of left predictors (only for DC) */
248
9.04k
    UWORD8 u1_usetop; /* availability of top predictors (only for DC) */
249
9.04k
    UWORD8 *pu1_left = NULL; /* Pointer to start of left predictors */
250
9.04k
    UWORD8 *pu1_top = NULL; /* Pointer to start of top predictors */
251
9.04k
    WORD32 dst_strd2, dst_strd3;
252
9.04k
    WORD32 val = 0;
253
9.04k
    UNUSED(src_strd);
254
9.04k
    UNUSED(ngbr_avail);
255
9.04k
    u1_useleft = BOOLEAN(ngbr_avail & LEFT_MB_AVAILABLE_MASK);
256
9.04k
    u1_usetop = BOOLEAN(ngbr_avail & TOP_MB_AVAILABLE_MASK);
257
9.04k
    pu1_top = pu1_src + BLK_SIZE + 1;
258
9.04k
    pu1_left = pu1_src + BLK_SIZE - 1;
259
9.04k
260
9.04k
    if(u1_useleft)
261
8.55k
    {
262
8.55k
        val += *pu1_left--;
263
8.55k
        val += *pu1_left--;
264
8.55k
        val += *pu1_left--;
265
8.55k
        val += *pu1_left + 2;
266
8.55k
    }
267
9.04k
    if(u1_usetop)
268
8.82k
    {
269
8.82k
        val += *pu1_top + *(pu1_top + 1) + *(pu1_top + 2) + *(pu1_top + 3)
270
8.82k
                        + 2;
271
8.82k
    }
272
9.04k
    /* Since 2 is added if either left/top pred is there,
273
9.04k
     val still being zero implies both preds are not there */
274
9.04k
    val = (val) ? (val >> (1 + u1_useleft + u1_usetop)) : 128;
275
9.04k
276
9.04k
    val = val + (val << 8) + (val << 16) + (val << 24);
277
9.04k
278
9.04k
    dst_strd2 = dst_strd << 1;
279
9.04k
    dst_strd3 = dst_strd + dst_strd2;
280
9.04k
281
9.04k
    *((WORD32 *)(pu1_dst)) = val;
282
9.04k
    *((WORD32 *)(pu1_dst + dst_strd)) = val;
283
9.04k
    *((WORD32 *)(pu1_dst + dst_strd2)) = val;
284
9.04k
    *((WORD32 *)(pu1_dst + dst_strd3)) = val;
285
9.04k
}
286
287
/**
288
 *******************************************************************************
289
 *
290
 * ih264_intra_pred_luma_4x4_mode_diag_dl_ssse3
291
 *
292
 * @brief
293
 *  Perform Intra prediction for luma_4x4 mode:Diagonal_Down_Left
294
 *
295
 * @par Description:
296
 *  Perform Intra prediction for luma_4x4 mode:Diagonal_Down_Left ,described in sec 8.3.1.2.4
297
 *
298
 * @param[in] pu1_src
299
 *  UWORD8 pointer to the source
300
 *
301
 * @param[out] pu1_dst
302
 *  UWORD8 pointer to the destination
303
 *
304
 * @param[in] src_strd
305
 *  integer source stride
306
 *
307
 * @param[in] dst_strd
308
 *  integer destination stride
309
 *
310
 * @param[in] ngbr_avail
311
 * availability of neighbouring pixels(Not used in this function)
312
 *
313
 * @returns
314
 *
315
 * @remarks
316
 *  None
317
 *
318
 *******************************************************************************/
319
void ih264_intra_pred_luma_4x4_mode_diag_dl_ssse3(UWORD8 *pu1_src,
320
                                                  UWORD8 *pu1_dst,
321
                                                  WORD32 src_strd,
322
                                                  WORD32 dst_strd,
323
                                                  WORD32 ngbr_avail)
324
1.16k
{
325
1.16k
    UWORD8 *pu1_top;
326
1.16k
    WORD32 dst_strd2, dst_strd3;
327
1.16k
328
1.16k
    __m128i top_16x8b, top_8x16b, top_sh_8x16b;
329
1.16k
    __m128i res1_8x16b, res2_8x16b, res_16x8b;
330
1.16k
    __m128i zero_vector, const_2_8x16b;
331
1.16k
    WORD32 row1,row2,row3,row4;
332
1.16k
333
1.16k
    UNUSED(src_strd);
334
1.16k
    UNUSED(ngbr_avail);
335
1.16k
336
1.16k
    pu1_top = pu1_src + BLK_SIZE + 1;
337
1.16k
338
1.16k
    top_16x8b = _mm_loadl_epi64((__m128i *)pu1_top);
339
1.16k
    zero_vector = _mm_setzero_si128();
340
1.16k
    top_8x16b = _mm_unpacklo_epi8(top_16x8b, zero_vector);    //t0 t1 t2 t3 t4 t5 t6 t7
341
1.16k
342
1.16k
    top_sh_8x16b = _mm_srli_si128(top_8x16b, 2);              //t1 t2 t3 t4 t5 t6 t7 0
343
1.16k
    const_2_8x16b = _mm_set1_epi16(2);
344
1.16k
345
1.16k
    top_sh_8x16b = _mm_shufflehi_epi16(top_sh_8x16b, 0xa4);   //t1 t2 t3 t4 t5 t6 t7 t7
346
1.16k
    res1_8x16b = _mm_add_epi16(top_8x16b, top_sh_8x16b);
347
1.16k
    res2_8x16b = _mm_srli_si128(res1_8x16b, 2);
348
1.16k
349
1.16k
    res1_8x16b = _mm_add_epi16(res1_8x16b, const_2_8x16b);
350
1.16k
    res1_8x16b = _mm_add_epi16(res2_8x16b, res1_8x16b);
351
1.16k
    res1_8x16b = _mm_srai_epi16(res1_8x16b, 2);
352
1.16k
353
1.16k
    dst_strd2 = dst_strd << 1;
354
1.16k
    dst_strd3 = dst_strd + dst_strd2;
355
1.16k
356
1.16k
    res_16x8b = _mm_packus_epi16(res1_8x16b, res1_8x16b);
357
1.16k
    row1 = _mm_cvtsi128_si32(res_16x8b);
358
1.16k
    res_16x8b = _mm_srli_si128(res_16x8b, 1);
359
1.16k
    row2 = _mm_cvtsi128_si32(res_16x8b);
360
1.16k
    res_16x8b = _mm_srli_si128(res_16x8b, 1);
361
1.16k
    row3 = _mm_cvtsi128_si32(res_16x8b);
362
1.16k
    res_16x8b = _mm_srli_si128(res_16x8b, 1);
363
1.16k
    row4 = _mm_cvtsi128_si32(res_16x8b);
364
1.16k
365
1.16k
    *((WORD32 *)(pu1_dst)) = row1;
366
1.16k
    *((WORD32 *)(pu1_dst + dst_strd)) = row2;
367
1.16k
    *((WORD32 *)(pu1_dst + dst_strd2)) = row3;
368
1.16k
    *((WORD32 *)(pu1_dst + dst_strd3)) = row4;
369
1.16k
}
370
371
/**
372
 *******************************************************************************
373
 *
374
 * ih264_intra_pred_luma_4x4_mode_diag_dr_ssse3
375
 *
376
 * @brief
377
 *  Perform Intra prediction for luma_4x4 mode:Diagonal_Down_Right
378
 *
379
 * @par Description:
380
 *  Perform Intra prediction for luma_4x4 mode:Diagonal_Down_Right ,described in sec 8.3.1.2.5
381
 *
382
 * @param[in] pu1_src
383
 *  UWORD8 pointer to the source
384
 *
385
 * @param[out] pu1_dst
386
 *  UWORD8 pointer to the destination
387
 *
388
 * @param[in] src_strd
389
 *  integer source stride
390
 *
391
 * @param[in] dst_strd
392
 *  integer destination stride
393
 *
394
 * @param[in] ngbr_avail
395
 * availability of neighbouring pixels(Not used in this function)
396
 *
397
 * @returns
398
 *
399
 * @remarks
400
 *  None
401
 *
402
 *******************************************************************************/
403
void ih264_intra_pred_luma_4x4_mode_diag_dr_ssse3(UWORD8 *pu1_src,
404
                                                  UWORD8 *pu1_dst,
405
                                                  WORD32 src_strd,
406
                                                  WORD32 dst_strd,
407
                                                  WORD32 ngbr_avail)
408
1.19k
{
409
1.19k
    UWORD8 *pu1_left;
410
1.19k
    WORD32 dst_strd2, dst_strd3;
411
1.19k
412
1.19k
    __m128i top_left_16x8b, top_left_8x16b;
413
1.19k
    __m128i top_left_sh_16x8b, top_left_sh_8x16b;
414
1.19k
    __m128i res1_8x16b, res2_8x16b;
415
1.19k
    __m128i res1_16x8b, res2_16x8b;
416
1.19k
    __m128i zero_vector, const_2_8x16b;
417
1.19k
    WORD32 row1,row2,row3,row4;
418
1.19k
419
1.19k
    UNUSED(src_strd);
420
1.19k
    UNUSED(ngbr_avail);
421
1.19k
422
1.19k
    pu1_left = pu1_src + BLK_SIZE - 1;
423
1.19k
424
1.19k
    top_left_16x8b = _mm_loadu_si128((__m128i *)(pu1_left - 3));             //l3 l2 l1 l0 tl t0 t1 t2...
425
1.19k
    zero_vector = _mm_setzero_si128();
426
1.19k
    top_left_sh_16x8b = _mm_srli_si128(top_left_16x8b, 1);                   //l2 l1 l0 tl t0 t1 t2 t3...
427
1.19k
428
1.19k
    top_left_8x16b = _mm_unpacklo_epi8(top_left_16x8b, zero_vector);
429
1.19k
    top_left_sh_8x16b = _mm_unpacklo_epi8(top_left_sh_16x8b, zero_vector);
430
1.19k
431
1.19k
    res1_8x16b = _mm_add_epi16(top_left_8x16b, top_left_sh_8x16b);           //l3+l2 l2+l1 l1+l0 l0+tl tl+t0 t0+t1 t1+t2 t2+t3...
432
1.19k
    const_2_8x16b = _mm_set1_epi16(2);
433
1.19k
    res2_8x16b = _mm_srli_si128(res1_8x16b, 2);                              //l2+l1 l1+l0 l0+tl tl+t0 t0+t1 t1+t2 t2+t3...
434
1.19k
435
1.19k
    res1_8x16b = _mm_add_epi16(res1_8x16b, const_2_8x16b);
436
1.19k
    res1_8x16b = _mm_add_epi16(res2_8x16b, res1_8x16b);                      //l3+2*l2+l1+2 l2+2*l1+l0+2...
437
1.19k
    res1_8x16b = _mm_srai_epi16(res1_8x16b, 2);
438
1.19k
    res1_16x8b = _mm_packus_epi16(res1_8x16b, res1_8x16b);
439
1.19k
440
1.19k
    dst_strd2 = dst_strd << 1;
441
1.19k
    dst_strd3 = dst_strd + dst_strd2;
442
1.19k
443
1.19k
    res2_16x8b = _mm_srli_si128(res1_16x8b, 3);
444
1.19k
445
1.19k
    row1 = _mm_cvtsi128_si32(res2_16x8b);
446
1.19k
    res2_16x8b = _mm_srli_si128(res1_16x8b, 2);
447
1.19k
    row2 = _mm_cvtsi128_si32(res2_16x8b);
448
1.19k
    res2_16x8b = _mm_srli_si128(res1_16x8b, 1);
449
1.19k
    row3 = _mm_cvtsi128_si32(res2_16x8b);
450
1.19k
    row4 = _mm_cvtsi128_si32(res1_16x8b);
451
1.19k
452
1.19k
    *((WORD32 *)(pu1_dst)) = row1;
453
1.19k
    *((WORD32 *)(pu1_dst + dst_strd)) = row2;
454
1.19k
    *((WORD32 *)(pu1_dst + dst_strd2)) = row3;
455
1.19k
    *((WORD32 *)(pu1_dst + dst_strd3)) = row4;
456
1.19k
}
457
458
/**
459
 *******************************************************************************
460
 *
461
 * ih264_intra_pred_luma_4x4_mode_vert_r_ssse3
462
 *
463
 * @brief
464
 *  Perform Intra prediction for luma_4x4 mode:Vertical_Right
465
 *
466
 * @par Description:
467
 *  Perform Intra prediction for luma_4x4 mode:Vertical_Right ,described in sec 8.3.1.2.6
468
 *
469
 * @param[in] pu1_src
470
 *  UWORD8 pointer to the source
471
 *
472
 * @param[out] pu1_dst
473
 *  UWORD8 pointer to the destination
474
 *
475
 * @param[in] src_strd
476
 *  integer source stride
477
 *
478
 * @param[in] dst_strd
479
 *  integer destination stride
480
 *
481
 * @param[in] ngbr_avail
482
 * availability of neighbouring pixels(Not used in this function)
483
 *
484
 * @returns
485
 *
486
 * @remarks
487
 *  None
488
 *
489
 *******************************************************************************/
490
void ih264_intra_pred_luma_4x4_mode_vert_r_ssse3(UWORD8 *pu1_src,
491
                                                 UWORD8 *pu1_dst,
492
                                                 WORD32 src_strd,
493
                                                 WORD32 dst_strd,
494
                                                 WORD32 ngbr_avail)
495
1.27k
{
496
1.27k
    UWORD8 *pu1_left;
497
1.27k
    WORD32 dst_strd2, dst_strd3;
498
1.27k
499
1.27k
    __m128i val_16x8b, temp_16x8b;
500
1.27k
    __m128i w11_a1_16x8b, w11_a2_16x8b;
501
1.27k
    __m128i w121_a1_8x16b, w121_a2_8x16b, w121_sh_8x16b;
502
1.27k
    __m128i row1_16x8b, row2_16x8b, row3_16x8b, row4_16x8b;
503
1.27k
    __m128i zero_vector, const_2_8x16b;
504
1.27k
    WORD32 row1,row2,row3,row4;
505
1.27k
506
1.27k
    UNUSED(src_strd);
507
1.27k
    UNUSED(ngbr_avail);
508
1.27k
509
1.27k
    pu1_left = pu1_src + BLK_SIZE - 1;
510
1.27k
511
1.27k
    val_16x8b = _mm_loadl_epi64((__m128i *)(pu1_left - 2));
512
1.27k
    zero_vector = _mm_setzero_si128();
513
1.27k
514
1.27k
    w121_a1_8x16b = _mm_unpacklo_epi8(val_16x8b, zero_vector);        //l2 l1 l0 tl t0 t1 t2 t3
515
1.27k
    w11_a1_16x8b = _mm_srli_si128(val_16x8b, 3);
516
1.27k
    w121_a2_8x16b = _mm_srli_si128(w121_a1_8x16b, 2);                 //l1 l0 tl t0 t1 t2 t3 0
517
1.27k
    w11_a2_16x8b = _mm_srli_si128(val_16x8b, 4);
518
1.27k
519
1.27k
    w121_a1_8x16b = _mm_add_epi16(w121_a1_8x16b, w121_a2_8x16b);      //l2+l1 l1+l0 l0+tl tl+t0 t0+t1 t1+t2 t2+t3 t3
520
1.27k
    row1_16x8b = _mm_avg_epu8(w11_a1_16x8b, w11_a2_16x8b);
521
1.27k
    w121_a2_8x16b = _mm_srli_si128(w121_a1_8x16b, 2);                 //l1+l0 l0+tl tl+t0 t0+t1 t1+t2 t2+t3 t3    0
522
1.27k
523
1.27k
    const_2_8x16b = _mm_set1_epi16(2);
524
1.27k
    w121_a1_8x16b = _mm_add_epi16(w121_a1_8x16b, w121_a2_8x16b);      //l2+2*l1+l0 l1+2*l0+tl ...
525
1.27k
    w121_a1_8x16b = _mm_add_epi16(w121_a1_8x16b, const_2_8x16b);
526
1.27k
    w121_a1_8x16b = _mm_srai_epi16(w121_a1_8x16b, 2);
527
1.27k
528
1.27k
    w121_sh_8x16b = _mm_shufflelo_epi16(w121_a1_8x16b, 0xe1);
529
1.27k
    w121_sh_8x16b = _mm_srli_si128(w121_sh_8x16b, 2);
530
1.27k
531
1.27k
    row4_16x8b = _mm_packus_epi16(w121_sh_8x16b, w121_sh_8x16b);
532
1.27k
    temp_16x8b = _mm_slli_si128(w121_a1_8x16b, 13);
533
1.27k
    row2_16x8b = _mm_srli_si128(row4_16x8b, 1);
534
1.27k
    row3_16x8b = _mm_alignr_epi8(row1_16x8b, temp_16x8b, 15);
535
1.27k
536
1.27k
    dst_strd2 = dst_strd << 1;
537
1.27k
    dst_strd3 = dst_strd + dst_strd2;
538
1.27k
539
1.27k
    row1 = _mm_cvtsi128_si32(row1_16x8b);
540
1.27k
    row2 = _mm_cvtsi128_si32(row2_16x8b);
541
1.27k
    row3 = _mm_cvtsi128_si32(row3_16x8b);
542
1.27k
    row4 = _mm_cvtsi128_si32(row4_16x8b);
543
1.27k
544
1.27k
    *((WORD32 *)(pu1_dst)) = row1;
545
1.27k
    *((WORD32 *)(pu1_dst + dst_strd)) = row2;
546
1.27k
    *((WORD32 *)(pu1_dst + dst_strd2)) = row3;
547
1.27k
    *((WORD32 *)(pu1_dst + dst_strd3)) = row4;
548
1.27k
}
549
550
/*
551
 *******************************************************************************
552
 *
553
 * ih264_intra_pred_luma_4x4_mode_horz_d_ssse3
554
 *
555
 * @brief
556
 *  Perform Intra prediction for luma_4x4 mode:Horizontal_Down
557
 *
558
 * @par Description:
559
 *  Perform Intra prediction for luma_4x4 mode:Horizontal_Down ,described in sec 8.3.1.2.7
560
 *
561
 * @param[in] pu1_src
562
 *  UWORD8 pointer to the source
563
 *
564
 * @param[out] pu1_dst
565
 *  UWORD8 pointer to the destination
566
 *
567
 * @param[in] src_strd
568
 *  integer source stride
569
 *
570
 * @param[in] dst_strd
571
 *  integer destination stride
572
 *
573
 * @param[in] ngbr_avail
574
 * availability of neighbouring pixels(Not used in this function)
575
 *
576
 * @returns
577
 *
578
 * @remarks
579
 *  None
580
 *
581
 *******************************************************************************/
582
void ih264_intra_pred_luma_4x4_mode_horz_d_ssse3(UWORD8 *pu1_src,
583
                                           UWORD8 *pu1_dst,
584
                                           WORD32 src_strd,
585
                                           WORD32 dst_strd,
586
                                           WORD32 ngbr_avail)
587
1.05k
{
588
1.05k
    UWORD8 *pu1_left;
589
1.05k
    WORD32 dst_strd2, dst_strd3;
590
1.05k
    WORD32 val_121_t0t1;
591
1.05k
592
1.05k
    __m128i val_16x8b, val_sh_16x8b;
593
1.05k
    __m128i w11_16x8b;
594
1.05k
    __m128i w121_a1_8x16b, w121_a2_8x16b, w121_16x8b;
595
1.05k
    __m128i row1_16x8b, row2_16x8b, row3_16x8b, row4_16x8b;
596
1.05k
597
1.05k
    __m128i zero_vector, const_2_8x16b;
598
1.05k
    WORD32 row1,row2,row3,row4;
599
1.05k
600
1.05k
    UNUSED(src_strd);
601
1.05k
    UNUSED(ngbr_avail);
602
1.05k
603
1.05k
    pu1_left = pu1_src + BLK_SIZE - 1;
604
1.05k
605
1.05k
    val_16x8b = _mm_loadl_epi64((__m128i *)(pu1_left - 3));
606
1.05k
    zero_vector = _mm_setzero_si128();
607
1.05k
    val_sh_16x8b = _mm_srli_si128(val_16x8b, 1);
608
1.05k
    w11_16x8b = _mm_avg_epu8(val_16x8b, val_sh_16x8b);
609
1.05k
610
1.05k
    w121_a1_8x16b = _mm_unpacklo_epi8(val_16x8b, zero_vector);        //l3 l2 l1 l0 tl t0 t1 t2
611
1.05k
    w121_a2_8x16b = _mm_srli_si128(w121_a1_8x16b, 2);                 //l2 l1 l0 tl t0 t1 t2 0
612
1.05k
    w121_a1_8x16b = _mm_add_epi16(w121_a1_8x16b, w121_a2_8x16b);      //l3+l2 l2+l1 l1+l0 l0+tl tl+t0 t0+t1 t1+t2 t2
613
1.05k
    w121_a2_8x16b = _mm_srli_si128(w121_a1_8x16b, 2);                 //l2+l1 l1+l0 l0+tl tl+t0 t0+t1 t1+t2 t2    0
614
1.05k
615
1.05k
    zero_vector = _mm_setzero_si128();
616
1.05k
    const_2_8x16b = _mm_set1_epi16(2);
617
1.05k
618
1.05k
    w121_a1_8x16b = _mm_add_epi16(w121_a1_8x16b, w121_a2_8x16b);      //l3+2*l2+l1 l2+2*l1+l0 l1+2*l0+tl ...
619
1.05k
    w121_a1_8x16b = _mm_add_epi16(w121_a1_8x16b, const_2_8x16b);
620
1.05k
    w121_a1_8x16b = _mm_srai_epi16(w121_a1_8x16b, 2);
621
1.05k
622
1.05k
    w121_16x8b = _mm_packus_epi16(w121_a1_8x16b, w121_a1_8x16b);
623
1.05k
624
1.05k
    row4_16x8b = _mm_unpacklo_epi8(w11_16x8b, w121_16x8b);
625
1.05k
    val_121_t0t1 = _mm_extract_epi16(w121_16x8b, 2);
626
1.05k
    row4_16x8b = _mm_insert_epi16(row4_16x8b, val_121_t0t1, 4);
627
1.05k
628
1.05k
    dst_strd2 = dst_strd << 1;
629
1.05k
    dst_strd3 = dst_strd + dst_strd2;
630
1.05k
631
1.05k
    row1_16x8b = _mm_srli_si128(row4_16x8b, 6);
632
1.05k
    row2_16x8b = _mm_srli_si128(row4_16x8b, 4);
633
1.05k
    row3_16x8b = _mm_srli_si128(row4_16x8b, 2);
634
1.05k
635
1.05k
    row1 = _mm_cvtsi128_si32(row1_16x8b);
636
1.05k
    row2 = _mm_cvtsi128_si32(row2_16x8b);
637
1.05k
    row3 = _mm_cvtsi128_si32(row3_16x8b);
638
1.05k
    row4 = _mm_cvtsi128_si32(row4_16x8b);
639
1.05k
640
1.05k
    *((WORD32 *)(pu1_dst)) = row1;
641
1.05k
    *((WORD32 *)(pu1_dst + dst_strd)) = row2;
642
1.05k
    *((WORD32 *)(pu1_dst + dst_strd2)) = row3;
643
1.05k
    *((WORD32 *)(pu1_dst + dst_strd3)) = row4;
644
1.05k
}
645
646
/**
647
 *******************************************************************************
648
 *
649
 * ih264_intra_pred_luma_4x4_mode_vert_l_ssse3
650
 *
651
 * @brief
652
 *  Perform Intra prediction for luma_4x4 mode:Vertical_Left
653
 *
654
 * @par Description:
655
 *  Perform Intra prediction for luma_4x4 mode:Vertical_Left ,described in sec 8.3.1.2.8
656
 *
657
 * @param[in] pu1_src
658
 *  UWORD8 pointer to the source
659
 *
660
 * @param[out] pu1_dst
661
 *  UWORD8 pointer to the destination
662
 *
663
 * @param[in] src_strd
664
 *  integer source stride
665
 *
666
 * @param[in] dst_strd
667
 *  integer destination stride
668
 *
669
 * @param[in] ngbr_avail
670
 * availability of neighbouring pixels(Not used in this function)
671
 *
672
 * @returns
673
 *
674
 * @remarks
675
 *  None
676
 *
677
 *******************************************************************************/
678
void ih264_intra_pred_luma_4x4_mode_vert_l_ssse3(UWORD8 *pu1_src,
679
                                                 UWORD8 *pu1_dst,
680
                                                 WORD32 src_strd,
681
                                                 WORD32 dst_strd,
682
                                                 WORD32 ngbr_avail)
683
1.18k
{
684
1.18k
    UWORD8 *pu1_top;
685
1.18k
    WORD32 dst_strd2, dst_strd3;
686
1.18k
687
1.18k
    __m128i val_16x8b, val_sh_16x8b;
688
1.18k
    __m128i w121_a1_8x16b, w121_a2_8x16b;
689
1.18k
    __m128i row1_16x8b, row2_16x8b, row3_16x8b, row4_16x8b;
690
1.18k
691
1.18k
    __m128i zero_vector, const_2_8x16b;
692
1.18k
    WORD32 row1,row2,row3,row4;
693
1.18k
694
1.18k
    UNUSED(src_strd);
695
1.18k
    UNUSED(ngbr_avail);
696
1.18k
697
1.18k
    pu1_top = pu1_src +BLK_SIZE + 1;
698
1.18k
699
1.18k
    val_16x8b = _mm_loadl_epi64((__m128i *)pu1_top);
700
1.18k
    zero_vector = _mm_setzero_si128();
701
1.18k
    val_sh_16x8b = _mm_srli_si128(val_16x8b, 1);
702
1.18k
    row1_16x8b = _mm_avg_epu8(val_16x8b, val_sh_16x8b);
703
1.18k
704
1.18k
    w121_a1_8x16b = _mm_unpacklo_epi8(val_16x8b, zero_vector);        //t0 t1 t2 t3 t4 t5...
705
1.18k
    w121_a2_8x16b = _mm_srli_si128(w121_a1_8x16b, 2);                 //t1 t2 t3 t4 t5 t6...
706
1.18k
    w121_a1_8x16b = _mm_add_epi16(w121_a1_8x16b, w121_a2_8x16b);      //t0+t1 t1+t2 t2+t3 t3+t4 t4+t5...
707
1.18k
    w121_a2_8x16b = _mm_srli_si128(w121_a1_8x16b, 2);                 //t1+t2 t2+t3 t3+t4 t4+t5 t5+t6...
708
1.18k
709
1.18k
    zero_vector = _mm_setzero_si128();
710
1.18k
    const_2_8x16b = _mm_set1_epi16(2);
711
1.18k
712
1.18k
    w121_a1_8x16b = _mm_add_epi16(w121_a1_8x16b, w121_a2_8x16b);      //t0+2*t1+t2 t1+2*t2+t3 t2+2*t3+t4...
713
1.18k
    w121_a1_8x16b = _mm_add_epi16(w121_a1_8x16b, const_2_8x16b);
714
1.18k
    w121_a1_8x16b = _mm_srai_epi16(w121_a1_8x16b, 2);
715
1.18k
716
1.18k
    row2_16x8b = _mm_packus_epi16(w121_a1_8x16b, w121_a1_8x16b);
717
1.18k
718
1.18k
    dst_strd2 = dst_strd << 1;
719
1.18k
    dst_strd3 = dst_strd + dst_strd2;
720
1.18k
721
1.18k
    row3_16x8b = _mm_srli_si128(row1_16x8b, 1);
722
1.18k
    row4_16x8b = _mm_srli_si128(row2_16x8b, 1);
723
1.18k
724
1.18k
    row1 = _mm_cvtsi128_si32(row1_16x8b);
725
1.18k
    row2 = _mm_cvtsi128_si32(row2_16x8b);
726
1.18k
    row3 = _mm_cvtsi128_si32(row3_16x8b);
727
1.18k
    row4 = _mm_cvtsi128_si32(row4_16x8b);
728
1.18k
729
1.18k
    *((WORD32 *)(pu1_dst)) = row1;
730
1.18k
    *((WORD32 *)(pu1_dst + dst_strd)) = row2;
731
1.18k
    *((WORD32 *)(pu1_dst + dst_strd2)) = row3;
732
1.18k
    *((WORD32 *)(pu1_dst + dst_strd3)) = row4;
733
1.18k
}
734
735
/**
736
 *******************************************************************************
737
 *
738
 * ih264_intra_pred_luma_4x4_mode_horz_u_ssse3
739
 *
740
 * @brief
741
 *  Perform Intra prediction for luma_4x4 mode:Horizontal_Up
742
 *
743
 * @par Description:
744
 *  Perform Intra prediction for luma_4x4 mode:Horizontal_Up ,described in sec 8.3.1.2.9
745
 *
746
 * @param[in] pu1_src
747
 *  UWORD8 pointer to the source
748
 *
749
 * @param[out] pu1_dst
750
 *  UWORD8 pointer to the destination
751
 *
752
 * @param[in] src_strd
753
 *  integer source stride
754
 *
755
 * @param[in] dst_strd
756
 *  integer destination stride
757
 *
758
 * @param[in] ngbr_avail
759
 * availability of neighbouring pixels(Not used in this function)
760
 *
761
 * @returns
762
 *
763
 * @remarks
764
 *  None
765
 *
766
 *******************************************************************************/
767
void ih264_intra_pred_luma_4x4_mode_horz_u_ssse3(UWORD8 *pu1_src,
768
                                                 UWORD8 *pu1_dst,
769
                                                 WORD32 src_strd,
770
                                                 WORD32 dst_strd,
771
                                                 WORD32 ngbr_avail)
772
814
{
773
814
    UWORD8 *pu1_left;
774
814
    WORD32 dst_strd2, dst_strd3;
775
814
776
814
    __m128i val_16x8b, val_sh_16x8b;
777
814
    __m128i w11_16x8b;
778
814
    __m128i w121_a1_8x16b, w121_a2_8x16b, w121_16x8b;
779
814
    __m128i row1_16x8b, row2_16x8b, row3_16x8b, row4_16x8b;
780
814
781
814
    __m128i zero_vector, const_2_8x16b, rev_16x8b;
782
814
    WORD32 row1,row2,row3,row4;
783
814
784
814
    UNUSED(src_strd);
785
814
    UNUSED(ngbr_avail);
786
814
787
814
    pu1_left = pu1_src + BLK_SIZE - 1;
788
814
789
814
    zero_vector = _mm_setzero_si128();
790
814
    rev_16x8b = _mm_setr_epi8(3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
791
814
792
814
    val_16x8b = _mm_loadl_epi64((__m128i *)(pu1_left - 3));           //l3 l2 l1 l0 0  0  0...
793
814
    val_16x8b = _mm_shuffle_epi8(val_16x8b, rev_16x8b);                //l0 l1 l2 l3 l3 l3 l3...
794
814
795
814
    val_sh_16x8b = _mm_srli_si128(val_16x8b, 1);
796
814
    w11_16x8b = _mm_avg_epu8(val_16x8b, val_sh_16x8b);
797
814
798
814
    w121_a1_8x16b = _mm_unpacklo_epi8(val_16x8b, zero_vector);        //l0 l1 l2 l3 l3 l3...
799
814
    w121_a2_8x16b = _mm_srli_si128(w121_a1_8x16b, 2);                 //l1 l2 l3 l3 l3 l3...
800
814
801
814
    w121_a1_8x16b = _mm_add_epi16(w121_a1_8x16b, w121_a2_8x16b);      //l0+t1 l1+l2 l2+l3 2*l3 2*l3...
802
814
    w121_a2_8x16b = _mm_srli_si128(w121_a1_8x16b, 2);                 //l1+t2 l2+l3 2*l3  2*l3 2*l3...
803
814
804
814
    zero_vector = _mm_setzero_si128();
805
814
    const_2_8x16b = _mm_set1_epi16(2);
806
814
807
814
    w121_a1_8x16b = _mm_add_epi16(w121_a1_8x16b, w121_a2_8x16b);      //l0+2*l1+l2 l1+2*l2+l3 l2+3*l3 4*l3 4*l3...
808
814
    w121_a1_8x16b = _mm_add_epi16(w121_a1_8x16b, const_2_8x16b);
809
814
    w121_a1_8x16b = _mm_srai_epi16(w121_a1_8x16b, 2);
810
814
811
814
    w121_16x8b = _mm_packus_epi16(w121_a1_8x16b, w121_a1_8x16b);
812
814
813
814
    dst_strd2 = dst_strd << 1;
814
814
    dst_strd3 = dst_strd + dst_strd2;
815
814
816
814
    row1_16x8b = _mm_unpacklo_epi8(w11_16x8b, w121_16x8b);
817
814
    row2_16x8b = _mm_srli_si128(row1_16x8b, 2);
818
814
    row3_16x8b = _mm_srli_si128(row1_16x8b, 4);
819
814
    row4_16x8b = _mm_srli_si128(row1_16x8b, 6);
820
814
821
814
    row1 = _mm_cvtsi128_si32(row1_16x8b);
822
814
    row2 = _mm_cvtsi128_si32(row2_16x8b);
823
814
    row3 = _mm_cvtsi128_si32(row3_16x8b);
824
814
    row4 = _mm_cvtsi128_si32(row4_16x8b);
825
814
826
814
    *((WORD32 *)(pu1_dst)) = row1;
827
814
    *((WORD32 *)(pu1_dst + dst_strd)) = row2;
828
814
    *((WORD32 *)(pu1_dst + dst_strd2)) = row3;
829
814
    *((WORD32 *)(pu1_dst + dst_strd3)) = row4;
830
814
}
831
832
/*******************    8x8 Modes    *******************/
833
834
/**
835
 *******************************************************************************
836
 *
837
 * ih264_intra_pred_luma_8x8_mode_vert_ssse3
838
 *
839
 * @brief
840
 *  Perform Intra prediction for luma_8x8 mode:vertical
841
 *
842
 * @par Description:
843
 *  Perform Intra prediction for luma_8x8 mode:vertical ,described in sec 8.3.2.2.2
844
 *
845
 * @param[in] pu1_src
846
 *  UWORD8 pointer to the source
847
 *
848
 * @param[out] pu1_dst
849
 *  UWORD8 pointer to the destination
850
 *
851
 * @param[in] src_strd
852
 *  integer source stride
853
 *
854
 * @param[in] dst_strd
855
 *  integer destination stride
856
 *
857
 * @param[in] ngbr_avail
858
 * availability of neighbouring pixels(Not used in this function)
859
 *
860
 * @returns
861
 *
862
 * @remarks
863
 *  None
864
 *
865
 *******************************************************************************
866
 */
867
void ih264_intra_pred_luma_8x8_mode_vert_ssse3(UWORD8 *pu1_src,
868
                                               UWORD8 *pu1_dst,
869
                                               WORD32 src_strd,
870
                                               WORD32 dst_strd,
871
                                               WORD32 ngbr_avail)
872
0
{
873
0
    UWORD8 *pu1_top = NULL;
874
0
    __m128i top_8x8b;
875
0
    UNUSED(src_strd);
876
0
    UNUSED(ngbr_avail);
877
0
    pu1_top = pu1_src + BLK8x8SIZE + 1;
878
0
879
0
    top_8x8b = _mm_loadl_epi64((__m128i *)pu1_top);
880
0
881
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 0 * dst_strd), top_8x8b);
882
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 1 * dst_strd), top_8x8b);
883
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 2 * dst_strd), top_8x8b);
884
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 3 * dst_strd), top_8x8b);
885
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 4 * dst_strd), top_8x8b);
886
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 5 * dst_strd), top_8x8b);
887
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 6 * dst_strd), top_8x8b);
888
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 7 * dst_strd), top_8x8b);
889
0
}
890
891
/**
892
 *******************************************************************************
893
 *
894
 * ih264_intra_pred_luma_8x8_mode_horz_ssse3
895
 *
896
 * @brief
897
 *  Perform Intra prediction for luma_8x8 mode:horizontal
898
 *
899
 * @par Description:
900
 *  Perform Intra prediction for  uma_8x8 mode:horizontal ,described in sec 8.3.2.2.2
901
 *
902
 * @param[in] pu1_src
903
 *  UWORD8 pointer to the source
904
 *
905
 * @param[out] pu1_dst
906
 *  UWORD8 pointer to the destination
907
 *
908
 * @param[in] src_strd
909
 *  integer source stride
910
 *
911
 * @param[in] dst_strd
912
 *  integer destination stride
913
 *
914
 * @param[in] ngbr_avail
915
 * availability of neighbouring pixels(Not used in this function)
916
 *
917
 * @returns
918
 *
919
 * @remarks
920
 *  None
921
 *
922
 *******************************************************************************
923
 */
924
void ih264_intra_pred_luma_8x8_mode_horz_ssse3(UWORD8 *pu1_src,
925
                                               UWORD8 *pu1_dst,
926
                                               WORD32 src_strd,
927
                                               WORD32 dst_strd,
928
                                               WORD32 ngbr_avail)
929
0
{
930
0
    UWORD8 *pu1_left = pu1_src + BLK8x8SIZE - 1;
931
0
    __m128i row1_8x8b, row2_8x8b, row3_8x8b, row4_8x8b;
932
0
    __m128i row5_8x8b, row6_8x8b, row7_8x8b, row8_8x8b;
933
0
934
0
    UNUSED(src_strd);
935
0
    UNUSED(ngbr_avail);
936
0
937
0
    row1_8x8b = _mm_set1_epi8(pu1_left[0]);
938
0
    row2_8x8b = _mm_set1_epi8(pu1_left[-1]);
939
0
    row3_8x8b = _mm_set1_epi8(pu1_left[-2]);
940
0
    row4_8x8b = _mm_set1_epi8(pu1_left[-3]);
941
0
    row5_8x8b = _mm_set1_epi8(pu1_left[-4]);
942
0
    row6_8x8b = _mm_set1_epi8(pu1_left[-5]);
943
0
    row7_8x8b = _mm_set1_epi8(pu1_left[-6]);
944
0
    row8_8x8b = _mm_set1_epi8(pu1_left[-7]);
945
0
946
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 0 * dst_strd), row1_8x8b);
947
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 1 * dst_strd), row2_8x8b);
948
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 2 * dst_strd), row3_8x8b);
949
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 3 * dst_strd), row4_8x8b);
950
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 4 * dst_strd), row5_8x8b);
951
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 5 * dst_strd), row6_8x8b);
952
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 6 * dst_strd), row7_8x8b);
953
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 7 * dst_strd), row8_8x8b);
954
0
}
955
956
/**
957
 *******************************************************************************
958
 *
959
 * ih264_intra_pred_luma_8x8_mode_dc_ssse3
960
 *
961
 * @brief
962
 *  Perform Intra prediction for luma_8x8 mode:DC
963
 *
964
 * @par Description:
965
 *  Perform Intra prediction for luma_8x8 mode:DC ,described in sec 8.3.2.2.4
966
 *
967
 * @param[in] pu1_src
968
 *  UWORD8 pointer to the source
969
 *
970
 * @param[out] pu1_dst
971
 *  UWORD8 pointer to the destination
972
 *
973
 * @param[in] src_strd
974
 *  integer source stride
975
 *
976
 * @param[in] dst_strd
977
 *  integer destination stride
978
 *
979
 * @param[in] ngbr_avail
980
 *  availability of neighbouring pixels
981
 *
982
 * @returns
983
 *
984
 * @remarks
985
 *  None
986
 *
987
 *******************************************************************************/
988
void ih264_intra_pred_luma_8x8_mode_dc_ssse3(UWORD8 *pu1_src,
989
                                             UWORD8 *pu1_dst,
990
                                             WORD32 src_strd,
991
                                             WORD32 dst_strd,
992
                                             WORD32 ngbr_avail)
993
0
{
994
0
    UWORD8 u1_useleft; /* availability of left predictors (only for DC) */
995
0
    UWORD8 u1_usetop; /* availability of top predictors (only for DC) */
996
0
    UWORD8 *pu1_left = NULL; /* Pointer to start of left predictors */
997
0
    UWORD8 *pu1_top = NULL; /* Pointer to start of top predictors */
998
0
    __m128i dc_val_8x8b;
999
0
    WORD32 dc_val = 0;
1000
0
    UNUSED(src_strd);
1001
0
1002
0
    u1_useleft = BOOLEAN(ngbr_avail & LEFT_MB_AVAILABLE_MASK);
1003
0
    u1_usetop = BOOLEAN(ngbr_avail & TOP_MB_AVAILABLE_MASK);
1004
0
    pu1_top = pu1_src + BLK8x8SIZE + 1;
1005
0
    pu1_left = pu1_src + BLK8x8SIZE - 1;
1006
0
1007
0
    if(u1_useleft || u1_usetop)
1008
0
    {
1009
0
        WORD32 shft = 2;
1010
0
        __m128i val_8x8b, zero_8x8b, sum_8x16b;
1011
0
1012
0
        zero_8x8b = _mm_setzero_si128();
1013
0
1014
0
        if(u1_useleft)
1015
0
        {
1016
0
            val_8x8b = _mm_loadl_epi64((__m128i *)(pu1_left - 7));
1017
0
            sum_8x16b = _mm_sad_epu8(zero_8x8b, val_8x8b);
1018
0
1019
0
            shft++;
1020
0
            dc_val += 4;
1021
0
            dc_val += _mm_extract_epi16(sum_8x16b, 0);
1022
0
        }
1023
0
        if(u1_usetop)
1024
0
        {
1025
0
            val_8x8b = _mm_loadl_epi64((__m128i *)pu1_top);
1026
0
            sum_8x16b = _mm_sad_epu8(zero_8x8b, val_8x8b);
1027
0
1028
0
            shft++;
1029
0
            dc_val += 4;
1030
0
            dc_val += _mm_extract_epi16(sum_8x16b, 0);
1031
0
        }
1032
0
        dc_val = dc_val >> shft;
1033
0
    }
1034
0
    else
1035
0
        dc_val = 128;
1036
0
1037
0
    dc_val_8x8b = _mm_set1_epi8(dc_val);
1038
0
1039
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 0 * dst_strd), dc_val_8x8b);
1040
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 1 * dst_strd), dc_val_8x8b);
1041
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 2 * dst_strd), dc_val_8x8b);
1042
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 3 * dst_strd), dc_val_8x8b);
1043
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 4 * dst_strd), dc_val_8x8b);
1044
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 5 * dst_strd), dc_val_8x8b);
1045
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 6 * dst_strd), dc_val_8x8b);
1046
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 7 * dst_strd), dc_val_8x8b);
1047
0
}
1048
1049
/**
1050
 *******************************************************************************
1051
 *
1052
 * ih264_intra_pred_luma_8x8_mode_diag_dl_ssse3
1053
 *
1054
 * @brief
1055
 *  Perform Intra prediction for luma_8x8 mode:Diagonal_Down_Left
1056
 *
1057
 * @par Description:
1058
 *  Perform Intra prediction for luma_8x8 mode:Diagonal_Down_Left ,described in sec 8.3.2.2.5
1059
 *
1060
 * @param[in] pu1_src
1061
 *  UWORD8 pointer to the source
1062
 *
1063
 * @param[out] pu1_dst
1064
 *  UWORD8 pointer to the destination
1065
 *
1066
 * @param[in] src_strd
1067
 *  integer source stride
1068
 *
1069
 * @param[in] dst_strd
1070
 *  integer destination stride
1071
 *
1072
 * @param[in] ngbr_avail
1073
 * availability of neighbouring pixels(Not used in this function)
1074
 *
1075
 * @returns
1076
 *
1077
 * @remarks
1078
 *  None
1079
 *
1080
 *******************************************************************************/
1081
void ih264_intra_pred_luma_8x8_mode_diag_dl_ssse3(UWORD8 *pu1_src,
1082
                                                  UWORD8 *pu1_dst,
1083
                                                  WORD32 src_strd,
1084
                                                  WORD32 dst_strd,
1085
                                                  WORD32 ngbr_avail)
1086
0
{
1087
0
    UWORD8 *pu1_top = NULL; /* Pointer to start of top predictors */
1088
0
    __m128i top_16x8;
1089
0
    __m128i out_15x16;
1090
0
    __m128i a0_8x16, a1_8x16, a2_8x16;
1091
0
    __m128i temp1, temp2;
1092
0
    __m128i res1_8x16, res2_8x16;
1093
0
    __m128i zero = _mm_setzero_si128();
1094
0
    __m128i const_val2_8x16 = _mm_set1_epi16(2);
1095
0
1096
0
    UNUSED(src_strd);
1097
0
    UNUSED(ngbr_avail);
1098
0
1099
0
    pu1_top = pu1_src + BLK8x8SIZE + 1;
1100
0
1101
0
    top_16x8 = _mm_loadu_si128((__m128i *)(pu1_top));
1102
0
1103
0
    temp1 = _mm_srli_si128(top_16x8, 1);
1104
0
    temp2 = _mm_srli_si128(top_16x8, 2);
1105
0
    a0_8x16 = _mm_unpacklo_epi8(top_16x8, zero);
1106
0
    a1_8x16 = _mm_unpacklo_epi8(temp1, zero);
1107
0
    a2_8x16 = _mm_unpacklo_epi8(temp2, zero);
1108
0
1109
0
    a0_8x16 = _mm_add_epi16(a0_8x16, a2_8x16);
1110
0
    a1_8x16 = _mm_add_epi16(a1_8x16, a1_8x16);
1111
0
    a0_8x16 = _mm_add_epi16(a0_8x16, const_val2_8x16);
1112
0
    a0_8x16 = _mm_add_epi16(a0_8x16, a1_8x16);
1113
0
    res1_8x16 = _mm_srai_epi16(a0_8x16, 2);
1114
0
1115
0
    temp2 = _mm_srli_si128(top_16x8, 2);
1116
0
    temp1 = _mm_srli_si128(top_16x8, 1);
1117
0
    a2_8x16 = _mm_unpackhi_epi8(temp2, zero);
1118
0
    a0_8x16 = _mm_unpackhi_epi8(top_16x8, zero);
1119
0
    a2_8x16 = _mm_shufflehi_epi16(a2_8x16, 0x14);
1120
0
    a1_8x16 = _mm_unpackhi_epi8(temp1, zero);
1121
0
1122
0
    a0_8x16 = _mm_add_epi16(a0_8x16, a2_8x16);
1123
0
    a1_8x16 = _mm_add_epi16(a1_8x16, a1_8x16);
1124
0
    a0_8x16 = _mm_add_epi16(a0_8x16, const_val2_8x16);
1125
0
    a0_8x16 = _mm_add_epi16(a0_8x16, a1_8x16);
1126
0
    res2_8x16 = _mm_srai_epi16(a0_8x16, 2);
1127
0
1128
0
    out_15x16 = _mm_packus_epi16(res1_8x16, res2_8x16);
1129
0
1130
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 0 * dst_strd), out_15x16);
1131
0
    out_15x16 = _mm_srli_si128(out_15x16, 1);
1132
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 1 * dst_strd), out_15x16);
1133
0
    out_15x16 = _mm_srli_si128(out_15x16, 1);
1134
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 2 * dst_strd), out_15x16);
1135
0
    out_15x16 = _mm_srli_si128(out_15x16, 1);
1136
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 3 * dst_strd), out_15x16);
1137
0
    out_15x16 = _mm_srli_si128(out_15x16, 1);
1138
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 4 * dst_strd), out_15x16);
1139
0
    out_15x16 = _mm_srli_si128(out_15x16, 1);
1140
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 5 * dst_strd), out_15x16);
1141
0
    out_15x16 = _mm_srli_si128(out_15x16, 1);
1142
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 6 * dst_strd), out_15x16);
1143
0
    out_15x16 = _mm_srli_si128(out_15x16, 1);
1144
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 7 * dst_strd), out_15x16);
1145
0
}
1146
1147
/**
1148
 *******************************************************************************
1149
 *
1150
 * ih264_intra_pred_luma_8x8_mode_diag_dr_ssse3
1151
 *
1152
 * @brief
1153
 *  Perform Intra prediction for luma_8x8 mode:Diagonal_Down_Right
1154
 *
1155
 * @par Description:
1156
 *  Perform Intra prediction for luma_8x8 mode:Diagonal_Down_Right ,described in sec 8.3.2.2.6
1157
 *
1158
 * @param[in] pu1_src
1159
 *  UWORD8 pointer to the source
1160
 *
1161
 * @param[out] pu1_dst
1162
 *  UWORD8 pointer to the destination
1163
 *
1164
 * @param[in] src_strd
1165
 *  integer source stride
1166
 *
1167
 * @param[in] dst_strd
1168
 *  integer destination stride
1169
 *
1170
 * @param[in] ngbr_avail
1171
 * availability of neighbouring pixels(Not used in this function)
1172
 *
1173
 * @returns
1174
 *
1175
 * @remarks
1176
 *  None
1177
 *
1178
 *******************************************************************************/
1179
void ih264_intra_pred_luma_8x8_mode_diag_dr_ssse3(UWORD8 *pu1_src,
1180
                                                  UWORD8 *pu1_dst,
1181
                                                  WORD32 src_strd,
1182
                                                  WORD32 dst_strd,
1183
                                                  WORD32 ngbr_avail)
1184
0
{
1185
0
    UWORD8 *pu1_left = NULL; /* Pointer to start of left predictors */
1186
0
    UWORD8 *pu1_top = NULL; /* Pointer to start of top predictors */
1187
0
    __m128i top_8x8, left_16x8;
1188
0
    __m128i out_15x16;
1189
0
    __m128i a0_8x16, a1_8x16, a2_8x16;
1190
0
    __m128i temp1, temp2;
1191
0
    __m128i res1_8x16, res2_8x16;
1192
0
    __m128i zero = _mm_setzero_si128();
1193
0
    __m128i const_val2_8x16 = _mm_set1_epi16(2);
1194
0
    __m128i str_8x8;
1195
0
1196
0
    UNUSED(src_strd);
1197
0
    UNUSED(ngbr_avail);
1198
0
1199
0
    pu1_left = pu1_src + BLK8x8SIZE - 1;
1200
0
    pu1_top = pu1_src + BLK8x8SIZE + 1;
1201
0
1202
0
    left_16x8 = _mm_loadu_si128((__m128i *)(pu1_left - 7));
1203
0
1204
0
    temp1 = _mm_srli_si128(left_16x8, 1);
1205
0
    temp2 = _mm_srli_si128(left_16x8, 2);
1206
0
    a0_8x16 = _mm_unpacklo_epi8(left_16x8, zero);
1207
0
    a1_8x16 = _mm_unpacklo_epi8(temp1, zero);
1208
0
    a2_8x16 = _mm_unpacklo_epi8(temp2, zero);
1209
0
1210
0
    a0_8x16 = _mm_add_epi16(a0_8x16, a2_8x16);
1211
0
    a1_8x16 = _mm_add_epi16(a1_8x16, a1_8x16);
1212
0
    a0_8x16 = _mm_add_epi16(a0_8x16, const_val2_8x16);
1213
0
    a0_8x16 = _mm_add_epi16(a0_8x16, a1_8x16);
1214
0
    res1_8x16 = _mm_srai_epi16(a0_8x16, 2);
1215
0
1216
0
    top_8x8 = _mm_loadu_si128((__m128i *)(pu1_top - 1));
1217
0
1218
0
    temp1 = _mm_srli_si128(top_8x8, 1);
1219
0
    temp2 = _mm_srli_si128(top_8x8, 2);
1220
0
    a0_8x16 = _mm_unpacklo_epi8(top_8x8, zero);
1221
0
    a1_8x16 = _mm_unpacklo_epi8(temp1, zero);
1222
0
    a2_8x16 = _mm_unpacklo_epi8(temp2, zero);
1223
0
1224
0
    a0_8x16 = _mm_add_epi16(a0_8x16, a2_8x16);
1225
0
    a1_8x16 = _mm_add_epi16(a1_8x16, a1_8x16);
1226
0
    a0_8x16 = _mm_add_epi16(a0_8x16, const_val2_8x16);
1227
0
    a0_8x16 = _mm_add_epi16(a0_8x16, a1_8x16);
1228
0
    res2_8x16 = _mm_srai_epi16(a0_8x16, 2);
1229
0
1230
0
    out_15x16 = _mm_packus_epi16(res1_8x16, res2_8x16);
1231
0
1232
0
    str_8x8 = _mm_srli_si128(out_15x16, 7);
1233
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 0 * dst_strd), str_8x8);
1234
0
    str_8x8 = _mm_srli_si128(out_15x16, 6);
1235
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 1 * dst_strd), str_8x8);
1236
0
    str_8x8 = _mm_srli_si128(out_15x16, 5);
1237
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 2 * dst_strd), str_8x8);
1238
0
    str_8x8 = _mm_srli_si128(out_15x16, 4);
1239
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 3 * dst_strd), str_8x8);
1240
0
    str_8x8 = _mm_srli_si128(out_15x16, 3);
1241
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 4 * dst_strd), str_8x8);
1242
0
    str_8x8 = _mm_srli_si128(out_15x16, 2);
1243
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 5 * dst_strd), str_8x8);
1244
0
    str_8x8 = _mm_srli_si128(out_15x16, 1);
1245
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 6 * dst_strd), str_8x8);
1246
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 7 * dst_strd), out_15x16);
1247
0
}
1248
1249
/**
1250
 *******************************************************************************
1251
 *
1252
 * ih264_intra_pred_luma_8x8_mode_vert_r_ssse3
1253
 *
1254
 * @brief
1255
 *  Perform Intra prediction for luma_8x8 mode:Vertical_Right
1256
 *
1257
 * @par Description:
1258
 *  Perform Intra prediction for luma_8x8 mode:Vertical_Right ,described in sec 8.3.2.2.7
1259
 *
1260
 * @param[in] pu1_src
1261
 *  UWORD8 pointer to the source
1262
 *
1263
 * @param[out] pu1_dst
1264
 *  UWORD8 pointer to the destination
1265
 *
1266
 * @param[in] src_strd
1267
 *  integer source stride
1268
 *
1269
 * @param[in] dst_strd
1270
 *  integer destination stride
1271
 *
1272
 * @param[in] ngbr_avail
1273
 * availability of neighbouring pixels(Not used in this function)
1274
 *
1275
 * @returns
1276
 *
1277
 * @remarks
1278
 *  None
1279
 *
1280
 *******************************************************************************/
1281
void ih264_intra_pred_luma_8x8_mode_vert_r_ssse3(UWORD8 *pu1_src,
1282
                                                 UWORD8 *pu1_dst,
1283
                                                 WORD32 src_strd,
1284
                                                 WORD32 dst_strd,
1285
                                                 WORD32 ngbr_avail)
1286
0
{
1287
0
    UWORD8 *pu1_left = NULL; /* Pointer to start of left predictors */
1288
0
    UWORD8 *pu1_top = NULL; /* Pointer to start of top predictors */
1289
0
    __m128i top_8x8, left_16x8;
1290
0
    __m128i out1_16x16, out2_16x16;
1291
0
    __m128i a0_8x16, a1_8x16, a2_8x16;
1292
0
    __m128i temp1, temp2;
1293
0
    __m128i res1_8x16, res2_8x16, res3_8x16;
1294
0
    __m128i zero = _mm_setzero_si128();
1295
0
    __m128i const_val2_8x16 = _mm_set1_epi16(2);
1296
0
    __m128i str_8x8;
1297
0
    __m128i mask = _mm_set1_epi32(0xFFFF);
1298
0
1299
0
    UNUSED(src_strd);
1300
0
    UNUSED(ngbr_avail);
1301
0
1302
0
    pu1_left = pu1_src + BLK8x8SIZE - 1;
1303
0
    pu1_top = pu1_src + BLK8x8SIZE + 1;
1304
0
1305
0
    left_16x8 = _mm_loadu_si128((__m128i *)(pu1_left - 6));
1306
0
1307
0
    temp1 = _mm_srli_si128(left_16x8, 1);
1308
0
    temp2 = _mm_srli_si128(left_16x8, 2);
1309
0
    a0_8x16 = _mm_unpacklo_epi8(left_16x8, zero);
1310
0
    a1_8x16 = _mm_unpacklo_epi8(temp1, zero);
1311
0
    a2_8x16 = _mm_unpacklo_epi8(temp2, zero);
1312
0
1313
0
    a0_8x16 = _mm_add_epi16(a0_8x16, a2_8x16);
1314
0
    a1_8x16 = _mm_add_epi16(a1_8x16, a1_8x16);
1315
0
    a0_8x16 = _mm_add_epi16(a0_8x16, const_val2_8x16);
1316
0
    a0_8x16 = _mm_add_epi16(a0_8x16, a1_8x16);
1317
0
    res1_8x16 = _mm_srai_epi16(a0_8x16, 2);
1318
0
1319
0
    top_8x8 = _mm_loadu_si128((__m128i *)(pu1_top - 1));
1320
0
1321
0
    temp1 = _mm_srli_si128(top_8x8, 1);
1322
0
    temp2 = _mm_srli_si128(top_8x8, 2);
1323
0
    a0_8x16 = _mm_unpacklo_epi8(top_8x8, zero);
1324
0
    a1_8x16 = _mm_unpacklo_epi8(temp1, zero);
1325
0
    a2_8x16 = _mm_unpacklo_epi8(temp2, zero);
1326
0
1327
0
    res3_8x16 = _mm_avg_epu16(a0_8x16, a1_8x16);
1328
0
1329
0
    a0_8x16 = _mm_add_epi16(a0_8x16, a2_8x16);
1330
0
    a1_8x16 = _mm_add_epi16(a1_8x16, a1_8x16);
1331
0
    a0_8x16 = _mm_add_epi16(a0_8x16, const_val2_8x16);
1332
0
    a0_8x16 = _mm_add_epi16(a0_8x16, a1_8x16);
1333
0
    res2_8x16 = _mm_srai_epi16(a0_8x16, 2);
1334
0
1335
0
    str_8x8 = _mm_packus_epi16(res3_8x16, zero);
1336
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 0 * dst_strd), str_8x8);
1337
0
1338
0
    temp1 = _mm_and_si128(res1_8x16, mask);
1339
0
    temp1 = _mm_packs_epi32(temp1, temp1);
1340
0
    out1_16x16 = _mm_packus_epi16(temp1, res2_8x16);
1341
0
1342
0
    res1_8x16 = _mm_slli_si128(res1_8x16, 2);
1343
0
    temp1 = _mm_and_si128(res1_8x16, mask);
1344
0
    temp1 = _mm_packs_epi32(temp1, temp1);
1345
0
    out2_16x16 = _mm_packus_epi16(temp1, res3_8x16);
1346
0
1347
0
    str_8x8 = _mm_srli_si128(out1_16x16, 7);
1348
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 1 * dst_strd), str_8x8);
1349
0
1350
0
    str_8x8 = _mm_srli_si128(out2_16x16, 7);
1351
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 2 * dst_strd), str_8x8);
1352
0
1353
0
    str_8x8 = _mm_srli_si128(out1_16x16, 6);
1354
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 3 * dst_strd), str_8x8);
1355
0
1356
0
    str_8x8 = _mm_srli_si128(out2_16x16, 6);
1357
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 4 * dst_strd), str_8x8);
1358
0
1359
0
    str_8x8 = _mm_srli_si128(out1_16x16, 5);
1360
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 5 * dst_strd), str_8x8);
1361
0
1362
0
    str_8x8 = _mm_srli_si128(out2_16x16, 5);
1363
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 6 * dst_strd), str_8x8);
1364
0
1365
0
    str_8x8 = _mm_srli_si128(out1_16x16, 4);
1366
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 7 * dst_strd), str_8x8);
1367
0
}
1368
1369
/*
1370
 *******************************************************************************
1371
 *
1372
 * ih264_intra_pred_luma_8x8_mode_horz_d_ssse3
1373
 *
1374
 * @brief
1375
 *  Perform Intra prediction for luma_8x8 mode:Horizontal_Down
1376
 *
1377
 * @par Description:
1378
 *  Perform Intra prediction for luma_8x8 mode:Horizontal_Down ,described in sec 8.3.2.2.8
1379
 *
1380
 * @param[in] pu1_src
1381
 *  UWORD8 pointer to the source
1382
 *
1383
 * @param[out] pu1_dst
1384
 *  UWORD8 pointer to the destination
1385
 *
1386
 * @param[in] src_strd
1387
 *  integer source stride
1388
 *
1389
 * @param[in] dst_strd
1390
 *  integer destination stride
1391
 *
1392
 * @param[in] ngbr_avail
1393
 * availability of neighbouring pixels(Not used in this function)
1394
 *
1395
 * @returns
1396
 *
1397
 * @remarks
1398
 *  None
1399
 *
1400
 *******************************************************************************/
1401
void ih264_intra_pred_luma_8x8_mode_horz_d_ssse3(UWORD8 *pu1_src,
1402
                                                 UWORD8 *pu1_dst,
1403
                                                 WORD32 src_strd,
1404
                                                 WORD32 dst_strd,
1405
                                                 WORD32 ngbr_avail)
1406
0
{
1407
0
    UWORD8 *pu1_left = NULL; /* Pointer to start of left predictors */
1408
0
    __m128i pels_16x16;
1409
0
    __m128i temp1, temp2, temp3, temp4;
1410
0
    __m128i a0_8x16, a1_8x16, a2_8x16;
1411
0
    __m128i zero = _mm_setzero_si128();
1412
0
    __m128i const_val2_8x16 = _mm_set1_epi16(2);
1413
0
    __m128i res1_8x16, res2_8x16;
1414
0
    __m128i out1_16x16, out2_16x16;
1415
0
    __m128i str_8x8;
1416
0
    UNUSED(src_strd);
1417
0
    UNUSED(ngbr_avail);
1418
0
1419
0
    pu1_left = pu1_src + BLK8x8SIZE - 1;
1420
0
1421
0
    pels_16x16 = _mm_loadu_si128((__m128i *)(pu1_left - 7));
1422
0
1423
0
    temp1 = _mm_srli_si128(pels_16x16, 1);
1424
0
    temp2 = _mm_srli_si128(pels_16x16, 2);
1425
0
    a0_8x16 = _mm_unpacklo_epi8(pels_16x16, zero);
1426
0
    a1_8x16 = _mm_unpacklo_epi8(temp1, zero);
1427
0
    a2_8x16 = _mm_unpacklo_epi8(temp2, zero);
1428
0
1429
0
    res1_8x16 = _mm_avg_epu16(a0_8x16, a1_8x16);
1430
0
1431
0
    a0_8x16 = _mm_add_epi16(a0_8x16, a2_8x16);
1432
0
    a1_8x16 = _mm_add_epi16(a1_8x16, a1_8x16);
1433
0
    a0_8x16 = _mm_add_epi16(a0_8x16, const_val2_8x16);
1434
0
    a0_8x16 = _mm_add_epi16(a0_8x16, a1_8x16);
1435
0
    res2_8x16 = _mm_srai_epi16(a0_8x16, 2);
1436
0
1437
0
    temp3 = _mm_unpacklo_epi16(res1_8x16, res2_8x16);
1438
0
    temp4 = _mm_unpackhi_epi16(res1_8x16, res2_8x16);
1439
0
    out2_16x16 = _mm_packus_epi16(temp3, temp4);
1440
0
1441
0
    a0_8x16 = _mm_unpackhi_epi8(pels_16x16, zero);
1442
0
    a1_8x16 = _mm_unpackhi_epi8(temp1, zero);
1443
0
    a2_8x16 = _mm_unpackhi_epi8(temp2, zero);
1444
0
1445
0
    a0_8x16 = _mm_add_epi16(a0_8x16, a2_8x16);
1446
0
    a1_8x16 = _mm_add_epi16(a1_8x16, a1_8x16);
1447
0
    a0_8x16 = _mm_add_epi16(a0_8x16, const_val2_8x16);
1448
0
    a0_8x16 = _mm_add_epi16(a0_8x16, a1_8x16);
1449
0
    res2_8x16 = _mm_srai_epi16(a0_8x16, 2);
1450
0
1451
0
    out1_16x16 = _mm_packus_epi16(res2_8x16, zero);
1452
0
    temp1 = _mm_srli_si128(out2_16x16, 8);
1453
0
    out1_16x16 = _mm_unpacklo_epi64(temp1, out1_16x16);
1454
0
1455
0
    str_8x8 = _mm_srli_si128(out1_16x16, 6);
1456
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 0 * dst_strd), str_8x8);
1457
0
    str_8x8 = _mm_srli_si128(out1_16x16, 4);
1458
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 1 * dst_strd), str_8x8);
1459
0
    str_8x8 = _mm_srli_si128(out1_16x16, 2);
1460
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 2 * dst_strd), str_8x8);
1461
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 3 * dst_strd), out1_16x16);
1462
0
1463
0
    str_8x8 = _mm_srli_si128(out2_16x16, 6);
1464
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 4 * dst_strd), str_8x8);
1465
0
    str_8x8 = _mm_srli_si128(out2_16x16, 4);
1466
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 5 * dst_strd), str_8x8);
1467
0
    str_8x8 = _mm_srli_si128(out2_16x16, 2);
1468
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 6 * dst_strd), str_8x8);
1469
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 7 * dst_strd), out2_16x16);
1470
0
}
1471
1472
/**
1473
 *******************************************************************************
1474
 *
1475
 * ih264_intra_pred_luma_8x8_mode_vert_l_ssse3
1476
 *
1477
 * @brief
1478
 *  Perform Intra prediction for luma_8x8 mode:Vertical_Left
1479
 *
1480
 * @par Description:
1481
 *  Perform Intra prediction for luma_8x8 mode:Vertical_Left ,described in sec 8.3.2.2.9
1482
 *
1483
 * @param[in] pu1_src
1484
 *  UWORD8 pointer to the source
1485
 *
1486
 * @param[out] pu1_dst
1487
 *  UWORD8 pointer to the destination
1488
 *
1489
 * @param[in] src_strd
1490
 *  integer source stride
1491
 *
1492
 * @param[in] dst_strd
1493
 *  integer destination stride
1494
 *
1495
 * @param[in] ngbr_avail
1496
 * availability of neighbouring pixels(Not used in this function)
1497
 *
1498
 * @returns
1499
 *
1500
 * @remarks
1501
 *  None
1502
 *
1503
 *******************************************************************************/
1504
1505
void ih264_intra_pred_luma_8x8_mode_vert_l_ssse3(UWORD8 *pu1_src,
1506
                                                 UWORD8 *pu1_dst,
1507
                                                 WORD32 src_strd,
1508
                                                 WORD32 dst_strd,
1509
                                                 WORD32 ngbr_avail)
1510
0
{
1511
0
    UWORD8 *pu1_top = NULL; /* Pointer to start of top predictors */
1512
0
    __m128i top_16x16;
1513
0
    __m128i temp1, temp2;
1514
0
    __m128i a0_8x16, a1_8x16, a2_8x16;
1515
0
    __m128i zero = _mm_setzero_si128();
1516
0
    __m128i const_val2_8x16 = _mm_set1_epi16(2);
1517
0
    __m128i res1_8x16, res2_8x16, res3_8x16, res4_8x16;
1518
0
    __m128i out1_16x16, out2_16x16;
1519
0
    UNUSED(src_strd);
1520
0
    UNUSED(ngbr_avail);
1521
0
    pu1_top = pu1_src + BLK8x8SIZE + 1;
1522
0
1523
0
    top_16x16 = _mm_loadu_si128((__m128i *)(pu1_top));
1524
0
    temp1 = _mm_srli_si128(top_16x16, 1);
1525
0
    temp2 = _mm_srli_si128(top_16x16, 2);
1526
0
    a0_8x16 = _mm_unpacklo_epi8(top_16x16, zero);
1527
0
    a1_8x16 = _mm_unpacklo_epi8(temp1, zero);
1528
0
    a2_8x16 = _mm_unpacklo_epi8(temp2, zero);
1529
0
1530
0
    res1_8x16 = _mm_avg_epu16(a0_8x16, a1_8x16);
1531
0
1532
0
    a0_8x16 = _mm_add_epi16(a0_8x16, a2_8x16);
1533
0
    a1_8x16 = _mm_add_epi16(a1_8x16, a1_8x16);
1534
0
    a0_8x16 = _mm_add_epi16(a0_8x16, const_val2_8x16);
1535
0
    a0_8x16 = _mm_add_epi16(a0_8x16, a1_8x16);
1536
0
    res2_8x16 = _mm_srai_epi16(a0_8x16, 2);
1537
0
1538
0
    a0_8x16 = _mm_unpackhi_epi8(top_16x16, zero);
1539
0
    a1_8x16 = _mm_unpackhi_epi8(temp1, zero);
1540
0
    a2_8x16 = _mm_unpackhi_epi8(temp2, zero);
1541
0
1542
0
    res3_8x16 = _mm_avg_epu16(a0_8x16, a1_8x16);
1543
0
1544
0
    a0_8x16 = _mm_add_epi16(a0_8x16, a2_8x16);
1545
0
    a1_8x16 = _mm_add_epi16(a1_8x16, a1_8x16);
1546
0
    a0_8x16 = _mm_add_epi16(a0_8x16, const_val2_8x16);
1547
0
    a0_8x16 = _mm_add_epi16(a0_8x16, a1_8x16);
1548
0
    res4_8x16 = _mm_srai_epi16(a0_8x16, 2);
1549
0
1550
0
    out1_16x16 = _mm_packus_epi16(res1_8x16, res3_8x16);
1551
0
    out2_16x16 = _mm_packus_epi16(res2_8x16, res4_8x16);
1552
0
1553
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 0 * dst_strd), out1_16x16);
1554
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 1 * dst_strd), out2_16x16);
1555
0
    out1_16x16 = _mm_srli_si128(out1_16x16, 1);
1556
0
    out2_16x16 = _mm_srli_si128(out2_16x16, 1);
1557
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 2 * dst_strd), out1_16x16);
1558
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 3 * dst_strd), out2_16x16);
1559
0
    out1_16x16 = _mm_srli_si128(out1_16x16, 1);
1560
0
    out2_16x16 = _mm_srli_si128(out2_16x16, 1);
1561
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 4 * dst_strd), out1_16x16);
1562
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 5 * dst_strd), out2_16x16);
1563
0
    out1_16x16 = _mm_srli_si128(out1_16x16, 1);
1564
0
    out2_16x16 = _mm_srli_si128(out2_16x16, 1);
1565
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 6 * dst_strd), out1_16x16);
1566
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 7 * dst_strd), out2_16x16);
1567
0
}
1568
1569
/**
1570
 *******************************************************************************
1571
 *
1572
 * ih264_intra_pred_luma_8x8_mode_horz_u_ssse3
1573
 *
1574
 * @brief
1575
 *  Perform Intra prediction for luma_8x8 mode:Horizontal_Up
1576
 *
1577
 * @par Description:
1578
 *  Perform Intra prediction for luma_8x8 mode:Horizontal_Up ,described in sec 8.3.2.2.10
1579
 *
1580
 * @param[in] pu1_src
1581
 *  UWORD8 pointer to the source
1582
 *
1583
 * @param[out] pu1_dst
1584
 *  UWORD8 pointer to the destination
1585
 *
1586
 * @param[in] src_strd
1587
 *  integer source stride
1588
 *
1589
 * @param[in] dst_strd
1590
 *  integer destination stride
1591
 *
1592
 * @param[in] ngbr_avail
1593
 * availability of neighbouring pixels(Not used in this function)
1594
 *
1595
 * @returns
1596
 *
1597
 * @remarks
1598
 *  None
1599
 *
1600
 *******************************************************************************/
1601
void ih264_intra_pred_luma_8x8_mode_horz_u_ssse3(UWORD8 *pu1_src,
1602
                                                 UWORD8 *pu1_dst,
1603
                                                 WORD32 src_strd,
1604
                                                 WORD32 dst_strd,
1605
                                                 WORD32 ngbr_avail)
1606
0
{
1607
0
    UWORD8 *pu1_left = NULL; /* Pointer to start of left predictors */
1608
0
    __m128i left_16x16;
1609
0
    __m128i temp1, temp2;
1610
0
    __m128i a0_8x16, a1_8x16, a2_8x16;
1611
0
    __m128i zero = _mm_setzero_si128();
1612
0
    __m128i const_val2_8x16 = _mm_set1_epi16(2);
1613
0
    __m128i res1_8x16, res2_8x16;
1614
0
    __m128i out1_16x16;
1615
0
    __m128i str_8x8;
1616
0
    __m128i shuffle_16x16;
1617
0
    UNUSED(src_strd);
1618
0
    UNUSED(ngbr_avail);
1619
0
1620
0
    pu1_left = pu1_src + BLK8x8SIZE - 1;
1621
0
    shuffle_16x16 = _mm_set_epi8(0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1622
0
                                 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
1623
0
                                 0x0F);
1624
0
1625
0
    left_16x16 = _mm_loadu_si128((__m128i *)(pu1_left - 7));
1626
0
    temp1 = _mm_srli_si128(left_16x16, 1);
1627
0
    a0_8x16 = _mm_unpacklo_epi8(left_16x16, zero);
1628
0
    a0_8x16 = _mm_slli_si128(a0_8x16, 2);
1629
0
    a1_8x16 = _mm_unpacklo_epi8(left_16x16, zero);
1630
0
    a0_8x16 = _mm_shufflelo_epi16(a0_8x16, 0xE5);
1631
0
    a2_8x16 = _mm_unpacklo_epi8(temp1, zero);
1632
0
1633
0
    res1_8x16 = _mm_avg_epu16(a0_8x16, a1_8x16);
1634
0
1635
0
    a0_8x16 = _mm_add_epi16(a0_8x16, a2_8x16);
1636
0
    a1_8x16 = _mm_add_epi16(a1_8x16, a1_8x16);
1637
0
    a0_8x16 = _mm_add_epi16(a0_8x16, const_val2_8x16);
1638
0
    a0_8x16 = _mm_add_epi16(a0_8x16, a1_8x16);
1639
0
    res2_8x16 = _mm_srai_epi16(a0_8x16, 2);
1640
0
1641
0
    temp1 = _mm_unpacklo_epi16(res1_8x16, res2_8x16);
1642
0
    temp2 = _mm_unpackhi_epi16(res1_8x16, res2_8x16);
1643
0
    out1_16x16 = _mm_packus_epi16(temp1, temp2);
1644
0
    out1_16x16 = _mm_shuffle_epi8(out1_16x16, shuffle_16x16);
1645
0
1646
0
    str_8x8 = _mm_srli_si128(out1_16x16, 1);
1647
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 0 * dst_strd), str_8x8);
1648
0
    str_8x8 = _mm_srli_si128(out1_16x16, 3);
1649
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 1 * dst_strd), str_8x8);
1650
0
    str_8x8 = _mm_srli_si128(out1_16x16, 5);
1651
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 2 * dst_strd), str_8x8);
1652
0
    str_8x8 = _mm_srli_si128(out1_16x16, 7);
1653
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 3 * dst_strd), str_8x8);
1654
0
    temp1 = _mm_set1_epi8(pu1_left[-7]);
1655
0
    str_8x8 = _mm_unpacklo_epi64(str_8x8, temp1);
1656
0
    str_8x8 = _mm_srli_si128(str_8x8, 2);
1657
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 4 * dst_strd), str_8x8);
1658
0
    str_8x8 = _mm_srli_si128(str_8x8, 2);
1659
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 5 * dst_strd), str_8x8);
1660
0
    str_8x8 = _mm_srli_si128(str_8x8, 2);
1661
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 6 * dst_strd), str_8x8);
1662
0
    str_8x8 = _mm_srli_si128(str_8x8, 2);
1663
0
    _mm_storel_epi64((__m128i *)(pu1_dst + 7 * dst_strd), str_8x8);
1664
0
1665
0
}
1666
1667
1668
/*******************    16x16 Modes    *******************/
1669
1670
/**
1671
 *******************************************************************************
1672
 *
1673
 *ih264_intra_pred_luma_16x16_mode_vert_ssse3
1674
 *
1675
 * @brief
1676
 *  Perform Intra prediction for luma_16x16 mode:Vertical
1677
 *
1678
 * @par Description:
1679
 *  Perform Intra prediction for luma_16x16 mode:Vertical, described in sec 8.3.3.1
1680
 *
1681
 * @param[in] pu1_src
1682
 *  UWORD8 pointer to the source
1683
 *
1684
 * @param[out] pu1_dst
1685
 *  UWORD8 pointer to the destination
1686
 *
1687
 * @param[in] src_strd
1688
 *  integer source stride
1689
 *
1690
 * @param[in] dst_strd
1691
 *  integer destination stride
1692
 *
1693
 * @param[in] ngbr_avail
1694
 *  availability of neighbouring pixels (Not used in this function)
1695
 *
1696
 * @returns
1697
 *
1698
 * @remarks
1699
 *  None
1700
 *
1701
 *******************************************************************************/
1702
void ih264_intra_pred_luma_16x16_mode_vert_ssse3(UWORD8 *pu1_src,
1703
                                                 UWORD8 *pu1_dst,
1704
                                                 WORD32 src_strd,
1705
                                                 WORD32 dst_strd,
1706
                                                 WORD32 ngbr_avail)
1707
77
{
1708
77
    UWORD8 *pu1_top;
1709
77
    WORD32 dst_strd2, dst_strd3, dst_strd4;
1710
77
1711
77
    __m128i top_16x8b;
1712
77
1713
77
    UNUSED(src_strd);
1714
77
    UNUSED(ngbr_avail);
1715
77
1716
77
    pu1_top = pu1_src + MB_SIZE + 1;
1717
77
1718
77
    dst_strd2 = dst_strd << 1;
1719
77
    dst_strd4 = dst_strd << 2;
1720
77
1721
77
    top_16x8b = _mm_loadu_si128((__m128i *)pu1_top);
1722
77
1723
77
    dst_strd3 = dst_strd + dst_strd2;
1724
77
1725
77
    _mm_storeu_si128((__m128i *)pu1_dst, top_16x8b);
1726
77
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), top_16x8b);
1727
77
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd2), top_16x8b);
1728
77
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd3), top_16x8b);
1729
77
    pu1_dst += dst_strd4;
1730
77
1731
77
    _mm_storeu_si128((__m128i *)pu1_dst, top_16x8b);
1732
77
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), top_16x8b);
1733
77
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd2), top_16x8b);
1734
77
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd3), top_16x8b);
1735
77
    pu1_dst += dst_strd4;
1736
77
1737
77
    _mm_storeu_si128((__m128i *)pu1_dst, top_16x8b);
1738
77
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), top_16x8b);
1739
77
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd2), top_16x8b);
1740
77
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd3), top_16x8b);
1741
77
    pu1_dst += dst_strd4;
1742
77
1743
77
    _mm_storeu_si128((__m128i *)pu1_dst, top_16x8b);
1744
77
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), top_16x8b);
1745
77
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd2), top_16x8b);
1746
77
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd3), top_16x8b);
1747
77
}
1748
1749
/**
1750
 *******************************************************************************
1751
 *
1752
 *ih264_intra_pred_luma_16x16_mode_horz_ssse3
1753
 *
1754
 * @brief
1755
 *  Perform Intra prediction for luma_16x16 mode:Horizontal
1756
 *
1757
 * @par Description:
1758
 *  Perform Intra prediction for luma_16x16 mode:Horizontal, described in sec 8.3.3.2
1759
 *
1760
 * @param[in] pu1_src
1761
 *  UWORD8 pointer to the source
1762
 *
1763
 * @param[out] pu1_dst
1764
 *  UWORD8 pointer to the destination
1765
 *
1766
 * @param[in] src_strd
1767
 *  integer source stride
1768
 *
1769
 * @param[in] dst_strd
1770
 *  integer destination stride
1771
 *
1772
 * @param[in] ngbr_avail
1773
 * availability of neighbouring pixels(Not used in this function)
1774
 *
1775
 * @returns
1776
 *
1777
 * @remarks
1778
 *  None
1779
 *
1780
 *******************************************************************************/
1781
void ih264_intra_pred_luma_16x16_mode_horz_ssse3(UWORD8 *pu1_src,
1782
                                                 UWORD8 *pu1_dst,
1783
                                                 WORD32 src_strd,
1784
                                                 WORD32 dst_strd,
1785
                                                 WORD32 ngbr_avail)
1786
605
{
1787
605
    UWORD8 *pu1_left;
1788
605
    WORD32 dst_strd2, dst_strd3, dst_strd4;
1789
605
1790
605
    __m128i row1_16x8b, row2_16x8b, row3_16x8b, row4_16x8b;
1791
605
1792
605
    UNUSED(src_strd);
1793
605
    UNUSED(ngbr_avail);
1794
605
1795
605
    pu1_left = pu1_src + MB_SIZE - 1;
1796
605
1797
605
    dst_strd4 = dst_strd << 2;
1798
605
1799
605
    dst_strd2 = dst_strd << 1;
1800
605
    dst_strd3 = dst_strd4 - dst_strd;
1801
605
1802
605
    row1_16x8b = _mm_set1_epi8(*(pu1_left));
1803
605
    row2_16x8b = _mm_set1_epi8(*(pu1_left - 1));
1804
605
    row3_16x8b = _mm_set1_epi8(*(pu1_left - 2));
1805
605
    row4_16x8b = _mm_set1_epi8(*(pu1_left - 3));
1806
605
1807
605
    _mm_storeu_si128((__m128i *)pu1_dst, row1_16x8b);
1808
605
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), row2_16x8b);
1809
605
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd2), row3_16x8b);
1810
605
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd3), row4_16x8b);
1811
605
1812
605
    pu1_dst += dst_strd4;
1813
605
    row1_16x8b = _mm_set1_epi8(*(pu1_left - 4));
1814
605
    row2_16x8b = _mm_set1_epi8(*(pu1_left - 5));
1815
605
    row3_16x8b = _mm_set1_epi8(*(pu1_left - 6));
1816
605
    row4_16x8b = _mm_set1_epi8(*(pu1_left - 7));
1817
605
1818
605
    _mm_storeu_si128((__m128i *)pu1_dst, row1_16x8b);
1819
605
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), row2_16x8b);
1820
605
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd2), row3_16x8b);
1821
605
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd3), row4_16x8b);
1822
605
1823
605
    pu1_dst += dst_strd4;
1824
605
    row1_16x8b = _mm_set1_epi8(*(pu1_left - 8));
1825
605
    row2_16x8b = _mm_set1_epi8(*(pu1_left - 9));
1826
605
    row3_16x8b = _mm_set1_epi8(*(pu1_left - 10));
1827
605
    row4_16x8b = _mm_set1_epi8(*(pu1_left - 11));
1828
605
1829
605
    _mm_storeu_si128((__m128i *)pu1_dst, row1_16x8b);
1830
605
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), row2_16x8b);
1831
605
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd2), row3_16x8b);
1832
605
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd3), row4_16x8b);
1833
605
1834
605
    pu1_dst += dst_strd4;
1835
605
    row1_16x8b = _mm_set1_epi8(*(pu1_left - 12));
1836
605
    row2_16x8b = _mm_set1_epi8(*(pu1_left - 13));
1837
605
    row3_16x8b = _mm_set1_epi8(*(pu1_left - 14));
1838
605
    row4_16x8b = _mm_set1_epi8(*(pu1_left - 15));
1839
605
1840
605
    _mm_storeu_si128((__m128i *)pu1_dst, row1_16x8b);
1841
605
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), row2_16x8b);
1842
605
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd2), row3_16x8b);
1843
605
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd3), row4_16x8b);
1844
605
}
1845
1846
/**
1847
 *******************************************************************************
1848
 *
1849
 *ih264_intra_pred_luma_16x16_mode_dc_ssse3
1850
 *
1851
 * @brief
1852
 *  Perform Intra prediction for  luma_16x16 mode:DC
1853
 *
1854
 * @par Description:
1855
 *  Perform Intra prediction for  luma_16x16 mode:DC, described in sec 8.3.3.3
1856
 *
1857
 * @param[in] pu1_src
1858
 *  UWORD8 pointer to the source
1859
 *
1860
 * @param[out] pu1_dst
1861
 *  UWORD8 pointer to the destination
1862
 *
1863
 * @param[in] src_strd
1864
 *  integer source stride
1865
 *
1866
 * @param[in] dst_strd
1867
 *  integer destination stride
1868
 *
1869
 ** @param[in] ngbr_avail
1870
 *  availability of neighbouring pixels
1871
 *
1872
 * @returns
1873
 *
1874
 * @remarks
1875
 *  None
1876
 *
1877
 *******************************************************************************/
1878
void ih264_intra_pred_luma_16x16_mode_dc_ssse3(UWORD8 *pu1_src,
1879
                                               UWORD8 *pu1_dst,
1880
                                               WORD32 src_strd,
1881
                                               WORD32 dst_strd,
1882
                                               WORD32 ngbr_avail)
1883
1.83k
{
1884
1.83k
    WORD8 u1_useleft, u1_usetop;
1885
1.83k
    WORD32 dc_val;
1886
1.83k
1887
1.83k
    WORD32 dst_strd2, dst_strd3, dst_strd4;
1888
1.83k
1889
1.83k
    __m128i dc_val_16x8b;
1890
1.83k
1891
1.83k
    UNUSED(src_strd);
1892
1.83k
1893
1.83k
    u1_useleft = BOOLEAN(ngbr_avail & LEFT_MB_AVAILABLE_MASK);
1894
1.83k
    u1_usetop = BOOLEAN(ngbr_avail & TOP_MB_AVAILABLE_MASK);
1895
1.83k
1896
1.83k
    if(u1_useleft || u1_usetop)
1897
1.83k
    {
1898
1.83k
        WORD32 shft;
1899
1.83k
        __m128i val_16x8b, zero_16x8b, sum_8x16b;
1900
1.83k
1901
1.83k
        dc_val = 0;
1902
1.83k
        shft = 3;
1903
1.83k
1904
1.83k
        zero_16x8b = _mm_setzero_si128();
1905
1.83k
1906
1.83k
        if(u1_useleft)
1907
1.73k
        {
1908
1.73k
            UWORD8 *pu1_left;
1909
1.73k
1910
1.73k
            pu1_left = pu1_src + MB_SIZE - 1;
1911
1.73k
1912
1.73k
            val_16x8b = _mm_loadu_si128((__m128i *)(pu1_left - 15));
1913
1.73k
            sum_8x16b = _mm_sad_epu8(zero_16x8b, val_16x8b);
1914
1.73k
1915
1.73k
            shft++;
1916
1.73k
            dc_val += 8;
1917
1.73k
            dc_val += _mm_extract_epi16(sum_8x16b, 0);
1918
1.73k
            dc_val += _mm_extract_epi16(sum_8x16b, 4);
1919
1.73k
        }
1920
1.83k
        if(u1_usetop)
1921
1.83k
        {
1922
1.83k
            UWORD8 *pu1_top;
1923
1.83k
1924
1.83k
            pu1_top = pu1_src + MB_SIZE + 1;
1925
1.83k
1926
1.83k
            val_16x8b = _mm_loadu_si128((__m128i *)pu1_top);
1927
1.83k
            sum_8x16b = _mm_sad_epu8(zero_16x8b, val_16x8b);
1928
1.83k
1929
1.83k
            shft++;
1930
1.83k
            dc_val += 8;
1931
1.83k
            dc_val += _mm_extract_epi16(sum_8x16b, 0);
1932
1.83k
            dc_val += _mm_extract_epi16(sum_8x16b, 4);
1933
1.83k
        }
1934
1.83k
        dc_val = dc_val >> shft;
1935
1.83k
    }
1936
0
    else
1937
0
        dc_val = 128;
1938
1.83k
1939
1.83k
    dc_val_16x8b =  _mm_set1_epi8(dc_val);
1940
1.83k
1941
1.83k
    dst_strd2 = dst_strd << 1;
1942
1.83k
    dst_strd4 = dst_strd << 2;
1943
1.83k
    dst_strd3 = dst_strd + dst_strd2;
1944
1.83k
1945
1.83k
    _mm_storeu_si128((__m128i *)pu1_dst, dc_val_16x8b);
1946
1.83k
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), dc_val_16x8b);
1947
1.83k
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd2), dc_val_16x8b);
1948
1.83k
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd3), dc_val_16x8b);
1949
1.83k
    pu1_dst += dst_strd4;
1950
1.83k
1951
1.83k
    _mm_storeu_si128((__m128i *)pu1_dst, dc_val_16x8b);
1952
1.83k
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), dc_val_16x8b);
1953
1.83k
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd2), dc_val_16x8b);
1954
1.83k
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd3), dc_val_16x8b);
1955
1.83k
    pu1_dst += dst_strd4;
1956
1.83k
1957
1.83k
    _mm_storeu_si128((__m128i *)pu1_dst, dc_val_16x8b);
1958
1.83k
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), dc_val_16x8b);
1959
1.83k
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd2), dc_val_16x8b);
1960
1.83k
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd3), dc_val_16x8b);
1961
1.83k
    pu1_dst += dst_strd4;
1962
1.83k
1963
1.83k
    _mm_storeu_si128((__m128i *)pu1_dst, dc_val_16x8b);
1964
1.83k
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), dc_val_16x8b);
1965
1.83k
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd2), dc_val_16x8b);
1966
1.83k
    _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd3), dc_val_16x8b);
1967
1.83k
}
1968
1969
/**
1970
 *******************************************************************************
1971
 *
1972
 *ih264_intra_pred_luma_16x16_mode_plane_ssse3
1973
 *
1974
 * @brief
1975
 *  Perform Intra prediction for  luma_16x16 mode:PLANE
1976
 *
1977
 * @par Description:
1978
 *  Perform Intra prediction for  luma_16x16 mode:PLANE, described in sec 8.3.3.4
1979
 *
1980
 * @param[in] pu1_src
1981
 *  UWORD8 pointer to the source
1982
 *
1983
 * @param[out] pu1_dst
1984
 *  UWORD8 pointer to the destination
1985
 *
1986
 * @param[in] src_strd
1987
 *  integer source stride
1988
 *
1989
 * @param[in] dst_strd
1990
 *  integer destination stride
1991
 *
1992
 * @param[in] ngbr_avail
1993
 * availability of neighbouring pixels(Not used in this function)
1994
 *
1995
 * @returns
1996
 *
1997
 * @remarks
1998
 *  None
1999
 *
2000
 *******************************************************************************/
2001
void ih264_intra_pred_luma_16x16_mode_plane_ssse3(UWORD8 *pu1_src,
2002
                                                  UWORD8 *pu1_dst,
2003
                                                  WORD32 src_strd,
2004
                                                  WORD32 dst_strd,
2005
                                                  WORD32 ngbr_avail)
2006
0
{
2007
0
    UWORD8 *pu1_left, *pu1_top;
2008
0
    WORD32 a, b, c;
2009
0
2010
0
    __m128i rev_8x16b, mul_8x16b, zero_16x8b;
2011
0
2012
0
    UNUSED(src_strd);
2013
0
    UNUSED(ngbr_avail);
2014
0
2015
0
    pu1_top = pu1_src + MB_SIZE + 1;
2016
0
    pu1_left = pu1_src + MB_SIZE - 1;
2017
0
2018
0
    rev_8x16b = _mm_setr_epi16(0x0f0e, 0x0d0c, 0x0b0a, 0x0908, 0x0706, 0x0504, 0x0302, 0x0100);
2019
0
    //used to reverse the order of 16-bit values in a vector
2020
0
2021
0
    mul_8x16b = _mm_setr_epi16(1, 2, 3, 4, 5, 6, 7, 8);
2022
0
    zero_16x8b = _mm_setzero_si128();
2023
0
2024
0
    //calculating a, b and c
2025
0
    {
2026
0
        WORD32 h, v;
2027
0
2028
0
        __m128i h_val1_16x8b, h_val2_16x8b;
2029
0
        __m128i h_val1_8x16b, h_val2_8x16b, h_val_4x32b;
2030
0
        __m128i v_val1_16x8b, v_val2_16x8b;
2031
0
        __m128i v_val1_8x16b, v_val2_8x16b, v_val_4x32b;
2032
0
        __m128i hv_val_4x32b;
2033
0
2034
0
        a = (pu1_top[15] + pu1_left[-15]) << 4;
2035
0
2036
0
        h_val1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_top + 8));
2037
0
        h_val2_16x8b = _mm_loadl_epi64((__m128i *)(pu1_top - 1));
2038
0
        v_val1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_left - 15));
2039
0
        v_val2_16x8b = _mm_loadl_epi64((__m128i *)(pu1_left - 6));
2040
0
2041
0
        h_val1_8x16b = _mm_unpacklo_epi8(h_val1_16x8b, zero_16x8b);
2042
0
        h_val2_8x16b = _mm_unpacklo_epi8(h_val2_16x8b, zero_16x8b);
2043
0
        v_val1_8x16b = _mm_unpacklo_epi8(v_val1_16x8b, zero_16x8b);
2044
0
        v_val2_8x16b = _mm_unpacklo_epi8(v_val2_16x8b, zero_16x8b);
2045
0
2046
0
        h_val2_8x16b = _mm_shuffle_epi8(h_val2_8x16b, rev_8x16b);
2047
0
        v_val1_8x16b = _mm_shuffle_epi8(v_val1_8x16b, rev_8x16b);
2048
0
2049
0
        h_val1_8x16b = _mm_sub_epi16(h_val1_8x16b, h_val2_8x16b);
2050
0
        v_val1_8x16b = _mm_sub_epi16(v_val1_8x16b, v_val2_8x16b);
2051
0
2052
0
        h_val_4x32b = _mm_madd_epi16(mul_8x16b, h_val1_8x16b);
2053
0
        v_val_4x32b = _mm_madd_epi16(mul_8x16b, v_val1_8x16b);
2054
0
2055
0
        hv_val_4x32b = _mm_hadd_epi32(h_val_4x32b, v_val_4x32b);
2056
0
        hv_val_4x32b = _mm_hadd_epi32(hv_val_4x32b, hv_val_4x32b);
2057
0
2058
0
        h = _mm_extract_epi16(hv_val_4x32b, 0);
2059
0
        v = _mm_extract_epi16(hv_val_4x32b, 2);
2060
0
        h = (h << 16) >> 16;
2061
0
        v = (v << 16) >> 16;
2062
0
2063
0
        b = ((h << 2) + h + 32) >> 6;
2064
0
        c = ((v << 2) + v + 32) >> 6;
2065
0
    }
2066
0
2067
0
    //using a, b and c to compute the fitted plane values
2068
0
    {
2069
0
        __m128i const_8x16b, b_8x16b, c_8x16b, c2_8x16b;
2070
0
        __m128i res1_l_8x16b, res1_h_8x16b;
2071
0
        __m128i res2_l_8x16b, res2_h_8x16b;
2072
0
        __m128i res1_sh_l_8x16b, res1_sh_h_8x16b, res1_16x8b;
2073
0
        __m128i res2_sh_l_8x16b, res2_sh_h_8x16b, res2_16x8b;
2074
0
2075
0
        b_8x16b = _mm_set1_epi16(b);
2076
0
        c_8x16b = _mm_set1_epi16(c);
2077
0
        c2_8x16b = _mm_set1_epi16(c << 1);
2078
0
        const_8x16b = _mm_set1_epi16(a - c*7 + 16);
2079
0
2080
0
        res1_h_8x16b = _mm_mullo_epi16(mul_8x16b, b_8x16b);
2081
0
        //contains {b*1, b*2, b*3,... b*8}
2082
0
2083
0
        res1_l_8x16b = _mm_shuffle_epi8(res1_h_8x16b, rev_8x16b);
2084
0
        res1_l_8x16b = _mm_srli_si128(res1_l_8x16b, 2);
2085
0
        res1_l_8x16b = _mm_sub_epi16(zero_16x8b, res1_l_8x16b);
2086
0
        //contains {-b*7, -b*6,... -b*1, b*0}
2087
0
2088
0
        // rows 1, 2
2089
0
        res1_h_8x16b = _mm_add_epi16(res1_h_8x16b, const_8x16b);
2090
0
        res1_l_8x16b = _mm_add_epi16(res1_l_8x16b, const_8x16b);
2091
0
        res2_h_8x16b = _mm_add_epi16(res1_h_8x16b, c_8x16b);
2092
0
        res2_l_8x16b = _mm_add_epi16(res1_l_8x16b, c_8x16b);
2093
0
2094
0
        res1_sh_h_8x16b = _mm_srai_epi16(res1_h_8x16b, 5);
2095
0
        res1_sh_l_8x16b = _mm_srai_epi16(res1_l_8x16b, 5);
2096
0
        res2_sh_h_8x16b = _mm_srai_epi16(res2_h_8x16b, 5);
2097
0
        res2_sh_l_8x16b = _mm_srai_epi16(res2_l_8x16b, 5);
2098
0
2099
0
        res1_16x8b = _mm_packus_epi16(res1_sh_l_8x16b, res1_sh_h_8x16b);
2100
0
        res2_16x8b = _mm_packus_epi16(res2_sh_l_8x16b, res2_sh_h_8x16b);
2101
0
2102
0
        _mm_storeu_si128((__m128i *)pu1_dst, res1_16x8b);
2103
0
        _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), res2_16x8b);
2104
0
2105
0
        // rows 3, 4
2106
0
        res1_h_8x16b = _mm_add_epi16(res1_h_8x16b, c2_8x16b);
2107
0
        res1_l_8x16b = _mm_add_epi16(res1_l_8x16b, c2_8x16b);
2108
0
        res2_h_8x16b = _mm_add_epi16(res2_h_8x16b, c2_8x16b);
2109
0
        res2_l_8x16b = _mm_add_epi16(res2_l_8x16b, c2_8x16b);
2110
0
2111
0
        res1_sh_h_8x16b = _mm_srai_epi16(res1_h_8x16b, 5);
2112
0
        res1_sh_l_8x16b = _mm_srai_epi16(res1_l_8x16b, 5);
2113
0
        res2_sh_h_8x16b = _mm_srai_epi16(res2_h_8x16b, 5);
2114
0
        res2_sh_l_8x16b = _mm_srai_epi16(res2_l_8x16b, 5);
2115
0
2116
0
        pu1_dst += dst_strd << 1;
2117
0
2118
0
        res1_16x8b = _mm_packus_epi16(res1_sh_l_8x16b, res1_sh_h_8x16b);
2119
0
        res2_16x8b = _mm_packus_epi16(res2_sh_l_8x16b, res2_sh_h_8x16b);
2120
0
2121
0
        _mm_storeu_si128((__m128i *)pu1_dst, res1_16x8b);
2122
0
        _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), res2_16x8b);
2123
0
2124
0
        // rows 5, 6
2125
0
        res1_h_8x16b = _mm_add_epi16(res1_h_8x16b, c2_8x16b);
2126
0
        res1_l_8x16b = _mm_add_epi16(res1_l_8x16b, c2_8x16b);
2127
0
        res2_h_8x16b = _mm_add_epi16(res2_h_8x16b, c2_8x16b);
2128
0
        res2_l_8x16b = _mm_add_epi16(res2_l_8x16b, c2_8x16b);
2129
0
2130
0
        res1_sh_h_8x16b = _mm_srai_epi16(res1_h_8x16b, 5);
2131
0
        res1_sh_l_8x16b = _mm_srai_epi16(res1_l_8x16b, 5);
2132
0
        res2_sh_h_8x16b = _mm_srai_epi16(res2_h_8x16b, 5);
2133
0
        res2_sh_l_8x16b = _mm_srai_epi16(res2_l_8x16b, 5);
2134
0
2135
0
        pu1_dst += dst_strd << 1;
2136
0
2137
0
        res1_16x8b = _mm_packus_epi16(res1_sh_l_8x16b, res1_sh_h_8x16b);
2138
0
        res2_16x8b = _mm_packus_epi16(res2_sh_l_8x16b, res2_sh_h_8x16b);
2139
0
2140
0
        _mm_storeu_si128((__m128i *)pu1_dst, res1_16x8b);
2141
0
        _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), res2_16x8b);
2142
0
2143
0
        // rows 7, 8
2144
0
        res1_h_8x16b = _mm_add_epi16(res1_h_8x16b, c2_8x16b);
2145
0
        res1_l_8x16b = _mm_add_epi16(res1_l_8x16b, c2_8x16b);
2146
0
        res2_h_8x16b = _mm_add_epi16(res2_h_8x16b, c2_8x16b);
2147
0
        res2_l_8x16b = _mm_add_epi16(res2_l_8x16b, c2_8x16b);
2148
0
2149
0
        res1_sh_h_8x16b = _mm_srai_epi16(res1_h_8x16b, 5);
2150
0
        res1_sh_l_8x16b = _mm_srai_epi16(res1_l_8x16b, 5);
2151
0
        res2_sh_h_8x16b = _mm_srai_epi16(res2_h_8x16b, 5);
2152
0
        res2_sh_l_8x16b = _mm_srai_epi16(res2_l_8x16b, 5);
2153
0
2154
0
        pu1_dst += dst_strd << 1;
2155
0
2156
0
        res1_16x8b = _mm_packus_epi16(res1_sh_l_8x16b, res1_sh_h_8x16b);
2157
0
        res2_16x8b = _mm_packus_epi16(res2_sh_l_8x16b, res2_sh_h_8x16b);
2158
0
2159
0
        _mm_storeu_si128((__m128i *)pu1_dst, res1_16x8b);
2160
0
        _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), res2_16x8b);
2161
0
2162
0
        // rows 9, 10
2163
0
        res1_h_8x16b = _mm_add_epi16(res1_h_8x16b, c2_8x16b);
2164
0
        res1_l_8x16b = _mm_add_epi16(res1_l_8x16b, c2_8x16b);
2165
0
        res2_h_8x16b = _mm_add_epi16(res2_h_8x16b, c2_8x16b);
2166
0
        res2_l_8x16b = _mm_add_epi16(res2_l_8x16b, c2_8x16b);
2167
0
2168
0
        res1_sh_h_8x16b = _mm_srai_epi16(res1_h_8x16b, 5);
2169
0
        res1_sh_l_8x16b = _mm_srai_epi16(res1_l_8x16b, 5);
2170
0
        res2_sh_h_8x16b = _mm_srai_epi16(res2_h_8x16b, 5);
2171
0
        res2_sh_l_8x16b = _mm_srai_epi16(res2_l_8x16b, 5);
2172
0
2173
0
        pu1_dst += dst_strd << 1;
2174
0
2175
0
        res1_16x8b = _mm_packus_epi16(res1_sh_l_8x16b, res1_sh_h_8x16b);
2176
0
        res2_16x8b = _mm_packus_epi16(res2_sh_l_8x16b, res2_sh_h_8x16b);
2177
0
2178
0
        _mm_storeu_si128((__m128i *)pu1_dst, res1_16x8b);
2179
0
        _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), res2_16x8b);
2180
0
2181
0
        // rows 11, 12
2182
0
        res1_h_8x16b = _mm_add_epi16(res1_h_8x16b, c2_8x16b);
2183
0
        res1_l_8x16b = _mm_add_epi16(res1_l_8x16b, c2_8x16b);
2184
0
        res2_h_8x16b = _mm_add_epi16(res2_h_8x16b, c2_8x16b);
2185
0
        res2_l_8x16b = _mm_add_epi16(res2_l_8x16b, c2_8x16b);
2186
0
2187
0
        res1_sh_h_8x16b = _mm_srai_epi16(res1_h_8x16b, 5);
2188
0
        res1_sh_l_8x16b = _mm_srai_epi16(res1_l_8x16b, 5);
2189
0
        res2_sh_h_8x16b = _mm_srai_epi16(res2_h_8x16b, 5);
2190
0
        res2_sh_l_8x16b = _mm_srai_epi16(res2_l_8x16b, 5);
2191
0
2192
0
        pu1_dst += dst_strd << 1;
2193
0
2194
0
        res1_16x8b = _mm_packus_epi16(res1_sh_l_8x16b, res1_sh_h_8x16b);
2195
0
        res2_16x8b = _mm_packus_epi16(res2_sh_l_8x16b, res2_sh_h_8x16b);
2196
0
2197
0
        _mm_storeu_si128((__m128i *)pu1_dst, res1_16x8b);
2198
0
        _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), res2_16x8b);
2199
0
2200
0
        // rows 13, 14
2201
0
        res1_h_8x16b = _mm_add_epi16(res1_h_8x16b, c2_8x16b);
2202
0
        res1_l_8x16b = _mm_add_epi16(res1_l_8x16b, c2_8x16b);
2203
0
        res2_h_8x16b = _mm_add_epi16(res2_h_8x16b, c2_8x16b);
2204
0
        res2_l_8x16b = _mm_add_epi16(res2_l_8x16b, c2_8x16b);
2205
0
2206
0
        res1_sh_h_8x16b = _mm_srai_epi16(res1_h_8x16b, 5);
2207
0
        res1_sh_l_8x16b = _mm_srai_epi16(res1_l_8x16b, 5);
2208
0
        res2_sh_h_8x16b = _mm_srai_epi16(res2_h_8x16b, 5);
2209
0
        res2_sh_l_8x16b = _mm_srai_epi16(res2_l_8x16b, 5);
2210
0
2211
0
        pu1_dst += dst_strd << 1;
2212
0
2213
0
        res1_16x8b = _mm_packus_epi16(res1_sh_l_8x16b, res1_sh_h_8x16b);
2214
0
        res2_16x8b = _mm_packus_epi16(res2_sh_l_8x16b, res2_sh_h_8x16b);
2215
0
2216
0
        _mm_storeu_si128((__m128i *)pu1_dst, res1_16x8b);
2217
0
        _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), res2_16x8b);
2218
0
2219
0
        // rows 15, 16
2220
0
        res1_h_8x16b = _mm_add_epi16(res1_h_8x16b, c2_8x16b);
2221
0
        res1_l_8x16b = _mm_add_epi16(res1_l_8x16b, c2_8x16b);
2222
0
        res2_h_8x16b = _mm_add_epi16(res2_h_8x16b, c2_8x16b);
2223
0
        res2_l_8x16b = _mm_add_epi16(res2_l_8x16b, c2_8x16b);
2224
0
2225
0
        res1_sh_h_8x16b = _mm_srai_epi16(res1_h_8x16b, 5);
2226
0
        res1_sh_l_8x16b = _mm_srai_epi16(res1_l_8x16b, 5);
2227
0
        res2_sh_h_8x16b = _mm_srai_epi16(res2_h_8x16b, 5);
2228
0
        res2_sh_l_8x16b = _mm_srai_epi16(res2_l_8x16b, 5);
2229
0
2230
0
        pu1_dst += dst_strd << 1;
2231
0
2232
0
        res1_16x8b = _mm_packus_epi16(res1_sh_l_8x16b, res1_sh_h_8x16b);
2233
0
        res2_16x8b = _mm_packus_epi16(res2_sh_l_8x16b, res2_sh_h_8x16b);
2234
0
2235
0
        _mm_storeu_si128((__m128i *)pu1_dst, res1_16x8b);
2236
0
        _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), res2_16x8b);
2237
0
    }
2238
0
}
/proc/self/cwd/external/libavc/common/x86/ih264_padding_ssse3.c
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/**
21
*******************************************************************************
22
* @file
23
*  ih264_padding_atom_intr.c
24
*
25
* @brief
26
*  Contains function definitions for Padding
27
*
28
* @author
29
*  Srinivas T
30
*
31
* @par List of Functions:
32
*   - ih264_pad_left_luma_ssse3()
33
*   - ih264_pad_left_chroma_ssse3()
34
*   - ih264_pad_right_luma_ssse3()
35
*   - ih264_pad_right_chroma_ssse3()
36
*
37
* @remarks
38
*  None
39
*
40
*******************************************************************************
41
*/
42
43
#include <string.h>
44
#include <assert.h>
45
#include "ih264_typedefs.h"
46
#include "ih264_platform_macros.h"
47
#include "ih264_mem_fns.h"
48
#include "ih264_debug.h"
49
50
#include <immintrin.h>
51
52
53
/**
54
*******************************************************************************
55
*
56
* @brief
57
*   Padding (luma block) at the left of a 2d array
58
*
59
* @par Description:
60
*   The left column of a 2d array is replicated for pad_size times at the left
61
*
62
*
63
* @param[in] pu1_src
64
*  UWORD8 pointer to the source
65
*
66
* @param[in] src_strd
67
*  integer source stride
68
*
69
* @param[in] ht
70
*  integer height of the array
71
*
72
* @param[in] wd
73
*  integer width of the array
74
*
75
* @param[in] pad_size
76
*  integer -padding size of the array
77
*
78
* @param[in] ht
79
*  integer height of the array
80
*
81
* @param[in] wd
82
*  integer width of the array
83
*
84
* @returns
85
*
86
* @remarks
87
*  None
88
*
89
*******************************************************************************
90
*/
91
92
void ih264_pad_left_luma_ssse3(UWORD8 *pu1_src,
93
                               WORD32 src_strd,
94
                               WORD32 ht,
95
                               WORD32 pad_size)
96
11
{
97
11
    WORD32 row;
98
11
    WORD32 i;
99
11
    UWORD8 *pu1_dst;
100
11
101
11
    ASSERT(pad_size % 8 == 0);
102
11
103
3.53k
    for(row = 0; row < ht; row++)
104
3.52k
    {
105
3.52k
        __m128i src_temp0_16x8b;
106
3.52k
107
3.52k
        pu1_dst = pu1_src - pad_size;
108
3.52k
        src_temp0_16x8b = _mm_set1_epi8(*pu1_src);
109
17.6k
        for(i = 0; i < pad_size; i += 8)
110
14.0k
        {
111
14.0k
            _mm_storel_epi64((__m128i *)(pu1_dst + i), src_temp0_16x8b);
112
14.0k
        }
113
3.52k
        pu1_src += src_strd;
114
3.52k
    }
115
11
116
11
}
117
118
119
120
/**
121
*******************************************************************************
122
*
123
* @brief
124
*   Padding (chroma block) at the left of a 2d array
125
*
126
* @par Description:
127
*   The left column of a 2d array is replicated for pad_size times at the left
128
*
129
*
130
* @param[in] pu1_src
131
*  UWORD8 pointer to the source
132
*
133
* @param[in] src_strd
134
*  integer source stride
135
*
136
* @param[in] ht
137
*  integer height of the array
138
*
139
* @param[in] wd
140
*  integer width of the array (each colour component)
141
*
142
* @param[in] pad_size
143
*  integer -padding size of the array
144
*
145
* @param[in] ht
146
*  integer height of the array
147
*
148
* @param[in] wd
149
*  integer width of the array
150
*
151
* @returns
152
*
153
* @remarks
154
*  None
155
*
156
*******************************************************************************
157
*/
158
159
void ih264_pad_left_chroma_ssse3(UWORD8 *pu1_src,
160
                                 WORD32 src_strd,
161
                                 WORD32 ht,
162
                                 WORD32 pad_size)
163
11
{
164
11
    WORD32 row;
165
11
    WORD32 col;
166
11
    UWORD8 *pu1_dst;
167
11
168
11
    ASSERT(pad_size % 8 == 0);
169
1.77k
    for(row = 0; row < ht; row++)
170
1.76k
    {
171
1.76k
        __m128i src_temp0_16x8b;
172
1.76k
173
1.76k
        pu1_dst = pu1_src - pad_size;
174
1.76k
        src_temp0_16x8b = _mm_set1_epi16(*((UWORD16 *)pu1_src));
175
8.80k
        for(col = 0; col < pad_size; col += 8)
176
7.04k
        {
177
7.04k
            _mm_storel_epi64((__m128i *)(pu1_dst + col), src_temp0_16x8b);
178
7.04k
        }
179
1.76k
        pu1_src += src_strd;
180
1.76k
    }
181
11
182
11
}
183
184
185
186
/**
187
*******************************************************************************
188
*
189
* @brief
190
* Padding (luma block) at the right of a 2d array
191
*
192
* @par Description:
193
* The right column of a 2d array is replicated for pad_size times at the right
194
*
195
*
196
* @param[in] pu1_src
197
*  UWORD8 pointer to the source
198
*
199
* @param[in] src_strd
200
*  integer source stride
201
*
202
* @param[in] ht
203
*  integer height of the array
204
*
205
* @param[in] wd
206
*  integer width of the array
207
*
208
* @param[in] pad_size
209
*  integer -padding size of the array
210
*
211
* @param[in] ht
212
*  integer height of the array
213
*
214
* @param[in] wd
215
*  integer width of the array
216
*
217
* @returns
218
*
219
* @remarks
220
*  None
221
*
222
*******************************************************************************
223
*/
224
225
void ih264_pad_right_luma_ssse3(UWORD8 *pu1_src,
226
                                WORD32 src_strd,
227
                                WORD32 ht,
228
                                WORD32 pad_size)
229
11
{
230
11
    WORD32 row;
231
11
    WORD32 col;
232
11
    UWORD8 *pu1_dst;
233
11
234
11
    ASSERT(pad_size % 8 == 0);
235
11
236
3.53k
    for(row = 0; row < ht; row++)
237
3.52k
    {
238
3.52k
        __m128i src_temp0_16x8b;
239
3.52k
240
3.52k
        pu1_dst = pu1_src;
241
3.52k
        src_temp0_16x8b = _mm_set1_epi8(*(pu1_src - 1));
242
17.6k
        for(col = 0; col < pad_size; col += 8)
243
14.0k
        {
244
14.0k
            _mm_storel_epi64((__m128i *)(pu1_dst + col), src_temp0_16x8b);
245
14.0k
        }
246
3.52k
        pu1_src += src_strd;
247
3.52k
    }
248
11
249
11
}
250
251
252
253
/**
254
*******************************************************************************
255
*
256
* @brief
257
* Padding (chroma block) at the right of a 2d array
258
*
259
* @par Description:
260
* The right column of a 2d array is replicated for pad_size times at the right
261
*
262
*
263
* @param[in] pu1_src
264
*  UWORD8 pointer to the source
265
*
266
* @param[in] src_strd
267
*  integer source stride
268
*
269
* @param[in] ht
270
*  integer height of the array
271
*
272
* @param[in] wd
273
*  integer width of the array (each colour component)
274
*
275
* @param[in] pad_size
276
*  integer -padding size of the array
277
*
278
* @param[in] ht
279
*  integer height of the array
280
*
281
* @param[in] wd
282
*  integer width of the array
283
*
284
* @returns
285
*
286
* @remarks
287
*  None
288
*
289
*******************************************************************************
290
*/
291
292
void ih264_pad_right_chroma_ssse3(UWORD8 *pu1_src,
293
                                  WORD32 src_strd,
294
                                  WORD32 ht,
295
                                  WORD32 pad_size)
296
11
{
297
11
    WORD32 row;
298
11
    WORD32 col;
299
11
    UWORD8 *pu1_dst;
300
11
301
11
    ASSERT(pad_size % 8 == 0);
302
11
303
1.77k
    for(row = 0; row < ht; row++)
304
1.76k
    {
305
1.76k
        __m128i src_temp0_16x8b;
306
1.76k
307
1.76k
        pu1_dst = pu1_src;
308
1.76k
        src_temp0_16x8b = _mm_set1_epi16(*((UWORD16 *)(pu1_src - 2)));
309
8.80k
        for(col = 0; col < pad_size; col += 8)
310
7.04k
        {
311
7.04k
            _mm_storel_epi64((__m128i *)(pu1_dst + col), src_temp0_16x8b);
312
7.04k
        }
313
1.76k
314
1.76k
        pu1_src += src_strd;
315
1.76k
    }
316
11
}
317
/proc/self/cwd/external/libavc/common/x86/ih264_platform_macros.h
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/**
21
*******************************************************************************
22
* @file
23
*  ih264_platform_macros.h
24
*
25
* @brief
26
*  Platform specific Macro definitions used in the codec
27
*
28
* @author
29
*  Ittiam
30
*
31
* @remarks
32
*  None
33
*
34
*******************************************************************************
35
*/
36
37
38
#ifndef _IH264_PLATFORM_MACROS_H_
39
#define _IH264_PLATFORM_MACROS_H_
40
41
#include <immintrin.h>
42
43
44
0
#define CLIP_U8(x) CLIP3(0, 255, (x))
45
#define CLIP_S8(x) CLIP3(-128, 127, (x))
46
47
#define CLIP_U10(x) CLIP3(0, 1023, (x))
48
#define CLIP_S10(x) CLIP3(-512, 511, (x))
49
50
#define CLIP_U12(x) CLIP3(0, 4095, (x))
51
#define CLIP_S12(x) CLIP3(-2048, 2047, (x))
52
53
#define CLIP_U16(x) CLIP3(0, 65535, (x))
54
#define CLIP_S16(x) CLIP3(-32768, 32767, (x))
55
56
#define MEM_ALIGN16 __attribute__ ((aligned (16)))
57
58
#define SHL(x,y) (((y) < 32) ? ((x) << (y)) : 0)
59
#define SHR(x,y) (((y) < 32) ? ((x) >> (y)) : 0)
60
61
#define SHR_NEG(val,shift)  ((shift>0)?(val>>shift):(val<<(-shift)))
62
#define SHL_NEG(val,shift)  ((shift<0)?(val>>(-shift)):(val<<shift))
63
64
65
#define ITT_BIG_ENDIAN(x)   __builtin_bswap32(x);
66
67
3.92M
#define NOP(nop_cnt) {UWORD32 nop_i; for (nop_i = 0; nop_i < nop_cnt; nop_i++) asm("nop");}
68
69
#define PLD(a)
70
71
static __inline UWORD32 CLZ(UWORD32 u4_word)
72
462k
{
73
462k
    if(u4_word)
74
462k
    return(__builtin_clz(u4_word));
75
0
    else
76
0
        return 32;
77
462k
}
Unexecuted instantiation: ih264d_api.c:CLZ
ih264d_utils.c:CLZ
Line
Count
Source
72
10.1k
{
73
10.1k
    if(u4_word)
74
10.1k
    return(__builtin_clz(u4_word));
75
0
    else
76
0
        return 32;
77
10.1k
}
Unexecuted instantiation: ih264d_dpb_mgr.c:CLZ
ih264d_parse_cavlc.c:CLZ
Line
Count
Source
72
222k
{
73
222k
    if(u4_word)
74
222k
    return(__builtin_clz(u4_word));
75
0
    else
76
0
        return 32;
77
222k
}
Unexecuted instantiation: ih264d_tables.c:CLZ
Unexecuted instantiation: ih264d_bitstrm.c:CLZ
Unexecuted instantiation: ih264d_deblocking.c:CLZ
Unexecuted instantiation: ih264d_compute_bs.c:CLZ
Unexecuted instantiation: ih264d_format_conv.c:CLZ
Unexecuted instantiation: ih264d_nal.c:CLZ
Unexecuted instantiation: ih264d_thread_parse_decode.c:CLZ
Unexecuted instantiation: ih264d_mb_utils.c:CLZ
Unexecuted instantiation: ih264d_cabac.c:CLZ
Unexecuted instantiation: ih264d_cabac_init_tables.c:CLZ
Unexecuted instantiation: ih264d_process_pslice.c:CLZ
Unexecuted instantiation: ih264d_inter_pred.c:CLZ
Unexecuted instantiation: ih264d_mvpred.c:CLZ
ih264d_process_intra_mb.c:CLZ
Line
Count
Source
72
212k
{
73
212k
    if(u4_word)
74
212k
    return(__builtin_clz(u4_word));
75
0
    else
76
0
        return 32;
77
212k
}
Unexecuted instantiation: ih264d_process_bslice.c:CLZ
Unexecuted instantiation: ih264d_parse_headers.c:CLZ
Unexecuted instantiation: ih264d_quant_scaling.c:CLZ
Unexecuted instantiation: ih264d_vui.c:CLZ
Unexecuted instantiation: ih264d_parse_slice.c:CLZ
Unexecuted instantiation: ih264d_parse_pslice.c:CLZ
Unexecuted instantiation: ih264d_parse_mb_header.c:CLZ
Unexecuted instantiation: ih264d_parse_cabac.c:CLZ
ih264d_parse_islice.c:CLZ
Line
Count
Source
72
17.6k
{
73
17.6k
    if(u4_word)
74
17.6k
    return(__builtin_clz(u4_word));
75
0
    else
76
0
        return 32;
77
17.6k
}
Unexecuted instantiation: ih264d_parse_bslice.c:CLZ
Unexecuted instantiation: ih264d_sei.c:CLZ
Unexecuted instantiation: ih264d_thread_compute_bs.c:CLZ
Unexecuted instantiation: ih264d_function_selector.c:CLZ
Unexecuted instantiation: ih264d_function_selector_generic.c:CLZ
Unexecuted instantiation: ih264_luma_intra_pred_filters.c:CLZ
Unexecuted instantiation: ih264_chroma_intra_pred_filters.c:CLZ
Unexecuted instantiation: ih264_weighted_pred.c:CLZ
Unexecuted instantiation: ih264_iquant_itrans_recon.c:CLZ
Unexecuted instantiation: ih264_deblk_edge_filters.c:CLZ
Unexecuted instantiation: ih264_inter_pred_filters.c:CLZ
Unexecuted instantiation: ih264d_function_selector_sse42.c:CLZ
Unexecuted instantiation: ih264d_function_selector_ssse3.c:CLZ
Unexecuted instantiation: ih264_inter_pred_filters_ssse3.c:CLZ
Unexecuted instantiation: ih264_deblk_luma_ssse3.c:CLZ
Unexecuted instantiation: ih264_deblk_chroma_ssse3.c:CLZ
Unexecuted instantiation: ih264_padding_ssse3.c:CLZ
Unexecuted instantiation: ih264_iquant_itrans_recon_dc_ssse3.c:CLZ
Unexecuted instantiation: ih264_iquant_itrans_recon_ssse3.c:CLZ
Unexecuted instantiation: ih264_luma_intra_pred_filters_ssse3.c:CLZ
Unexecuted instantiation: ih264_chroma_intra_pred_filters_ssse3.c:CLZ
Unexecuted instantiation: ih264_iquant_itrans_recon_sse42.c:CLZ
Unexecuted instantiation: ih264_weighted_pred_sse42.c:CLZ
78
79
static __inline UWORD32 CTZ(UWORD32 u4_word)
80
0
{
81
0
    if(0 == u4_word)
82
0
        return 31;
83
0
    else
84
0
    {
85
0
        unsigned int index;
86
0
        index = __builtin_ctz(u4_word);
87
0
        return (UWORD32)index;
88
0
    }
89
0
}
Unexecuted instantiation: ih264d_api.c:CTZ
Unexecuted instantiation: ih264d_utils.c:CTZ
Unexecuted instantiation: ih264d_dpb_mgr.c:CTZ
Unexecuted instantiation: ih264d_parse_cavlc.c:CTZ
Unexecuted instantiation: ih264d_tables.c:CTZ
Unexecuted instantiation: ih264d_bitstrm.c:CTZ
Unexecuted instantiation: ih264d_deblocking.c:CTZ
Unexecuted instantiation: ih264d_compute_bs.c:CTZ
Unexecuted instantiation: ih264d_format_conv.c:CTZ
Unexecuted instantiation: ih264d_nal.c:CTZ
Unexecuted instantiation: ih264d_thread_parse_decode.c:CTZ
Unexecuted instantiation: ih264d_mb_utils.c:CTZ
Unexecuted instantiation: ih264d_cabac.c:CTZ
Unexecuted instantiation: ih264d_cabac_init_tables.c:CTZ
Unexecuted instantiation: ih264d_process_pslice.c:CTZ
Unexecuted instantiation: ih264d_inter_pred.c:CTZ
Unexecuted instantiation: ih264d_mvpred.c:CTZ
Unexecuted instantiation: ih264d_process_intra_mb.c:CTZ
Unexecuted instantiation: ih264d_process_bslice.c:CTZ
Unexecuted instantiation: ih264d_parse_headers.c:CTZ
Unexecuted instantiation: ih264d_quant_scaling.c:CTZ
Unexecuted instantiation: ih264d_vui.c:CTZ
Unexecuted instantiation: ih264d_parse_slice.c:CTZ
Unexecuted instantiation: ih264d_parse_pslice.c:CTZ
Unexecuted instantiation: ih264d_parse_mb_header.c:CTZ
Unexecuted instantiation: ih264d_parse_cabac.c:CTZ
Unexecuted instantiation: ih264d_parse_islice.c:CTZ
Unexecuted instantiation: ih264d_parse_bslice.c:CTZ
Unexecuted instantiation: ih264d_sei.c:CTZ
Unexecuted instantiation: ih264d_thread_compute_bs.c:CTZ
Unexecuted instantiation: ih264d_function_selector.c:CTZ
Unexecuted instantiation: ih264d_function_selector_generic.c:CTZ
Unexecuted instantiation: ih264_luma_intra_pred_filters.c:CTZ
Unexecuted instantiation: ih264_chroma_intra_pred_filters.c:CTZ
Unexecuted instantiation: ih264_weighted_pred.c:CTZ
Unexecuted instantiation: ih264_iquant_itrans_recon.c:CTZ
Unexecuted instantiation: ih264_deblk_edge_filters.c:CTZ
Unexecuted instantiation: ih264_inter_pred_filters.c:CTZ
Unexecuted instantiation: ih264d_function_selector_sse42.c:CTZ
Unexecuted instantiation: ih264d_function_selector_ssse3.c:CTZ
Unexecuted instantiation: ih264_inter_pred_filters_ssse3.c:CTZ
Unexecuted instantiation: ih264_deblk_luma_ssse3.c:CTZ
Unexecuted instantiation: ih264_deblk_chroma_ssse3.c:CTZ
Unexecuted instantiation: ih264_padding_ssse3.c:CTZ
Unexecuted instantiation: ih264_iquant_itrans_recon_dc_ssse3.c:CTZ
Unexecuted instantiation: ih264_iquant_itrans_recon_ssse3.c:CTZ
Unexecuted instantiation: ih264_luma_intra_pred_filters_ssse3.c:CTZ
Unexecuted instantiation: ih264_chroma_intra_pred_filters_ssse3.c:CTZ
Unexecuted instantiation: ih264_iquant_itrans_recon_sse42.c:CTZ
Unexecuted instantiation: ih264_weighted_pred_sse42.c:CTZ
90
91
10.1k
#define DATA_SYNC()  __sync_synchronize()
92
93
94
95
//#define INLINE __inline
96
#define INLINE inline
97
98
#define PREFETCH_ENABLE 1
99
100
#if PREFETCH_ENABLE
101
#define PREFETCH(ptr, type) _mm_prefetch(ptr, type);
102
#else
103
#define PREFETCH(ptr, type)
104
#endif
105
106
#define MEM_ALIGN8 __attribute__ ((aligned (8)))
107
#define MEM_ALIGN16 __attribute__ ((aligned (16)))
108
#define MEM_ALIGN32 __attribute__ ((aligned (32)))
109
110
#endif /* _IH264_PLATFORM_MACROS_H_ */
/proc/self/cwd/external/libavc/common/x86/ih264_weighted_pred_sse42.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/*****************************************************************************/
21
/*                                                                           */
22
/*  File Name         : ih264_weighted_pred_intr_sse42.c                     */
23
/*                                                                           */
24
/*  Description       : Contains function definitions for weighted           */
25
/*                      prediction functions in x86 sse4 intrinsics          */
26
/*                                                                           */
27
/*  List of Functions : ih264_default_weighted_pred_luma_sse42()             */
28
/*                      ih264_default_weighted_pred_chroma_sse42()           */
29
/*                      ih264_weighted_pred_luma_sse42()                     */
30
/*                      ih264_weighted_pred_chroma_sse42()                   */
31
/*                      ih264_weighted_bipred_luma_sse42()                   */
32
/*                      ih264_weighted_bipred_chroma_sse42()                 */
33
/*                                                                           */
34
/*  Issues / Problems : None                                                 */
35
/*                                                                           */
36
/*  Revision History  :                                                      */
37
/*                                                                           */
38
/*         DD MM YYYY   Author(s)       Changes                              */
39
/*         30 01 2015   Kaushik         Initial version                      */
40
/*                      Senthoor                                             */
41
/*                                                                           */
42
/*****************************************************************************/
43
/*****************************************************************************/
44
/* File Includes                                                             */
45
/*****************************************************************************/
46
47
#include <immintrin.h>
48
#include "ih264_typedefs.h"
49
#include "ih264_macros.h"
50
#include "ih264_platform_macros.h"
51
#include "ih264_weighted_pred.h"
52
53
/*****************************************************************************/
54
/*  Function definitions .                                                   */
55
/*****************************************************************************/
56
/*****************************************************************************/
57
/*                                                                           */
58
/*  Function Name : ih264_default_weighted_pred_luma_sse42                   */
59
/*                                                                           */
60
/*  Description   : This function performs the default weighted prediction   */
61
/*                  as described in sec 8.4.2.3.1 titled "Default weighted   */
62
/*                  sample prediction process" for luma. The function gets   */
63
/*                  two ht x wd blocks, calculates their rounded-average and */
64
/*                  stores it in the destination block. (ht,wd) can be       */
65
/*                  (4,4), (8,4), (4,8), (8,8), (16,8), (8,16) or (16,16).   */
66
/*                                                                           */
67
/*  Inputs        : pu1_src1  - Pointer to source 1                          */
68
/*                  pu1_src2  - Pointer to source 2                          */
69
/*                  pu1_dst   - Pointer to destination                       */
70
/*                  src_strd1 - stride for source 1                          */
71
/*                  src_strd1 - stride for source 2                          */
72
/*                  dst_strd  - stride for destination                       */
73
/*                  ht        - height of the block                          */
74
/*                  wd        - width of the block                           */
75
/*                                                                           */
76
/*  Issues        : None                                                     */
77
/*                                                                           */
78
/*  Revision History:                                                        */
79
/*                                                                           */
80
/*         DD MM YYYY   Author(s)       Changes                              */
81
/*         04 02 2015   Kaushik         Initial Version                      */
82
/*                      Senthoor                                             */
83
/*                                                                           */
84
/*****************************************************************************/
85
void ih264_default_weighted_pred_luma_sse42(UWORD8 *pu1_src1,
86
                                            UWORD8 *pu1_src2,
87
                                            UWORD8 *pu1_dst,
88
                                            WORD32 src_strd1,
89
                                            WORD32 src_strd2,
90
                                            WORD32 dst_strd,
91
                                            WORD32 ht,
92
                                            WORD32 wd)
93
0
{
94
0
    __m128i y0_0_16x8b, y0_1_16x8b, y0_2_16x8b, y0_3_16x8b;
95
0
    __m128i y1_0_16x8b, y1_1_16x8b, y1_2_16x8b, y1_3_16x8b;
96
0
97
0
    if(wd == 4)
98
0
    {
99
0
        do
100
0
        {
101
0
            y0_0_16x8b = _mm_loadl_epi64((__m128i *)pu1_src1);
102
0
            y0_1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src1 + src_strd1));
103
0
            y0_2_16x8b = _mm_loadl_epi64(
104
0
                            (__m128i *)(pu1_src1 + (src_strd1 << 1)));
105
0
            y0_3_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src1 + src_strd1 * 3));
106
0
107
0
            y1_0_16x8b = _mm_loadl_epi64((__m128i *)pu1_src2);
108
0
            y1_1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src2 + src_strd2));
109
0
            y1_2_16x8b = _mm_loadl_epi64(
110
0
                            (__m128i *)(pu1_src2 + (src_strd2 << 1)));
111
0
            y1_3_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src2 + src_strd2 * 3));
112
0
113
0
            y0_0_16x8b = _mm_avg_epu8(y0_0_16x8b, y1_0_16x8b);
114
0
            y0_1_16x8b = _mm_avg_epu8(y0_1_16x8b, y1_1_16x8b);
115
0
            y0_2_16x8b = _mm_avg_epu8(y0_2_16x8b, y1_2_16x8b);
116
0
            y0_3_16x8b = _mm_avg_epu8(y0_3_16x8b, y1_3_16x8b);
117
0
118
0
            *((WORD32 *)(pu1_dst)) = _mm_cvtsi128_si32(y0_0_16x8b);
119
0
            *((WORD32 *)(pu1_dst + dst_strd)) = _mm_cvtsi128_si32(y0_1_16x8b);
120
0
            *((WORD32 *)(pu1_dst + (dst_strd << 1))) = _mm_cvtsi128_si32(y0_2_16x8b);
121
0
            *((WORD32 *)(pu1_dst + dst_strd * 3)) = _mm_cvtsi128_si32(y0_3_16x8b);
122
0
123
0
            ht -= 4;
124
0
            pu1_src1 += src_strd1 << 2;
125
0
            pu1_src2 += src_strd2 << 2;
126
0
            pu1_dst += dst_strd << 2;
127
0
        }
128
0
        while(ht > 0);
129
0
    }
130
0
    else if(wd == 8)
131
0
    {
132
0
        do
133
0
        {
134
0
            y0_0_16x8b = _mm_loadl_epi64((__m128i *)pu1_src1);
135
0
            y0_1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src1 + src_strd1));
136
0
            y0_2_16x8b = _mm_loadl_epi64(
137
0
                            (__m128i *)(pu1_src1 + (src_strd1 << 1)));
138
0
            y0_3_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src1 + src_strd1 * 3));
139
0
140
0
            y1_0_16x8b = _mm_loadl_epi64((__m128i *)pu1_src2);
141
0
            y1_1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src2 + src_strd2));
142
0
            y1_2_16x8b = _mm_loadl_epi64(
143
0
                            (__m128i *)(pu1_src2 + (src_strd2 << 1)));
144
0
            y1_3_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src2 + src_strd2 * 3));
145
0
146
0
            y0_0_16x8b = _mm_avg_epu8(y0_0_16x8b, y1_0_16x8b);
147
0
            y0_1_16x8b = _mm_avg_epu8(y0_1_16x8b, y1_1_16x8b);
148
0
            y0_2_16x8b = _mm_avg_epu8(y0_2_16x8b, y1_2_16x8b);
149
0
            y0_3_16x8b = _mm_avg_epu8(y0_3_16x8b, y1_3_16x8b);
150
0
151
0
            _mm_storel_epi64((__m128i *)pu1_dst, y0_0_16x8b);
152
0
            _mm_storel_epi64((__m128i *)(pu1_dst + dst_strd), y0_1_16x8b);
153
0
            _mm_storel_epi64((__m128i *)(pu1_dst + (dst_strd << 1)), y0_2_16x8b);
154
0
            _mm_storel_epi64((__m128i *)(pu1_dst + dst_strd * 3), y0_3_16x8b);
155
0
156
0
            ht -= 4;
157
0
            pu1_src1 += src_strd1 << 2;
158
0
            pu1_src2 += src_strd2 << 2;
159
0
            pu1_dst += dst_strd << 2;
160
0
        }
161
0
        while(ht > 0);
162
0
    }
163
0
    else // wd == 16
164
0
    {
165
0
        __m128i y0_4_16x8b, y0_5_16x8b, y0_6_16x8b, y0_7_16x8b;
166
0
        __m128i y1_4_16x8b, y1_5_16x8b, y1_6_16x8b, y1_7_16x8b;
167
0
168
0
        do
169
0
        {
170
0
            y0_0_16x8b = _mm_loadu_si128((__m128i *)pu1_src1);
171
0
            y0_1_16x8b = _mm_loadu_si128((__m128i *)(pu1_src1 + src_strd1));
172
0
            y0_2_16x8b = _mm_loadu_si128(
173
0
                            (__m128i *)(pu1_src1 + (src_strd1 << 1)));
174
0
            y0_3_16x8b = _mm_loadu_si128((__m128i *)(pu1_src1 + src_strd1 * 3));
175
0
            y0_4_16x8b = _mm_loadu_si128(
176
0
                            (__m128i *)(pu1_src1 + (src_strd1 << 2)));
177
0
            y0_5_16x8b = _mm_loadu_si128((__m128i *)(pu1_src1 + src_strd1 * 5));
178
0
            y0_6_16x8b = _mm_loadu_si128((__m128i *)(pu1_src1 + src_strd1 * 6));
179
0
            y0_7_16x8b = _mm_loadu_si128((__m128i *)(pu1_src1 + src_strd1 * 7));
180
0
181
0
            y1_0_16x8b = _mm_loadu_si128((__m128i *)pu1_src2);
182
0
            y1_1_16x8b = _mm_loadu_si128((__m128i *)(pu1_src2 + src_strd2));
183
0
            y1_2_16x8b = _mm_loadu_si128(
184
0
                            (__m128i *)(pu1_src2 + (src_strd2 << 1)));
185
0
            y1_3_16x8b = _mm_loadu_si128((__m128i *)(pu1_src2 + src_strd2 * 3));
186
0
            y1_4_16x8b = _mm_loadu_si128(
187
0
                            (__m128i *)(pu1_src2 + (src_strd2 << 2)));
188
0
            y1_5_16x8b = _mm_loadu_si128((__m128i *)(pu1_src2 + src_strd2 * 5));
189
0
            y1_6_16x8b = _mm_loadu_si128((__m128i *)(pu1_src2 + src_strd2 * 6));
190
0
            y1_7_16x8b = _mm_loadu_si128((__m128i *)(pu1_src2 + src_strd2 * 7));
191
0
192
0
            y0_0_16x8b = _mm_avg_epu8(y0_0_16x8b, y1_0_16x8b);
193
0
            y0_1_16x8b = _mm_avg_epu8(y0_1_16x8b, y1_1_16x8b);
194
0
            y0_2_16x8b = _mm_avg_epu8(y0_2_16x8b, y1_2_16x8b);
195
0
            y0_3_16x8b = _mm_avg_epu8(y0_3_16x8b, y1_3_16x8b);
196
0
            y0_4_16x8b = _mm_avg_epu8(y0_4_16x8b, y1_4_16x8b);
197
0
            y0_5_16x8b = _mm_avg_epu8(y0_5_16x8b, y1_5_16x8b);
198
0
            y0_6_16x8b = _mm_avg_epu8(y0_6_16x8b, y1_6_16x8b);
199
0
            y0_7_16x8b = _mm_avg_epu8(y0_7_16x8b, y1_7_16x8b);
200
0
201
0
            _mm_storeu_si128((__m128i *)pu1_dst, y0_0_16x8b);
202
0
            _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), y0_1_16x8b);
203
0
            _mm_storeu_si128((__m128i *)(pu1_dst + (dst_strd << 1)), y0_2_16x8b);
204
0
            _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd * 3), y0_3_16x8b);
205
0
            _mm_storeu_si128((__m128i *)(pu1_dst + (dst_strd << 2)), y0_4_16x8b);
206
0
            _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd * 5), y0_5_16x8b);
207
0
            _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd * 6), y0_6_16x8b);
208
0
            _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd * 7), y0_7_16x8b);
209
0
210
0
            ht -= 8;
211
0
            pu1_src1 += src_strd1 << 3;
212
0
            pu1_src2 += src_strd2 << 3;
213
0
            pu1_dst += dst_strd << 3;
214
0
        }
215
0
        while(ht > 0);
216
0
    }
217
0
}
218
219
/*****************************************************************************/
220
/*                                                                           */
221
/*  Function Name : ih264_default_weighted_pred_chroma_sse42                 */
222
/*                                                                           */
223
/*  Description   : This function performs the default weighted prediction   */
224
/*                  as described in sec 8.4.2.3.1 titled "Default weighted   */
225
/*                  sample prediction process" for chroma. The function gets */
226
/*                  two ht x wd blocks, calculates their rounded-average and */
227
/*                  stores it in the destination block. (ht,wd) can be       */
228
/*                  (2,2), (4,2) , (2,4), (4,4), (8,4), (4,8) or (8,8).      */
229
/*                                                                           */
230
/*  Inputs        : pu1_src1  - Pointer to source 1                          */
231
/*                  pu1_src2  - Pointer to source 2                          */
232
/*                  pu1_dst   - Pointer to destination                       */
233
/*                  src_strd1 - stride for source 1                          */
234
/*                  src_strd1 - stride for source 2                          */
235
/*                  dst_strd  - stride for destination                       */
236
/*                  ht        - height of the block                          */
237
/*                  wd        - width of the block                           */
238
/*                                                                           */
239
/*  Issues        : None                                                     */
240
/*                                                                           */
241
/*  Revision History:                                                        */
242
/*                                                                           */
243
/*         DD MM YYYY   Author(s)       Changes                              */
244
/*         04 02 2015   Kaushik         Initial Version                      */
245
/*                      Senthoor                                             */
246
/*                                                                           */
247
/*****************************************************************************/
248
void ih264_default_weighted_pred_chroma_sse42(UWORD8 *pu1_src1,
249
                                              UWORD8 *pu1_src2,
250
                                              UWORD8 *pu1_dst,
251
                                              WORD32 src_strd1,
252
                                              WORD32 src_strd2,
253
                                              WORD32 dst_strd,
254
                                              WORD32 ht,
255
                                              WORD32 wd)
256
0
{
257
0
    __m128i uv0_0_16x8b, uv0_1_16x8b;
258
0
    __m128i uv1_0_16x8b, uv1_1_16x8b;
259
0
260
0
    if(wd == 2)
261
0
    {
262
0
        do
263
0
        {
264
0
            uv0_0_16x8b = _mm_loadl_epi64((__m128i *)pu1_src1);
265
0
            uv0_1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src1 + src_strd1));
266
0
267
0
            uv1_0_16x8b = _mm_loadl_epi64((__m128i *)pu1_src2);
268
0
            uv1_1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src2 + src_strd2));
269
0
270
0
            uv0_0_16x8b = _mm_avg_epu8(uv0_0_16x8b, uv1_0_16x8b);
271
0
            uv0_1_16x8b = _mm_avg_epu8(uv0_1_16x8b, uv1_1_16x8b);
272
0
273
0
            *((WORD32 *)(pu1_dst)) = _mm_cvtsi128_si32(uv0_0_16x8b);
274
0
            *((WORD32 *)(pu1_dst + dst_strd)) = _mm_cvtsi128_si32(uv0_1_16x8b);
275
0
276
0
            ht -= 2;
277
0
            pu1_src1 += src_strd1 << 1;
278
0
            pu1_src2 += src_strd2 << 1;
279
0
            pu1_dst += dst_strd << 1;
280
0
        }
281
0
        while(ht > 0);
282
0
    }
283
0
    else if(wd == 4)
284
0
    {
285
0
        do
286
0
        {
287
0
            uv0_0_16x8b = _mm_loadl_epi64((__m128i *)pu1_src1);
288
0
            uv0_1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src1 + src_strd1));
289
0
290
0
            uv1_0_16x8b = _mm_loadl_epi64((__m128i *)pu1_src2);
291
0
            uv1_1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src2 + src_strd2));
292
0
293
0
            uv0_0_16x8b = _mm_avg_epu8(uv0_0_16x8b, uv1_0_16x8b);
294
0
            uv0_1_16x8b = _mm_avg_epu8(uv0_1_16x8b, uv1_1_16x8b);
295
0
296
0
            _mm_storel_epi64((__m128i *)pu1_dst, uv0_0_16x8b);
297
0
            _mm_storel_epi64((__m128i *)(pu1_dst + dst_strd), uv0_1_16x8b);
298
0
299
0
            ht -= 2;
300
0
            pu1_src1 += src_strd1 << 1;
301
0
            pu1_src2 += src_strd2 << 1;
302
0
            pu1_dst += dst_strd << 1;
303
0
        }
304
0
        while(ht > 0);
305
0
    }
306
0
    else // wd == 8
307
0
    {
308
0
        __m128i uv0_2_16x8b, uv0_3_16x8b;
309
0
        __m128i uv1_2_16x8b, uv1_3_16x8b;
310
0
311
0
        do
312
0
        {
313
0
            uv0_0_16x8b = _mm_loadu_si128((__m128i *)pu1_src1);
314
0
            uv0_1_16x8b = _mm_loadu_si128((__m128i *)(pu1_src1 + src_strd1));
315
0
            uv0_2_16x8b = _mm_loadu_si128(
316
0
                            (__m128i *)(pu1_src1 + (src_strd1 << 1)));
317
0
            uv0_3_16x8b = _mm_loadu_si128(
318
0
                            (__m128i *)(pu1_src1 + src_strd1 * 3));
319
0
320
0
            uv1_0_16x8b = _mm_loadu_si128((__m128i *)pu1_src2);
321
0
            uv1_1_16x8b = _mm_loadu_si128((__m128i *)(pu1_src2 + src_strd2));
322
0
            uv1_2_16x8b = _mm_loadu_si128(
323
0
                            (__m128i *)(pu1_src2 + (src_strd2 << 1)));
324
0
            uv1_3_16x8b = _mm_loadu_si128(
325
0
                            (__m128i *)(pu1_src2 + src_strd2 * 3));
326
0
327
0
            uv0_0_16x8b = _mm_avg_epu8(uv0_0_16x8b, uv1_0_16x8b);
328
0
            uv0_1_16x8b = _mm_avg_epu8(uv0_1_16x8b, uv1_1_16x8b);
329
0
            uv0_2_16x8b = _mm_avg_epu8(uv0_2_16x8b, uv1_2_16x8b);
330
0
            uv0_3_16x8b = _mm_avg_epu8(uv0_3_16x8b, uv1_3_16x8b);
331
0
332
0
            _mm_storeu_si128((__m128i *)pu1_dst, uv0_0_16x8b);
333
0
            _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), uv0_1_16x8b);
334
0
            _mm_storeu_si128(
335
0
                            (__m128i *)(pu1_dst + (dst_strd << 1)), uv0_2_16x8b);
336
0
            _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd * 3), uv0_3_16x8b);
337
0
338
0
            ht -= 4;
339
0
            pu1_src1 += src_strd1 << 2;
340
0
            pu1_src2 += src_strd2 << 2;
341
0
            pu1_dst += dst_strd << 2;
342
0
        }
343
0
        while(ht > 0);
344
0
    }
345
0
}
346
347
/*****************************************************************************/
348
/*                                                                           */
349
/*  Function Name : ih264_weighted_pred_luma_sse42                           */
350
/*                                                                           */
351
/*  Description   : This function performs the weighted prediction as        */
352
/*                  described in sec 8.4.2.3.2 titled "Weighted sample       */
353
/*                  prediction process" for luma. The function gets one      */
354
/*                  ht x wd block, weights it, rounds it off, offsets it,    */
355
/*                  saturates it to unsigned 8-bit and stores it in the      */
356
/*                  destination block. (ht,wd) can be (4,4), (8,4), (4,8),   */
357
/*                  (8,8), (16,8), (8,16) or (16,16).                        */
358
/*                                                                           */
359
/*  Inputs        : pu1_src  - Pointer to source                             */
360
/*                  pu1_dst  - Pointer to destination                        */
361
/*                  src_strd - stride for source                             */
362
/*                  dst_strd - stride for destination                        */
363
/*                  log_wd   - number of bits to be rounded off              */
364
/*                  wt       - weight value                                  */
365
/*                  ofst     - offset value                                  */
366
/*                  ht       - height of the block                           */
367
/*                  wd       - width of the block                            */
368
/*                                                                           */
369
/*  Issues        : None                                                     */
370
/*                                                                           */
371
/*  Revision History:                                                        */
372
/*                                                                           */
373
/*         DD MM YYYY   Author(s)       Changes                              */
374
/*         04 02 2015   Kaushik         Initial Version                      */
375
/*                      Senthoor                                             */
376
/*                                                                           */
377
/*****************************************************************************/
378
void ih264_weighted_pred_luma_sse42(UWORD8 *pu1_src,
379
                                    UWORD8 *pu1_dst,
380
                                    WORD32 src_strd,
381
                                    WORD32 dst_strd,
382
                                    WORD32 log_wd,
383
                                    WORD32 wt,
384
                                    WORD32 ofst,
385
                                    WORD32 ht,
386
                                    WORD32 wd)
387
0
{
388
0
    __m128i y_0_16x8b, y_1_16x8b, y_2_16x8b, y_3_16x8b;
389
0
390
0
    __m128i wt_8x16b, round_8x16b, ofst_8x16b;
391
0
392
0
    WORD32 round_val;
393
0
394
0
    wt = (WORD16)(wt & 0xffff);
395
0
    round_val = 1 << (log_wd - 1);
396
0
    ofst = (WORD8)(ofst & 0xff);
397
0
398
0
    wt_8x16b = _mm_set1_epi16(wt);
399
0
    round_8x16b = _mm_set1_epi16(round_val);
400
0
    ofst_8x16b = _mm_set1_epi16(ofst);
401
0
402
0
    if(wd == 4)
403
0
    {
404
0
        __m128i y_0_8x16b, y_2_8x16b;
405
0
406
0
        do
407
0
        {
408
0
            y_0_16x8b = _mm_loadl_epi64((__m128i *)pu1_src);
409
0
            y_1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src + src_strd));
410
0
            y_2_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src + (src_strd << 1)));
411
0
            y_3_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src + src_strd * 3));
412
0
413
0
            y_0_16x8b = _mm_unpacklo_epi32(y_0_16x8b, y_1_16x8b);
414
0
            y_2_16x8b = _mm_unpacklo_epi32(y_2_16x8b, y_3_16x8b);
415
0
416
0
            y_0_8x16b = _mm_cvtepu8_epi16(y_0_16x8b);
417
0
            y_2_8x16b = _mm_cvtepu8_epi16(y_2_16x8b);
418
0
419
0
            y_0_8x16b = _mm_mullo_epi16(y_0_8x16b, wt_8x16b);
420
0
            y_2_8x16b = _mm_mullo_epi16(y_2_8x16b, wt_8x16b);
421
0
422
0
            y_0_8x16b = _mm_adds_epi16(round_8x16b, y_0_8x16b);
423
0
            y_2_8x16b = _mm_adds_epi16(round_8x16b, y_2_8x16b);
424
0
425
0
            y_0_8x16b = _mm_srai_epi16(y_0_8x16b, log_wd);
426
0
            y_2_8x16b = _mm_srai_epi16(y_2_8x16b, log_wd);
427
0
428
0
            y_0_8x16b = _mm_adds_epi16(ofst_8x16b, y_0_8x16b);
429
0
            y_2_8x16b = _mm_adds_epi16(ofst_8x16b, y_2_8x16b);
430
0
431
0
            y_0_16x8b = _mm_packus_epi16(y_0_8x16b, y_2_8x16b);
432
0
            y_1_16x8b = _mm_srli_si128(y_0_16x8b, 4);
433
0
            y_2_16x8b = _mm_srli_si128(y_0_16x8b, 8);
434
0
            y_3_16x8b = _mm_srli_si128(y_0_16x8b, 12);
435
0
436
0
            *((WORD32 *)(pu1_dst)) = _mm_cvtsi128_si32(y_0_16x8b);
437
0
            *((WORD32 *)(pu1_dst + dst_strd)) = _mm_cvtsi128_si32(y_1_16x8b);
438
0
            *((WORD32 *)(pu1_dst + (dst_strd << 1))) = _mm_cvtsi128_si32(y_2_16x8b);
439
0
            *((WORD32 *)(pu1_dst + dst_strd * 3)) = _mm_cvtsi128_si32(y_3_16x8b);
440
0
441
0
            ht -= 4;
442
0
            pu1_src += src_strd << 2;
443
0
            pu1_dst += dst_strd << 2;
444
0
        }
445
0
        while(ht > 0);
446
0
    }
447
0
    else if(wd == 8)
448
0
    {
449
0
        __m128i y_0_8x16b, y_1_8x16b, y_2_8x16b, y_3_8x16b;
450
0
451
0
        do
452
0
        {
453
0
            y_0_16x8b = _mm_loadl_epi64((__m128i *)pu1_src);
454
0
            y_1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src + src_strd));
455
0
            y_2_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src + (src_strd << 1)));
456
0
            y_3_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src + src_strd * 3));
457
0
458
0
            y_0_8x16b = _mm_cvtepu8_epi16(y_0_16x8b);
459
0
            y_1_8x16b = _mm_cvtepu8_epi16(y_1_16x8b);
460
0
            y_2_8x16b = _mm_cvtepu8_epi16(y_2_16x8b);
461
0
            y_3_8x16b = _mm_cvtepu8_epi16(y_3_16x8b);
462
0
463
0
            y_0_8x16b = _mm_mullo_epi16(y_0_8x16b, wt_8x16b);
464
0
            y_1_8x16b = _mm_mullo_epi16(y_1_8x16b, wt_8x16b);
465
0
            y_2_8x16b = _mm_mullo_epi16(y_2_8x16b, wt_8x16b);
466
0
            y_3_8x16b = _mm_mullo_epi16(y_3_8x16b, wt_8x16b);
467
0
468
0
            y_0_8x16b = _mm_adds_epi16(round_8x16b, y_0_8x16b);
469
0
            y_1_8x16b = _mm_adds_epi16(round_8x16b, y_1_8x16b);
470
0
            y_2_8x16b = _mm_adds_epi16(round_8x16b, y_2_8x16b);
471
0
            y_3_8x16b = _mm_adds_epi16(round_8x16b, y_3_8x16b);
472
0
473
0
            y_0_8x16b = _mm_srai_epi16(y_0_8x16b, log_wd);
474
0
            y_1_8x16b = _mm_srai_epi16(y_1_8x16b, log_wd);
475
0
            y_2_8x16b = _mm_srai_epi16(y_2_8x16b, log_wd);
476
0
            y_3_8x16b = _mm_srai_epi16(y_3_8x16b, log_wd);
477
0
478
0
            y_0_8x16b = _mm_adds_epi16(ofst_8x16b, y_0_8x16b);
479
0
            y_1_8x16b = _mm_adds_epi16(ofst_8x16b, y_1_8x16b);
480
0
            y_2_8x16b = _mm_adds_epi16(ofst_8x16b, y_2_8x16b);
481
0
            y_3_8x16b = _mm_adds_epi16(ofst_8x16b, y_3_8x16b);
482
0
483
0
            y_0_16x8b = _mm_packus_epi16(y_0_8x16b, y_1_8x16b);
484
0
            y_2_16x8b = _mm_packus_epi16(y_2_8x16b, y_3_8x16b);
485
0
            y_1_16x8b = _mm_srli_si128(y_0_16x8b, 8);
486
0
            y_3_16x8b = _mm_srli_si128(y_2_16x8b, 8);
487
0
488
0
            _mm_storel_epi64((__m128i *)pu1_dst, y_0_16x8b);
489
0
            _mm_storel_epi64((__m128i *)(pu1_dst + dst_strd), y_1_16x8b);
490
0
            _mm_storel_epi64((__m128i *)(pu1_dst + (dst_strd << 1)), y_2_16x8b);
491
0
            _mm_storel_epi64((__m128i *)(pu1_dst + dst_strd * 3), y_3_16x8b);
492
0
493
0
            ht -= 4;
494
0
            pu1_src += src_strd << 2;
495
0
            pu1_dst += dst_strd << 2;
496
0
        }
497
0
        while(ht > 0);
498
0
    }
499
0
    else // wd == 16
500
0
    {
501
0
        __m128i y_0L_8x16b, y_1L_8x16b, y_2L_8x16b, y_3L_8x16b;
502
0
        __m128i y_0H_8x16b, y_1H_8x16b, y_2H_8x16b, y_3H_8x16b;
503
0
504
0
        __m128i zero_16x8b;
505
0
        zero_16x8b = _mm_set1_epi8(0);
506
0
507
0
        do
508
0
        {
509
0
            y_0_16x8b = _mm_loadu_si128((__m128i *)pu1_src);
510
0
            y_1_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + src_strd));
511
0
            y_2_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + (src_strd << 1)));
512
0
            y_3_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + src_strd * 3));
513
0
514
0
            y_0L_8x16b = _mm_cvtepu8_epi16(y_0_16x8b);
515
0
            y_0H_8x16b = _mm_unpackhi_epi8(y_0_16x8b, zero_16x8b);
516
0
            y_1L_8x16b = _mm_cvtepu8_epi16(y_1_16x8b);
517
0
            y_1H_8x16b = _mm_unpackhi_epi8(y_1_16x8b, zero_16x8b);
518
0
            y_2L_8x16b = _mm_cvtepu8_epi16(y_2_16x8b);
519
0
            y_2H_8x16b = _mm_unpackhi_epi8(y_2_16x8b, zero_16x8b);
520
0
            y_3L_8x16b = _mm_cvtepu8_epi16(y_3_16x8b);
521
0
            y_3H_8x16b = _mm_unpackhi_epi8(y_3_16x8b, zero_16x8b);
522
0
523
0
            y_0L_8x16b = _mm_mullo_epi16(y_0L_8x16b, wt_8x16b);
524
0
            y_0H_8x16b = _mm_mullo_epi16(y_0H_8x16b, wt_8x16b);
525
0
            y_1L_8x16b = _mm_mullo_epi16(y_1L_8x16b, wt_8x16b);
526
0
            y_1H_8x16b = _mm_mullo_epi16(y_1H_8x16b, wt_8x16b);
527
0
            y_2L_8x16b = _mm_mullo_epi16(y_2L_8x16b, wt_8x16b);
528
0
            y_2H_8x16b = _mm_mullo_epi16(y_2H_8x16b, wt_8x16b);
529
0
            y_3L_8x16b = _mm_mullo_epi16(y_3L_8x16b, wt_8x16b);
530
0
            y_3H_8x16b = _mm_mullo_epi16(y_3H_8x16b, wt_8x16b);
531
0
532
0
            y_0L_8x16b = _mm_adds_epi16(round_8x16b, y_0L_8x16b);
533
0
            y_0H_8x16b = _mm_adds_epi16(round_8x16b, y_0H_8x16b);
534
0
            y_1L_8x16b = _mm_adds_epi16(round_8x16b, y_1L_8x16b);
535
0
            y_1H_8x16b = _mm_adds_epi16(round_8x16b, y_1H_8x16b);
536
0
            y_2L_8x16b = _mm_adds_epi16(round_8x16b, y_2L_8x16b);
537
0
            y_2H_8x16b = _mm_adds_epi16(round_8x16b, y_2H_8x16b);
538
0
            y_3L_8x16b = _mm_adds_epi16(round_8x16b, y_3L_8x16b);
539
0
            y_3H_8x16b = _mm_adds_epi16(round_8x16b, y_3H_8x16b);
540
0
541
0
            y_0L_8x16b = _mm_srai_epi16(y_0L_8x16b, log_wd);
542
0
            y_0H_8x16b = _mm_srai_epi16(y_0H_8x16b, log_wd);
543
0
            y_1L_8x16b = _mm_srai_epi16(y_1L_8x16b, log_wd);
544
0
            y_1H_8x16b = _mm_srai_epi16(y_1H_8x16b, log_wd);
545
0
            y_2L_8x16b = _mm_srai_epi16(y_2L_8x16b, log_wd);
546
0
            y_2H_8x16b = _mm_srai_epi16(y_2H_8x16b, log_wd);
547
0
            y_3L_8x16b = _mm_srai_epi16(y_3L_8x16b, log_wd);
548
0
            y_3H_8x16b = _mm_srai_epi16(y_3H_8x16b, log_wd);
549
0
550
0
            y_0L_8x16b = _mm_adds_epi16(ofst_8x16b, y_0L_8x16b);
551
0
            y_0H_8x16b = _mm_adds_epi16(ofst_8x16b, y_0H_8x16b);
552
0
            y_1L_8x16b = _mm_adds_epi16(ofst_8x16b, y_1L_8x16b);
553
0
            y_1H_8x16b = _mm_adds_epi16(ofst_8x16b, y_1H_8x16b);
554
0
            y_2L_8x16b = _mm_adds_epi16(ofst_8x16b, y_2L_8x16b);
555
0
            y_2H_8x16b = _mm_adds_epi16(ofst_8x16b, y_2H_8x16b);
556
0
            y_3L_8x16b = _mm_adds_epi16(ofst_8x16b, y_3L_8x16b);
557
0
            y_3H_8x16b = _mm_adds_epi16(ofst_8x16b, y_3H_8x16b);
558
0
559
0
            y_0_16x8b = _mm_packus_epi16(y_0L_8x16b, y_0H_8x16b);
560
0
            y_1_16x8b = _mm_packus_epi16(y_1L_8x16b, y_1H_8x16b);
561
0
            y_2_16x8b = _mm_packus_epi16(y_2L_8x16b, y_2H_8x16b);
562
0
            y_3_16x8b = _mm_packus_epi16(y_3L_8x16b, y_3H_8x16b);
563
0
564
0
            _mm_storeu_si128((__m128i *)pu1_dst, y_0_16x8b);
565
0
            _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), y_1_16x8b);
566
0
            _mm_storeu_si128((__m128i *)(pu1_dst + (dst_strd << 1)), y_2_16x8b);
567
0
            _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd * 3), y_3_16x8b);
568
0
569
0
            ht -= 4;
570
0
            pu1_src += src_strd << 2;
571
0
            pu1_dst += dst_strd << 2;
572
0
        }
573
0
        while(ht > 0);
574
0
    }
575
0
}
576
577
/*****************************************************************************/
578
/*                                                                           */
579
/*  Function Name : ih264_weighted_pred_chroma_sse42                         */
580
/*                                                                           */
581
/*  Description   : This function performs the weighted prediction as        */
582
/*                  described in sec 8.4.2.3.2 titled "Weighted sample       */
583
/*                  prediction process" for chroma. The function gets one    */
584
/*                  ht x wd block, weights it, rounds it off, offsets it,    */
585
/*                  saturates it to unsigned 8-bit and stores it in the      */
586
/*                  destination block. (ht,wd) can be (2,2), (4,2), (2,4),   */
587
/*                  (4,4), (8,4), (4,8) or (8,8).                            */
588
/*                                                                           */
589
/*  Inputs        : pu1_src  - Pointer to source                             */
590
/*                  pu1_dst  - Pointer to destination                        */
591
/*                  src_strd - stride for source                             */
592
/*                  dst_strd - stride for destination                        */
593
/*                  log_wd   - number of bits to be rounded off              */
594
/*                  wt       - weight values for u and v                     */
595
/*                  ofst     - offset values for u and v                     */
596
/*                  ht       - height of the block                           */
597
/*                  wd       - width of the block                            */
598
/*                                                                           */
599
/*  Issues        : None                                                     */
600
/*                                                                           */
601
/*  Revision History:                                                        */
602
/*                                                                           */
603
/*         DD MM YYYY   Author(s)       Changes                              */
604
/*         04 02 2015   Kaushik         Initial Version                      */
605
/*                      Senthoor                                             */
606
/*                                                                           */
607
/*****************************************************************************/
608
void ih264_weighted_pred_chroma_sse42(UWORD8 *pu1_src,
609
                                      UWORD8 *pu1_dst,
610
                                      WORD32 src_strd,
611
                                      WORD32 dst_strd,
612
                                      WORD32 log_wd,
613
                                      WORD32 wt,
614
                                      WORD32 ofst,
615
                                      WORD32 ht,
616
                                      WORD32 wd)
617
0
{
618
0
    __m128i y_0_16x8b, y_1_16x8b;
619
0
620
0
    __m128i wt_8x16b, round_8x16b, ofst_8x16b;
621
0
622
0
    WORD32 ofst_u, ofst_v;
623
0
    WORD32 round_val;
624
0
625
0
    ofst_u = (WORD8)(ofst & 0xff);
626
0
    ofst_v = (WORD8)(ofst >> 8);
627
0
    round_val = 1 << (log_wd - 1);
628
0
    ofst = (ofst_u & 0xffff) | (ofst_v << 16);
629
0
630
0
    wt_8x16b = _mm_set1_epi32(wt);
631
0
    round_8x16b = _mm_set1_epi16(round_val);
632
0
    ofst_8x16b = _mm_set1_epi32(ofst);
633
0
634
0
    if(wd == 2)
635
0
    {
636
0
        __m128i y_0_8x16b;
637
0
638
0
        do
639
0
        {
640
0
            y_0_16x8b = _mm_loadl_epi64((__m128i *)pu1_src);
641
0
            y_1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src + src_strd));
642
0
643
0
            y_0_16x8b = _mm_unpacklo_epi32(y_0_16x8b, y_1_16x8b);
644
0
645
0
            y_0_8x16b = _mm_cvtepu8_epi16(y_0_16x8b);
646
0
647
0
            y_0_8x16b = _mm_mullo_epi16(y_0_8x16b, wt_8x16b);
648
0
649
0
            y_0_8x16b = _mm_adds_epi16(round_8x16b, y_0_8x16b);
650
0
651
0
            y_0_8x16b = _mm_srai_epi16(y_0_8x16b, log_wd);
652
0
653
0
            y_0_8x16b = _mm_adds_epi16(ofst_8x16b, y_0_8x16b);
654
0
655
0
            y_0_16x8b = _mm_packus_epi16(y_0_8x16b, y_0_8x16b);
656
0
            y_1_16x8b = _mm_srli_si128(y_0_16x8b, 4);
657
0
658
0
            *((WORD32 *)(pu1_dst)) = _mm_cvtsi128_si32(y_0_16x8b);
659
0
            *((WORD32 *)(pu1_dst + dst_strd)) = _mm_cvtsi128_si32(y_1_16x8b);
660
0
661
0
            ht -= 2;
662
0
            pu1_src += src_strd << 1;
663
0
            pu1_dst += dst_strd << 1;
664
0
        }
665
0
        while(ht > 0);
666
0
    }
667
0
    else if(wd == 4)
668
0
    {
669
0
        __m128i y_0_8x16b, y_1_8x16b;
670
0
671
0
        do
672
0
        {
673
0
            y_0_16x8b = _mm_loadl_epi64((__m128i *)pu1_src);
674
0
            y_1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src + src_strd));
675
0
676
0
            y_0_8x16b = _mm_cvtepu8_epi16(y_0_16x8b);
677
0
            y_1_8x16b = _mm_cvtepu8_epi16(y_1_16x8b);
678
0
679
0
            y_0_8x16b = _mm_mullo_epi16(y_0_8x16b, wt_8x16b);
680
0
            y_1_8x16b = _mm_mullo_epi16(y_1_8x16b, wt_8x16b);
681
0
682
0
            y_0_8x16b = _mm_adds_epi16(round_8x16b, y_0_8x16b);
683
0
            y_1_8x16b = _mm_adds_epi16(round_8x16b, y_1_8x16b);
684
0
685
0
            y_0_8x16b = _mm_srai_epi16(y_0_8x16b, log_wd);
686
0
            y_1_8x16b = _mm_srai_epi16(y_1_8x16b, log_wd);
687
0
688
0
            y_0_8x16b = _mm_adds_epi16(ofst_8x16b, y_0_8x16b);
689
0
            y_1_8x16b = _mm_adds_epi16(ofst_8x16b, y_1_8x16b);
690
0
691
0
            y_0_16x8b = _mm_packus_epi16(y_0_8x16b, y_1_8x16b);
692
0
            y_1_16x8b = _mm_srli_si128(y_0_16x8b, 8);
693
0
694
0
            _mm_storel_epi64((__m128i *)pu1_dst, y_0_16x8b);
695
0
            _mm_storel_epi64((__m128i *)(pu1_dst + dst_strd), y_1_16x8b);
696
0
697
0
            ht -= 2;
698
0
            pu1_src += src_strd << 1;
699
0
            pu1_dst += dst_strd << 1;
700
0
        }
701
0
        while(ht > 0);
702
0
    }
703
0
    else // wd == 16
704
0
    {
705
0
        __m128i y_2_16x8b, y_3_16x8b;
706
0
        __m128i y_0L_8x16b, y_1L_8x16b, y_2L_8x16b, y_3L_8x16b;
707
0
        __m128i y_0H_8x16b, y_1H_8x16b, y_2H_8x16b, y_3H_8x16b;
708
0
709
0
        __m128i zero_16x8b;
710
0
        zero_16x8b = _mm_set1_epi8(0);
711
0
712
0
        do
713
0
        {
714
0
            y_0_16x8b = _mm_loadu_si128((__m128i *)pu1_src);
715
0
            y_1_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + src_strd));
716
0
            y_2_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + (src_strd << 1)));
717
0
            y_3_16x8b = _mm_loadu_si128((__m128i *)(pu1_src + src_strd * 3));
718
0
719
0
            y_0L_8x16b = _mm_cvtepu8_epi16(y_0_16x8b);
720
0
            y_0H_8x16b = _mm_unpackhi_epi8(y_0_16x8b, zero_16x8b);
721
0
            y_1L_8x16b = _mm_cvtepu8_epi16(y_1_16x8b);
722
0
            y_1H_8x16b = _mm_unpackhi_epi8(y_1_16x8b, zero_16x8b);
723
0
            y_2L_8x16b = _mm_cvtepu8_epi16(y_2_16x8b);
724
0
            y_2H_8x16b = _mm_unpackhi_epi8(y_2_16x8b, zero_16x8b);
725
0
            y_3L_8x16b = _mm_cvtepu8_epi16(y_3_16x8b);
726
0
            y_3H_8x16b = _mm_unpackhi_epi8(y_3_16x8b, zero_16x8b);
727
0
728
0
            y_0L_8x16b = _mm_mullo_epi16(y_0L_8x16b, wt_8x16b);
729
0
            y_0H_8x16b = _mm_mullo_epi16(y_0H_8x16b, wt_8x16b);
730
0
            y_1L_8x16b = _mm_mullo_epi16(y_1L_8x16b, wt_8x16b);
731
0
            y_1H_8x16b = _mm_mullo_epi16(y_1H_8x16b, wt_8x16b);
732
0
            y_2L_8x16b = _mm_mullo_epi16(y_2L_8x16b, wt_8x16b);
733
0
            y_2H_8x16b = _mm_mullo_epi16(y_2H_8x16b, wt_8x16b);
734
0
            y_3L_8x16b = _mm_mullo_epi16(y_3L_8x16b, wt_8x16b);
735
0
            y_3H_8x16b = _mm_mullo_epi16(y_3H_8x16b, wt_8x16b);
736
0
737
0
            y_0L_8x16b = _mm_adds_epi16(round_8x16b, y_0L_8x16b);
738
0
            y_0H_8x16b = _mm_adds_epi16(round_8x16b, y_0H_8x16b);
739
0
            y_1L_8x16b = _mm_adds_epi16(round_8x16b, y_1L_8x16b);
740
0
            y_1H_8x16b = _mm_adds_epi16(round_8x16b, y_1H_8x16b);
741
0
            y_2L_8x16b = _mm_adds_epi16(round_8x16b, y_2L_8x16b);
742
0
            y_2H_8x16b = _mm_adds_epi16(round_8x16b, y_2H_8x16b);
743
0
            y_3L_8x16b = _mm_adds_epi16(round_8x16b, y_3L_8x16b);
744
0
            y_3H_8x16b = _mm_adds_epi16(round_8x16b, y_3H_8x16b);
745
0
746
0
            y_0L_8x16b = _mm_srai_epi16(y_0L_8x16b, log_wd);
747
0
            y_0H_8x16b = _mm_srai_epi16(y_0H_8x16b, log_wd);
748
0
            y_1L_8x16b = _mm_srai_epi16(y_1L_8x16b, log_wd);
749
0
            y_1H_8x16b = _mm_srai_epi16(y_1H_8x16b, log_wd);
750
0
            y_2L_8x16b = _mm_srai_epi16(y_2L_8x16b, log_wd);
751
0
            y_2H_8x16b = _mm_srai_epi16(y_2H_8x16b, log_wd);
752
0
            y_3L_8x16b = _mm_srai_epi16(y_3L_8x16b, log_wd);
753
0
            y_3H_8x16b = _mm_srai_epi16(y_3H_8x16b, log_wd);
754
0
755
0
            y_0L_8x16b = _mm_adds_epi16(ofst_8x16b, y_0L_8x16b);
756
0
            y_0H_8x16b = _mm_adds_epi16(ofst_8x16b, y_0H_8x16b);
757
0
            y_1L_8x16b = _mm_adds_epi16(ofst_8x16b, y_1L_8x16b);
758
0
            y_1H_8x16b = _mm_adds_epi16(ofst_8x16b, y_1H_8x16b);
759
0
            y_2L_8x16b = _mm_adds_epi16(ofst_8x16b, y_2L_8x16b);
760
0
            y_2H_8x16b = _mm_adds_epi16(ofst_8x16b, y_2H_8x16b);
761
0
            y_3L_8x16b = _mm_adds_epi16(ofst_8x16b, y_3L_8x16b);
762
0
            y_3H_8x16b = _mm_adds_epi16(ofst_8x16b, y_3H_8x16b);
763
0
764
0
            y_0_16x8b = _mm_packus_epi16(y_0L_8x16b, y_0H_8x16b);
765
0
            y_1_16x8b = _mm_packus_epi16(y_1L_8x16b, y_1H_8x16b);
766
0
            y_2_16x8b = _mm_packus_epi16(y_2L_8x16b, y_2H_8x16b);
767
0
            y_3_16x8b = _mm_packus_epi16(y_3L_8x16b, y_3H_8x16b);
768
0
769
0
            _mm_storeu_si128((__m128i *)pu1_dst, y_0_16x8b);
770
0
            _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), y_1_16x8b);
771
0
            _mm_storeu_si128((__m128i *)(pu1_dst + (dst_strd << 1)), y_2_16x8b);
772
0
            _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd * 3), y_3_16x8b);
773
0
774
0
            ht -= 4;
775
0
            pu1_src += src_strd << 2;
776
0
            pu1_dst += dst_strd << 2;
777
0
        }
778
0
        while(ht > 0);
779
0
    }
780
0
}
781
782
/*****************************************************************************/
783
/*                                                                           */
784
/*  Function Name : ih264_weighted_bi_pred_luma_sse42                        */
785
/*                                                                           */
786
/*  Description   : This function performs the weighted biprediction as      */
787
/*                  described in sec 8.4.2.3.2 titled "Weighted sample       */
788
/*                  prediction process" for luma. The function gets two      */
789
/*                  ht x wd blocks, weights them, adds them, rounds off the  */
790
/*                  sum, offsets it, saturates it to unsigned 8-bit and      */
791
/*                  stores it in the destination block. (ht,wd) can be       */
792
/*                  (4,4), (8,4), (4,8), (8,8), (16,8), (8,16) or (16,16).   */
793
/*                                                                           */
794
/*  Inputs        : pu1_src1  - Pointer to source 1                          */
795
/*                  pu1_src2  - Pointer to source 2                          */
796
/*                  pu1_dst   - Pointer to destination                       */
797
/*                  src_strd1 - stride for source 1                          */
798
/*                  src_strd2 - stride for source 2                          */
799
/*                  dst_strd2 - stride for destination                       */
800
/*                  log_wd    - number of bits to be rounded off             */
801
/*                  wt1       - weight value for source 1                    */
802
/*                  wt2       - weight value for source 2                    */
803
/*                  ofst1     - offset value for source 1                    */
804
/*                  ofst2     - offset value for source 2                    */
805
/*                  ht        - height of the block                          */
806
/*                  wd        - width of the block                           */
807
/*                                                                           */
808
/*  Issues        : None                                                     */
809
/*                                                                           */
810
/*  Revision History:                                                        */
811
/*                                                                           */
812
/*         DD MM YYYY   Author(s)       Changes                              */
813
/*         04 02 2015   Kaushik         Initial Version                      */
814
/*                      Senthoor                                             */
815
/*                                                                           */
816
/*****************************************************************************/
817
void ih264_weighted_bi_pred_luma_sse42(UWORD8 *pu1_src1,
818
                                       UWORD8 *pu1_src2,
819
                                       UWORD8 *pu1_dst,
820
                                       WORD32 src_strd1,
821
                                       WORD32 src_strd2,
822
                                       WORD32 dst_strd,
823
                                       WORD32 log_wd,
824
                                       WORD32 wt1,
825
                                       WORD32 wt2,
826
                                       WORD32 ofst1,
827
                                       WORD32 ofst2,
828
                                       WORD32 ht,
829
                                       WORD32 wd)
830
0
{
831
0
    __m128i y1_0_16x8b, y1_1_16x8b;
832
0
    __m128i y2_0_16x8b, y2_1_16x8b;
833
0
834
0
    __m128i wt1_8x16b, wt2_8x16b;
835
0
    __m128i ofst_8x16b, round_8x16b;
836
0
837
0
    WORD32 ofst;
838
0
    WORD32 round_val, shft;
839
0
840
0
    wt1 = (WORD16)(wt1 & 0xffff);
841
0
    wt2 = (WORD16)(wt2 & 0xffff);
842
0
    round_val = 1 << log_wd;
843
0
    shft = log_wd + 1;
844
0
    ofst1 = (WORD8)(ofst1 & 0xff);
845
0
    ofst2 = (WORD8)(ofst2 & 0xff);
846
0
    ofst = (ofst1 + ofst2 + 1) >> 1;
847
0
848
0
    wt1_8x16b = _mm_set1_epi16(wt1);
849
0
    wt2_8x16b = _mm_set1_epi16(wt2);
850
0
    round_8x16b = _mm_set1_epi16(round_val);
851
0
    ofst_8x16b = _mm_set1_epi16(ofst);
852
0
853
0
    if(wd == 4)
854
0
    {
855
0
        __m128i y1_2_16x8b, y1_3_16x8b;
856
0
        __m128i y2_2_16x8b, y2_3_16x8b;
857
0
858
0
        __m128i y1_0_8x16b, y1_2_8x16b;
859
0
        __m128i y2_0_8x16b, y2_2_8x16b;
860
0
861
0
        do
862
0
        {
863
0
            y1_0_16x8b = _mm_loadl_epi64((__m128i *)pu1_src1);
864
0
            y1_1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src1 + src_strd1));
865
0
            y1_2_16x8b = _mm_loadl_epi64(
866
0
                            (__m128i *)(pu1_src1 + (src_strd1 << 1)));
867
0
            y1_3_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src1 + src_strd1 * 3));
868
0
869
0
            y2_0_16x8b = _mm_loadl_epi64((__m128i *)pu1_src2);
870
0
            y2_1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src2 + src_strd2));
871
0
            y2_2_16x8b = _mm_loadl_epi64(
872
0
                            (__m128i *)(pu1_src2 + (src_strd2 << 1)));
873
0
            y2_3_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src2 + src_strd2 * 3));
874
0
875
0
            y1_0_16x8b = _mm_unpacklo_epi32(y1_0_16x8b, y1_1_16x8b);
876
0
            y1_2_16x8b = _mm_unpacklo_epi32(y1_2_16x8b, y1_3_16x8b);
877
0
            y2_0_16x8b = _mm_unpacklo_epi32(y2_0_16x8b, y2_1_16x8b);
878
0
            y2_2_16x8b = _mm_unpacklo_epi32(y2_2_16x8b, y2_3_16x8b);
879
0
880
0
            y1_0_8x16b = _mm_cvtepu8_epi16(y1_0_16x8b);
881
0
            y1_2_8x16b = _mm_cvtepu8_epi16(y1_2_16x8b);
882
0
            y2_0_8x16b = _mm_cvtepu8_epi16(y2_0_16x8b);
883
0
            y2_2_8x16b = _mm_cvtepu8_epi16(y2_2_16x8b);
884
0
885
0
            y1_0_8x16b = _mm_mullo_epi16(y1_0_8x16b, wt1_8x16b);
886
0
            y2_0_8x16b = _mm_mullo_epi16(y2_0_8x16b, wt2_8x16b);
887
0
            y1_2_8x16b = _mm_mullo_epi16(y1_2_8x16b, wt1_8x16b);
888
0
            y2_2_8x16b = _mm_mullo_epi16(y2_2_8x16b, wt2_8x16b);
889
0
890
0
            y1_0_8x16b = _mm_adds_epi16(y1_0_8x16b, y2_0_8x16b);
891
0
            y1_2_8x16b = _mm_adds_epi16(y1_2_8x16b, y2_2_8x16b);
892
0
893
0
            y1_0_8x16b = _mm_adds_epi16(round_8x16b, y1_0_8x16b);
894
0
            y1_2_8x16b = _mm_adds_epi16(round_8x16b, y1_2_8x16b);
895
0
896
0
            y1_0_8x16b = _mm_srai_epi16(y1_0_8x16b, shft);
897
0
            y1_2_8x16b = _mm_srai_epi16(y1_2_8x16b, shft);
898
0
899
0
            y1_0_8x16b = _mm_adds_epi16(ofst_8x16b, y1_0_8x16b);
900
0
            y1_2_8x16b = _mm_adds_epi16(ofst_8x16b, y1_2_8x16b);
901
0
902
0
            y1_0_16x8b = _mm_packus_epi16(y1_0_8x16b, y1_2_8x16b);
903
0
            y1_1_16x8b = _mm_srli_si128(y1_0_16x8b, 4);
904
0
            y1_2_16x8b = _mm_srli_si128(y1_0_16x8b, 8);
905
0
            y1_3_16x8b = _mm_srli_si128(y1_0_16x8b, 12);
906
0
907
0
            *((WORD32 *)(pu1_dst)) = _mm_cvtsi128_si32(y1_0_16x8b);
908
0
            *((WORD32 *)(pu1_dst + dst_strd)) = _mm_cvtsi128_si32(y1_1_16x8b);
909
0
            *((WORD32 *)(pu1_dst + (dst_strd << 1))) = _mm_cvtsi128_si32(y1_2_16x8b);
910
0
            *((WORD32 *)(pu1_dst + dst_strd * 3)) = _mm_cvtsi128_si32(y1_3_16x8b);
911
0
912
0
913
0
            ht -= 4;
914
0
            pu1_src1 += src_strd1 << 2;
915
0
            pu1_src2 += src_strd2 << 2;
916
0
            pu1_dst += dst_strd << 2;
917
0
        }
918
0
        while(ht > 0);
919
0
    }
920
0
    else if(wd == 8)
921
0
    {
922
0
        __m128i y1_2_16x8b, y1_3_16x8b;
923
0
        __m128i y2_2_16x8b, y2_3_16x8b;
924
0
925
0
        __m128i y1_0_8x16b, y1_1_8x16b, y1_2_8x16b, y1_3_8x16b;
926
0
        __m128i y2_0_8x16b, y2_1_8x16b, y2_2_8x16b, y2_3_8x16b;
927
0
928
0
        do
929
0
        {
930
0
            y1_0_16x8b = _mm_loadl_epi64((__m128i *)pu1_src1);
931
0
            y1_1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src1 + src_strd1));
932
0
            y1_2_16x8b = _mm_loadl_epi64(
933
0
                            (__m128i *)(pu1_src1 + (src_strd1 << 1)));
934
0
            y1_3_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src1 + src_strd1 * 3));
935
0
936
0
            y2_0_16x8b = _mm_loadl_epi64((__m128i *)pu1_src2);
937
0
            y2_1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src2 + src_strd2));
938
0
            y2_2_16x8b = _mm_loadl_epi64(
939
0
                            (__m128i *)(pu1_src2 + (src_strd2 << 1)));
940
0
            y2_3_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src2 + src_strd2 * 3));
941
0
942
0
            y1_0_8x16b = _mm_cvtepu8_epi16(y1_0_16x8b);
943
0
            y1_1_8x16b = _mm_cvtepu8_epi16(y1_1_16x8b);
944
0
            y1_2_8x16b = _mm_cvtepu8_epi16(y1_2_16x8b);
945
0
            y1_3_8x16b = _mm_cvtepu8_epi16(y1_3_16x8b);
946
0
947
0
            y2_0_8x16b = _mm_cvtepu8_epi16(y2_0_16x8b);
948
0
            y2_1_8x16b = _mm_cvtepu8_epi16(y2_1_16x8b);
949
0
            y2_2_8x16b = _mm_cvtepu8_epi16(y2_2_16x8b);
950
0
            y2_3_8x16b = _mm_cvtepu8_epi16(y2_3_16x8b);
951
0
952
0
            y1_0_8x16b = _mm_mullo_epi16(y1_0_8x16b, wt1_8x16b);
953
0
            y2_0_8x16b = _mm_mullo_epi16(y2_0_8x16b, wt2_8x16b);
954
0
            y1_1_8x16b = _mm_mullo_epi16(y1_1_8x16b, wt1_8x16b);
955
0
            y2_1_8x16b = _mm_mullo_epi16(y2_1_8x16b, wt2_8x16b);
956
0
957
0
            y1_2_8x16b = _mm_mullo_epi16(y1_2_8x16b, wt1_8x16b);
958
0
            y2_2_8x16b = _mm_mullo_epi16(y2_2_8x16b, wt2_8x16b);
959
0
            y1_3_8x16b = _mm_mullo_epi16(y1_3_8x16b, wt1_8x16b);
960
0
            y2_3_8x16b = _mm_mullo_epi16(y2_3_8x16b, wt2_8x16b);
961
0
962
0
            y1_0_8x16b = _mm_adds_epi16(y1_0_8x16b, y2_0_8x16b);
963
0
            y1_1_8x16b = _mm_adds_epi16(y1_1_8x16b, y2_1_8x16b);
964
0
            y1_2_8x16b = _mm_adds_epi16(y1_2_8x16b, y2_2_8x16b);
965
0
            y1_3_8x16b = _mm_adds_epi16(y1_3_8x16b, y2_3_8x16b);
966
0
967
0
            y1_0_8x16b = _mm_adds_epi16(round_8x16b, y1_0_8x16b);
968
0
            y1_1_8x16b = _mm_adds_epi16(round_8x16b, y1_1_8x16b);
969
0
            y1_2_8x16b = _mm_adds_epi16(round_8x16b, y1_2_8x16b);
970
0
            y1_3_8x16b = _mm_adds_epi16(round_8x16b, y1_3_8x16b);
971
0
972
0
            y1_0_8x16b = _mm_srai_epi16(y1_0_8x16b, shft);
973
0
            y1_1_8x16b = _mm_srai_epi16(y1_1_8x16b, shft);
974
0
            y1_2_8x16b = _mm_srai_epi16(y1_2_8x16b, shft);
975
0
            y1_3_8x16b = _mm_srai_epi16(y1_3_8x16b, shft);
976
0
977
0
            y1_0_8x16b = _mm_adds_epi16(ofst_8x16b, y1_0_8x16b);
978
0
            y1_1_8x16b = _mm_adds_epi16(ofst_8x16b, y1_1_8x16b);
979
0
            y1_2_8x16b = _mm_adds_epi16(ofst_8x16b, y1_2_8x16b);
980
0
            y1_3_8x16b = _mm_adds_epi16(ofst_8x16b, y1_3_8x16b);
981
0
982
0
            y1_0_16x8b = _mm_packus_epi16(y1_0_8x16b, y1_1_8x16b);
983
0
            y1_2_16x8b = _mm_packus_epi16(y1_2_8x16b, y1_3_8x16b);
984
0
            y1_1_16x8b = _mm_srli_si128(y1_0_16x8b, 8);
985
0
            y1_3_16x8b = _mm_srli_si128(y1_2_16x8b, 8);
986
0
987
0
            _mm_storel_epi64((__m128i *)pu1_dst, y1_0_16x8b);
988
0
            _mm_storel_epi64((__m128i *)(pu1_dst + dst_strd), y1_1_16x8b);
989
0
            _mm_storel_epi64((__m128i *)(pu1_dst + (dst_strd << 1)), y1_2_16x8b);
990
0
            _mm_storel_epi64((__m128i *)(pu1_dst + dst_strd * 3), y1_3_16x8b);
991
0
992
0
            ht -= 4;
993
0
            pu1_src1 += src_strd1 << 2;
994
0
            pu1_src2 += src_strd2 << 2;
995
0
            pu1_dst += dst_strd << 2;
996
0
        }
997
0
        while(ht > 0);
998
0
    }
999
0
    else // wd == 16
1000
0
    {
1001
0
        __m128i y1_0L_8x16b, y1_0H_8x16b, y1_1L_8x16b, y1_1H_8x16b;
1002
0
        __m128i y2_0L_8x16b, y2_0H_8x16b, y2_1L_8x16b, y2_1H_8x16b;
1003
0
1004
0
        __m128i zero_16x8b;
1005
0
        zero_16x8b = _mm_set1_epi8(0);
1006
0
1007
0
        do
1008
0
        {
1009
0
            y1_0_16x8b = _mm_loadu_si128((__m128i *)pu1_src1);
1010
0
            y1_1_16x8b = _mm_loadu_si128((__m128i *)(pu1_src1 + src_strd1));
1011
0
            y2_0_16x8b = _mm_loadu_si128((__m128i *)pu1_src2);
1012
0
            y2_1_16x8b = _mm_loadu_si128((__m128i *)(pu1_src2 + src_strd2));
1013
0
1014
0
            y1_0L_8x16b = _mm_cvtepu8_epi16(y1_0_16x8b);
1015
0
            y1_0H_8x16b = _mm_unpackhi_epi8(y1_0_16x8b, zero_16x8b);
1016
0
            y1_1L_8x16b = _mm_cvtepu8_epi16(y1_1_16x8b);
1017
0
            y1_1H_8x16b = _mm_unpackhi_epi8(y1_1_16x8b, zero_16x8b);
1018
0
1019
0
            y2_0L_8x16b = _mm_cvtepu8_epi16(y2_0_16x8b);
1020
0
            y2_0H_8x16b = _mm_unpackhi_epi8(y2_0_16x8b, zero_16x8b);
1021
0
            y2_1L_8x16b = _mm_cvtepu8_epi16(y2_1_16x8b);
1022
0
            y2_1H_8x16b = _mm_unpackhi_epi8(y2_1_16x8b, zero_16x8b);
1023
0
1024
0
            y1_0L_8x16b = _mm_mullo_epi16(y1_0L_8x16b, wt1_8x16b);
1025
0
            y1_0H_8x16b = _mm_mullo_epi16(y1_0H_8x16b, wt1_8x16b);
1026
0
            y1_1L_8x16b = _mm_mullo_epi16(y1_1L_8x16b, wt1_8x16b);
1027
0
            y1_1H_8x16b = _mm_mullo_epi16(y1_1H_8x16b, wt1_8x16b);
1028
0
1029
0
            y2_0L_8x16b = _mm_mullo_epi16(y2_0L_8x16b, wt2_8x16b);
1030
0
            y2_0H_8x16b = _mm_mullo_epi16(y2_0H_8x16b, wt2_8x16b);
1031
0
            y2_1L_8x16b = _mm_mullo_epi16(y2_1L_8x16b, wt2_8x16b);
1032
0
            y2_1H_8x16b = _mm_mullo_epi16(y2_1H_8x16b, wt2_8x16b);
1033
0
1034
0
            y1_0L_8x16b = _mm_adds_epi16(y1_0L_8x16b, y2_0L_8x16b);
1035
0
            y1_0H_8x16b = _mm_adds_epi16(y1_0H_8x16b, y2_0H_8x16b);
1036
0
            y1_1L_8x16b = _mm_adds_epi16(y1_1L_8x16b, y2_1L_8x16b);
1037
0
            y1_1H_8x16b = _mm_adds_epi16(y1_1H_8x16b, y2_1H_8x16b);
1038
0
1039
0
            y1_0L_8x16b = _mm_adds_epi16(round_8x16b, y1_0L_8x16b);
1040
0
            y1_0H_8x16b = _mm_adds_epi16(round_8x16b, y1_0H_8x16b);
1041
0
            y1_1L_8x16b = _mm_adds_epi16(round_8x16b, y1_1L_8x16b);
1042
0
            y1_1H_8x16b = _mm_adds_epi16(round_8x16b, y1_1H_8x16b);
1043
0
1044
0
            y1_0L_8x16b = _mm_srai_epi16(y1_0L_8x16b, shft);
1045
0
            y1_0H_8x16b = _mm_srai_epi16(y1_0H_8x16b, shft);
1046
0
            y1_1L_8x16b = _mm_srai_epi16(y1_1L_8x16b, shft);
1047
0
            y1_1H_8x16b = _mm_srai_epi16(y1_1H_8x16b, shft);
1048
0
1049
0
            y1_0L_8x16b = _mm_adds_epi16(ofst_8x16b, y1_0L_8x16b);
1050
0
            y1_0H_8x16b = _mm_adds_epi16(ofst_8x16b, y1_0H_8x16b);
1051
0
            y1_1L_8x16b = _mm_adds_epi16(ofst_8x16b, y1_1L_8x16b);
1052
0
            y1_1H_8x16b = _mm_adds_epi16(ofst_8x16b, y1_1H_8x16b);
1053
0
1054
0
            y1_0_16x8b = _mm_packus_epi16(y1_0L_8x16b, y1_0H_8x16b);
1055
0
            y1_1_16x8b = _mm_packus_epi16(y1_1L_8x16b, y1_1H_8x16b);
1056
0
1057
0
            _mm_storeu_si128((__m128i *)pu1_dst, y1_0_16x8b);
1058
0
            _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), y1_1_16x8b);
1059
0
1060
0
            ht -= 2;
1061
0
            pu1_src1 += src_strd1 << 1;
1062
0
            pu1_src2 += src_strd2 << 1;
1063
0
            pu1_dst += dst_strd << 1;
1064
0
        }
1065
0
        while(ht > 0);
1066
0
    }
1067
0
}
1068
1069
/*****************************************************************************/
1070
/*                                                                           */
1071
/*  Function Name : ih264_weighted_bi_pred_chroma_sse42                      */
1072
/*                                                                           */
1073
/*  Description   : This function performs the weighted biprediction as      */
1074
/*                  described in sec 8.4.2.3.2 titled "Weighted sample       */
1075
/*                  prediction process" for chroma. The function gets two    */
1076
/*                  ht x wd blocks, weights them, adds them, rounds off the  */
1077
/*                  sum, offsets it, saturates it to unsigned 8-bit and      */
1078
/*                  stores it in the destination block. (ht,wd) can be       */
1079
/*                  (2,2), (4,2), (2,4), (4,4), (8,4), (4,8) or (8,8).       */
1080
/*                                                                           */
1081
/*  Inputs        : pu1_src1  - Pointer to source 1                          */
1082
/*                  pu1_src2  - Pointer to source 2                          */
1083
/*                  pu1_dst   - Pointer to destination                       */
1084
/*                  src_strd1 - stride for source 1                          */
1085
/*                  src_strd2 - stride for source 2                          */
1086
/*                  dst_strd2 - stride for destination                       */
1087
/*                  log_wd    - number of bits to be rounded off             */
1088
/*                  wt1       - weight values for u and v in source 1        */
1089
/*                  wt2       - weight values for u and v in source 2        */
1090
/*                  ofst1     - offset value for u and v in source 1         */
1091
/*                  ofst2     - offset value for u and v in source 2         */
1092
/*                  ht        - height of the block                          */
1093
/*                  wd        - width of the block                           */
1094
/*                                                                           */
1095
/*  Issues        : None                                                     */
1096
/*                                                                           */
1097
/*  Revision History:                                                        */
1098
/*                                                                           */
1099
/*         DD MM YYYY   Author(s)       Changes                              */
1100
/*         04 02 2015   Kaushik         Initial Version                      */
1101
/*                      Senthoor                                             */
1102
/*                                                                           */
1103
/*****************************************************************************/
1104
void ih264_weighted_bi_pred_chroma_sse42(UWORD8 *pu1_src1,
1105
                                         UWORD8 *pu1_src2,
1106
                                         UWORD8 *pu1_dst,
1107
                                         WORD32 src_strd1,
1108
                                         WORD32 src_strd2,
1109
                                         WORD32 dst_strd,
1110
                                         WORD32 log_wd,
1111
                                         WORD32 wt1,
1112
                                         WORD32 wt2,
1113
                                         WORD32 ofst1,
1114
                                         WORD32 ofst2,
1115
                                         WORD32 ht,
1116
                                         WORD32 wd)
1117
0
{
1118
0
    __m128i y1_0_16x8b, y1_1_16x8b;
1119
0
    __m128i y2_0_16x8b, y2_1_16x8b;
1120
0
1121
0
    __m128i wt1_8x16b, wt2_8x16b;
1122
0
    __m128i ofst_8x16b, round_8x16b;
1123
0
1124
0
    WORD32 ofst1_u, ofst2_u, ofst_u;
1125
0
    WORD32 ofst1_v, ofst2_v, ofst_v;
1126
0
    WORD32 round_val, shft, ofst_val;
1127
0
1128
0
    round_val = 1 << log_wd;
1129
0
    shft = log_wd + 1;
1130
0
1131
0
    ofst1_u = (WORD8)(ofst1 & 0xff);
1132
0
    ofst1_v = (WORD8)(ofst1 >> 8);
1133
0
    ofst2_u = (WORD8)(ofst2 & 0xff);
1134
0
    ofst2_v = (WORD8)(ofst2 >> 8);
1135
0
1136
0
    wt1_8x16b = _mm_set1_epi32(wt1);
1137
0
    wt2_8x16b = _mm_set1_epi32(wt2);
1138
0
1139
0
    ofst_u = (ofst1_u + ofst2_u + 1) >> 1;
1140
0
    ofst_v = (ofst1_v + ofst2_v + 1) >> 1;
1141
0
    ofst_val = (ofst_u & 0xffff) | (ofst_v << 16);
1142
0
1143
0
    round_8x16b = _mm_set1_epi16(round_val);
1144
0
    ofst_8x16b = _mm_set1_epi32(ofst_val);
1145
0
1146
0
    if(wd == 2)
1147
0
    {
1148
0
        __m128i y1_0_8x16b, y2_0_8x16b;
1149
0
1150
0
        do
1151
0
        {
1152
0
            y1_0_16x8b = _mm_loadl_epi64((__m128i *)pu1_src1);
1153
0
            y1_1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src1 + src_strd1));
1154
0
1155
0
            y2_0_16x8b = _mm_loadl_epi64((__m128i *)pu1_src2);
1156
0
            y2_1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src2 + src_strd2));
1157
0
1158
0
            y1_0_16x8b = _mm_unpacklo_epi32(y1_0_16x8b, y1_1_16x8b);
1159
0
            y2_0_16x8b = _mm_unpacklo_epi32(y2_0_16x8b, y2_1_16x8b);
1160
0
1161
0
            y1_0_8x16b = _mm_cvtepu8_epi16(y1_0_16x8b);
1162
0
            y2_0_8x16b = _mm_cvtepu8_epi16(y2_0_16x8b);
1163
0
1164
0
            y1_0_8x16b = _mm_mullo_epi16(y1_0_8x16b, wt1_8x16b);
1165
0
            y2_0_8x16b = _mm_mullo_epi16(y2_0_8x16b, wt2_8x16b);
1166
0
1167
0
            y1_0_8x16b = _mm_adds_epi16(y1_0_8x16b, y2_0_8x16b);
1168
0
            y1_0_8x16b = _mm_adds_epi16(round_8x16b, y1_0_8x16b);
1169
0
1170
0
            y1_0_8x16b = _mm_srai_epi16(y1_0_8x16b, shft);
1171
0
            y1_0_8x16b = _mm_adds_epi16(ofst_8x16b, y1_0_8x16b);
1172
0
1173
0
            y1_0_16x8b = _mm_packus_epi16(y1_0_8x16b, y1_0_8x16b);
1174
0
            y1_1_16x8b = _mm_srli_si128(y1_0_16x8b, 4);
1175
0
1176
0
            *((WORD32 *)(pu1_dst)) = _mm_cvtsi128_si32(y1_0_16x8b);
1177
0
            *((WORD32 *)(pu1_dst + dst_strd)) = _mm_cvtsi128_si32(y1_1_16x8b);
1178
0
1179
0
            ht -= 2;
1180
0
            pu1_src1 += src_strd1 << 1;
1181
0
            pu1_src2 += src_strd2 << 1;
1182
0
            pu1_dst += dst_strd << 1;
1183
0
        }
1184
0
        while(ht > 0);
1185
0
    }
1186
0
    else if(wd == 4)
1187
0
    {
1188
0
        __m128i y1_0_8x16b, y1_1_8x16b;
1189
0
        __m128i y2_0_8x16b, y2_1_8x16b;
1190
0
1191
0
        do
1192
0
        {
1193
0
            y1_0_16x8b = _mm_loadl_epi64((__m128i *)pu1_src1);
1194
0
            y1_1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src1 + src_strd1));
1195
0
1196
0
            y2_0_16x8b = _mm_loadl_epi64((__m128i *)pu1_src2);
1197
0
            y2_1_16x8b = _mm_loadl_epi64((__m128i *)(pu1_src2 + src_strd2));
1198
0
1199
0
            y1_0_8x16b = _mm_cvtepu8_epi16(y1_0_16x8b);
1200
0
            y1_1_8x16b = _mm_cvtepu8_epi16(y1_1_16x8b);
1201
0
1202
0
            y2_0_8x16b = _mm_cvtepu8_epi16(y2_0_16x8b);
1203
0
            y2_1_8x16b = _mm_cvtepu8_epi16(y2_1_16x8b);
1204
0
1205
0
            y1_0_8x16b = _mm_mullo_epi16(y1_0_8x16b, wt1_8x16b);
1206
0
            y2_0_8x16b = _mm_mullo_epi16(y2_0_8x16b, wt2_8x16b);
1207
0
            y1_1_8x16b = _mm_mullo_epi16(y1_1_8x16b, wt1_8x16b);
1208
0
            y2_1_8x16b = _mm_mullo_epi16(y2_1_8x16b, wt2_8x16b);
1209
0
1210
0
            y1_0_8x16b = _mm_adds_epi16(y1_0_8x16b, y2_0_8x16b);
1211
0
            y1_1_8x16b = _mm_adds_epi16(y1_1_8x16b, y2_1_8x16b);
1212
0
1213
0
            y1_0_8x16b = _mm_adds_epi16(round_8x16b, y1_0_8x16b);
1214
0
            y1_1_8x16b = _mm_adds_epi16(round_8x16b, y1_1_8x16b);
1215
0
1216
0
            y1_0_8x16b = _mm_srai_epi16(y1_0_8x16b, shft);
1217
0
            y1_1_8x16b = _mm_srai_epi16(y1_1_8x16b, shft);
1218
0
1219
0
            y1_0_8x16b = _mm_adds_epi16(ofst_8x16b, y1_0_8x16b);
1220
0
            y1_1_8x16b = _mm_adds_epi16(ofst_8x16b, y1_1_8x16b);
1221
0
1222
0
            y1_0_16x8b = _mm_packus_epi16(y1_0_8x16b, y1_1_8x16b);
1223
0
            y1_1_16x8b = _mm_srli_si128(y1_0_16x8b, 8);
1224
0
1225
0
            _mm_storel_epi64((__m128i *)pu1_dst, y1_0_16x8b);
1226
0
            _mm_storel_epi64((__m128i *)(pu1_dst + dst_strd), y1_1_16x8b);
1227
0
1228
0
            ht -= 2;
1229
0
            pu1_src1 += src_strd1 << 1;
1230
0
            pu1_src2 += src_strd2 << 1;
1231
0
            pu1_dst += dst_strd << 1;
1232
0
        }
1233
0
        while(ht > 0);
1234
0
    }
1235
0
    else // wd == 8
1236
0
    {
1237
0
        __m128i y1_0L_8x16b, y1_0H_8x16b, y1_1L_8x16b, y1_1H_8x16b;
1238
0
        __m128i y2_0L_8x16b, y2_0H_8x16b, y2_1L_8x16b, y2_1H_8x16b;
1239
0
1240
0
        __m128i zero_16x8b;
1241
0
        zero_16x8b = _mm_set1_epi8(0);
1242
0
1243
0
        do
1244
0
        {
1245
0
            y1_0_16x8b = _mm_loadu_si128((__m128i *)pu1_src1);
1246
0
            y1_1_16x8b = _mm_loadu_si128((__m128i *)(pu1_src1 + src_strd1));
1247
0
            y2_0_16x8b = _mm_loadu_si128((__m128i *)pu1_src2);
1248
0
            y2_1_16x8b = _mm_loadu_si128((__m128i *)(pu1_src2 + src_strd2));
1249
0
1250
0
            y1_0L_8x16b = _mm_cvtepu8_epi16(y1_0_16x8b);
1251
0
            y1_0H_8x16b = _mm_unpackhi_epi8(y1_0_16x8b, zero_16x8b);
1252
0
            y1_1L_8x16b = _mm_cvtepu8_epi16(y1_1_16x8b);
1253
0
            y1_1H_8x16b = _mm_unpackhi_epi8(y1_1_16x8b, zero_16x8b);
1254
0
1255
0
            y2_0L_8x16b = _mm_cvtepu8_epi16(y2_0_16x8b);
1256
0
            y2_0H_8x16b = _mm_unpackhi_epi8(y2_0_16x8b, zero_16x8b);
1257
0
            y2_1L_8x16b = _mm_cvtepu8_epi16(y2_1_16x8b);
1258
0
            y2_1H_8x16b = _mm_unpackhi_epi8(y2_1_16x8b, zero_16x8b);
1259
0
1260
0
            y1_0L_8x16b = _mm_mullo_epi16(y1_0L_8x16b, wt1_8x16b);
1261
0
            y1_0H_8x16b = _mm_mullo_epi16(y1_0H_8x16b, wt1_8x16b);
1262
0
            y1_1L_8x16b = _mm_mullo_epi16(y1_1L_8x16b, wt1_8x16b);
1263
0
            y1_1H_8x16b = _mm_mullo_epi16(y1_1H_8x16b, wt1_8x16b);
1264
0
1265
0
            y2_0L_8x16b = _mm_mullo_epi16(y2_0L_8x16b, wt2_8x16b);
1266
0
            y2_0H_8x16b = _mm_mullo_epi16(y2_0H_8x16b, wt2_8x16b);
1267
0
            y2_1L_8x16b = _mm_mullo_epi16(y2_1L_8x16b, wt2_8x16b);
1268
0
            y2_1H_8x16b = _mm_mullo_epi16(y2_1H_8x16b, wt2_8x16b);
1269
0
1270
0
            y1_0L_8x16b = _mm_adds_epi16(y1_0L_8x16b, y2_0L_8x16b);
1271
0
            y1_0H_8x16b = _mm_adds_epi16(y1_0H_8x16b, y2_0H_8x16b);
1272
0
            y1_1L_8x16b = _mm_adds_epi16(y1_1L_8x16b, y2_1L_8x16b);
1273
0
            y1_1H_8x16b = _mm_adds_epi16(y1_1H_8x16b, y2_1H_8x16b);
1274
0
1275
0
            y1_0L_8x16b = _mm_adds_epi16(round_8x16b, y1_0L_8x16b);
1276
0
            y1_0H_8x16b = _mm_adds_epi16(round_8x16b, y1_0H_8x16b);
1277
0
            y1_1L_8x16b = _mm_adds_epi16(round_8x16b, y1_1L_8x16b);
1278
0
            y1_1H_8x16b = _mm_adds_epi16(round_8x16b, y1_1H_8x16b);
1279
0
1280
0
            y1_0L_8x16b = _mm_srai_epi16(y1_0L_8x16b, shft);
1281
0
            y1_0H_8x16b = _mm_srai_epi16(y1_0H_8x16b, shft);
1282
0
            y1_1L_8x16b = _mm_srai_epi16(y1_1L_8x16b, shft);
1283
0
            y1_1H_8x16b = _mm_srai_epi16(y1_1H_8x16b, shft);
1284
0
1285
0
            y1_0L_8x16b = _mm_adds_epi16(ofst_8x16b, y1_0L_8x16b);
1286
0
            y1_0H_8x16b = _mm_adds_epi16(ofst_8x16b, y1_0H_8x16b);
1287
0
            y1_1L_8x16b = _mm_adds_epi16(ofst_8x16b, y1_1L_8x16b);
1288
0
            y1_1H_8x16b = _mm_adds_epi16(ofst_8x16b, y1_1H_8x16b);
1289
0
1290
0
            y1_0_16x8b = _mm_packus_epi16(y1_0L_8x16b, y1_0H_8x16b);
1291
0
            y1_1_16x8b = _mm_packus_epi16(y1_1L_8x16b, y1_1H_8x16b);
1292
0
1293
0
            _mm_storeu_si128((__m128i *)pu1_dst, y1_0_16x8b);
1294
0
            _mm_storeu_si128((__m128i *)(pu1_dst + dst_strd), y1_1_16x8b);
1295
0
1296
0
            ht -= 2;
1297
0
            pu1_src1 += src_strd1 << 1;
1298
0
            pu1_src2 += src_strd2 << 1;
1299
0
            pu1_dst += dst_strd << 1;
1300
0
        }
1301
0
        while(ht > 0);
1302
0
    }
1303
0
}
/proc/self/cwd/external/libavc/decoder/ih264d_api.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
21
/*****************************************************************************/
22
/*                                                                           */
23
/*  File Name         : ih264d_api.c                                         */
24
/*                                                                           */
25
/*  Description       : Has all  API related functions                       */
26
/*                                                                           */
27
/*                                                                           */
28
/*  List of Functions : api_check_struct_sanity                              */
29
/*          ih264d_set_processor                                             */
30
/*          ih264d_create                                                    */
31
/*          ih264d_delete                                                    */
32
/*          ih264d_init                                                      */
33
/*          ih264d_map_error                                                 */
34
/*          ih264d_video_decode                                              */
35
/*          ih264d_get_version                                               */
36
/*          ih264d_get_display_frame                                         */
37
/*          ih264d_set_display_frame                                         */
38
/*          ih264d_set_flush_mode                                            */
39
/*          ih264d_get_status                                                */
40
/*          ih264d_get_buf_info                                              */
41
/*          ih264d_set_params                                                */
42
/*          ih264d_set_default_params                                        */
43
/*          ih264d_reset                                                     */
44
/*          ih264d_ctl                                                       */
45
/*          ih264d_rel_display_frame                                         */
46
/*          ih264d_set_degrade                                               */
47
/*          ih264d_get_frame_dimensions                                      */
48
/*          ih264d_set_num_cores                                             */
49
/*          ih264d_fill_output_struct_from_context                           */
50
/*          ih264d_api_function                                              */
51
/*                                                                           */
52
/*  Issues / Problems : None                                                 */
53
/*                                                                           */
54
/*  Revision History  :                                                      */
55
/*                                                                           */
56
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
57
/*         14 10 2008   100356(SKV)     Draft                                */
58
/*                                                                           */
59
/*****************************************************************************/
60
#include "ih264_typedefs.h"
61
#include "ih264_macros.h"
62
#include "ih264_platform_macros.h"
63
#include "ih264d_tables.h"
64
#include "iv.h"
65
#include "ivd.h"
66
#include "ih264d.h"
67
#include "ih264d_defs.h"
68
69
#include <string.h>
70
#include <limits.h>
71
#include <stddef.h>
72
73
#include "ih264d_inter_pred.h"
74
75
#include "ih264d_structs.h"
76
#include "ih264d_nal.h"
77
#include "ih264d_error_handler.h"
78
79
#include "ih264d_defs.h"
80
81
#include "ithread.h"
82
#include "ih264d_parse_slice.h"
83
#include "ih264d_function_selector.h"
84
#include "ih264_error.h"
85
#include "ih264_disp_mgr.h"
86
#include "ih264_buf_mgr.h"
87
#include "ih264d_deblocking.h"
88
#include "ih264d_parse_cavlc.h"
89
#include "ih264d_parse_cabac.h"
90
#include "ih264d_utils.h"
91
#include "ih264d_format_conv.h"
92
#include "ih264d_parse_headers.h"
93
#include "ih264d_thread_compute_bs.h"
94
#include <assert.h>
95
96
97
/*********************/
98
/* Codec Versioning  */
99
/*********************/
100
//Move this to where it is used
101
#define CODEC_NAME              "H264VDEC"
102
#define CODEC_RELEASE_TYPE      "production"
103
#define CODEC_RELEASE_VER       "05.00"
104
#define CODEC_VENDOR            "ITTIAM"
105
2
#define MAXVERSION_STRLEN       511
106
#ifdef __ANDROID__
107
#define VERSION(version_string, codec_name, codec_release_type, codec_release_ver, codec_vendor)    \
108
1
    snprintf(version_string, MAXVERSION_STRLEN,                                                     \
109
1
             "@(#)Id:%s_%s Ver:%s Released by %s",                                                  \
110
1
             codec_name, codec_release_type, codec_release_ver, codec_vendor)
111
#else
112
#define VERSION(version_string, codec_name, codec_release_type, codec_release_ver, codec_vendor)    \
113
    snprintf(version_string, MAXVERSION_STRLEN,                                                     \
114
             "@(#)Id:%s_%s Ver:%s Released by %s Build: %s @ %s",                                   \
115
             codec_name, codec_release_type, codec_release_ver, codec_vendor, __DATE__, __TIME__)
116
#endif
117
118
119
0
#define MIN_IN_BUFS             1
120
11
#define MIN_OUT_BUFS_420        3
121
0
#define MIN_OUT_BUFS_422ILE     1
122
0
#define MIN_OUT_BUFS_RGB565     1
123
0
#define MIN_OUT_BUFS_420SP      2
124
125
#define NUM_FRAMES_LIMIT_ENABLED 0
126
127
#if NUM_FRAMES_LIMIT_ENABLED
128
#define NUM_FRAMES_LIMIT 10000
129
#else
130
13
#define NUM_FRAMES_LIMIT 0x7FFFFFFF
131
#endif
132
133
134
UWORD32 ih264d_get_extra_mem_external(UWORD32 width, UWORD32 height);
135
WORD32 ih264d_get_frame_dimensions(iv_obj_t *dec_hdl,
136
                                   void *pv_api_ip,
137
                                   void *pv_api_op);
138
WORD32 ih264d_get_vui_params(iv_obj_t *dec_hdl,
139
                             void *pv_api_ip,
140
                             void *pv_api_op);
141
142
WORD32 ih264d_set_num_cores(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op);
143
144
WORD32 ih264d_deblock_display(dec_struct_t *ps_dec);
145
146
void ih264d_signal_decode_thread(dec_struct_t *ps_dec);
147
148
void ih264d_signal_bs_deblk_thread(dec_struct_t *ps_dec);
149
void ih264d_decode_picture_thread(dec_struct_t *ps_dec);
150
151
WORD32 ih264d_set_degrade(iv_obj_t *ps_codec_obj,
152
                          void *pv_api_ip,
153
                          void *pv_api_op);
154
155
void ih264d_fill_output_struct_from_context(dec_struct_t *ps_dec,
156
                                            ivd_video_decode_op_t *ps_dec_op);
157
158
static IV_API_CALL_STATUS_T api_check_struct_sanity(iv_obj_t *ps_handle,
159
                                                    void *pv_api_ip,
160
                                                    void *pv_api_op)
161
33
{
162
33
    IVD_API_COMMAND_TYPE_T e_cmd;
163
33
    UWORD32 *pu4_api_ip;
164
33
    UWORD32 *pu4_api_op;
165
33
    UWORD32 i, j;
166
33
167
33
    if(NULL == pv_api_op)
168
0
        return (IV_FAIL);
169
33
170
33
    if(NULL == pv_api_ip)
171
0
        return (IV_FAIL);
172
33
173
33
    pu4_api_ip = (UWORD32 *)pv_api_ip;
174
33
    pu4_api_op = (UWORD32 *)pv_api_op;
175
33
    e_cmd = *(pu4_api_ip + 1);
176
33
177
33
    /* error checks on handle */
178
33
    switch((WORD32)e_cmd)
179
33
    {
180
33
        case IVD_CMD_CREATE:
181
1
            break;
182
33
183
33
        case IVD_CMD_REL_DISPLAY_FRAME:
184
32
        case IVD_CMD_SET_DISPLAY_FRAME:
185
32
        case IVD_CMD_GET_DISPLAY_FRAME:
186
32
        case IVD_CMD_VIDEO_DECODE:
187
32
        case IVD_CMD_DELETE:
188
32
        case IVD_CMD_VIDEO_CTL:
189
32
            if(ps_handle == NULL)
190
32
            {
191
0
                *(pu4_api_op + 1) |= 1 << IVD_UNSUPPORTEDPARAM;
192
0
                *(pu4_api_op + 1) |= IVD_HANDLE_NULL;
193
0
                return IV_FAIL;
194
0
            }
195
32
196
32
            if(ps_handle->u4_size != sizeof(iv_obj_t))
197
0
            {
198
0
                *(pu4_api_op + 1) |= 1 << IVD_UNSUPPORTEDPARAM;
199
0
                *(pu4_api_op + 1) |= IVD_HANDLE_STRUCT_SIZE_INCORRECT;
200
0
                return IV_FAIL;
201
0
            }
202
32
203
32
            if(ps_handle->pv_fxns != ih264d_api_function)
204
0
            {
205
0
                *(pu4_api_op + 1) |= 1 << IVD_UNSUPPORTEDPARAM;
206
0
                *(pu4_api_op + 1) |= IVD_INVALID_HANDLE_NULL;
207
0
                return IV_FAIL;
208
0
            }
209
32
210
32
            if(ps_handle->pv_codec_handle == NULL)
211
32
            {
212
0
                *(pu4_api_op + 1) |= 1 << IVD_UNSUPPORTEDPARAM;
213
0
                *(pu4_api_op + 1) |= IVD_INVALID_HANDLE_NULL;
214
0
                return IV_FAIL;
215
0
            }
216
32
            break;
217
32
        default:
218
0
            *(pu4_api_op + 1) |= 1 << IVD_UNSUPPORTEDPARAM;
219
0
            *(pu4_api_op + 1) |= IVD_INVALID_API_CMD;
220
0
            return IV_FAIL;
221
33
    }
222
33
223
33
    switch((WORD32)e_cmd)
224
33
    {
225
33
        case IVD_CMD_CREATE:
226
1
        {
227
1
            ih264d_create_ip_t *ps_ip = (ih264d_create_ip_t *)pv_api_ip;
228
1
            ih264d_create_op_t *ps_op = (ih264d_create_op_t *)pv_api_op;
229
1
230
1
231
1
            ps_op->s_ivd_create_op_t.u4_error_code = 0;
232
1
233
1
            if((ps_ip->s_ivd_create_ip_t.u4_size > sizeof(ih264d_create_ip_t))
234
1
                            || (ps_ip->s_ivd_create_ip_t.u4_size
235
1
                                            < sizeof(ivd_create_ip_t)))
236
0
            {
237
0
                ps_op->s_ivd_create_op_t.u4_error_code |= 1
238
0
                                << IVD_UNSUPPORTEDPARAM;
239
0
                ps_op->s_ivd_create_op_t.u4_error_code |=
240
0
                                IVD_IP_API_STRUCT_SIZE_INCORRECT;
241
0
                H264_DEC_DEBUG_PRINT("\n");
242
0
                return (IV_FAIL);
243
0
            }
244
1
245
1
            if((ps_op->s_ivd_create_op_t.u4_size != sizeof(ih264d_create_op_t))
246
1
                            && (ps_op->s_ivd_create_op_t.u4_size
247
0
                                            != sizeof(ivd_create_op_t)))
248
0
            {
249
0
                ps_op->s_ivd_create_op_t.u4_error_code |= 1
250
0
                                << IVD_UNSUPPORTEDPARAM;
251
0
                ps_op->s_ivd_create_op_t.u4_error_code |=
252
0
                                IVD_OP_API_STRUCT_SIZE_INCORRECT;
253
0
                H264_DEC_DEBUG_PRINT("\n");
254
0
                return (IV_FAIL);
255
0
            }
256
1
257
1
258
1
            if((ps_ip->s_ivd_create_ip_t.e_output_format != IV_YUV_420P)
259
1
                            && (ps_ip->s_ivd_create_ip_t.e_output_format
260
0
                                            != IV_YUV_422ILE)
261
1
                            && (ps_ip->s_ivd_create_ip_t.e_output_format
262
0
                                            != IV_RGB_565)
263
1
                            && (ps_ip->s_ivd_create_ip_t.e_output_format
264
0
                                            != IV_YUV_420SP_UV)
265
1
                            && (ps_ip->s_ivd_create_ip_t.e_output_format
266
0
                                            != IV_YUV_420SP_VU))
267
0
            {
268
0
                ps_op->s_ivd_create_op_t.u4_error_code |= 1
269
0
                                << IVD_UNSUPPORTEDPARAM;
270
0
                ps_op->s_ivd_create_op_t.u4_error_code |=
271
0
                                IVD_INIT_DEC_COL_FMT_NOT_SUPPORTED;
272
0
                H264_DEC_DEBUG_PRINT("\n");
273
0
                return (IV_FAIL);
274
0
            }
275
1
276
1
        }
277
1
            break;
278
1
279
1
        case IVD_CMD_GET_DISPLAY_FRAME:
280
0
        {
281
0
            ih264d_get_display_frame_ip_t *ps_ip =
282
0
                            (ih264d_get_display_frame_ip_t *)pv_api_ip;
283
0
            ih264d_get_display_frame_op_t *ps_op =
284
0
                            (ih264d_get_display_frame_op_t *)pv_api_op;
285
0
286
0
            ps_op->s_ivd_get_display_frame_op_t.u4_error_code = 0;
287
0
288
0
            if((ps_ip->s_ivd_get_display_frame_ip_t.u4_size
289
0
                            != sizeof(ih264d_get_display_frame_ip_t))
290
0
                            && (ps_ip->s_ivd_get_display_frame_ip_t.u4_size
291
0
                                            != sizeof(ivd_get_display_frame_ip_t)))
292
0
            {
293
0
                ps_op->s_ivd_get_display_frame_op_t.u4_error_code |= 1
294
0
                                << IVD_UNSUPPORTEDPARAM;
295
0
                ps_op->s_ivd_get_display_frame_op_t.u4_error_code |=
296
0
                                IVD_IP_API_STRUCT_SIZE_INCORRECT;
297
0
                return (IV_FAIL);
298
0
            }
299
0
300
0
            if((ps_op->s_ivd_get_display_frame_op_t.u4_size
301
0
                            != sizeof(ih264d_get_display_frame_op_t))
302
0
                            && (ps_op->s_ivd_get_display_frame_op_t.u4_size
303
0
                                            != sizeof(ivd_get_display_frame_op_t)))
304
0
            {
305
0
                ps_op->s_ivd_get_display_frame_op_t.u4_error_code |= 1
306
0
                                << IVD_UNSUPPORTEDPARAM;
307
0
                ps_op->s_ivd_get_display_frame_op_t.u4_error_code |=
308
0
                                IVD_OP_API_STRUCT_SIZE_INCORRECT;
309
0
                return (IV_FAIL);
310
0
            }
311
0
        }
312
0
            break;
313
0
314
0
        case IVD_CMD_REL_DISPLAY_FRAME:
315
0
        {
316
0
            ih264d_rel_display_frame_ip_t *ps_ip =
317
0
                            (ih264d_rel_display_frame_ip_t *)pv_api_ip;
318
0
            ih264d_rel_display_frame_op_t *ps_op =
319
0
                            (ih264d_rel_display_frame_op_t *)pv_api_op;
320
0
321
0
            ps_op->s_ivd_rel_display_frame_op_t.u4_error_code = 0;
322
0
323
0
            if((ps_ip->s_ivd_rel_display_frame_ip_t.u4_size
324
0
                            != sizeof(ih264d_rel_display_frame_ip_t))
325
0
                            && (ps_ip->s_ivd_rel_display_frame_ip_t.u4_size
326
0
                                            != sizeof(ivd_rel_display_frame_ip_t)))
327
0
            {
328
0
                ps_op->s_ivd_rel_display_frame_op_t.u4_error_code |= 1
329
0
                                << IVD_UNSUPPORTEDPARAM;
330
0
                ps_op->s_ivd_rel_display_frame_op_t.u4_error_code |=
331
0
                                IVD_IP_API_STRUCT_SIZE_INCORRECT;
332
0
                return (IV_FAIL);
333
0
            }
334
0
335
0
            if((ps_op->s_ivd_rel_display_frame_op_t.u4_size
336
0
                            != sizeof(ih264d_rel_display_frame_op_t))
337
0
                            && (ps_op->s_ivd_rel_display_frame_op_t.u4_size
338
0
                                            != sizeof(ivd_rel_display_frame_op_t)))
339
0
            {
340
0
                ps_op->s_ivd_rel_display_frame_op_t.u4_error_code |= 1
341
0
                                << IVD_UNSUPPORTEDPARAM;
342
0
                ps_op->s_ivd_rel_display_frame_op_t.u4_error_code |=
343
0
                                IVD_OP_API_STRUCT_SIZE_INCORRECT;
344
0
                return (IV_FAIL);
345
0
            }
346
0
347
0
        }
348
0
            break;
349
0
350
0
        case IVD_CMD_SET_DISPLAY_FRAME:
351
0
        {
352
0
            ih264d_set_display_frame_ip_t *ps_ip =
353
0
                            (ih264d_set_display_frame_ip_t *)pv_api_ip;
354
0
            ih264d_set_display_frame_op_t *ps_op =
355
0
                            (ih264d_set_display_frame_op_t *)pv_api_op;
356
0
            UWORD32 j;
357
0
358
0
            ps_op->s_ivd_set_display_frame_op_t.u4_error_code = 0;
359
0
360
0
            if((ps_ip->s_ivd_set_display_frame_ip_t.u4_size
361
0
                            != sizeof(ih264d_set_display_frame_ip_t))
362
0
                            && (ps_ip->s_ivd_set_display_frame_ip_t.u4_size
363
0
                                            != sizeof(ivd_set_display_frame_ip_t)))
364
0
            {
365
0
                ps_op->s_ivd_set_display_frame_op_t.u4_error_code |= 1
366
0
                                << IVD_UNSUPPORTEDPARAM;
367
0
                ps_op->s_ivd_set_display_frame_op_t.u4_error_code |=
368
0
                                IVD_IP_API_STRUCT_SIZE_INCORRECT;
369
0
                return (IV_FAIL);
370
0
            }
371
0
372
0
            if((ps_op->s_ivd_set_display_frame_op_t.u4_size
373
0
                            != sizeof(ih264d_set_display_frame_op_t))
374
0
                            && (ps_op->s_ivd_set_display_frame_op_t.u4_size
375
0
                                            != sizeof(ivd_set_display_frame_op_t)))
376
0
            {
377
0
                ps_op->s_ivd_set_display_frame_op_t.u4_error_code |= 1
378
0
                                << IVD_UNSUPPORTEDPARAM;
379
0
                ps_op->s_ivd_set_display_frame_op_t.u4_error_code |=
380
0
                                IVD_OP_API_STRUCT_SIZE_INCORRECT;
381
0
                return (IV_FAIL);
382
0
            }
383
0
384
0
            if(ps_ip->s_ivd_set_display_frame_ip_t.num_disp_bufs == 0)
385
0
            {
386
0
                ps_op->s_ivd_set_display_frame_op_t.u4_error_code |= 1
387
0
                                << IVD_UNSUPPORTEDPARAM;
388
0
                ps_op->s_ivd_set_display_frame_op_t.u4_error_code |=
389
0
                                IVD_DISP_FRM_ZERO_OP_BUFS;
390
0
                return IV_FAIL;
391
0
            }
392
0
393
0
            for(j = 0; j < ps_ip->s_ivd_set_display_frame_ip_t.num_disp_bufs;
394
0
                            j++)
395
0
            {
396
0
                if(ps_ip->s_ivd_set_display_frame_ip_t.s_disp_buffer[j].u4_num_bufs
397
0
                                == 0)
398
0
                {
399
0
                    ps_op->s_ivd_set_display_frame_op_t.u4_error_code |= 1
400
0
                                    << IVD_UNSUPPORTEDPARAM;
401
0
                    ps_op->s_ivd_set_display_frame_op_t.u4_error_code |=
402
0
                                    IVD_DISP_FRM_ZERO_OP_BUFS;
403
0
                    return IV_FAIL;
404
0
                }
405
0
406
0
                for(i = 0;
407
0
                                i
408
0
                                                < ps_ip->s_ivd_set_display_frame_ip_t.s_disp_buffer[j].u4_num_bufs;
409
0
                                i++)
410
0
                {
411
0
                    if(ps_ip->s_ivd_set_display_frame_ip_t.s_disp_buffer[j].pu1_bufs[i]
412
0
                                    == NULL)
413
0
                    {
414
0
                        ps_op->s_ivd_set_display_frame_op_t.u4_error_code |= 1
415
0
                                        << IVD_UNSUPPORTEDPARAM;
416
0
                        ps_op->s_ivd_set_display_frame_op_t.u4_error_code |=
417
0
                                        IVD_DISP_FRM_OP_BUF_NULL;
418
0
                        return IV_FAIL;
419
0
                    }
420
0
421
0
                    if(ps_ip->s_ivd_set_display_frame_ip_t.s_disp_buffer[j].u4_min_out_buf_size[i]
422
0
                                    == 0)
423
0
                    {
424
0
                        ps_op->s_ivd_set_display_frame_op_t.u4_error_code |= 1
425
0
                                        << IVD_UNSUPPORTEDPARAM;
426
0
                        ps_op->s_ivd_set_display_frame_op_t.u4_error_code |=
427
0
                                        IVD_DISP_FRM_ZERO_OP_BUF_SIZE;
428
0
                        return IV_FAIL;
429
0
                    }
430
0
                }
431
0
            }
432
0
        }
433
0
            break;
434
0
435
13
        case IVD_CMD_VIDEO_DECODE:
436
13
        {
437
13
            ih264d_video_decode_ip_t *ps_ip =
438
13
                            (ih264d_video_decode_ip_t *)pv_api_ip;
439
13
            ih264d_video_decode_op_t *ps_op =
440
13
                            (ih264d_video_decode_op_t *)pv_api_op;
441
13
442
13
            H264_DEC_DEBUG_PRINT("The input bytes is: %d",
443
13
                                 ps_ip->s_ivd_video_decode_ip_t.u4_num_Bytes);
444
13
            ps_op->s_ivd_video_decode_op_t.u4_error_code = 0;
445
13
446
13
            if(ps_ip->s_ivd_video_decode_ip_t.u4_size
447
13
                            != sizeof(ih264d_video_decode_ip_t)&&
448
13
                            ps_ip->s_ivd_video_decode_ip_t.u4_size != offsetof(ivd_video_decode_ip_t, s_out_buffer))
449
13
            {
450
0
                ps_op->s_ivd_video_decode_op_t.u4_error_code |= 1
451
0
                                << IVD_UNSUPPORTEDPARAM;
452
0
                ps_op->s_ivd_video_decode_op_t.u4_error_code |=
453
0
                                IVD_IP_API_STRUCT_SIZE_INCORRECT;
454
0
                return (IV_FAIL);
455
0
            }
456
13
457
13
            if(ps_op->s_ivd_video_decode_op_t.u4_size
458
13
                            != sizeof(ih264d_video_decode_op_t)&&
459
13
                            ps_op->s_ivd_video_decode_op_t.u4_size != offsetof(ivd_video_decode_op_t, u4_output_present))
460
13
            {
461
0
                ps_op->s_ivd_video_decode_op_t.u4_error_code |= 1
462
0
                                << IVD_UNSUPPORTEDPARAM;
463
0
                ps_op->s_ivd_video_decode_op_t.u4_error_code |=
464
0
                                IVD_OP_API_STRUCT_SIZE_INCORRECT;
465
0
                return (IV_FAIL);
466
0
            }
467
13
468
13
        }
469
13
            break;
470
13
471
13
        case IVD_CMD_DELETE:
472
1
        {
473
1
            ih264d_delete_ip_t *ps_ip =
474
1
                            (ih264d_delete_ip_t *)pv_api_ip;
475
1
            ih264d_delete_op_t *ps_op =
476
1
                            (ih264d_delete_op_t *)pv_api_op;
477
1
478
1
            ps_op->s_ivd_delete_op_t.u4_error_code = 0;
479
1
480
1
            if(ps_ip->s_ivd_delete_ip_t.u4_size
481
1
                            != sizeof(ih264d_delete_ip_t))
482
0
            {
483
0
                ps_op->s_ivd_delete_op_t.u4_error_code |= 1
484
0
                                << IVD_UNSUPPORTEDPARAM;
485
0
                ps_op->s_ivd_delete_op_t.u4_error_code |=
486
0
                                IVD_IP_API_STRUCT_SIZE_INCORRECT;
487
0
                return (IV_FAIL);
488
0
            }
489
1
490
1
            if(ps_op->s_ivd_delete_op_t.u4_size
491
1
                            != sizeof(ih264d_delete_op_t))
492
0
            {
493
0
                ps_op->s_ivd_delete_op_t.u4_error_code |= 1
494
0
                                << IVD_UNSUPPORTEDPARAM;
495
0
                ps_op->s_ivd_delete_op_t.u4_error_code |=
496
0
                                IVD_OP_API_STRUCT_SIZE_INCORRECT;
497
0
                return (IV_FAIL);
498
0
            }
499
1
500
1
        }
501
1
            break;
502
1
503
18
        case IVD_CMD_VIDEO_CTL:
504
18
        {
505
18
            UWORD32 *pu4_ptr_cmd;
506
18
            UWORD32 sub_command;
507
18
508
18
            pu4_ptr_cmd = (UWORD32 *)pv_api_ip;
509
18
            pu4_ptr_cmd += 2;
510
18
            sub_command = *pu4_ptr_cmd;
511
18
512
18
            switch(sub_command)
513
18
            {
514
18
                case IVD_CMD_CTL_SETPARAMS:
515
1
                {
516
1
                    ih264d_ctl_set_config_ip_t *ps_ip;
517
1
                    ih264d_ctl_set_config_op_t *ps_op;
518
1
                    ps_ip = (ih264d_ctl_set_config_ip_t *)pv_api_ip;
519
1
                    ps_op = (ih264d_ctl_set_config_op_t *)pv_api_op;
520
1
521
1
                    if(ps_ip->s_ivd_ctl_set_config_ip_t.u4_size
522
1
                                    != sizeof(ih264d_ctl_set_config_ip_t))
523
0
                    {
524
0
                        ps_op->s_ivd_ctl_set_config_op_t.u4_error_code |= 1
525
0
                                        << IVD_UNSUPPORTEDPARAM;
526
0
                        ps_op->s_ivd_ctl_set_config_op_t.u4_error_code |=
527
0
                                        IVD_IP_API_STRUCT_SIZE_INCORRECT;
528
0
                        return IV_FAIL;
529
0
                    }
530
1
                }
531
1
                    //no break; is needed here
532
2
                case IVD_CMD_CTL_SETDEFAULT:
533
2
                {
534
2
                    ih264d_ctl_set_config_op_t *ps_op;
535
2
                    ps_op = (ih264d_ctl_set_config_op_t *)pv_api_op;
536
2
                    if(ps_op->s_ivd_ctl_set_config_op_t.u4_size
537
1
                                    != sizeof(ih264d_ctl_set_config_op_t))
538
0
                    {
539
0
                        ps_op->s_ivd_ctl_set_config_op_t.u4_error_code |= 1
540
0
                                        << IVD_UNSUPPORTEDPARAM;
541
0
                        ps_op->s_ivd_ctl_set_config_op_t.u4_error_code |=
542
0
                                        IVD_OP_API_STRUCT_SIZE_INCORRECT;
543
0
                        return IV_FAIL;
544
0
                    }
545
1
                }
546
1
                    break;
547
1
548
1
                case IVD_CMD_CTL_GETPARAMS:
549
0
                {
550
0
                    ih264d_ctl_getstatus_ip_t *ps_ip;
551
0
                    ih264d_ctl_getstatus_op_t *ps_op;
552
0
553
0
                    ps_ip = (ih264d_ctl_getstatus_ip_t *)pv_api_ip;
554
0
                    ps_op = (ih264d_ctl_getstatus_op_t *)pv_api_op;
555
0
                    if(ps_ip->s_ivd_ctl_getstatus_ip_t.u4_size
556
0
                                    != sizeof(ih264d_ctl_getstatus_ip_t))
557
0
                    {
558
0
                        ps_op->s_ivd_ctl_getstatus_op_t.u4_error_code |= 1
559
0
                                        << IVD_UNSUPPORTEDPARAM;
560
0
                        ps_op->s_ivd_ctl_getstatus_op_t.u4_error_code |=
561
0
                                        IVD_IP_API_STRUCT_SIZE_INCORRECT;
562
0
                        return IV_FAIL;
563
0
                    }
564
0
                    if(ps_op->s_ivd_ctl_getstatus_op_t.u4_size
565
0
                                    != sizeof(ih264d_ctl_getstatus_op_t))
566
0
                    {
567
0
                        ps_op->s_ivd_ctl_getstatus_op_t.u4_error_code |= 1
568
0
                                        << IVD_UNSUPPORTEDPARAM;
569
0
                        ps_op->s_ivd_ctl_getstatus_op_t.u4_error_code |=
570
0
                                        IVD_OP_API_STRUCT_SIZE_INCORRECT;
571
0
                        return IV_FAIL;
572
0
                    }
573
0
                }
574
0
                    break;
575
0
576
0
                case IVD_CMD_CTL_GETBUFINFO:
577
0
                {
578
0
                    ih264d_ctl_getbufinfo_ip_t *ps_ip;
579
0
                    ih264d_ctl_getbufinfo_op_t *ps_op;
580
0
                    ps_ip = (ih264d_ctl_getbufinfo_ip_t *)pv_api_ip;
581
0
                    ps_op = (ih264d_ctl_getbufinfo_op_t *)pv_api_op;
582
0
583
0
                    if(ps_ip->s_ivd_ctl_getbufinfo_ip_t.u4_size
584
0
                                    != sizeof(ih264d_ctl_getbufinfo_ip_t))
585
0
                    {
586
0
                        ps_op->s_ivd_ctl_getbufinfo_op_t.u4_error_code |= 1
587
0
                                        << IVD_UNSUPPORTEDPARAM;
588
0
                        ps_op->s_ivd_ctl_getbufinfo_op_t.u4_error_code |=
589
0
                                        IVD_IP_API_STRUCT_SIZE_INCORRECT;
590
0
                        return IV_FAIL;
591
0
                    }
592
0
                    if(ps_op->s_ivd_ctl_getbufinfo_op_t.u4_size
593
0
                                    != sizeof(ih264d_ctl_getbufinfo_op_t))
594
0
                    {
595
0
                        ps_op->s_ivd_ctl_getbufinfo_op_t.u4_error_code |= 1
596
0
                                        << IVD_UNSUPPORTEDPARAM;
597
0
                        ps_op->s_ivd_ctl_getbufinfo_op_t.u4_error_code |=
598
0
                                        IVD_OP_API_STRUCT_SIZE_INCORRECT;
599
0
                        return IV_FAIL;
600
0
                    }
601
0
                }
602
0
                    break;
603
0
604
1
                case IVD_CMD_CTL_GETVERSION:
605
1
                {
606
1
                    ih264d_ctl_getversioninfo_ip_t *ps_ip;
607
1
                    ih264d_ctl_getversioninfo_op_t *ps_op;
608
1
                    ps_ip = (ih264d_ctl_getversioninfo_ip_t *)pv_api_ip;
609
1
                    ps_op = (ih264d_ctl_getversioninfo_op_t *)pv_api_op;
610
1
                    if(ps_ip->s_ivd_ctl_getversioninfo_ip_t.u4_size
611
1
                                    != sizeof(ih264d_ctl_getversioninfo_ip_t))
612
0
                    {
613
0
                        ps_op->s_ivd_ctl_getversioninfo_op_t.u4_error_code |= 1
614
0
                                        << IVD_UNSUPPORTEDPARAM;
615
0
                        ps_op->s_ivd_ctl_getversioninfo_op_t.u4_error_code |=
616
0
                                        IVD_IP_API_STRUCT_SIZE_INCORRECT;
617
0
                        return IV_FAIL;
618
0
                    }
619
1
                    if(ps_op->s_ivd_ctl_getversioninfo_op_t.u4_size
620
1
                                    != sizeof(ih264d_ctl_getversioninfo_op_t))
621
0
                    {
622
0
                        ps_op->s_ivd_ctl_getversioninfo_op_t.u4_error_code |= 1
623
0
                                        << IVD_UNSUPPORTEDPARAM;
624
0
                        ps_op->s_ivd_ctl_getversioninfo_op_t.u4_error_code |=
625
0
                                        IVD_OP_API_STRUCT_SIZE_INCORRECT;
626
0
                        return IV_FAIL;
627
0
                    }
628
1
                }
629
1
                    break;
630
1
631
1
                case IVD_CMD_CTL_FLUSH:
632
0
                {
633
0
                    ih264d_ctl_flush_ip_t *ps_ip;
634
0
                    ih264d_ctl_flush_op_t *ps_op;
635
0
                    ps_ip = (ih264d_ctl_flush_ip_t *)pv_api_ip;
636
0
                    ps_op = (ih264d_ctl_flush_op_t *)pv_api_op;
637
0
                    if(ps_ip->s_ivd_ctl_flush_ip_t.u4_size
638
0
                                    != sizeof(ih264d_ctl_flush_ip_t))
639
0
                    {
640
0
                        ps_op->s_ivd_ctl_flush_op_t.u4_error_code |= 1
641
0
                                        << IVD_UNSUPPORTEDPARAM;
642
0
                        ps_op->s_ivd_ctl_flush_op_t.u4_error_code |=
643
0
                                        IVD_IP_API_STRUCT_SIZE_INCORRECT;
644
0
                        return IV_FAIL;
645
0
                    }
646
0
                    if(ps_op->s_ivd_ctl_flush_op_t.u4_size
647
0
                                    != sizeof(ih264d_ctl_flush_op_t))
648
0
                    {
649
0
                        ps_op->s_ivd_ctl_flush_op_t.u4_error_code |= 1
650
0
                                        << IVD_UNSUPPORTEDPARAM;
651
0
                        ps_op->s_ivd_ctl_flush_op_t.u4_error_code |=
652
0
                                        IVD_OP_API_STRUCT_SIZE_INCORRECT;
653
0
                        return IV_FAIL;
654
0
                    }
655
0
                }
656
0
                    break;
657
0
658
1
                case IVD_CMD_CTL_RESET:
659
1
                {
660
1
                    ih264d_ctl_reset_ip_t *ps_ip;
661
1
                    ih264d_ctl_reset_op_t *ps_op;
662
1
                    ps_ip = (ih264d_ctl_reset_ip_t *)pv_api_ip;
663
1
                    ps_op = (ih264d_ctl_reset_op_t *)pv_api_op;
664
1
                    if(ps_ip->s_ivd_ctl_reset_ip_t.u4_size
665
1
                                    != sizeof(ih264d_ctl_reset_ip_t))
666
0
                    {
667
0
                        ps_op->s_ivd_ctl_reset_op_t.u4_error_code |= 1
668
0
                                        << IVD_UNSUPPORTEDPARAM;
669
0
                        ps_op->s_ivd_ctl_reset_op_t.u4_error_code |=
670
0
                                        IVD_IP_API_STRUCT_SIZE_INCORRECT;
671
0
                        return IV_FAIL;
672
0
                    }
673
1
                    if(ps_op->s_ivd_ctl_reset_op_t.u4_size
674
1
                                    != sizeof(ih264d_ctl_reset_op_t))
675
0
                    {
676
0
                        ps_op->s_ivd_ctl_reset_op_t.u4_error_code |= 1
677
0
                                        << IVD_UNSUPPORTEDPARAM;
678
0
                        ps_op->s_ivd_ctl_reset_op_t.u4_error_code |=
679
0
                                        IVD_OP_API_STRUCT_SIZE_INCORRECT;
680
0
                        return IV_FAIL;
681
0
                    }
682
1
                }
683
1
                    break;
684
1
685
1
                case IH264D_CMD_CTL_DEGRADE:
686
0
                {
687
0
                    ih264d_ctl_degrade_ip_t *ps_ip;
688
0
                    ih264d_ctl_degrade_op_t *ps_op;
689
0
690
0
                    ps_ip = (ih264d_ctl_degrade_ip_t *)pv_api_ip;
691
0
                    ps_op = (ih264d_ctl_degrade_op_t *)pv_api_op;
692
0
693
0
                    if(ps_ip->u4_size != sizeof(ih264d_ctl_degrade_ip_t))
694
0
                    {
695
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
696
0
                        ps_op->u4_error_code |=
697
0
                                        IVD_IP_API_STRUCT_SIZE_INCORRECT;
698
0
                        return IV_FAIL;
699
0
                    }
700
0
701
0
                    if(ps_op->u4_size != sizeof(ih264d_ctl_degrade_op_t))
702
0
                    {
703
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
704
0
                        ps_op->u4_error_code |=
705
0
                                        IVD_OP_API_STRUCT_SIZE_INCORRECT;
706
0
                        return IV_FAIL;
707
0
                    }
708
0
709
0
                    if((ps_ip->i4_degrade_pics < 0)
710
0
                                    || (ps_ip->i4_degrade_pics > 4)
711
0
                                    || (ps_ip->i4_nondegrade_interval < 0)
712
0
                                    || (ps_ip->i4_degrade_type < 0)
713
0
                                    || (ps_ip->i4_degrade_type > 15))
714
0
                    {
715
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
716
0
                        return IV_FAIL;
717
0
                    }
718
0
719
0
                    break;
720
0
                }
721
0
722
0
                case IH264D_CMD_CTL_GET_BUFFER_DIMENSIONS:
723
0
                {
724
0
                    ih264d_ctl_get_frame_dimensions_ip_t *ps_ip;
725
0
                    ih264d_ctl_get_frame_dimensions_op_t *ps_op;
726
0
727
0
                    ps_ip = (ih264d_ctl_get_frame_dimensions_ip_t *)pv_api_ip;
728
0
                    ps_op = (ih264d_ctl_get_frame_dimensions_op_t *)pv_api_op;
729
0
730
0
                    if(ps_ip->u4_size
731
0
                                    != sizeof(ih264d_ctl_get_frame_dimensions_ip_t))
732
0
                    {
733
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
734
0
                        ps_op->u4_error_code |=
735
0
                                        IVD_IP_API_STRUCT_SIZE_INCORRECT;
736
0
                        return IV_FAIL;
737
0
                    }
738
0
739
0
                    if(ps_op->u4_size
740
0
                                    != sizeof(ih264d_ctl_get_frame_dimensions_op_t))
741
0
                    {
742
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
743
0
                        ps_op->u4_error_code |=
744
0
                                        IVD_OP_API_STRUCT_SIZE_INCORRECT;
745
0
                        return IV_FAIL;
746
0
                    }
747
0
748
0
                    break;
749
0
                }
750
13
                case IH264D_CMD_CTL_GET_VUI_PARAMS:
751
13
                {
752
13
                    ih264d_ctl_get_vui_params_ip_t *ps_ip;
753
13
                    ih264d_ctl_get_vui_params_op_t *ps_op;
754
13
755
13
                    ps_ip =
756
13
                                    (ih264d_ctl_get_vui_params_ip_t *)pv_api_ip;
757
13
                    ps_op =
758
13
                                    (ih264d_ctl_get_vui_params_op_t *)pv_api_op;
759
13
760
13
                    if(ps_ip->u4_size
761
13
                                    != sizeof(ih264d_ctl_get_vui_params_ip_t))
762
0
                    {
763
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
764
0
                        ps_op->u4_error_code |=
765
0
                                        IVD_IP_API_STRUCT_SIZE_INCORRECT;
766
0
                        return IV_FAIL;
767
0
                    }
768
13
769
13
                    if(ps_op->u4_size
770
13
                                    != sizeof(ih264d_ctl_get_vui_params_op_t))
771
0
                    {
772
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
773
0
                        ps_op->u4_error_code |=
774
0
                                        IVD_OP_API_STRUCT_SIZE_INCORRECT;
775
0
                        return IV_FAIL;
776
0
                    }
777
13
778
13
                    break;
779
13
                }
780
13
                case IH264D_CMD_CTL_SET_NUM_CORES:
781
2
                {
782
2
                    ih264d_ctl_set_num_cores_ip_t *ps_ip;
783
2
                    ih264d_ctl_set_num_cores_op_t *ps_op;
784
2
785
2
                    ps_ip = (ih264d_ctl_set_num_cores_ip_t *)pv_api_ip;
786
2
                    ps_op = (ih264d_ctl_set_num_cores_op_t *)pv_api_op;
787
2
788
2
                    if(ps_ip->u4_size != sizeof(ih264d_ctl_set_num_cores_ip_t))
789
0
                    {
790
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
791
0
                        ps_op->u4_error_code |=
792
0
                                        IVD_IP_API_STRUCT_SIZE_INCORRECT;
793
0
                        return IV_FAIL;
794
0
                    }
795
2
796
2
                    if(ps_op->u4_size != sizeof(ih264d_ctl_set_num_cores_op_t))
797
0
                    {
798
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
799
0
                        ps_op->u4_error_code |=
800
0
                                        IVD_OP_API_STRUCT_SIZE_INCORRECT;
801
0
                        return IV_FAIL;
802
0
                    }
803
2
804
2
                    if((ps_ip->u4_num_cores != 1) && (ps_ip->u4_num_cores != 2)
805
2
                                    && (ps_ip->u4_num_cores != 3)
806
2
                                    && (ps_ip->u4_num_cores != 4))
807
0
                    {
808
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
809
0
                        return IV_FAIL;
810
0
                    }
811
2
                    break;
812
2
                }
813
2
                case IH264D_CMD_CTL_SET_PROCESSOR:
814
0
                {
815
0
                    ih264d_ctl_set_processor_ip_t *ps_ip;
816
0
                    ih264d_ctl_set_processor_op_t *ps_op;
817
0
818
0
                    ps_ip = (ih264d_ctl_set_processor_ip_t *)pv_api_ip;
819
0
                    ps_op = (ih264d_ctl_set_processor_op_t *)pv_api_op;
820
0
821
0
                    if(ps_ip->u4_size != sizeof(ih264d_ctl_set_processor_ip_t))
822
0
                    {
823
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
824
0
                        ps_op->u4_error_code |=
825
0
                                        IVD_IP_API_STRUCT_SIZE_INCORRECT;
826
0
                        return IV_FAIL;
827
0
                    }
828
0
829
0
                    if(ps_op->u4_size != sizeof(ih264d_ctl_set_processor_op_t))
830
0
                    {
831
0
                        ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
832
0
                        ps_op->u4_error_code |=
833
0
                                        IVD_OP_API_STRUCT_SIZE_INCORRECT;
834
0
                        return IV_FAIL;
835
0
                    }
836
0
837
0
                    break;
838
0
                }
839
0
                default:
840
0
                    *(pu4_api_op + 1) |= 1 << IVD_UNSUPPORTEDPARAM;
841
0
                    *(pu4_api_op + 1) |= IVD_UNSUPPORTED_API_CMD;
842
0
                    return IV_FAIL;
843
0
                    break;
844
18
            }
845
18
        }
846
18
            break;
847
33
    }
848
33
849
33
    return IV_SUCCESS;
850
33
}
851
852
853
/**
854
 *******************************************************************************
855
 *
856
 * @brief
857
 *  Sets Processor type
858
 *
859
 * @par Description:
860
 *  Sets Processor type
861
 *
862
 * @param[in] ps_codec_obj
863
 *  Pointer to codec object at API level
864
 *
865
 * @param[in] pv_api_ip
866
 *  Pointer to input argument structure
867
 *
868
 * @param[out] pv_api_op
869
 *  Pointer to output argument structure
870
 *
871
 * @returns  Status
872
 *
873
 * @remarks
874
 *
875
 *
876
 *******************************************************************************
877
 */
878
879
WORD32 ih264d_set_processor(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
880
0
{
881
0
    ih264d_ctl_set_processor_ip_t *ps_ip;
882
0
    ih264d_ctl_set_processor_op_t *ps_op;
883
0
    dec_struct_t *ps_codec = (dec_struct_t *)dec_hdl->pv_codec_handle;
884
0
885
0
    ps_ip = (ih264d_ctl_set_processor_ip_t *)pv_api_ip;
886
0
    ps_op = (ih264d_ctl_set_processor_op_t *)pv_api_op;
887
0
888
0
    ps_codec->e_processor_arch = (IVD_ARCH_T)ps_ip->u4_arch;
889
0
    ps_codec->e_processor_soc = (IVD_SOC_T)ps_ip->u4_soc;
890
0
891
0
    ih264d_init_function_ptr(ps_codec);
892
0
893
0
    ps_op->u4_error_code = 0;
894
0
    return IV_SUCCESS;
895
0
}
896
897
898
/**************************************************************************
899
 * \if Function name : ih264d_init_decoder \endif
900
 *
901
 *
902
 * \brief
903
 *    Initializes the decoder
904
 *
905
 * \param apiVersion               : Version of the api being used.
906
 * \param errorHandlingMechanism   : Mechanism to be used for errror handling.
907
 * \param postFilteringType: Type of post filtering operation to be used.
908
 * \param uc_outputFormat: Format of the decoded picture [default 4:2:0].
909
 * \param uc_dispBufs: Number of Display Buffers.
910
 * \param p_NALBufAPI: Pointer to NAL Buffer API.
911
 * \param p_DispBufAPI: Pointer to Display Buffer API.
912
 * \param ih264d_dec_mem_manager  :Pointer to the function that will be called by decoder
913
 *                        for memory allocation and freeing.
914
 *
915
 * \return
916
 *    0 on Success and -1 on error
917
 *
918
 **************************************************************************
919
 */
920
void ih264d_init_decoder(void * ps_dec_params)
921
2
{
922
2
    dec_struct_t * ps_dec = (dec_struct_t *)ps_dec_params;
923
2
    dec_slice_params_t *ps_cur_slice;
924
2
    pocstruct_t *ps_prev_poc, *ps_cur_poc;
925
2
    WORD32 size;
926
2
927
2
    size = sizeof(pred_info_t) * 2 * 32;
928
2
    memset(ps_dec->ps_pred, 0 , size);
929
2
930
2
    size = sizeof(disp_mgr_t);
931
2
    memset(ps_dec->pv_disp_buf_mgr, 0 , size);
932
2
933
2
    size = sizeof(buf_mgr_t) + ithread_get_mutex_lock_size();
934
2
    memset(ps_dec->pv_pic_buf_mgr, 0, size);
935
2
936
2
    size = sizeof(dec_err_status_t);
937
2
    memset(ps_dec->ps_dec_err_status, 0, size);
938
2
939
2
    size = sizeof(sei);
940
2
    memset(ps_dec->ps_sei, 0, size);
941
2
942
2
    size = sizeof(dpb_commands_t);
943
2
    memset(ps_dec->ps_dpb_cmds, 0, size);
944
2
945
2
    size = sizeof(dec_bit_stream_t);
946
2
    memset(ps_dec->ps_bitstrm, 0, size);
947
2
948
2
    size = sizeof(dec_slice_params_t);
949
2
    memset(ps_dec->ps_cur_slice, 0, size);
950
2
951
2
    size = MAX(sizeof(dec_seq_params_t), sizeof(dec_pic_params_t));
952
2
    memset(ps_dec->pv_scratch_sps_pps, 0, size);
953
2
954
2
    size = sizeof(ctxt_inc_mb_info_t);
955
2
    memset(ps_dec->ps_left_mb_ctxt_info, 0, size);
956
2
957
2
    size = (sizeof(neighbouradd_t) << 2);
958
2
    memset(ps_dec->ps_left_mvpred_addr, 0 ,size);
959
2
960
2
    size = sizeof(buf_mgr_t) + ithread_get_mutex_lock_size();
961
2
    memset(ps_dec->pv_mv_buf_mgr, 0, size);
962
2
963
2
    /* Free any dynamic buffers that are allocated */
964
2
    ih264d_free_dynamic_bufs(ps_dec);
965
2
966
2
    ps_cur_slice = ps_dec->ps_cur_slice;
967
2
    ps_dec->init_done = 0;
968
2
969
2
    ps_dec->u4_num_cores = 1;
970
2
971
2
    ps_dec->u2_pic_ht = ps_dec->u2_pic_wd = 0;
972
2
973
2
    ps_dec->u1_separate_parse = DEFAULT_SEPARATE_PARSE;
974
2
    ps_dec->u4_app_disable_deblk_frm = 0;
975
2
    ps_dec->i4_degrade_type = 0;
976
2
    ps_dec->i4_degrade_pics = 0;
977
2
978
2
    ps_dec->i4_app_skip_mode = IVD_SKIP_NONE;
979
2
    ps_dec->i4_dec_skip_mode = IVD_SKIP_NONE;
980
2
981
2
    memset(ps_dec->ps_pps, 0,
982
2
           ((sizeof(dec_pic_params_t)) * MAX_NUM_PIC_PARAMS));
983
2
    memset(ps_dec->ps_sps, 0,
984
2
           ((sizeof(dec_seq_params_t)) * MAX_NUM_SEQ_PARAMS));
985
2
986
2
    /* Initialization of function pointers ih264d_deblock_picture function*/
987
2
988
2
    ps_dec->p_DeblockPicture[0] = ih264d_deblock_picture_non_mbaff;
989
2
    ps_dec->p_DeblockPicture[1] = ih264d_deblock_picture_mbaff;
990
2
991
2
    ps_dec->s_cab_dec_env.pv_codec_handle = ps_dec;
992
2
993
2
    ps_dec->u4_num_fld_in_frm = 0;
994
2
995
2
    ps_dec->ps_dpb_mgr->pv_codec_handle = ps_dec;
996
2
997
2
    /* Initialize the sei validity u4_flag with zero indiacting sei is not valid*/
998
2
    ps_dec->ps_sei->u1_is_valid = 0;
999
2
1000
2
    /* decParams Initializations */
1001
2
    ps_dec->ps_cur_pps = NULL;
1002
2
    ps_dec->ps_cur_sps = NULL;
1003
2
    ps_dec->u1_init_dec_flag = 0;
1004
2
    ps_dec->u1_first_slice_in_stream = 1;
1005
2
    ps_dec->u1_last_pic_not_decoded = 0;
1006
2
    ps_dec->u4_app_disp_width = 0;
1007
2
    ps_dec->i4_header_decoded = 0;
1008
2
    ps_dec->u4_total_frames_decoded = 0;
1009
2
1010
2
    ps_dec->i4_error_code = 0;
1011
2
    ps_dec->i4_content_type = -1;
1012
2
    ps_dec->ps_cur_slice->u1_mbaff_frame_flag = 0;
1013
2
1014
2
    ps_dec->ps_dec_err_status->u1_err_flag = ACCEPT_ALL_PICS; //REJECT_PB_PICS;
1015
2
    ps_dec->ps_dec_err_status->u1_cur_pic_type = PIC_TYPE_UNKNOWN;
1016
2
    ps_dec->ps_dec_err_status->u4_frm_sei_sync = SYNC_FRM_DEFAULT;
1017
2
    ps_dec->ps_dec_err_status->u4_cur_frm = INIT_FRAME;
1018
2
    ps_dec->ps_dec_err_status->u1_pic_aud_i = PIC_TYPE_UNKNOWN;
1019
2
1020
2
    ps_dec->u1_pr_sl_type = 0xFF;
1021
2
    ps_dec->u2_mbx = 0xffff;
1022
2
    ps_dec->u2_mby = 0;
1023
2
    ps_dec->u2_total_mbs_coded = 0;
1024
2
1025
2
    /* POC initializations */
1026
2
    ps_prev_poc = &ps_dec->s_prev_pic_poc;
1027
2
    ps_cur_poc = &ps_dec->s_cur_pic_poc;
1028
2
    ps_prev_poc->i4_pic_order_cnt_lsb = ps_cur_poc->i4_pic_order_cnt_lsb = 0;
1029
2
    ps_prev_poc->i4_pic_order_cnt_msb = ps_cur_poc->i4_pic_order_cnt_msb = 0;
1030
2
    ps_prev_poc->i4_delta_pic_order_cnt_bottom =
1031
2
                    ps_cur_poc->i4_delta_pic_order_cnt_bottom = 0;
1032
2
    ps_prev_poc->i4_delta_pic_order_cnt[0] =
1033
2
                    ps_cur_poc->i4_delta_pic_order_cnt[0] = 0;
1034
2
    ps_prev_poc->i4_delta_pic_order_cnt[1] =
1035
2
                    ps_cur_poc->i4_delta_pic_order_cnt[1] = 0;
1036
2
    ps_prev_poc->u1_mmco_equalto5 = ps_cur_poc->u1_mmco_equalto5 = 0;
1037
2
    ps_prev_poc->i4_top_field_order_count = ps_cur_poc->i4_top_field_order_count =
1038
2
                    0;
1039
2
    ps_prev_poc->i4_bottom_field_order_count =
1040
2
                    ps_cur_poc->i4_bottom_field_order_count = 0;
1041
2
    ps_prev_poc->u1_bot_field = ps_cur_poc->u1_bot_field = 0;
1042
2
    ps_prev_poc->u1_mmco_equalto5 = ps_cur_poc->u1_mmco_equalto5 = 0;
1043
2
    ps_prev_poc->i4_prev_frame_num_ofst = ps_cur_poc->i4_prev_frame_num_ofst = 0;
1044
2
    ps_cur_slice->u1_mmco_equalto5 = 0;
1045
2
    ps_cur_slice->u2_frame_num = 0;
1046
2
1047
2
    ps_dec->i4_max_poc = 0;
1048
2
    ps_dec->i4_prev_max_display_seq = 0;
1049
2
    ps_dec->u1_recon_mb_grp = 4;
1050
2
1051
2
    /* Field PIC initializations */
1052
2
    ps_dec->u1_second_field = 0;
1053
2
    ps_dec->s_prev_seq_params.u1_eoseq_pending = 0;
1054
2
1055
2
    /* Set the cropping parameters as zero */
1056
2
    ps_dec->u2_crop_offset_y = 0;
1057
2
    ps_dec->u2_crop_offset_uv = 0;
1058
2
1059
2
    /* The Initial Frame Rate Info is not Present */
1060
2
    ps_dec->i4_vui_frame_rate = -1;
1061
2
    ps_dec->i4_pic_type = -1;
1062
2
    ps_dec->i4_frametype = -1;
1063
2
    ps_dec->i4_content_type = -1;
1064
2
1065
2
    ps_dec->u1_res_changed = 0;
1066
2
1067
2
1068
2
    ps_dec->u1_frame_decoded_flag = 0;
1069
2
1070
2
    /* Set the default frame seek mask mode */
1071
2
    ps_dec->u4_skip_frm_mask = SKIP_NONE;
1072
2
1073
2
    /********************************************************/
1074
2
    /* Initialize CAVLC residual decoding function pointers */
1075
2
    /********************************************************/
1076
2
    ps_dec->pf_cavlc_4x4res_block[0] = ih264d_cavlc_4x4res_block_totalcoeff_1;
1077
2
    ps_dec->pf_cavlc_4x4res_block[1] =
1078
2
                    ih264d_cavlc_4x4res_block_totalcoeff_2to10;
1079
2
    ps_dec->pf_cavlc_4x4res_block[2] =
1080
2
                    ih264d_cavlc_4x4res_block_totalcoeff_11to16;
1081
2
1082
2
    ps_dec->pf_cavlc_parse4x4coeff[0] = ih264d_cavlc_parse4x4coeff_n0to7;
1083
2
    ps_dec->pf_cavlc_parse4x4coeff[1] = ih264d_cavlc_parse4x4coeff_n8;
1084
2
1085
2
    ps_dec->pf_cavlc_parse_8x8block[0] =
1086
2
                    ih264d_cavlc_parse_8x8block_none_available;
1087
2
    ps_dec->pf_cavlc_parse_8x8block[1] =
1088
2
                    ih264d_cavlc_parse_8x8block_left_available;
1089
2
    ps_dec->pf_cavlc_parse_8x8block[2] =
1090
2
                    ih264d_cavlc_parse_8x8block_top_available;
1091
2
    ps_dec->pf_cavlc_parse_8x8block[3] =
1092
2
                    ih264d_cavlc_parse_8x8block_both_available;
1093
2
1094
2
    /***************************************************************************/
1095
2
    /* Initialize Bs calculation function pointers for P and B, 16x16/non16x16 */
1096
2
    /***************************************************************************/
1097
2
    ps_dec->pf_fill_bs1[0][0] = ih264d_fill_bs1_16x16mb_pslice;
1098
2
    ps_dec->pf_fill_bs1[0][1] = ih264d_fill_bs1_non16x16mb_pslice;
1099
2
1100
2
    ps_dec->pf_fill_bs1[1][0] = ih264d_fill_bs1_16x16mb_bslice;
1101
2
    ps_dec->pf_fill_bs1[1][1] = ih264d_fill_bs1_non16x16mb_bslice;
1102
2
1103
2
    ps_dec->pf_fill_bs_xtra_left_edge[0] =
1104
2
                    ih264d_fill_bs_xtra_left_edge_cur_frm;
1105
2
    ps_dec->pf_fill_bs_xtra_left_edge[1] =
1106
2
                    ih264d_fill_bs_xtra_left_edge_cur_fld;
1107
2
1108
2
    /* Initialize Reference Pic Buffers */
1109
2
    ih264d_init_ref_bufs(ps_dec->ps_dpb_mgr);
1110
2
1111
2
    ps_dec->u2_prv_frame_num = 0;
1112
2
    ps_dec->u1_top_bottom_decoded = 0;
1113
2
    ps_dec->u1_dangling_field = 0;
1114
2
1115
2
    ps_dec->s_cab_dec_env.cabac_table = gau4_ih264d_cabac_table;
1116
2
1117
2
    ps_dec->pu1_left_mv_ctxt_inc = ps_dec->u1_left_mv_ctxt_inc_arr[0];
1118
2
    ps_dec->pi1_left_ref_idx_ctxt_inc =
1119
2
                    &ps_dec->i1_left_ref_idx_ctx_inc_arr[0][0];
1120
2
    ps_dec->pu1_left_yuv_dc_csbp = &ps_dec->u1_yuv_dc_csbp_topmb;
1121
2
1122
2
    /* ! */
1123
2
    /* Initializing flush frame u4_flag */
1124
2
    ps_dec->u1_flushfrm = 0;
1125
2
1126
2
    {
1127
2
        ps_dec->s_cab_dec_env.pv_codec_handle = (void*)ps_dec;
1128
2
        ps_dec->ps_bitstrm->pv_codec_handle = (void*)ps_dec;
1129
2
        ps_dec->ps_cur_slice->pv_codec_handle = (void*)ps_dec;
1130
2
        ps_dec->ps_dpb_mgr->pv_codec_handle = (void*)ps_dec;
1131
2
    }
1132
2
1133
2
    memset(ps_dec->disp_bufs, 0, (MAX_DISP_BUFS_NEW) * sizeof(disp_buf_t));
1134
2
    memset(ps_dec->u4_disp_buf_mapping, 0,
1135
2
           (MAX_DISP_BUFS_NEW) * sizeof(UWORD32));
1136
2
    memset(ps_dec->u4_disp_buf_to_be_freed, 0,
1137
2
           (MAX_DISP_BUFS_NEW) * sizeof(UWORD32));
1138
2
    memset(ps_dec->ps_cur_slice, 0, sizeof(dec_slice_params_t));
1139
2
1140
2
    ih264d_init_arch(ps_dec);
1141
2
    ih264d_init_function_ptr(ps_dec);
1142
2
    ps_dec->e_frm_out_mode = IVD_DISPLAY_FRAME_OUT;
1143
2
    ps_dec->init_done = 1;
1144
2
1145
2
}
1146
WORD32 ih264d_free_static_bufs(iv_obj_t *dec_hdl)
1147
1
{
1148
1
    dec_struct_t *ps_dec;
1149
1
1150
1
    void (*pf_aligned_free)(void *pv_mem_ctxt, void *pv_buf);
1151
1
    void *pv_mem_ctxt;
1152
1
1153
1
    ps_dec = (dec_struct_t *)dec_hdl->pv_codec_handle;
1154
1
    pf_aligned_free = ps_dec->pf_aligned_free;
1155
1
    pv_mem_ctxt = ps_dec->pv_mem_ctxt;
1156
1
1157
1
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_sps);
1158
1
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_pps);
1159
1
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pv_dec_thread_handle);
1160
1
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pv_bs_deblk_thread_handle);
1161
1
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_dpb_mgr);
1162
1
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_pred);
1163
1
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pv_disp_buf_mgr);
1164
1
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pv_pic_buf_mgr);
1165
1
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_pic_buf_base);
1166
1
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_dec_err_status);
1167
1
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_sei);
1168
1
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_dpb_cmds);
1169
1
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_bitstrm);
1170
1
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_cur_slice);
1171
1
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pv_scratch_sps_pps);
1172
1
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_bits_buf_static);
1173
1
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ppv_map_ref_idx_to_poc_base);
1174
1
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->p_cabac_ctxt_table_t);
1175
1
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_left_mb_ctxt_info);
1176
1
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_ref_buff_base);
1177
1
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pi2_pred1);
1178
1
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_temp_mc_buffer);
1179
1
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_init_dpb_base);
1180
1
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu4_mbaff_wt_mat);
1181
1
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu4_wts_ofsts_mat);
1182
1
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_left_mvpred_addr);
1183
1
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pv_mv_buf_mgr);
1184
1
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_col_mv_base);
1185
1
    PS_DEC_ALIGNED_FREE(ps_dec, dec_hdl->pv_codec_handle);
1186
1
1187
1
    if(dec_hdl)
1188
1
    {
1189
1
        pf_aligned_free(pv_mem_ctxt, dec_hdl);
1190
1
    }
1191
1
    return IV_SUCCESS;
1192
1
}
1193
/*****************************************************************************/
1194
/*                                                                           */
1195
/*  Function Name : ih264d_create                                              */
1196
/*                                                                           */
1197
/*  Description   : creates decoder                                          */
1198
/*                                                                           */
1199
/*  Inputs        :iv_obj_t decoder handle                                   */
1200
/*                :pv_api_ip pointer to input structure                      */
1201
/*                :pv_api_op pointer to output structure                     */
1202
/*  Outputs       :                                                          */
1203
/*  Returns       : void                                                     */
1204
/*                                                                           */
1205
/*  Issues        : none                                                     */
1206
/*                                                                           */
1207
/*  Revision History:                                                        */
1208
/*                                                                           */
1209
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1210
/*         22 10 2008    100356         Draft                                */
1211
/*                                                                           */
1212
/*****************************************************************************/
1213
WORD32 ih264d_allocate_static_bufs(iv_obj_t **dec_hdl, void *pv_api_ip, void *pv_api_op)
1214
1
{
1215
1
    ih264d_create_ip_t *ps_create_ip;
1216
1
    ih264d_create_op_t *ps_create_op;
1217
1
    void *pv_buf;
1218
1
    UWORD8 *pu1_buf;
1219
1
    dec_struct_t *ps_dec;
1220
1
    void *(*pf_aligned_alloc)(void *pv_mem_ctxt, WORD32 alignment, WORD32 size);
1221
1
    void (*pf_aligned_free)(void *pv_mem_ctxt, void *pv_buf);
1222
1
    void *pv_mem_ctxt;
1223
1
    WORD32 size;
1224
1
1225
1
    ps_create_ip = (ih264d_create_ip_t *)pv_api_ip;
1226
1
    ps_create_op = (ih264d_create_op_t *)pv_api_op;
1227
1
1228
1
    ps_create_op->s_ivd_create_op_t.u4_error_code = 0;
1229
1
1230
1
    pf_aligned_alloc = ps_create_ip->s_ivd_create_ip_t.pf_aligned_alloc;
1231
1
    pf_aligned_free = ps_create_ip->s_ivd_create_ip_t.pf_aligned_free;
1232
1
    pv_mem_ctxt  = ps_create_ip->s_ivd_create_ip_t.pv_mem_ctxt;
1233
1
1234
1
    /* Initialize return handle to NULL */
1235
1
    ps_create_op->s_ivd_create_op_t.pv_handle = NULL;
1236
1
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, sizeof(iv_obj_t));
1237
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1238
1
    *dec_hdl = (iv_obj_t *)pv_buf;
1239
1
    ps_create_op->s_ivd_create_op_t.pv_handle = *dec_hdl;
1240
1
1241
1
    (*dec_hdl)->pv_codec_handle = NULL;
1242
1
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, sizeof(dec_struct_t));
1243
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1244
1
    (*dec_hdl)->pv_codec_handle = (dec_struct_t *)pv_buf;
1245
1
    ps_dec = (dec_struct_t *)pv_buf;
1246
1
1247
1
    memset(ps_dec, 0, sizeof(dec_struct_t));
1248
1
1249
1
#ifndef LOGO_EN
1250
1
    ps_dec->u4_share_disp_buf = ps_create_ip->s_ivd_create_ip_t.u4_share_disp_buf;
1251
#else
1252
    ps_dec->u4_share_disp_buf = 0;
1253
#endif
1254
1255
1
    ps_dec->u1_chroma_format =
1256
1
                    (UWORD8)(ps_create_ip->s_ivd_create_ip_t.e_output_format);
1257
1
1258
1
    if((ps_dec->u1_chroma_format != IV_YUV_420P)
1259
1
                    && (ps_dec->u1_chroma_format
1260
0
                                    != IV_YUV_420SP_UV)
1261
1
                    && (ps_dec->u1_chroma_format
1262
0
                                    != IV_YUV_420SP_VU))
1263
0
    {
1264
0
        ps_dec->u4_share_disp_buf = 0;
1265
0
    }
1266
1
1267
1
    ps_dec->pf_aligned_alloc = pf_aligned_alloc;
1268
1
    ps_dec->pf_aligned_free = pf_aligned_free;
1269
1
    ps_dec->pv_mem_ctxt = pv_mem_ctxt;
1270
1
1271
1
1272
1
    size = ((sizeof(dec_seq_params_t)) * MAX_NUM_SEQ_PARAMS);
1273
1
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1274
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1275
1
    ps_dec->ps_sps = pv_buf;
1276
1
1277
1
    size = (sizeof(dec_pic_params_t)) * MAX_NUM_PIC_PARAMS;
1278
1
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1279
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1280
1
    ps_dec->ps_pps = pv_buf;
1281
1
1282
1
    size = ithread_get_handle_size();
1283
1
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1284
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1285
1
    ps_dec->pv_dec_thread_handle = pv_buf;
1286
1
1287
1
    size = ithread_get_handle_size();
1288
1
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1289
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1290
1
    ps_dec->pv_bs_deblk_thread_handle = pv_buf;
1291
1
1292
1
    size = sizeof(dpb_manager_t);
1293
1
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1294
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1295
1
    ps_dec->ps_dpb_mgr = pv_buf;
1296
1
1297
1
    size = sizeof(pred_info_t) * 2 * 32;
1298
1
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1299
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1300
1
    ps_dec->ps_pred = pv_buf;
1301
1
1302
1
    size = sizeof(disp_mgr_t);
1303
1
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1304
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1305
1
    ps_dec->pv_disp_buf_mgr = pv_buf;
1306
1
1307
1
    size = sizeof(buf_mgr_t) + ithread_get_mutex_lock_size();
1308
1
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1309
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1310
1
    ps_dec->pv_pic_buf_mgr = pv_buf;
1311
1
1312
1
    size = sizeof(struct pic_buffer_t) * (H264_MAX_REF_PICS * 2);
1313
1
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1314
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1315
1
    ps_dec->ps_pic_buf_base = pv_buf;
1316
1
1317
1
    size = sizeof(dec_err_status_t);
1318
1
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1319
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1320
1
    ps_dec->ps_dec_err_status = (dec_err_status_t *)pv_buf;
1321
1
1322
1
    size = sizeof(sei);
1323
1
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1324
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1325
1
    ps_dec->ps_sei = (sei *)pv_buf;
1326
1
1327
1
    size = sizeof(dpb_commands_t);
1328
1
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1329
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1330
1
    ps_dec->ps_dpb_cmds = (dpb_commands_t *)pv_buf;
1331
1
1332
1
    size = sizeof(dec_bit_stream_t);
1333
1
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1334
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1335
1
    ps_dec->ps_bitstrm = (dec_bit_stream_t *)pv_buf;
1336
1
1337
1
    size = sizeof(dec_slice_params_t);
1338
1
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1339
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1340
1
    ps_dec->ps_cur_slice = (dec_slice_params_t *)pv_buf;
1341
1
1342
1
    size = MAX(sizeof(dec_seq_params_t), sizeof(dec_pic_params_t));
1343
1
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1344
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1345
1
    ps_dec->pv_scratch_sps_pps = pv_buf;
1346
1
1347
1
1348
1
    ps_dec->u4_static_bits_buf_size = 256000;
1349
1
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, ps_dec->u4_static_bits_buf_size);
1350
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1351
1
    ps_dec->pu1_bits_buf_static = pv_buf;
1352
1
1353
1
1354
1
    size = ((TOTAL_LIST_ENTRIES + PAD_MAP_IDX_POC)
1355
1
                        * sizeof(void *));
1356
1
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1357
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1358
1
    ps_dec->ppv_map_ref_idx_to_poc_base = pv_buf;
1359
1
    memset(ps_dec->ppv_map_ref_idx_to_poc_base, 0, size);
1360
1
1361
1
    ps_dec->ppv_map_ref_idx_to_poc = ps_dec->ppv_map_ref_idx_to_poc_base + OFFSET_MAP_IDX_POC;
1362
1
1363
1
1364
1
    size = (sizeof(bin_ctxt_model_t) * NUM_CABAC_CTXTS);
1365
1
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1366
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1367
1
    ps_dec->p_cabac_ctxt_table_t = pv_buf;
1368
1
1369
1
1370
1
1371
1
    size = sizeof(ctxt_inc_mb_info_t);
1372
1
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1373
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1374
1
    ps_dec->ps_left_mb_ctxt_info = pv_buf;
1375
1
1376
1
1377
1
1378
1
    size = MAX_REF_BUF_SIZE * 2;
1379
1
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1380
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1381
1
    ps_dec->pu1_ref_buff_base = pv_buf;
1382
1
    ps_dec->pu1_ref_buff = ps_dec->pu1_ref_buff_base + MAX_REF_BUF_SIZE;
1383
1
1384
1
1385
1
    size = ((sizeof(WORD16)) * PRED_BUFFER_WIDTH
1386
1
                        * PRED_BUFFER_HEIGHT * 2);
1387
1
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1388
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1389
1
    ps_dec->pi2_pred1 = pv_buf;
1390
1
1391
1
1392
1
    size = sizeof(UWORD8) * (MB_LUM_SIZE);
1393
1
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1394
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1395
1
    ps_dec->pu1_temp_mc_buffer = pv_buf;
1396
1
1397
1
1398
1
1399
1
1400
1
    size = 8 * MAX_REF_BUFS * sizeof(struct pic_buffer_t);
1401
1
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1402
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1403
1
1404
1
    ps_dec->pu1_init_dpb_base = pv_buf;
1405
1
    pu1_buf = pv_buf;
1406
1
    ps_dec->ps_dpb_mgr->ps_init_dpb[0][0] = (struct pic_buffer_t *)pu1_buf;
1407
1
1408
1
    pu1_buf += size / 2;
1409
1
    ps_dec->ps_dpb_mgr->ps_init_dpb[1][0] = (struct pic_buffer_t *)pu1_buf;
1410
1
1411
1
    size = (sizeof(UWORD32) * 2 * 3
1412
1
                        * ((MAX_FRAMES << 1) * (MAX_FRAMES << 1)) * 2);
1413
1
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1414
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1415
1
    ps_dec->pu4_mbaff_wt_mat = pv_buf;
1416
1
1417
1
    size = sizeof(UWORD32) * 2 * 3
1418
1
                        * ((MAX_FRAMES << 1) * (MAX_FRAMES << 1));
1419
1
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1420
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1421
1
    ps_dec->pu4_wts_ofsts_mat = pv_buf;
1422
1
1423
1
1424
1
    size = (sizeof(neighbouradd_t) << 2);
1425
1
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1426
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1427
1
    ps_dec->ps_left_mvpred_addr = pv_buf;
1428
1
1429
1
1430
1
    size = sizeof(buf_mgr_t) + ithread_get_mutex_lock_size();
1431
1
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1432
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1433
1
    ps_dec->pv_mv_buf_mgr = pv_buf;
1434
1
1435
1
1436
1
    size =  sizeof(col_mv_buf_t) * (H264_MAX_REF_PICS * 2);
1437
1
    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
1438
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1439
1
    ps_dec->ps_col_mv_base = pv_buf;
1440
1
    memset(ps_dec->ps_col_mv_base, 0, size);
1441
1
1442
1
    {
1443
1
        UWORD8 i;
1444
1
        struct pic_buffer_t *ps_init_dpb;
1445
1
        ps_init_dpb = ps_dec->ps_dpb_mgr->ps_init_dpb[0][0];
1446
65
        for(i = 0; i < 2 * MAX_REF_BUFS; i++)
1447
64
        {
1448
64
            ps_init_dpb->pu1_buf1 = NULL;
1449
64
            ps_init_dpb->u1_long_term_frm_idx = MAX_REF_BUFS + 1;
1450
64
            ps_dec->ps_dpb_mgr->ps_init_dpb[0][i] = ps_init_dpb;
1451
64
            ps_dec->ps_dpb_mgr->ps_mod_dpb[0][i] = ps_init_dpb;
1452
64
            ps_init_dpb++;
1453
64
        }
1454
1
1455
1
        ps_init_dpb = ps_dec->ps_dpb_mgr->ps_init_dpb[1][0];
1456
65
        for(i = 0; i < 2 * MAX_REF_BUFS; i++)
1457
64
        {
1458
64
            ps_init_dpb->pu1_buf1 = NULL;
1459
64
            ps_init_dpb->u1_long_term_frm_idx = MAX_REF_BUFS + 1;
1460
64
            ps_dec->ps_dpb_mgr->ps_init_dpb[1][i] = ps_init_dpb;
1461
64
            ps_dec->ps_dpb_mgr->ps_mod_dpb[1][i] = ps_init_dpb;
1462
64
            ps_init_dpb++;
1463
64
        }
1464
1
    }
1465
1
    ih264d_init_decoder(ps_dec);
1466
1
1467
1
    return IV_SUCCESS;
1468
1
}
1469
1470
1471
/*****************************************************************************/
1472
/*                                                                           */
1473
/*  Function Name : ih264d_create                                              */
1474
/*                                                                           */
1475
/*  Description   : creates decoder                                          */
1476
/*                                                                           */
1477
/*  Inputs        :iv_obj_t decoder handle                                   */
1478
/*                :pv_api_ip pointer to input structure                      */
1479
/*                :pv_api_op pointer to output structure                     */
1480
/*  Outputs       :                                                          */
1481
/*  Returns       : void                                                     */
1482
/*                                                                           */
1483
/*  Issues        : none                                                     */
1484
/*                                                                           */
1485
/*  Revision History:                                                        */
1486
/*                                                                           */
1487
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1488
/*         22 10 2008    100356         Draft                                */
1489
/*                                                                           */
1490
/*****************************************************************************/
1491
WORD32 ih264d_create(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
1492
1
{
1493
1
    ih264d_create_ip_t *ps_create_ip;
1494
1
    ih264d_create_op_t *ps_create_op;
1495
1
1496
1
    WORD32 ret;
1497
1
1498
1
    ps_create_ip = (ih264d_create_ip_t *)pv_api_ip;
1499
1
    ps_create_op = (ih264d_create_op_t *)pv_api_op;
1500
1
1501
1
    ps_create_op->s_ivd_create_op_t.u4_error_code = 0;
1502
1
    dec_hdl = NULL;
1503
1
    ret = ih264d_allocate_static_bufs(&dec_hdl, pv_api_ip, pv_api_op);
1504
1
1505
1
    /* If allocation of some buffer fails, then free buffers allocated till then */
1506
1
    if(IV_FAIL == ret)
1507
0
    {
1508
0
        if(dec_hdl)
1509
0
        {
1510
0
            if(dec_hdl->pv_codec_handle)
1511
0
            {
1512
0
                ih264d_free_static_bufs(dec_hdl);
1513
0
            }
1514
0
            else
1515
0
            {
1516
0
                void (*pf_aligned_free)(void *pv_mem_ctxt, void *pv_buf);
1517
0
                void *pv_mem_ctxt;
1518
0
1519
0
                pf_aligned_free = ps_create_ip->s_ivd_create_ip_t.pf_aligned_free;
1520
0
                pv_mem_ctxt  = ps_create_ip->s_ivd_create_ip_t.pv_mem_ctxt;
1521
0
                pf_aligned_free(pv_mem_ctxt, dec_hdl);
1522
0
            }
1523
0
        }
1524
0
        ps_create_op->s_ivd_create_op_t.u4_error_code = IVD_MEM_ALLOC_FAILED;
1525
0
        ps_create_op->s_ivd_create_op_t.u4_error_code = 1 << IVD_FATALERROR;
1526
0
1527
0
        return IV_FAIL;
1528
0
    }
1529
1
1530
1
    return IV_SUCCESS;
1531
1
}
1532
1533
/*****************************************************************************/
1534
/*                                                                           */
1535
/*  Function Name :  ih264d_map_error                                        */
1536
/*                                                                           */
1537
/*  Description   :  Maps error codes to IVD error groups                    */
1538
/*                                                                           */
1539
/*  Inputs        :                                                          */
1540
/*  Globals       : <Does it use any global variables?>                      */
1541
/*  Outputs       :                                                          */
1542
/*  Returns       : void                                                     */
1543
/*                                                                           */
1544
/*  Issues        : none                                                     */
1545
/*                                                                           */
1546
/*  Revision History:                                                        */
1547
/*                                                                           */
1548
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1549
/*         22 10 2008    100356         Draft                                */
1550
/*                                                                           */
1551
/*****************************************************************************/
1552
UWORD32 ih264d_map_error(UWORD32 i4_err_status)
1553
0
{
1554
0
    UWORD32 temp = 0;
1555
0
1556
0
    switch(i4_err_status)
1557
0
    {
1558
0
        case ERROR_MEM_ALLOC_ISRAM_T:
1559
0
        case ERROR_MEM_ALLOC_SDRAM_T:
1560
0
        case ERROR_BUF_MGR:
1561
0
        case ERROR_MB_GROUP_ASSGN_T:
1562
0
        case ERROR_FRAME_LIMIT_OVER:
1563
0
        case ERROR_ACTUAL_RESOLUTION_GREATER_THAN_INIT:
1564
0
        case ERROR_PROFILE_NOT_SUPPORTED:
1565
0
        case ERROR_INIT_NOT_DONE:
1566
0
        case IVD_MEM_ALLOC_FAILED:
1567
0
            temp = 1 << IVD_FATALERROR;
1568
0
            H264_DEC_DEBUG_PRINT("\nFatal Error\n");
1569
0
            break;
1570
0
1571
0
        case ERROR_DBP_MANAGER_T:
1572
0
        case ERROR_GAPS_IN_FRM_NUM:
1573
0
        case ERROR_UNKNOWN_NAL:
1574
0
        case ERROR_INV_MB_SLC_GRP_T:
1575
0
        case ERROR_MULTIPLE_SLC_GRP_T:
1576
0
        case ERROR_UNKNOWN_LEVEL:
1577
0
        case ERROR_UNAVAIL_PICBUF_T:
1578
0
        case ERROR_UNAVAIL_MVBUF_T:
1579
0
        case ERROR_UNAVAIL_DISPBUF_T:
1580
0
        case ERROR_NUM_REF:
1581
0
        case ERROR_REFIDX_ORDER_T:
1582
0
        case ERROR_PIC0_NOT_FOUND_T:
1583
0
        case ERROR_MB_TYPE:
1584
0
        case ERROR_SUB_MB_TYPE:
1585
0
        case ERROR_CBP:
1586
0
        case ERROR_REF_IDX:
1587
0
        case ERROR_NUM_MV:
1588
0
        case ERROR_CHROMA_PRED_MODE:
1589
0
        case ERROR_INTRAPRED:
1590
0
        case ERROR_NEXT_MB_ADDRESS_T:
1591
0
        case ERROR_MB_ADDRESS_T:
1592
0
        case ERROR_PIC1_NOT_FOUND_T:
1593
0
        case ERROR_CAVLC_NUM_COEFF_T:
1594
0
        case ERROR_CAVLC_SCAN_POS_T:
1595
0
        case ERROR_PRED_WEIGHT_TABLE_T:
1596
0
        case ERROR_CORRUPTED_SLICE:
1597
0
            temp = 1 << IVD_CORRUPTEDDATA;
1598
0
            break;
1599
0
1600
0
        case ERROR_NOT_SUPP_RESOLUTION:
1601
0
        case ERROR_FEATURE_UNAVAIL:
1602
0
        case ERROR_ACTUAL_LEVEL_GREATER_THAN_INIT:
1603
0
            temp = 1 << IVD_UNSUPPORTEDINPUT;
1604
0
            break;
1605
0
1606
0
        case ERROR_INVALID_PIC_PARAM:
1607
0
        case ERROR_INVALID_SEQ_PARAM:
1608
0
        case ERROR_EGC_EXCEED_32_1_T:
1609
0
        case ERROR_EGC_EXCEED_32_2_T:
1610
0
        case ERROR_INV_RANGE_TEV_T:
1611
0
        case ERROR_INV_SLC_TYPE_T:
1612
0
        case ERROR_INV_POC_TYPE_T:
1613
0
        case ERROR_INV_RANGE_QP_T:
1614
0
        case ERROR_INV_SPS_PPS_T:
1615
0
        case ERROR_INV_SLICE_HDR_T:
1616
0
            temp = 1 << IVD_CORRUPTEDHEADER;
1617
0
            break;
1618
0
1619
0
        case ERROR_EOB_FLUSHBITS_T:
1620
0
        case ERROR_EOB_GETBITS_T:
1621
0
        case ERROR_EOB_GETBIT_T:
1622
0
        case ERROR_EOB_BYPASS_T:
1623
0
        case ERROR_EOB_DECISION_T:
1624
0
        case ERROR_EOB_TERMINATE_T:
1625
0
        case ERROR_EOB_READCOEFF4X4CAB_T:
1626
0
            temp = 1 << IVD_INSUFFICIENTDATA;
1627
0
            break;
1628
0
        case ERROR_DYNAMIC_RESOLUTION_NOT_SUPPORTED:
1629
0
        case ERROR_DISP_WIDTH_RESET_TO_PIC_WIDTH:
1630
0
            temp = 1 << IVD_UNSUPPORTEDPARAM | 1 << IVD_FATALERROR;
1631
0
            break;
1632
0
1633
0
        case ERROR_DANGLING_FIELD_IN_PIC:
1634
0
            temp = 1 << IVD_APPLIEDCONCEALMENT;
1635
0
            break;
1636
0
1637
0
    }
1638
0
1639
0
    return temp;
1640
0
1641
0
}
1642
1643
UWORD32 ih264d_get_outbuf_size(WORD32 pic_wd,
1644
                               UWORD32 pic_ht,
1645
                               UWORD8 u1_chroma_format,
1646
                               UWORD32 *p_buf_size)
1647
11
{
1648
11
    UWORD32 u4_min_num_out_bufs = 0;
1649
11
1650
11
    if(u1_chroma_format == IV_YUV_420P)
1651
11
        u4_min_num_out_bufs = MIN_OUT_BUFS_420;
1652
11
    else if(u1_chroma_format == IV_YUV_422ILE)
1653
0
        u4_min_num_out_bufs = MIN_OUT_BUFS_422ILE;
1654
0
    else if(u1_chroma_format == IV_RGB_565)
1655
0
        u4_min_num_out_bufs = MIN_OUT_BUFS_RGB565;
1656
0
    else if((u1_chroma_format == IV_YUV_420SP_UV)
1657
0
                    || (u1_chroma_format == IV_YUV_420SP_VU))
1658
0
        u4_min_num_out_bufs = MIN_OUT_BUFS_420SP;
1659
11
1660
11
    if(u1_chroma_format == IV_YUV_420P)
1661
11
    {
1662
11
        p_buf_size[0] = (pic_wd * pic_ht);
1663
11
        p_buf_size[1] = (pic_wd * pic_ht) >> 2;
1664
11
        p_buf_size[2] = (pic_wd * pic_ht) >> 2;
1665
11
    }
1666
0
    else if(u1_chroma_format == IV_YUV_422ILE)
1667
0
    {
1668
0
        p_buf_size[0] = (pic_wd * pic_ht) * 2;
1669
0
        p_buf_size[1] = p_buf_size[2] = 0;
1670
0
    }
1671
0
    else if(u1_chroma_format == IV_RGB_565)
1672
0
    {
1673
0
        p_buf_size[0] = (pic_wd * pic_ht) * 2;
1674
0
        p_buf_size[1] = p_buf_size[2] = 0;
1675
0
    }
1676
0
    else if((u1_chroma_format == IV_YUV_420SP_UV)
1677
0
                    || (u1_chroma_format == IV_YUV_420SP_VU))
1678
0
    {
1679
0
        p_buf_size[0] = (pic_wd * pic_ht);
1680
0
        p_buf_size[1] = (pic_wd * pic_ht) >> 1;
1681
0
        p_buf_size[2] = 0;
1682
0
    }
1683
11
1684
11
    return u4_min_num_out_bufs;
1685
11
}
1686
1687
WORD32 check_app_out_buf_size(dec_struct_t *ps_dec)
1688
11
{
1689
11
    UWORD32 au4_min_out_buf_size[IVD_VIDDEC_MAX_IO_BUFFERS];
1690
11
    UWORD32 u4_min_num_out_bufs, i;
1691
11
    UWORD32 pic_wd, pic_ht;
1692
11
1693
11
    if(0 == ps_dec->u4_share_disp_buf)
1694
11
    {
1695
11
        pic_wd = ps_dec->u2_disp_width;
1696
11
        pic_ht = ps_dec->u2_disp_height;
1697
11
1698
11
    }
1699
0
    else
1700
0
    {
1701
0
        pic_wd = ps_dec->u2_frm_wd_y;
1702
0
        pic_ht = ps_dec->u2_frm_ht_y;
1703
0
    }
1704
11
1705
11
    if(ps_dec->u4_app_disp_width > pic_wd)
1706
0
        pic_wd = ps_dec->u4_app_disp_width;
1707
11
1708
11
    u4_min_num_out_bufs = ih264d_get_outbuf_size(pic_wd, pic_ht,
1709
11
                                                 ps_dec->u1_chroma_format,
1710
11
                                                 &au4_min_out_buf_size[0]);
1711
11
1712
11
1713
11
    if(0 == ps_dec->u4_share_disp_buf)
1714
11
    {
1715
11
        if(ps_dec->ps_out_buffer->u4_num_bufs < u4_min_num_out_bufs)
1716
0
            return IV_FAIL;
1717
11
1718
44
        for(i = 0; i < u4_min_num_out_bufs; i++)
1719
33
        {
1720
33
            if(ps_dec->ps_out_buffer->u4_min_out_buf_size[i]
1721
33
                            < au4_min_out_buf_size[i])
1722
0
                return (IV_FAIL);
1723
33
        }
1724
11
    }
1725
0
    else
1726
0
    {
1727
0
        if(ps_dec->disp_bufs[0].u4_num_bufs < u4_min_num_out_bufs)
1728
0
            return IV_FAIL;
1729
0
1730
0
        for(i = 0; i < u4_min_num_out_bufs; i++)
1731
0
        {
1732
0
            /* We need to check only with the disp_buffer[0], because we have
1733
0
             * already ensured that all the buffers are of the same size in
1734
0
             * ih264d_set_display_frame.
1735
0
             */
1736
0
            if(ps_dec->disp_bufs[0].u4_bufsize[i] < au4_min_out_buf_size[i])
1737
0
                return (IV_FAIL);
1738
0
        }
1739
0
1740
0
    }
1741
11
1742
11
    return (IV_SUCCESS);
1743
11
}
1744
1745
1746
/*****************************************************************************/
1747
/*                                                                           */
1748
/*  Function Name :  ih264d_video_decode                                     */
1749
/*                                                                           */
1750
/*  Description   :  handle video decode API command                         */
1751
/*                                                                           */
1752
/*  Inputs        :iv_obj_t decoder handle                                   */
1753
/*                :pv_api_ip pointer to input structure                      */
1754
/*                :pv_api_op pointer to output structure                     */
1755
/*  Outputs       :                                                          */
1756
/*  Returns       : void                                                     */
1757
/*                                                                           */
1758
/*  Issues        : none                                                     */
1759
/*                                                                           */
1760
/*  Revision History:                                                        */
1761
/*                                                                           */
1762
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1763
/*         22 10 2008    100356         Draft                                */
1764
/*                                                                           */
1765
/*****************************************************************************/
1766
1767
WORD32 ih264d_video_decode(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
1768
13
{
1769
13
    /* ! */
1770
13
1771
13
    dec_struct_t * ps_dec = (dec_struct_t *)(dec_hdl->pv_codec_handle);
1772
13
1773
13
    WORD32 i4_err_status = 0;
1774
13
    UWORD8 *pu1_buf = NULL;
1775
13
    WORD32 buflen;
1776
13
    UWORD32 u4_max_ofst, u4_length_of_start_code = 0;
1777
13
1778
13
    UWORD32 bytes_consumed = 0;
1779
13
    UWORD32 cur_slice_is_nonref = 0;
1780
13
    UWORD32 u4_next_is_aud;
1781
13
    UWORD32 u4_first_start_code_found = 0;
1782
13
    WORD32 ret = 0,api_ret_value = IV_SUCCESS;
1783
13
    WORD32 header_data_left = 0,frame_data_left = 0;
1784
13
    UWORD8 *pu1_bitstrm_buf;
1785
13
    ivd_video_decode_ip_t *ps_dec_ip;
1786
13
    ivd_video_decode_op_t *ps_dec_op;
1787
13
1788
13
    ithread_set_name((void*)"Parse_thread");
1789
13
1790
13
    ps_dec_ip = (ivd_video_decode_ip_t *)pv_api_ip;
1791
13
    ps_dec_op = (ivd_video_decode_op_t *)pv_api_op;
1792
13
1793
13
    {
1794
13
        UWORD32 u4_size;
1795
13
        u4_size = ps_dec_op->u4_size;
1796
13
        memset(ps_dec_op, 0, sizeof(ivd_video_decode_op_t));
1797
13
        ps_dec_op->u4_size = u4_size;
1798
13
    }
1799
13
1800
13
    ps_dec->pv_dec_out = ps_dec_op;
1801
13
    if(ps_dec->init_done != 1)
1802
0
    {
1803
0
        return IV_FAIL;
1804
0
    }
1805
13
1806
13
    /*Data memory barries instruction,so that bitstream write by the application is complete*/
1807
13
    DATA_SYNC();
1808
13
1809
13
    if(0 == ps_dec->u1_flushfrm)
1810
13
    {
1811
13
        if(ps_dec_ip->pv_stream_buffer == NULL)
1812
13
        {
1813
0
            ps_dec_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
1814
0
            ps_dec_op->u4_error_code |= IVD_DEC_FRM_BS_BUF_NULL;
1815
0
            return IV_FAIL;
1816
0
        }
1817
13
        if(ps_dec_ip->u4_num_Bytes <= 0)
1818
0
        {
1819
0
            ps_dec_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
1820
0
            ps_dec_op->u4_error_code |= IVD_DEC_NUMBYTES_INV;
1821
0
            return IV_FAIL;
1822
0
1823
0
        }
1824
13
    }
1825
13
    ps_dec->u1_pic_decode_done = 0;
1826
13
1827
13
    ps_dec_op->u4_num_bytes_consumed = 0;
1828
13
1829
13
    ps_dec->ps_out_buffer = NULL;
1830
13
1831
13
    if(ps_dec_ip->u4_size
1832
13
                    >= offsetof(ivd_video_decode_ip_t, s_out_buffer))
1833
13
        ps_dec->ps_out_buffer = &ps_dec_ip->s_out_buffer;
1834
13
1835
13
    ps_dec->u4_fmt_conv_cur_row = 0;
1836
13
1837
13
    ps_dec->u4_output_present = 0;
1838
13
    ps_dec->s_disp_op.u4_error_code = 1;
1839
13
    ps_dec->u4_fmt_conv_num_rows = FMT_CONV_NUM_ROWS;
1840
13
    if(0 == ps_dec->u4_share_disp_buf
1841
13
                    && ps_dec->i4_decode_header == 0)
1842
13
    {
1843
13
        UWORD32 i;
1844
13
        if((ps_dec->ps_out_buffer->u4_num_bufs == 0) ||
1845
13
           (ps_dec->ps_out_buffer->u4_num_bufs > IVD_VIDDEC_MAX_IO_BUFFERS))
1846
0
        {
1847
0
            ps_dec_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
1848
0
            ps_dec_op->u4_error_code |= IVD_DISP_FRM_ZERO_OP_BUFS;
1849
0
            return IV_FAIL;
1850
0
        }
1851
13
1852
52
        for(i = 0; i < ps_dec->ps_out_buffer->u4_num_bufs; i++)
1853
39
        {
1854
39
            if(ps_dec->ps_out_buffer->pu1_bufs[i] == NULL)
1855
39
            {
1856
0
                ps_dec_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
1857
0
                ps_dec_op->u4_error_code |= IVD_DISP_FRM_OP_BUF_NULL;
1858
0
                return IV_FAIL;
1859
0
            }
1860
39
1861
39
            if(ps_dec->ps_out_buffer->u4_min_out_buf_size[i] == 0)
1862
0
            {
1863
0
                ps_dec_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
1864
0
                ps_dec_op->u4_error_code |=
1865
0
                                IVD_DISP_FRM_ZERO_OP_BUF_SIZE;
1866
0
                return IV_FAIL;
1867
0
            }
1868
39
        }
1869
13
    }
1870
13
1871
13
    if(ps_dec->u4_total_frames_decoded >= NUM_FRAMES_LIMIT)
1872
13
    {
1873
0
        ps_dec_op->u4_error_code = ERROR_FRAME_LIMIT_OVER;
1874
0
        return IV_FAIL;
1875
0
    }
1876
13
1877
13
    /* ! */
1878
13
    ps_dec->u4_ts = ps_dec_ip->u4_ts;
1879
13
1880
13
    ps_dec_op->u4_error_code = 0;
1881
13
    ps_dec_op->e_pic_type = -1;
1882
13
    ps_dec_op->u4_output_present = 0;
1883
13
    ps_dec_op->u4_frame_decoded_flag = 0;
1884
13
1885
13
    ps_dec->i4_frametype = -1;
1886
13
    ps_dec->i4_content_type = -1;
1887
13
1888
13
    ps_dec->u4_slice_start_code_found = 0;
1889
13
1890
13
    /* In case the deocder is not in flush mode(in shared mode),
1891
13
     then decoder has to pick up a buffer to write current frame.
1892
13
     Check if a frame is available in such cases */
1893
13
1894
13
    if(ps_dec->u1_init_dec_flag == 1 && ps_dec->u4_share_disp_buf == 1
1895
13
                    && ps_dec->u1_flushfrm == 0)
1896
0
    {
1897
0
        UWORD32 i;
1898
0
1899
0
        WORD32 disp_avail = 0, free_id;
1900
0
1901
0
        /* Check if at least one buffer is available with the codec */
1902
0
        /* If not then return to application with error */
1903
0
        for(i = 0; i < ps_dec->u1_pic_bufs; i++)
1904
0
        {
1905
0
            if(0 == ps_dec->u4_disp_buf_mapping[i]
1906
0
                            || 1 == ps_dec->u4_disp_buf_to_be_freed[i])
1907
0
            {
1908
0
                disp_avail = 1;
1909
0
                break;
1910
0
            }
1911
0
1912
0
        }
1913
0
1914
0
        if(0 == disp_avail)
1915
0
        {
1916
0
            /* If something is queued for display wait for that buffer to be returned */
1917
0
1918
0
            ps_dec_op->u4_error_code = IVD_DEC_REF_BUF_NULL;
1919
0
            ps_dec_op->u4_error_code |= (1 << IVD_UNSUPPORTEDPARAM);
1920
0
            return (IV_FAIL);
1921
0
        }
1922
0
1923
0
        while(1)
1924
0
        {
1925
0
            pic_buffer_t *ps_pic_buf;
1926
0
            ps_pic_buf = (pic_buffer_t *)ih264_buf_mgr_get_next_free(
1927
0
                            (buf_mgr_t *)ps_dec->pv_pic_buf_mgr, &free_id);
1928
0
1929
0
            if(ps_pic_buf == NULL)
1930
0
            {
1931
0
                UWORD32 i, display_queued = 0;
1932
0
1933
0
                /* check if any buffer was given for display which is not returned yet */
1934
0
                for(i = 0; i < (MAX_DISP_BUFS_NEW); i++)
1935
0
                {
1936
0
                    if(0 != ps_dec->u4_disp_buf_mapping[i])
1937
0
                    {
1938
0
                        display_queued = 1;
1939
0
                        break;
1940
0
                    }
1941
0
                }
1942
0
                /* If some buffer is queued for display, then codec has to singal an error and wait
1943
0
                 for that buffer to be returned.
1944
0
                 If nothing is queued for display then codec has ownership of all display buffers
1945
0
                 and it can reuse any of the existing buffers and continue decoding */
1946
0
1947
0
                if(1 == display_queued)
1948
0
                {
1949
0
                    /* If something is queued for display wait for that buffer to be returned */
1950
0
                    ps_dec_op->u4_error_code = IVD_DEC_REF_BUF_NULL;
1951
0
                    ps_dec_op->u4_error_code |= (1
1952
0
                                    << IVD_UNSUPPORTEDPARAM);
1953
0
                    return (IV_FAIL);
1954
0
                }
1955
0
            }
1956
0
            else
1957
0
            {
1958
0
                /* If the buffer is with display, then mark it as in use and then look for a buffer again */
1959
0
                if(1 == ps_dec->u4_disp_buf_mapping[free_id])
1960
0
                {
1961
0
                    ih264_buf_mgr_set_status(
1962
0
                                    (buf_mgr_t *)ps_dec->pv_pic_buf_mgr,
1963
0
                                    free_id,
1964
0
                                    BUF_MGR_IO);
1965
0
                }
1966
0
                else
1967
0
                {
1968
0
                    /**
1969
0
                     *  Found a free buffer for present call. Release it now.
1970
0
                     *  Will be again obtained later.
1971
0
                     */
1972
0
                    ih264_buf_mgr_release((buf_mgr_t *)ps_dec->pv_pic_buf_mgr,
1973
0
                                          free_id,
1974
0
                                          BUF_MGR_IO);
1975
0
                    break;
1976
0
                }
1977
0
            }
1978
0
        }
1979
0
1980
0
    }
1981
13
1982
13
    if(ps_dec->u1_flushfrm)
1983
0
    {
1984
0
        if(ps_dec->u1_init_dec_flag == 0)
1985
0
        {
1986
0
            /*Come out of flush mode and return*/
1987
0
            ps_dec->u1_flushfrm = 0;
1988
0
            return (IV_FAIL);
1989
0
        }
1990
0
1991
0
1992
0
1993
0
        ih264d_get_next_display_field(ps_dec, ps_dec->ps_out_buffer,
1994
0
                                      &(ps_dec->s_disp_op));
1995
0
        if(0 == ps_dec->s_disp_op.u4_error_code)
1996
0
        {
1997
0
            /* check output buffer size given by the application */
1998
0
            if(check_app_out_buf_size(ps_dec) != IV_SUCCESS)
1999
0
            {
2000
0
                ps_dec_op->u4_error_code= IVD_DISP_FRM_ZERO_OP_BUF_SIZE;
2001
0
                return (IV_FAIL);
2002
0
            }
2003
0
2004
0
            ps_dec->u4_fmt_conv_cur_row = 0;
2005
0
            ps_dec->u4_fmt_conv_num_rows = ps_dec->s_disp_frame_info.u4_y_ht;
2006
0
            ih264d_format_convert(ps_dec, &(ps_dec->s_disp_op),
2007
0
                                  ps_dec->u4_fmt_conv_cur_row,
2008
0
                                  ps_dec->u4_fmt_conv_num_rows);
2009
0
            ps_dec->u4_fmt_conv_cur_row += ps_dec->u4_fmt_conv_num_rows;
2010
0
            ps_dec->u4_output_present = 1;
2011
0
2012
0
        }
2013
0
        ih264d_release_display_field(ps_dec, &(ps_dec->s_disp_op));
2014
0
2015
0
        ps_dec_op->u4_pic_wd = (UWORD32)ps_dec->u2_disp_width;
2016
0
        ps_dec_op->u4_pic_ht = (UWORD32)ps_dec->u2_disp_height;
2017
0
2018
0
        ps_dec_op->u4_new_seq = 0;
2019
0
2020
0
        ps_dec_op->u4_output_present = ps_dec->u4_output_present;
2021
0
        ps_dec_op->u4_progressive_frame_flag =
2022
0
                        ps_dec->s_disp_op.u4_progressive_frame_flag;
2023
0
        ps_dec_op->e_output_format =
2024
0
                        ps_dec->s_disp_op.e_output_format;
2025
0
        ps_dec_op->s_disp_frm_buf = ps_dec->s_disp_op.s_disp_frm_buf;
2026
0
        ps_dec_op->e4_fld_type = ps_dec->s_disp_op.e4_fld_type;
2027
0
        ps_dec_op->u4_ts = ps_dec->s_disp_op.u4_ts;
2028
0
        ps_dec_op->u4_disp_buf_id = ps_dec->s_disp_op.u4_disp_buf_id;
2029
0
2030
0
        /*In the case of flush ,since no frame is decoded set pic type as invalid*/
2031
0
        ps_dec_op->u4_is_ref_flag = -1;
2032
0
        ps_dec_op->e_pic_type = IV_NA_FRAME;
2033
0
        ps_dec_op->u4_frame_decoded_flag = 0;
2034
0
2035
0
        if(0 == ps_dec->s_disp_op.u4_error_code)
2036
0
        {
2037
0
            return (IV_SUCCESS);
2038
0
        }
2039
0
        else
2040
0
            return (IV_FAIL);
2041
13
2042
13
    }
2043
13
    if(ps_dec->u1_res_changed == 1)
2044
0
    {
2045
0
        /*if resolution has changed and all buffers have been flushed, reset decoder*/
2046
0
        ih264d_init_decoder(ps_dec);
2047
0
    }
2048
13
2049
13
    ps_dec->u4_prev_nal_skipped = 0;
2050
13
2051
13
    ps_dec->u2_cur_mb_addr = 0;
2052
13
    ps_dec->u2_total_mbs_coded = 0;
2053
13
    ps_dec->u2_cur_slice_num = 0;
2054
13
    ps_dec->cur_dec_mb_num = 0;
2055
13
    ps_dec->cur_recon_mb_num = 0;
2056
13
    ps_dec->u4_first_slice_in_pic = 1;
2057
13
    ps_dec->u1_slice_header_done = 0;
2058
13
    ps_dec->u1_dangling_field = 0;
2059
13
2060
13
    ps_dec->u4_dec_thread_created = 0;
2061
13
    ps_dec->u4_bs_deblk_thread_created = 0;
2062
13
    ps_dec->u4_cur_bs_mb_num = 0;
2063
13
    ps_dec->u4_start_recon_deblk  = 0;
2064
13
    ps_dec->u4_sps_cnt_in_process = 0;
2065
13
2066
13
    DEBUG_THREADS_PRINTF(" Starting process call\n");
2067
13
2068
13
2069
13
    ps_dec->u4_pic_buf_got = 0;
2070
13
2071
13
    do
2072
13
    {
2073
13
        WORD32 buf_size;
2074
13
2075
13
        pu1_buf = (UWORD8*)ps_dec_ip->pv_stream_buffer
2076
13
                        + ps_dec_op->u4_num_bytes_consumed;
2077
13
2078
13
        u4_max_ofst = ps_dec_ip->u4_num_Bytes
2079
13
                        - ps_dec_op->u4_num_bytes_consumed;
2080
13
2081
13
        /* If dynamic bitstream buffer is not allocated and
2082
13
         * header decode is done, then allocate dynamic bitstream buffer
2083
13
         */
2084
13
        if((NULL == ps_dec->pu1_bits_buf_dynamic) &&
2085
13
           (ps_dec->i4_header_decoded & 1))
2086
1
        {
2087
1
            WORD32 size;
2088
1
2089
1
            void *pv_buf;
2090
1
            void *pv_mem_ctxt = ps_dec->pv_mem_ctxt;
2091
1
            size = MAX(256000, ps_dec->u2_pic_wd * ps_dec->u2_pic_ht * 3 / 2);
2092
1
            pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128,
2093
1
                                              size + EXTRA_BS_OFFSET);
2094
1
            RETURN_IF((NULL == pv_buf), IV_FAIL);
2095
1
            ps_dec->pu1_bits_buf_dynamic = pv_buf;
2096
1
            ps_dec->u4_dynamic_bits_buf_size = size;
2097
1
        }
2098
13
2099
13
        if(ps_dec->pu1_bits_buf_dynamic)
2100
12
        {
2101
12
            pu1_bitstrm_buf = ps_dec->pu1_bits_buf_dynamic;
2102
12
            buf_size = ps_dec->u4_dynamic_bits_buf_size;
2103
12
        }
2104
1
        else
2105
1
        {
2106
1
            pu1_bitstrm_buf = ps_dec->pu1_bits_buf_static;
2107
1
            buf_size = ps_dec->u4_static_bits_buf_size;
2108
1
        }
2109
13
2110
13
        u4_next_is_aud = 0;
2111
13
2112
13
        buflen = ih264d_find_start_code(pu1_buf, 0, u4_max_ofst,
2113
13
                                               &u4_length_of_start_code,
2114
13
                                               &u4_next_is_aud);
2115
13
2116
13
        if(buflen == -1)
2117
0
            buflen = 0;
2118
13
        /* Ignore bytes beyond the allocated size of intermediate buffer */
2119
13
        /* Since 8 bytes are read ahead, ensure 8 bytes are free at the
2120
13
        end of the buffer, which will be memset to 0 after emulation prevention */
2121
13
        buflen = MIN(buflen, buf_size - 8);
2122
13
2123
13
        bytes_consumed = buflen + u4_length_of_start_code;
2124
13
        ps_dec_op->u4_num_bytes_consumed += bytes_consumed;
2125
13
2126
13
        {
2127
13
            UWORD8 u1_firstbyte, u1_nal_ref_idc;
2128
13
2129
13
            if(ps_dec->i4_app_skip_mode == IVD_SKIP_B)
2130
0
            {
2131
0
                u1_firstbyte = *(pu1_buf + u4_length_of_start_code);
2132
0
                u1_nal_ref_idc = (UWORD8)(NAL_REF_IDC(u1_firstbyte));
2133
0
                if(u1_nal_ref_idc == 0)
2134
0
                {
2135
0
                    /*skip non reference frames*/
2136
0
                    cur_slice_is_nonref = 1;
2137
0
                    continue;
2138
0
                }
2139
0
                else
2140
0
                {
2141
0
                    if(1 == cur_slice_is_nonref)
2142
0
                    {
2143
0
                        /*We have encountered a referenced frame,return to app*/
2144
0
                        ps_dec_op->u4_num_bytes_consumed -=
2145
0
                                        bytes_consumed;
2146
0
                        ps_dec_op->e_pic_type = IV_B_FRAME;
2147
0
                        ps_dec_op->u4_error_code =
2148
0
                                        IVD_DEC_FRM_SKIPPED;
2149
0
                        ps_dec_op->u4_error_code |= (1
2150
0
                                        << IVD_UNSUPPORTEDPARAM);
2151
0
                        ps_dec_op->u4_frame_decoded_flag = 0;
2152
0
                        ps_dec_op->u4_size =
2153
0
                                        sizeof(ivd_video_decode_op_t);
2154
0
                        /*signal the decode thread*/
2155
0
                        ih264d_signal_decode_thread(ps_dec);
2156
0
                        /* close deblock thread if it is not closed yet*/
2157
0
                        if(ps_dec->u4_num_cores == 3)
2158
0
                        {
2159
0
                            ih264d_signal_bs_deblk_thread(ps_dec);
2160
0
                        }
2161
0
2162
0
                        return (IV_FAIL);
2163
0
                    }
2164
13
                }
2165
0
2166
0
            }
2167
13
2168
13
        }
2169
13
2170
13
2171
13
        if(buflen)
2172
13
        {
2173
13
            memcpy(pu1_bitstrm_buf, pu1_buf + u4_length_of_start_code,
2174
13
                   buflen);
2175
13
            /* Decoder may read extra 8 bytes near end of the frame */
2176
13
            if((buflen + 8) < buf_size)
2177
13
            {
2178
13
                memset(pu1_bitstrm_buf + buflen, 0, 8);
2179
13
            }
2180
13
            u4_first_start_code_found = 1;
2181
13
2182
13
        }
2183
0
        else
2184
0
        {
2185
0
            /*start code not found*/
2186
0
2187
0
            if(u4_first_start_code_found == 0)
2188
0
            {
2189
0
                /*no start codes found in current process call*/
2190
0
2191
0
                ps_dec->i4_error_code = ERROR_START_CODE_NOT_FOUND;
2192
0
                ps_dec_op->u4_error_code |= 1 << IVD_INSUFFICIENTDATA;
2193
0
2194
0
                if(ps_dec->u4_pic_buf_got == 0)
2195
0
                {
2196
0
2197
0
                    ih264d_fill_output_struct_from_context(ps_dec,
2198
0
                                                           ps_dec_op);
2199
0
2200
0
                    ps_dec_op->u4_error_code = ps_dec->i4_error_code;
2201
0
                    ps_dec_op->u4_frame_decoded_flag = 0;
2202
0
2203
0
                    return (IV_FAIL);
2204
0
                }
2205
0
                else
2206
0
                {
2207
0
                    ps_dec->u1_pic_decode_done = 1;
2208
0
                    continue;
2209
0
                }
2210
0
            }
2211
0
            else
2212
0
            {
2213
0
                /* a start code has already been found earlier in the same process call*/
2214
0
                frame_data_left = 0;
2215
0
                header_data_left = 0;
2216
0
                continue;
2217
0
            }
2218
13
2219
13
        }
2220
13
2221
13
        ps_dec->u4_return_to_app = 0;
2222
13
        ret = ih264d_parse_nal_unit(dec_hdl, ps_dec_op,
2223
13
                              pu1_bitstrm_buf, buflen);
2224
13
        if(ret != OK)
2225
13
        {
2226
0
            UWORD32 error =  ih264d_map_error(ret);
2227
0
            ps_dec_op->u4_error_code = error | ret;
2228
0
            api_ret_value = IV_FAIL;
2229
0
2230
0
            if((ret == IVD_RES_CHANGED)
2231
0
                            || (ret == IVD_MEM_ALLOC_FAILED)
2232
0
                            || (ret == ERROR_UNAVAIL_PICBUF_T)
2233
0
                            || (ret == ERROR_UNAVAIL_MVBUF_T)
2234
0
                            || (ret == ERROR_INV_SPS_PPS_T)
2235
0
                            || (ret == IVD_DISP_FRM_ZERO_OP_BUF_SIZE))
2236
0
            {
2237
0
                ps_dec->u4_slice_start_code_found = 0;
2238
0
                break;
2239
0
            }
2240
0
2241
0
            if((ret == ERROR_INCOMPLETE_FRAME) || (ret == ERROR_DANGLING_FIELD_IN_PIC))
2242
0
            {
2243
0
                ps_dec_op->u4_num_bytes_consumed -= bytes_consumed;
2244
0
                api_ret_value = IV_FAIL;
2245
0
                break;
2246
0
            }
2247
0
2248
0
            if(ret == ERROR_IN_LAST_SLICE_OF_PIC)
2249
0
            {
2250
0
                api_ret_value = IV_FAIL;
2251
0
                break;
2252
0
            }
2253
13
2254
13
        }
2255
13
2256
13
        if(ps_dec->u4_return_to_app)
2257
0
        {
2258
0
            /*We have encountered a referenced frame,return to app*/
2259
0
            ps_dec_op->u4_num_bytes_consumed -= bytes_consumed;
2260
0
            ps_dec_op->u4_error_code = IVD_DEC_FRM_SKIPPED;
2261
0
            ps_dec_op->u4_error_code |= (1 << IVD_UNSUPPORTEDPARAM);
2262
0
            ps_dec_op->u4_frame_decoded_flag = 0;
2263
0
            ps_dec_op->u4_size = sizeof(ivd_video_decode_op_t);
2264
0
            /*signal the decode thread*/
2265
0
            ih264d_signal_decode_thread(ps_dec);
2266
0
            /* close deblock thread if it is not closed yet*/
2267
0
            if(ps_dec->u4_num_cores == 3)
2268
0
            {
2269
0
                ih264d_signal_bs_deblk_thread(ps_dec);
2270
0
            }
2271
0
            return (IV_FAIL);
2272
0
2273
0
        }
2274
13
2275
13
2276
13
2277
13
        header_data_left = ((ps_dec->i4_decode_header == 1)
2278
13
                        && (ps_dec->i4_header_decoded != 3)
2279
13
                        && (ps_dec_op->u4_num_bytes_consumed
2280
0
                                        < ps_dec_ip->u4_num_Bytes));
2281
13
        frame_data_left = (((ps_dec->i4_decode_header == 0)
2282
13
                        && ((ps_dec->u1_pic_decode_done == 0)
2283
13
                                        || (u4_next_is_aud == 1)))
2284
13
                        && (ps_dec_op->u4_num_bytes_consumed
2285
2
                                        < ps_dec_ip->u4_num_Bytes));
2286
13
    }
2287
13
    while(( header_data_left == 1)||(frame_data_left == 1));
2288
13
2289
13
    if((ps_dec->u4_pic_buf_got == 1)
2290
13
            && (ret != IVD_MEM_ALLOC_FAILED)
2291
13
            && ps_dec->u2_total_mbs_coded < ps_dec->u2_frm_ht_in_mbs * ps_dec->u2_frm_wd_in_mbs)
2292
0
    {
2293
0
        // last slice - missing/corruption
2294
0
        WORD32 num_mb_skipped;
2295
0
        WORD32 prev_slice_err;
2296
0
        pocstruct_t temp_poc;
2297
0
        WORD32 ret1;
2298
0
        WORD32 ht_in_mbs;
2299
0
        ht_in_mbs = ps_dec->u2_pic_ht >> (4 + ps_dec->ps_cur_slice->u1_field_pic_flag);
2300
0
        num_mb_skipped = (ht_in_mbs * ps_dec->u2_frm_wd_in_mbs)
2301
0
                            - ps_dec->u2_total_mbs_coded;
2302
0
2303
0
        if(ps_dec->u4_first_slice_in_pic && (ps_dec->u4_pic_buf_got == 0))
2304
0
            prev_slice_err = 1;
2305
0
        else
2306
0
            prev_slice_err = 2;
2307
0
2308
0
        if(ps_dec->u4_first_slice_in_pic && (ps_dec->u2_total_mbs_coded == 0))
2309
0
            prev_slice_err = 1;
2310
0
2311
0
        ret1 = ih264d_mark_err_slice_skip(ps_dec, num_mb_skipped, ps_dec->u1_nal_unit_type == IDR_SLICE_NAL, ps_dec->ps_cur_slice->u2_frame_num,
2312
0
                                   &temp_poc, prev_slice_err);
2313
0
2314
0
        if((ret1 == ERROR_UNAVAIL_PICBUF_T) || (ret1 == ERROR_UNAVAIL_MVBUF_T) ||
2315
0
                       (ret1 == ERROR_INV_SPS_PPS_T))
2316
0
        {
2317
0
            ret = ret1;
2318
0
        }
2319
0
    }
2320
13
2321
13
    if((ret == IVD_RES_CHANGED)
2322
13
                    || (ret == IVD_MEM_ALLOC_FAILED)
2323
13
                    || (ret == ERROR_UNAVAIL_PICBUF_T)
2324
13
                    || (ret == ERROR_UNAVAIL_MVBUF_T)
2325
13
                    || (ret == ERROR_INV_SPS_PPS_T))
2326
0
    {
2327
0
2328
0
        /* signal the decode thread */
2329
0
        ih264d_signal_decode_thread(ps_dec);
2330
0
        /* close deblock thread if it is not closed yet */
2331
0
        if(ps_dec->u4_num_cores == 3)
2332
0
        {
2333
0
            ih264d_signal_bs_deblk_thread(ps_dec);
2334
0
        }
2335
0
        /* dont consume bitstream for change in resolution case */
2336
0
        if(ret == IVD_RES_CHANGED)
2337
0
        {
2338
0
            ps_dec_op->u4_num_bytes_consumed -= bytes_consumed;
2339
0
        }
2340
0
        return IV_FAIL;
2341
0
    }
2342
13
2343
13
2344
13
    if(ps_dec->u1_separate_parse)
2345
13
    {
2346
13
        /* If Format conversion is not complete,
2347
13
         complete it here */
2348
13
        if(ps_dec->u4_num_cores == 2)
2349
0
        {
2350
0
2351
0
            /*do deblocking of all mbs*/
2352
0
            if((ps_dec->u4_nmb_deblk == 0) &&(ps_dec->u4_start_recon_deblk == 1) && (ps_dec->ps_cur_sps->u1_mb_aff_flag == 0))
2353
0
            {
2354
0
                UWORD32 u4_num_mbs,u4_max_addr;
2355
0
                tfr_ctxt_t s_tfr_ctxt;
2356
0
                tfr_ctxt_t *ps_tfr_cxt = &s_tfr_ctxt;
2357
0
                pad_mgr_t *ps_pad_mgr = &ps_dec->s_pad_mgr;
2358
0
2359
0
                /*BS is done for all mbs while parsing*/
2360
0
                u4_max_addr = (ps_dec->u2_frm_wd_in_mbs * ps_dec->u2_frm_ht_in_mbs) - 1;
2361
0
                ps_dec->u4_cur_bs_mb_num = u4_max_addr + 1;
2362
0
2363
0
2364
0
                ih264d_init_deblk_tfr_ctxt(ps_dec, ps_pad_mgr, ps_tfr_cxt,
2365
0
                                           ps_dec->u2_frm_wd_in_mbs, 0);
2366
0
2367
0
2368
0
                u4_num_mbs = u4_max_addr
2369
0
                                - ps_dec->u4_cur_deblk_mb_num + 1;
2370
0
2371
0
                DEBUG_PERF_PRINTF("mbs left for deblocking= %d \n",u4_num_mbs);
2372
0
2373
0
                if(u4_num_mbs != 0)
2374
0
                    ih264d_check_mb_map_deblk(ps_dec, u4_num_mbs,
2375
0
                                                   ps_tfr_cxt,1);
2376
0
2377
0
                ps_dec->u4_start_recon_deblk  = 0;
2378
0
2379
0
            }
2380
0
2381
0
        }
2382
13
2383
13
        /*signal the decode thread*/
2384
13
        ih264d_signal_decode_thread(ps_dec);
2385
13
        /* close deblock thread if it is not closed yet*/
2386
13
        if(ps_dec->u4_num_cores == 3)
2387
13
        {
2388
13
            ih264d_signal_bs_deblk_thread(ps_dec);
2389
13
        }
2390
13
    }
2391
13
2392
13
2393
13
    DATA_SYNC();
2394
13
2395
13
2396
13
    if((ps_dec_op->u4_error_code & 0xff)
2397
13
                    != ERROR_DYNAMIC_RESOLUTION_NOT_SUPPORTED)
2398
13
    {
2399
13
        ps_dec_op->u4_pic_wd = (UWORD32)ps_dec->u2_disp_width;
2400
13
        ps_dec_op->u4_pic_ht = (UWORD32)ps_dec->u2_disp_height;
2401
13
    }
2402
13
2403
13
//Report if header (sps and pps) has not been decoded yet
2404
13
    if(ps_dec->i4_header_decoded != 3)
2405
1
    {
2406
1
        ps_dec_op->u4_error_code |= (1 << IVD_INSUFFICIENTDATA);
2407
1
2408
1
    }
2409
13
2410
13
    if(ps_dec->i4_decode_header == 1 && ps_dec->i4_header_decoded != 3)
2411
0
    {
2412
0
        ps_dec_op->u4_error_code |= (1 << IVD_INSUFFICIENTDATA);
2413
0
2414
0
    }
2415
13
    if(ps_dec->u4_prev_nal_skipped)
2416
0
    {
2417
0
        /*We have encountered a referenced frame,return to app*/
2418
0
        ps_dec_op->u4_error_code = IVD_DEC_FRM_SKIPPED;
2419
0
        ps_dec_op->u4_error_code |= (1 << IVD_UNSUPPORTEDPARAM);
2420
0
        ps_dec_op->u4_frame_decoded_flag = 0;
2421
0
        ps_dec_op->u4_size = sizeof(ivd_video_decode_op_t);
2422
0
        /* close deblock thread if it is not closed yet*/
2423
0
        if(ps_dec->u4_num_cores == 3)
2424
0
        {
2425
0
            ih264d_signal_bs_deblk_thread(ps_dec);
2426
0
        }
2427
0
        return (IV_FAIL);
2428
0
2429
0
    }
2430
13
2431
13
    if((ps_dec->u4_pic_buf_got == 1)
2432
13
                    && (ERROR_DANGLING_FIELD_IN_PIC != i4_err_status))
2433
11
    {
2434
11
        /*
2435
11
         * For field pictures, set the bottom and top picture decoded u4_flag correctly.
2436
11
         */
2437
11
2438
11
        if(ps_dec->ps_cur_slice->u1_field_pic_flag)
2439
0
        {
2440
0
            if(1 == ps_dec->ps_cur_slice->u1_bottom_field_flag)
2441
0
            {
2442
0
                ps_dec->u1_top_bottom_decoded |= BOT_FIELD_ONLY;
2443
0
            }
2444
0
            else
2445
0
            {
2446
0
                ps_dec->u1_top_bottom_decoded |= TOP_FIELD_ONLY;
2447
0
            }
2448
0
        }
2449
11
        else
2450
11
        {
2451
11
                ps_dec->u1_top_bottom_decoded = TOP_FIELD_ONLY | BOT_FIELD_ONLY;
2452
11
        }
2453
11
2454
11
        /* if new frame in not found (if we are still getting slices from previous frame)
2455
11
         * ih264d_deblock_display is not called. Such frames will not be added to reference /display
2456
11
         */
2457
11
        if ((ps_dec->ps_dec_err_status->u1_err_flag & REJECT_CUR_PIC) == 0)
2458
11
        {
2459
11
            /* Calling Function to deblock Picture and Display */
2460
11
            ret = ih264d_deblock_display(ps_dec);
2461
11
        }
2462
11
2463
11
2464
11
        /*set to complete ,as we dont support partial frame decode*/
2465
11
        if(ps_dec->i4_header_decoded == 3)
2466
11
        {
2467
11
            ps_dec->u2_total_mbs_coded = ps_dec->ps_cur_sps->u2_max_mb_addr + 1;
2468
11
        }
2469
11
2470
11
        /*Update the i4_frametype at the end of picture*/
2471
11
        if(ps_dec->ps_cur_slice->u1_nal_unit_type == IDR_SLICE_NAL)
2472
11
        {
2473
11
            ps_dec->i4_frametype = IV_IDR_FRAME;
2474
11
        }
2475
0
        else if(ps_dec->i4_pic_type == B_SLICE)
2476
0
        {
2477
0
            ps_dec->i4_frametype = IV_B_FRAME;
2478
0
        }
2479
0
        else if(ps_dec->i4_pic_type == P_SLICE)
2480
0
        {
2481
0
            ps_dec->i4_frametype = IV_P_FRAME;
2482
0
        }
2483
0
        else if(ps_dec->i4_pic_type == I_SLICE)
2484
0
        {
2485
0
            ps_dec->i4_frametype = IV_I_FRAME;
2486
0
        }
2487
0
        else
2488
0
        {
2489
0
            H264_DEC_DEBUG_PRINT("Shouldn't come here\n");
2490
0
        }
2491
11
2492
11
        //Update the content type
2493
11
        ps_dec->i4_content_type = ps_dec->ps_cur_slice->u1_field_pic_flag;
2494
11
2495
11
        ps_dec->u4_total_frames_decoded = ps_dec->u4_total_frames_decoded + 2;
2496
11
        ps_dec->u4_total_frames_decoded = ps_dec->u4_total_frames_decoded
2497
11
                        - ps_dec->ps_cur_slice->u1_field_pic_flag;
2498
11
2499
11
    }
2500
13
2501
13
    /* close deblock thread if it is not closed yet*/
2502
13
    if(ps_dec->u4_num_cores == 3)
2503
13
    {
2504
13
        ih264d_signal_bs_deblk_thread(ps_dec);
2505
13
    }
2506
13
2507
13
2508
13
    {
2509
13
        /* In case the decoder is configured to run in low delay mode,
2510
13
         * then get display buffer and then format convert.
2511
13
         * Note in this mode, format conversion does not run paralelly in a thread and adds to the codec cycles
2512
13
         */
2513
13
2514
13
        if((IVD_DECODE_FRAME_OUT == ps_dec->e_frm_out_mode)
2515
13
                        && ps_dec->u1_init_dec_flag)
2516
0
        {
2517
0
2518
0
            ih264d_get_next_display_field(ps_dec, ps_dec->ps_out_buffer,
2519
0
                                          &(ps_dec->s_disp_op));
2520
0
            if(0 == ps_dec->s_disp_op.u4_error_code)
2521
0
            {
2522
0
                ps_dec->u4_fmt_conv_cur_row = 0;
2523
0
                ps_dec->u4_output_present = 1;
2524
0
            }
2525
0
        }
2526
13
2527
13
        ih264d_fill_output_struct_from_context(ps_dec, ps_dec_op);
2528
13
2529
13
        /* If Format conversion is not complete,
2530
13
         complete it here */
2531
13
        if(ps_dec->u4_output_present &&
2532
13
          (ps_dec->u4_fmt_conv_cur_row < ps_dec->s_disp_frame_info.u4_y_ht))
2533
0
        {
2534
0
            ps_dec->u4_fmt_conv_num_rows = ps_dec->s_disp_frame_info.u4_y_ht
2535
0
                            - ps_dec->u4_fmt_conv_cur_row;
2536
0
            ih264d_format_convert(ps_dec, &(ps_dec->s_disp_op),
2537
0
                                  ps_dec->u4_fmt_conv_cur_row,
2538
0
                                  ps_dec->u4_fmt_conv_num_rows);
2539
0
            ps_dec->u4_fmt_conv_cur_row += ps_dec->u4_fmt_conv_num_rows;
2540
0
        }
2541
13
2542
13
        ih264d_release_display_field(ps_dec, &(ps_dec->s_disp_op));
2543
13
    }
2544
13
2545
13
    if(ps_dec->i4_decode_header == 1 && (ps_dec->i4_header_decoded & 1) == 1)
2546
0
    {
2547
0
        ps_dec_op->u4_progressive_frame_flag = 1;
2548
0
        if((NULL != ps_dec->ps_cur_sps) && (1 == (ps_dec->ps_cur_sps->u1_is_valid)))
2549
0
        {
2550
0
            if((0 == ps_dec->ps_sps->u1_frame_mbs_only_flag)
2551
0
                            && (0 == ps_dec->ps_sps->u1_mb_aff_flag))
2552
0
                ps_dec_op->u4_progressive_frame_flag = 0;
2553
0
2554
0
        }
2555
0
    }
2556
13
2557
13
    if((TOP_FIELD_ONLY | BOT_FIELD_ONLY) == ps_dec->u1_top_bottom_decoded)
2558
11
    {
2559
11
        ps_dec->u1_top_bottom_decoded = 0;
2560
11
    }
2561
13
    /*--------------------------------------------------------------------*/
2562
13
    /* Do End of Pic processing.                                          */
2563
13
    /* Should be called only if frame was decoded in previous process call*/
2564
13
    /*--------------------------------------------------------------------*/
2565
13
    if(ps_dec->u4_pic_buf_got == 1)
2566
11
    {
2567
11
        if(1 == ps_dec->u1_last_pic_not_decoded)
2568
0
        {
2569
0
            ret = ih264d_end_of_pic_dispbuf_mgr(ps_dec);
2570
0
2571
0
            if(ret != OK)
2572
0
                return ret;
2573
0
2574
0
            ret = ih264d_end_of_pic(ps_dec);
2575
0
            if(ret != OK)
2576
0
                return ret;
2577
11
        }
2578
11
        else
2579
11
        {
2580
11
            ret = ih264d_end_of_pic(ps_dec);
2581
11
            if(ret != OK)
2582
11
                return ret;
2583
13
        }
2584
11
2585
11
    }
2586
13
2587
13
2588
13
    /*Data memory barrier instruction,so that yuv write by the library is complete*/
2589
13
    DATA_SYNC();
2590
13
2591
13
    H264_DEC_DEBUG_PRINT("The num bytes consumed: %d\n",
2592
13
                         ps_dec_op->u4_num_bytes_consumed);
2593
13
    return api_ret_value;
2594
13
}
2595
2596
WORD32 ih264d_get_version(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
2597
1
{
2598
1
    char version_string[MAXVERSION_STRLEN + 1];
2599
1
    UWORD32 version_string_len;
2600
1
2601
1
    ivd_ctl_getversioninfo_ip_t *ps_ip;
2602
1
    ivd_ctl_getversioninfo_op_t *ps_op;
2603
1
2604
1
    ps_ip = (ivd_ctl_getversioninfo_ip_t *)pv_api_ip;
2605
1
    ps_op = (ivd_ctl_getversioninfo_op_t *)pv_api_op;
2606
1
    UNUSED(dec_hdl);
2607
1
    ps_op->u4_error_code = IV_SUCCESS;
2608
1
2609
1
    VERSION(version_string, CODEC_NAME, CODEC_RELEASE_TYPE, CODEC_RELEASE_VER,
2610
1
            CODEC_VENDOR);
2611
1
2612
1
    if((WORD32)ps_ip->u4_version_buffer_size <= 0)
2613
0
    {
2614
0
        ps_op->u4_error_code = IH264D_VERS_BUF_INSUFFICIENT;
2615
0
        return (IV_FAIL);
2616
0
    }
2617
1
2618
1
    version_string_len = strnlen(version_string, MAXVERSION_STRLEN) + 1;
2619
1
2620
1
    if(ps_ip->u4_version_buffer_size >= version_string_len) //(WORD32)sizeof(sizeof(version_string)))
2621
1
    {
2622
1
        memcpy(ps_ip->pv_version_buffer, version_string, version_string_len);
2623
1
        ps_op->u4_error_code = IV_SUCCESS;
2624
1
    }
2625
0
    else
2626
0
    {
2627
0
        ps_op->u4_error_code = IH264D_VERS_BUF_INSUFFICIENT;
2628
0
        return IV_FAIL;
2629
0
    }
2630
1
    return (IV_SUCCESS);
2631
1
}
2632
2633
/*****************************************************************************/
2634
/*                                                                           */
2635
/*  Function Name :   ih264d_get_display_frame                               */
2636
/*                                                                           */
2637
/*  Description   :                                                          */
2638
/*  Inputs        :iv_obj_t decoder handle                                   */
2639
/*                :pv_api_ip pointer to input structure                      */
2640
/*                :pv_api_op pointer to output structure                     */
2641
/*  Outputs       :                                                          */
2642
/*  Returns       : void                                                     */
2643
/*                                                                           */
2644
/*  Issues        : none                                                     */
2645
/*                                                                           */
2646
/*  Revision History:                                                        */
2647
/*                                                                           */
2648
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
2649
/*         22 10 2008    100356         Draft                                */
2650
/*                                                                           */
2651
/*****************************************************************************/
2652
WORD32 ih264d_get_display_frame(iv_obj_t *dec_hdl,
2653
                                void *pv_api_ip,
2654
                                void *pv_api_op)
2655
0
{
2656
0
2657
0
    UNUSED(dec_hdl);
2658
0
    UNUSED(pv_api_ip);
2659
0
    UNUSED(pv_api_op);
2660
0
    // This function is no longer needed, output is returned in the process()
2661
0
    return IV_FAIL;
2662
0
}
2663
2664
/*****************************************************************************/
2665
/*                                                                           */
2666
/*  Function Name :  ih264d_set_display_frame                                */
2667
/*                                                                           */
2668
/*  Description   :                                                          */
2669
/*                                                                           */
2670
/*  Inputs        :iv_obj_t decoder handle                                   */
2671
/*                :pv_api_ip pointer to input structure                      */
2672
/*                :pv_api_op pointer to output structure                     */
2673
/*  Outputs       :                                                          */
2674
/*  Returns       : void                                                     */
2675
/*                                                                           */
2676
/*  Issues        : none                                                     */
2677
/*                                                                           */
2678
/*  Revision History:                                                        */
2679
/*                                                                           */
2680
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
2681
/*         22 10 2008    100356         Draft                                */
2682
/*                                                                           */
2683
/*****************************************************************************/
2684
WORD32 ih264d_set_display_frame(iv_obj_t *dec_hdl,
2685
                                void *pv_api_ip,
2686
                                void *pv_api_op)
2687
0
{
2688
0
2689
0
    UWORD32 u4_disp_buf_size[3], u4_num_disp_bufs;
2690
0
    ivd_set_display_frame_ip_t *dec_disp_ip;
2691
0
    ivd_set_display_frame_op_t *dec_disp_op;
2692
0
2693
0
    UWORD32 i;
2694
0
    dec_struct_t * ps_dec = (dec_struct_t *)(dec_hdl->pv_codec_handle);
2695
0
2696
0
    dec_disp_ip = (ivd_set_display_frame_ip_t *)pv_api_ip;
2697
0
    dec_disp_op = (ivd_set_display_frame_op_t *)pv_api_op;
2698
0
    dec_disp_op->u4_error_code = 0;
2699
0
2700
0
2701
0
    ps_dec->u4_num_disp_bufs = 0;
2702
0
    if(ps_dec->u4_share_disp_buf)
2703
0
    {
2704
0
        UWORD32 u4_num_bufs = dec_disp_ip->num_disp_bufs;
2705
0
2706
0
        u4_num_bufs = MIN(u4_num_bufs, MAX_DISP_BUFS_NEW);
2707
0
2708
0
        ps_dec->u4_num_disp_bufs = u4_num_bufs;
2709
0
2710
0
        /* Get the number and sizes of the first buffer. Compare this with the
2711
0
         * rest to make sure all the buffers are of the same size.
2712
0
         */
2713
0
        u4_num_disp_bufs = dec_disp_ip->s_disp_buffer[0].u4_num_bufs;
2714
0
2715
0
        u4_disp_buf_size[0] =
2716
0
          dec_disp_ip->s_disp_buffer[0].u4_min_out_buf_size[0];
2717
0
        u4_disp_buf_size[1] =
2718
0
          dec_disp_ip->s_disp_buffer[0].u4_min_out_buf_size[1];
2719
0
        u4_disp_buf_size[2] =
2720
0
          dec_disp_ip->s_disp_buffer[0].u4_min_out_buf_size[2];
2721
0
2722
0
        for(i = 0; i < u4_num_bufs; i++)
2723
0
        {
2724
0
            if(dec_disp_ip->s_disp_buffer[i].u4_num_bufs != u4_num_disp_bufs)
2725
0
            {
2726
0
                return IV_FAIL;
2727
0
            }
2728
0
2729
0
            if((dec_disp_ip->s_disp_buffer[i].u4_min_out_buf_size[0]
2730
0
                != u4_disp_buf_size[0])
2731
0
                || (dec_disp_ip->s_disp_buffer[i].u4_min_out_buf_size[1]
2732
0
                    != u4_disp_buf_size[1])
2733
0
                || (dec_disp_ip->s_disp_buffer[i].u4_min_out_buf_size[2]
2734
0
                    != u4_disp_buf_size[2]))
2735
0
            {
2736
0
                return IV_FAIL;
2737
0
            }
2738
0
2739
0
            ps_dec->disp_bufs[i].u4_num_bufs =
2740
0
                            dec_disp_ip->s_disp_buffer[i].u4_num_bufs;
2741
0
2742
0
            ps_dec->disp_bufs[i].buf[0] =
2743
0
                            dec_disp_ip->s_disp_buffer[i].pu1_bufs[0];
2744
0
            ps_dec->disp_bufs[i].buf[1] =
2745
0
                            dec_disp_ip->s_disp_buffer[i].pu1_bufs[1];
2746
0
            ps_dec->disp_bufs[i].buf[2] =
2747
0
                            dec_disp_ip->s_disp_buffer[i].pu1_bufs[2];
2748
0
2749
0
            ps_dec->disp_bufs[i].u4_bufsize[0] =
2750
0
                            dec_disp_ip->s_disp_buffer[i].u4_min_out_buf_size[0];
2751
0
            ps_dec->disp_bufs[i].u4_bufsize[1] =
2752
0
                            dec_disp_ip->s_disp_buffer[i].u4_min_out_buf_size[1];
2753
0
            ps_dec->disp_bufs[i].u4_bufsize[2] =
2754
0
                            dec_disp_ip->s_disp_buffer[i].u4_min_out_buf_size[2];
2755
0
2756
0
        }
2757
0
    }
2758
0
    return IV_SUCCESS;
2759
0
2760
0
}
2761
2762
/*****************************************************************************/
2763
/*                                                                           */
2764
/*  Function Name : ih264d_set_flush_mode                                    */
2765
/*                                                                           */
2766
/*  Description   :                                                          */
2767
/*                                                                           */
2768
/*  Inputs        :iv_obj_t decoder handle                                   */
2769
/*                :pv_api_ip pointer to input structure                      */
2770
/*                :pv_api_op pointer to output structure                     */
2771
/*  Globals       : <Does it use any global variables?>                      */
2772
/*  Outputs       :                                                          */
2773
/*  Returns       : void                                                     */
2774
/*                                                                           */
2775
/*  Issues        : none                                                     */
2776
/*                                                                           */
2777
/*  Revision History:                                                        */
2778
/*                                                                           */
2779
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
2780
/*         22 10 2008    100356         Draft                                */
2781
/*                                                                           */
2782
/*****************************************************************************/
2783
WORD32 ih264d_set_flush_mode(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
2784
0
{
2785
0
    dec_struct_t * ps_dec;
2786
0
    ivd_ctl_flush_op_t *ps_ctl_op = (ivd_ctl_flush_op_t*)pv_api_op;
2787
0
    ps_ctl_op->u4_error_code = 0;
2788
0
2789
0
    ps_dec = (dec_struct_t *)(dec_hdl->pv_codec_handle);
2790
0
    UNUSED(pv_api_ip);
2791
0
    /* ! */
2792
0
    /* Signal flush frame control call */
2793
0
    ps_dec->u1_flushfrm = 1;
2794
0
2795
0
    if(ps_dec->u1_init_dec_flag == 1)
2796
0
    {
2797
0
        ih264d_release_pics_in_dpb((void *)ps_dec, ps_dec->u1_pic_bufs);
2798
0
        ih264d_release_display_bufs(ps_dec);
2799
0
    }
2800
0
2801
0
    ps_ctl_op->u4_error_code = 0;
2802
0
2803
0
    /* Ignore dangling fields during flush */
2804
0
    ps_dec->u1_top_bottom_decoded = 0;
2805
0
2806
0
    return IV_SUCCESS;
2807
0
}
2808
2809
/*****************************************************************************/
2810
/*                                                                           */
2811
/*  Function Name : ih264d_get_status                                        */
2812
/*                                                                           */
2813
/*  Description   :                                                          */
2814
/*                                                                           */
2815
/*  Inputs        :iv_obj_t decoder handle                                   */
2816
/*                :pv_api_ip pointer to input structure                      */
2817
/*                :pv_api_op pointer to output structure                     */
2818
/*  Globals       : <Does it use any global variables?>                      */
2819
/*  Outputs       :                                                          */
2820
/*  Returns       : void                                                     */
2821
/*                                                                           */
2822
/*  Issues        : none                                                     */
2823
/*                                                                           */
2824
/*  Revision History:                                                        */
2825
/*                                                                           */
2826
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
2827
/*         22 10 2008    100356         Draft                                */
2828
/*                                                                           */
2829
/*****************************************************************************/
2830
2831
WORD32 ih264d_get_status(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
2832
0
{
2833
0
2834
0
    UWORD32 i;
2835
0
    dec_struct_t * ps_dec;
2836
0
    UWORD32 pic_wd, pic_ht;
2837
0
    ivd_ctl_getstatus_op_t *ps_ctl_op = (ivd_ctl_getstatus_op_t*)pv_api_op;
2838
0
    UNUSED(pv_api_ip);
2839
0
    ps_ctl_op->u4_error_code = 0;
2840
0
2841
0
    ps_dec = (dec_struct_t *)(dec_hdl->pv_codec_handle);
2842
0
2843
0
2844
0
    if((NULL != ps_dec->ps_cur_sps) && (1 == (ps_dec->ps_cur_sps->u1_is_valid)))
2845
0
    {
2846
0
        ps_ctl_op->u4_pic_ht = ps_dec->u2_disp_height;
2847
0
        ps_ctl_op->u4_pic_wd = ps_dec->u2_disp_width;
2848
0
2849
0
        if(0 == ps_dec->u4_share_disp_buf)
2850
0
        {
2851
0
            pic_wd = ps_dec->u2_disp_width;
2852
0
            pic_ht = ps_dec->u2_disp_height;
2853
0
2854
0
        }
2855
0
        else
2856
0
        {
2857
0
            pic_wd = ps_dec->u2_frm_wd_y;
2858
0
            pic_ht = ps_dec->u2_frm_ht_y;
2859
0
        }
2860
0
    }
2861
0
    else
2862
0
    {
2863
0
        pic_wd = 0;
2864
0
        pic_ht = 0;
2865
0
2866
0
        ps_ctl_op->u4_pic_ht = pic_wd;
2867
0
        ps_ctl_op->u4_pic_wd = pic_ht;
2868
0
2869
0
        if(1 == ps_dec->u4_share_disp_buf)
2870
0
        {
2871
0
            pic_wd += (PAD_LEN_Y_H << 1);
2872
0
            pic_ht += (PAD_LEN_Y_V << 2);
2873
0
2874
0
        }
2875
0
2876
0
    }
2877
0
2878
0
    if(ps_dec->u4_app_disp_width > pic_wd)
2879
0
        pic_wd = ps_dec->u4_app_disp_width;
2880
0
    if(0 == ps_dec->u4_share_disp_buf)
2881
0
        ps_ctl_op->u4_num_disp_bufs = 1;
2882
0
    else
2883
0
    {
2884
0
        if((NULL != ps_dec->ps_cur_sps) && (1 == (ps_dec->ps_cur_sps->u1_is_valid)))
2885
0
        {
2886
0
            if((ps_dec->ps_cur_sps->u1_vui_parameters_present_flag == 1) &&
2887
0
               (1 == ps_dec->ps_cur_sps->s_vui.u1_bitstream_restriction_flag))
2888
0
            {
2889
0
                ps_ctl_op->u4_num_disp_bufs =
2890
0
                                ps_dec->ps_cur_sps->s_vui.u4_num_reorder_frames + 1;
2891
0
            }
2892
0
            else
2893
0
            {
2894
0
                /*if VUI is not present assume maximum possible refrence frames for the level,
2895
0
                 * as max reorder frames*/
2896
0
                ps_ctl_op->u4_num_disp_bufs = ih264d_get_dpb_size(ps_dec->ps_cur_sps);
2897
0
            }
2898
0
2899
0
            ps_ctl_op->u4_num_disp_bufs +=
2900
0
                            ps_dec->ps_cur_sps->u1_num_ref_frames + 1;
2901
0
        }
2902
0
        else
2903
0
        {
2904
0
            ps_ctl_op->u4_num_disp_bufs = 32;
2905
0
        }
2906
0
        ps_ctl_op->u4_num_disp_bufs = MAX(
2907
0
                        ps_ctl_op->u4_num_disp_bufs, 6);
2908
0
        ps_ctl_op->u4_num_disp_bufs = MIN(
2909
0
                        ps_ctl_op->u4_num_disp_bufs, 32);
2910
0
    }
2911
0
2912
0
    ps_ctl_op->u4_error_code = ps_dec->i4_error_code;
2913
0
2914
0
    ps_ctl_op->u4_frame_rate = 0; //make it proper
2915
0
    ps_ctl_op->u4_bit_rate = 0; //make it proper
2916
0
    ps_ctl_op->e_content_type = ps_dec->i4_content_type;
2917
0
    ps_ctl_op->e_output_chroma_format = ps_dec->u1_chroma_format;
2918
0
    ps_ctl_op->u4_min_num_in_bufs = MIN_IN_BUFS;
2919
0
2920
0
    if(ps_dec->u1_chroma_format == IV_YUV_420P)
2921
0
    {
2922
0
        ps_ctl_op->u4_min_num_out_bufs = MIN_OUT_BUFS_420;
2923
0
    }
2924
0
    else if(ps_dec->u1_chroma_format == IV_YUV_422ILE)
2925
0
    {
2926
0
        ps_ctl_op->u4_min_num_out_bufs = MIN_OUT_BUFS_422ILE;
2927
0
    }
2928
0
    else if(ps_dec->u1_chroma_format == IV_RGB_565)
2929
0
    {
2930
0
        ps_ctl_op->u4_min_num_out_bufs = MIN_OUT_BUFS_RGB565;
2931
0
    }
2932
0
    else if((ps_dec->u1_chroma_format == IV_YUV_420SP_UV)
2933
0
                    || (ps_dec->u1_chroma_format == IV_YUV_420SP_VU))
2934
0
    {
2935
0
        ps_ctl_op->u4_min_num_out_bufs = MIN_OUT_BUFS_420SP;
2936
0
    }
2937
0
2938
0
    else
2939
0
    {
2940
0
        //Invalid chroma format; Error code may be updated, verify in testing if needed
2941
0
        ps_ctl_op->u4_error_code = ERROR_FEATURE_UNAVAIL;
2942
0
        return IV_FAIL;
2943
0
    }
2944
0
2945
0
    for(i = 0; i < ps_ctl_op->u4_min_num_in_bufs; i++)
2946
0
    {
2947
0
        ps_ctl_op->u4_min_in_buf_size[i] = MAX(256000, pic_wd * pic_ht * 3 / 2);
2948
0
    }
2949
0
2950
0
    /*!*/
2951
0
    if(ps_dec->u1_chroma_format == IV_YUV_420P)
2952
0
    {
2953
0
        ps_ctl_op->u4_min_out_buf_size[0] = (pic_wd * pic_ht);
2954
0
        ps_ctl_op->u4_min_out_buf_size[1] = (pic_wd * pic_ht)
2955
0
                        >> 2;
2956
0
        ps_ctl_op->u4_min_out_buf_size[2] = (pic_wd * pic_ht)
2957
0
                        >> 2;
2958
0
    }
2959
0
    else if(ps_dec->u1_chroma_format == IV_YUV_422ILE)
2960
0
    {
2961
0
        ps_ctl_op->u4_min_out_buf_size[0] = (pic_wd * pic_ht)
2962
0
                        * 2;
2963
0
        ps_ctl_op->u4_min_out_buf_size[1] =
2964
0
                        ps_ctl_op->u4_min_out_buf_size[2] = 0;
2965
0
    }
2966
0
    else if(ps_dec->u1_chroma_format == IV_RGB_565)
2967
0
    {
2968
0
        ps_ctl_op->u4_min_out_buf_size[0] = (pic_wd * pic_ht)
2969
0
                        * 2;
2970
0
        ps_ctl_op->u4_min_out_buf_size[1] =
2971
0
                        ps_ctl_op->u4_min_out_buf_size[2] = 0;
2972
0
    }
2973
0
    else if((ps_dec->u1_chroma_format == IV_YUV_420SP_UV)
2974
0
                    || (ps_dec->u1_chroma_format == IV_YUV_420SP_VU))
2975
0
    {
2976
0
        ps_ctl_op->u4_min_out_buf_size[0] = (pic_wd * pic_ht);
2977
0
        ps_ctl_op->u4_min_out_buf_size[1] = (pic_wd * pic_ht)
2978
0
                        >> 1;
2979
0
        ps_ctl_op->u4_min_out_buf_size[2] = 0;
2980
0
    }
2981
0
2982
0
    ps_dec->u4_num_disp_bufs_requested = ps_ctl_op->u4_num_disp_bufs;
2983
0
    return IV_SUCCESS;
2984
0
}
2985
2986
/*****************************************************************************/
2987
/*                                                                           */
2988
/*  Function Name :    ih264d_get_buf_info                                   */
2989
/*                                                                           */
2990
/*  Description   :                                                          */
2991
/*                                                                           */
2992
/*  Inputs        :iv_obj_t decoder handle                                   */
2993
/*                :pv_api_ip pointer to input structure                      */
2994
/*                :pv_api_op pointer to output structure                     */
2995
/*  Globals       : <Does it use any global variables?>                      */
2996
/*  Outputs       :                                                          */
2997
/*  Returns       : void                                                     */
2998
/*                                                                           */
2999
/*  Issues        : none                                                     */
3000
/*                                                                           */
3001
/*  Revision History:                                                        */
3002
/*                                                                           */
3003
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
3004
/*         22 10 2008    100356         Draft                                */
3005
/*                                                                           */
3006
/*****************************************************************************/
3007
WORD32 ih264d_get_buf_info(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
3008
0
{
3009
0
3010
0
    dec_struct_t * ps_dec;
3011
0
    UWORD8 i = 0; // Default for 420P format
3012
0
    UWORD16 pic_wd, pic_ht;
3013
0
    ivd_ctl_getbufinfo_op_t *ps_ctl_op =
3014
0
                    (ivd_ctl_getbufinfo_op_t*)pv_api_op;
3015
0
    UWORD32 au4_min_out_buf_size[IVD_VIDDEC_MAX_IO_BUFFERS];
3016
0
    UNUSED(pv_api_ip);
3017
0
3018
0
    ps_ctl_op->u4_error_code = 0;
3019
0
3020
0
    ps_dec = (dec_struct_t *)(dec_hdl->pv_codec_handle);
3021
0
3022
0
    ps_ctl_op->u4_min_num_in_bufs = MIN_IN_BUFS;
3023
0
3024
0
3025
0
    ps_ctl_op->u4_num_disp_bufs = 1;
3026
0
3027
0
3028
0
    pic_wd = 0;
3029
0
    pic_ht = 0;
3030
0
3031
0
    if(ps_dec->i4_header_decoded == 3)
3032
0
    {
3033
0
3034
0
        if(0 == ps_dec->u4_share_disp_buf)
3035
0
        {
3036
0
            pic_wd = ps_dec->u2_disp_width;
3037
0
            pic_ht = ps_dec->u2_disp_height;
3038
0
3039
0
        }
3040
0
        else
3041
0
        {
3042
0
            pic_wd = ps_dec->u2_frm_wd_y;
3043
0
            pic_ht = ps_dec->u2_frm_ht_y;
3044
0
        }
3045
0
3046
0
    }
3047
0
3048
0
    for(i = 0; i < ps_ctl_op->u4_min_num_in_bufs; i++)
3049
0
    {
3050
0
        ps_ctl_op->u4_min_in_buf_size[i] = MAX(256000, pic_wd * pic_ht * 3 / 2);
3051
0
    }
3052
0
    if((WORD32)ps_dec->u4_app_disp_width > pic_wd)
3053
0
        pic_wd = ps_dec->u4_app_disp_width;
3054
0
3055
0
    if(0 == ps_dec->u4_share_disp_buf)
3056
0
        ps_ctl_op->u4_num_disp_bufs = 1;
3057
0
    else
3058
0
    {
3059
0
        if((NULL != ps_dec->ps_cur_sps) && (1 == (ps_dec->ps_cur_sps->u1_is_valid)))
3060
0
        {
3061
0
            if((ps_dec->ps_cur_sps->u1_vui_parameters_present_flag == 1) &&
3062
0
               (1 == ps_dec->ps_cur_sps->s_vui.u1_bitstream_restriction_flag))
3063
0
            {
3064
0
                ps_ctl_op->u4_num_disp_bufs =
3065
0
                                ps_dec->ps_cur_sps->s_vui.u4_num_reorder_frames + 1;
3066
0
            }
3067
0
            else
3068
0
            {
3069
0
                /*if VUI is not present assume maximum possible refrence frames for the level,
3070
0
                 * as max reorder frames*/
3071
0
                ps_ctl_op->u4_num_disp_bufs = ih264d_get_dpb_size(ps_dec->ps_cur_sps);
3072
0
            }
3073
0
3074
0
            ps_ctl_op->u4_num_disp_bufs +=
3075
0
                            ps_dec->ps_cur_sps->u1_num_ref_frames + 1;
3076
0
3077
0
        }
3078
0
        else
3079
0
        {
3080
0
            ps_ctl_op->u4_num_disp_bufs = 32;
3081
0
3082
0
        }
3083
0
3084
0
        ps_ctl_op->u4_num_disp_bufs = MAX(
3085
0
                        ps_ctl_op->u4_num_disp_bufs, 6);
3086
0
        ps_ctl_op->u4_num_disp_bufs = MIN(
3087
0
                        ps_ctl_op->u4_num_disp_bufs, 32);
3088
0
    }
3089
0
3090
0
    ps_ctl_op->u4_min_num_out_bufs = ih264d_get_outbuf_size(
3091
0
                    pic_wd, pic_ht, ps_dec->u1_chroma_format,
3092
0
                    &au4_min_out_buf_size[0]);
3093
0
3094
0
    for(i = 0; i < ps_ctl_op->u4_min_num_out_bufs; i++)
3095
0
    {
3096
0
        ps_ctl_op->u4_min_out_buf_size[i] = au4_min_out_buf_size[i];
3097
0
    }
3098
0
3099
0
    ps_dec->u4_num_disp_bufs_requested = ps_ctl_op->u4_num_disp_bufs;
3100
0
3101
0
    return IV_SUCCESS;
3102
0
}
3103
3104
/*****************************************************************************/
3105
/*                                                                           */
3106
/*  Function Name : ih264d_set_params                                        */
3107
/*                                                                           */
3108
/*  Description   :                                                          */
3109
/*                                                                           */
3110
/*  Inputs        :iv_obj_t decoder handle                                   */
3111
/*                :pv_api_ip pointer to input structure                      */
3112
/*                :pv_api_op pointer to output structure                     */
3113
/*  Outputs       :                                                          */
3114
/*  Returns       : void                                                     */
3115
/*                                                                           */
3116
/*  Issues        : none                                                     */
3117
/*                                                                           */
3118
/*  Revision History:                                                        */
3119
/*                                                                           */
3120
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
3121
/*         22 10 2008    100356         Draft                                */
3122
/*                                                                           */
3123
/*****************************************************************************/
3124
WORD32 ih264d_set_params(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
3125
1
{
3126
1
3127
1
    dec_struct_t * ps_dec;
3128
1
    WORD32 ret = IV_SUCCESS;
3129
1
3130
1
    ivd_ctl_set_config_ip_t *ps_ctl_ip =
3131
1
                    (ivd_ctl_set_config_ip_t *)pv_api_ip;
3132
1
    ivd_ctl_set_config_op_t *ps_ctl_op =
3133
1
                    (ivd_ctl_set_config_op_t *)pv_api_op;
3134
1
3135
1
    ps_dec = (dec_struct_t *)(dec_hdl->pv_codec_handle);
3136
1
3137
1
    ps_dec->u4_skip_frm_mask = 0;
3138
1
3139
1
    ps_ctl_op->u4_error_code = 0;
3140
1
3141
1
    ps_dec->i4_app_skip_mode = ps_ctl_ip->e_frm_skip_mode;
3142
1
3143
1
    /*Is it really supported test it when you so the corner testing using test app*/
3144
1
3145
1
    if(ps_ctl_ip->e_frm_skip_mode != IVD_SKIP_NONE)
3146
0
    {
3147
0
3148
0
        if(ps_ctl_ip->e_frm_skip_mode == IVD_SKIP_P)
3149
0
            ps_dec->u4_skip_frm_mask |= 1 << P_SLC_BIT;
3150
0
        else if(ps_ctl_ip->e_frm_skip_mode == IVD_SKIP_B)
3151
0
            ps_dec->u4_skip_frm_mask |= 1 << B_SLC_BIT;
3152
0
        else if(ps_ctl_ip->e_frm_skip_mode == IVD_SKIP_PB)
3153
0
        {
3154
0
            ps_dec->u4_skip_frm_mask |= 1 << B_SLC_BIT;
3155
0
            ps_dec->u4_skip_frm_mask |= 1 << P_SLC_BIT;
3156
0
        }
3157
0
        else if(ps_ctl_ip->e_frm_skip_mode == IVD_SKIP_I)
3158
0
            ps_dec->u4_skip_frm_mask |= 1 << I_SLC_BIT;
3159
0
        else
3160
0
        {
3161
0
            //dynamic parameter not supported
3162
0
            //Put an appropriate error code to return the error..
3163
0
            //when you do the error code tests and after that remove this comment
3164
0
            ps_ctl_op->u4_error_code = (1 << IVD_UNSUPPORTEDPARAM);
3165
0
            ret = IV_FAIL;
3166
0
        }
3167
0
    }
3168
1
3169
1
    if(ps_ctl_ip->u4_disp_wd >= ps_dec->u2_pic_wd)
3170
1
    {
3171
1
        ps_dec->u4_app_disp_width = ps_ctl_ip->u4_disp_wd;
3172
1
    }
3173
0
    else if(0 == ps_dec->i4_header_decoded)
3174
0
    {
3175
0
        ps_dec->u4_app_disp_width = ps_ctl_ip->u4_disp_wd;
3176
0
    }
3177
0
    else if(ps_ctl_ip->u4_disp_wd == 0)
3178
0
    {
3179
0
        ps_dec->u4_app_disp_width = 0;
3180
0
    }
3181
0
    else
3182
0
    {
3183
0
        /*
3184
0
         * Set the display width to zero. This will ensure that the wrong value we had stored (0xFFFFFFFF)
3185
0
         * does not propogate.
3186
0
         */
3187
0
        ps_dec->u4_app_disp_width = 0;
3188
0
        ps_ctl_op->u4_error_code |= (1 << IVD_UNSUPPORTEDPARAM);
3189
0
        ps_ctl_op->u4_error_code |= ERROR_DISP_WIDTH_INVALID;
3190
0
        ret = IV_FAIL;
3191
0
    }
3192
1
3193
1
    if(ps_ctl_ip->e_vid_dec_mode == IVD_DECODE_FRAME)
3194
1
        ps_dec->i4_decode_header = 0;
3195
0
    else if(ps_ctl_ip->e_vid_dec_mode == IVD_DECODE_HEADER)
3196
0
        ps_dec->i4_decode_header = 1;
3197
0
    else
3198
0
    {
3199
0
        ps_ctl_op->u4_error_code = (1 << IVD_UNSUPPORTEDPARAM);
3200
0
        ps_dec->i4_decode_header = 1;
3201
0
        ret = IV_FAIL;
3202
0
    }
3203
1
    ps_dec->e_frm_out_mode = IVD_DISPLAY_FRAME_OUT;
3204
1
3205
1
    if((ps_ctl_ip->e_frm_out_mode != IVD_DECODE_FRAME_OUT) &&
3206
1
       (ps_ctl_ip->e_frm_out_mode != IVD_DISPLAY_FRAME_OUT))
3207
0
    {
3208
0
        ps_ctl_op->u4_error_code = (1 << IVD_UNSUPPORTEDPARAM);
3209
0
        ret = IV_FAIL;
3210
0
    }
3211
1
    ps_dec->e_frm_out_mode = ps_ctl_ip->e_frm_out_mode;
3212
1
    return ret;
3213
1
3214
1
}
3215
3216
/*****************************************************************************/
3217
/*                                                                           */
3218
/*  Function Name : ih264d_set_default_params                                */
3219
/*                                                                           */
3220
/*  Description   :                                                          */
3221
/*                                                                           */
3222
/*  Inputs        :iv_obj_t decoder handle                                   */
3223
/*                :pv_api_ip pointer to input structure                      */
3224
/*                :pv_api_op pointer to output structure                     */
3225
/*  Outputs       :                                                          */
3226
/*  Returns       : void                                                     */
3227
/*                                                                           */
3228
/*  Issues        : none                                                     */
3229
/*                                                                           */
3230
/*  Revision History:                                                        */
3231
/*                                                                           */
3232
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
3233
/*         08 08 2011   100421          Copied from set_params               */
3234
/*                                                                           */
3235
/*****************************************************************************/
3236
WORD32 ih264d_set_default_params(iv_obj_t *dec_hdl,
3237
                                 void *pv_api_ip,
3238
                                 void *pv_api_op)
3239
0
{
3240
0
3241
0
    dec_struct_t * ps_dec;
3242
0
    WORD32 ret = IV_SUCCESS;
3243
0
3244
0
    ivd_ctl_set_config_op_t *ps_ctl_op =
3245
0
                    (ivd_ctl_set_config_op_t *)pv_api_op;
3246
0
    ps_dec = (dec_struct_t *)(dec_hdl->pv_codec_handle);
3247
0
    UNUSED(pv_api_ip);
3248
0
3249
0
3250
0
    {
3251
0
        ps_dec->u4_app_disp_width = 0;
3252
0
        ps_dec->u4_skip_frm_mask = 0;
3253
0
        ps_dec->i4_decode_header = 1;
3254
0
3255
0
        ps_ctl_op->u4_error_code = 0;
3256
0
    }
3257
0
3258
0
3259
0
    return ret;
3260
0
}
3261
/*****************************************************************************/
3262
/*                                                                           */
3263
/*  Function Name :  ih264d_reset                                            */
3264
/*                                                                           */
3265
/*  Description   :                                                          */
3266
/*                                                                           */
3267
/*  Inputs        :iv_obj_t decoder handle                                   */
3268
/*                :pv_api_ip pointer to input structure                      */
3269
/*                :pv_api_op pointer to output structure                     */
3270
/*  Globals       : <Does it use any global variables?>                      */
3271
/*  Outputs       :                                                          */
3272
/*  Returns       : void                                                     */
3273
/*                                                                           */
3274
/*  Issues        : none                                                     */
3275
/*                                                                           */
3276
/*  Revision History:                                                        */
3277
/*                                                                           */
3278
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
3279
/*         22 10 2008    100356         Draft                                */
3280
/*                                                                           */
3281
/*****************************************************************************/
3282
WORD32 ih264d_delete(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
3283
1
{
3284
1
    dec_struct_t *ps_dec;
3285
1
    ih264d_delete_ip_t *ps_ip = (ih264d_delete_ip_t *)pv_api_ip;
3286
1
    ih264d_delete_op_t *ps_op = (ih264d_delete_op_t *)pv_api_op;
3287
1
3288
1
    ps_dec = (dec_struct_t *)(dec_hdl->pv_codec_handle);
3289
1
    UNUSED(ps_ip);
3290
1
    ps_op->s_ivd_delete_op_t.u4_error_code = 0;
3291
1
    ih264d_free_dynamic_bufs(ps_dec);
3292
1
    ih264d_free_static_bufs(dec_hdl);
3293
1
    return IV_SUCCESS;
3294
1
}
3295
/*****************************************************************************/
3296
/*                                                                           */
3297
/*  Function Name :  ih264d_reset                                            */
3298
/*                                                                           */
3299
/*  Description   :                                                          */
3300
/*                                                                           */
3301
/*  Inputs        :iv_obj_t decoder handle                                   */
3302
/*                :pv_api_ip pointer to input structure                      */
3303
/*                :pv_api_op pointer to output structure                     */
3304
/*  Globals       : <Does it use any global variables?>                      */
3305
/*  Outputs       :                                                          */
3306
/*  Returns       : void                                                     */
3307
/*                                                                           */
3308
/*  Issues        : none                                                     */
3309
/*                                                                           */
3310
/*  Revision History:                                                        */
3311
/*                                                                           */
3312
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
3313
/*         22 10 2008    100356         Draft                                */
3314
/*                                                                           */
3315
/*****************************************************************************/
3316
WORD32 ih264d_reset(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
3317
1
{
3318
1
    dec_struct_t * ps_dec;
3319
1
    ivd_ctl_reset_op_t *ps_ctl_op = (ivd_ctl_reset_op_t *)pv_api_op;
3320
1
    UNUSED(pv_api_ip);
3321
1
    ps_ctl_op->u4_error_code = 0;
3322
1
3323
1
    ps_dec = (dec_struct_t *)(dec_hdl->pv_codec_handle);
3324
1
3325
1
    if(ps_dec != NULL)
3326
1
    {
3327
1
        ih264d_init_decoder(ps_dec);
3328
1
    }
3329
0
    else
3330
0
    {
3331
0
        H264_DEC_DEBUG_PRINT(
3332
0
                        "\nReset called without Initializing the decoder\n");
3333
0
        ps_ctl_op->u4_error_code = ERROR_INIT_NOT_DONE;
3334
0
    }
3335
1
3336
1
    return IV_SUCCESS;
3337
1
}
3338
3339
/*****************************************************************************/
3340
/*                                                                           */
3341
/*  Function Name :  ih264d_ctl                                              */
3342
/*                                                                           */
3343
/*  Description   :                                                          */
3344
/*                                                                           */
3345
/*  Inputs        :iv_obj_t decoder handle                                   */
3346
/*                :pv_api_ip pointer to input structure                      */
3347
/*                :pv_api_op pointer to output structure                     */
3348
/*  Outputs       :                                                          */
3349
/*  Returns       : void                                                     */
3350
/*                                                                           */
3351
/*  Issues        : none                                                     */
3352
/*                                                                           */
3353
/*  Revision History:                                                        */
3354
/*                                                                           */
3355
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
3356
/*         22 10 2008    100356         Draft                                */
3357
/*                                                                           */
3358
/*****************************************************************************/
3359
WORD32 ih264d_ctl(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
3360
18
{
3361
18
    ivd_ctl_set_config_ip_t *ps_ctl_ip;
3362
18
    ivd_ctl_set_config_op_t *ps_ctl_op;
3363
18
    WORD32 ret = IV_SUCCESS;
3364
18
    UWORD32 subcommand;
3365
18
    dec_struct_t *ps_dec = dec_hdl->pv_codec_handle;
3366
18
3367
18
    if(ps_dec->init_done != 1)
3368
0
    {
3369
0
        //Return proper Error Code
3370
0
        return IV_FAIL;
3371
0
    }
3372
18
    ps_ctl_ip = (ivd_ctl_set_config_ip_t*)pv_api_ip;
3373
18
    ps_ctl_op = (ivd_ctl_set_config_op_t*)pv_api_op;
3374
18
    ps_ctl_op->u4_error_code = 0;
3375
18
    subcommand = ps_ctl_ip->e_sub_cmd;
3376
18
3377
18
    switch(subcommand)
3378
18
    {
3379
18
        case IVD_CMD_CTL_GETPARAMS:
3380
0
            ret = ih264d_get_status(dec_hdl, (void *)pv_api_ip,
3381
0
                                    (void *)pv_api_op);
3382
0
            break;
3383
18
        case IVD_CMD_CTL_SETPARAMS:
3384
1
            ret = ih264d_set_params(dec_hdl, (void *)pv_api_ip,
3385
1
                                    (void *)pv_api_op);
3386
1
            break;
3387
18
        case IVD_CMD_CTL_RESET:
3388
1
            ret = ih264d_reset(dec_hdl, (void *)pv_api_ip, (void *)pv_api_op);
3389
1
            break;
3390
18
        case IVD_CMD_CTL_SETDEFAULT:
3391
0
            ret = ih264d_set_default_params(dec_hdl, (void *)pv_api_ip,
3392
0
                                            (void *)pv_api_op);
3393
0
            break;
3394
18
        case IVD_CMD_CTL_FLUSH:
3395
0
            ret = ih264d_set_flush_mode(dec_hdl, (void *)pv_api_ip,
3396
0
                                        (void *)pv_api_op);
3397
0
            break;
3398
18
        case IVD_CMD_CTL_GETBUFINFO:
3399
0
            ret = ih264d_get_buf_info(dec_hdl, (void *)pv_api_ip,
3400
0
                                      (void *)pv_api_op);
3401
0
            break;
3402
18
        case IVD_CMD_CTL_GETVERSION:
3403
1
            ret = ih264d_get_version(dec_hdl, (void *)pv_api_ip,
3404
1
                                     (void *)pv_api_op);
3405
1
            break;
3406
18
        case IH264D_CMD_CTL_DEGRADE:
3407
0
            ret = ih264d_set_degrade(dec_hdl, (void *)pv_api_ip,
3408
0
                                     (void *)pv_api_op);
3409
0
            break;
3410
18
3411
18
        case IH264D_CMD_CTL_SET_NUM_CORES:
3412
2
            ret = ih264d_set_num_cores(dec_hdl, (void *)pv_api_ip,
3413
2
                                       (void *)pv_api_op);
3414
2
            break;
3415
18
        case IH264D_CMD_CTL_GET_BUFFER_DIMENSIONS:
3416
0
            ret = ih264d_get_frame_dimensions(dec_hdl, (void *)pv_api_ip,
3417
0
                                              (void *)pv_api_op);
3418
0
            break;
3419
18
        case IH264D_CMD_CTL_GET_VUI_PARAMS:
3420
13
            ret = ih264d_get_vui_params(dec_hdl, (void *)pv_api_ip,
3421
13
                                        (void *)pv_api_op);
3422
13
            break;
3423
18
3424
18
        case IH264D_CMD_CTL_SET_PROCESSOR:
3425
0
            ret = ih264d_set_processor(dec_hdl, (void *)pv_api_ip,
3426
0
                                       (void *)pv_api_op);
3427
0
            break;
3428
18
        default:
3429
0
            H264_DEC_DEBUG_PRINT("\ndo nothing\n")
3430
0
            ;
3431
0
            break;
3432
18
    }
3433
18
3434
18
    return ret;
3435
18
}
3436
/*****************************************************************************/
3437
/*                                                                           */
3438
/*  Function Name :   ih264d_rel_display_frame                               */
3439
/*                                                                           */
3440
/*  Description   :                                                          */
3441
/*                                                                           */
3442
/*  Inputs        :iv_obj_t decoder handle                                   */
3443
/*                :pv_api_ip pointer to input structure                      */
3444
/*                :pv_api_op pointer to output structure                     */
3445
/*  Outputs       :                                                          */
3446
/*  Returns       : void                                                     */
3447
/*                                                                           */
3448
/*  Issues        : none                                                     */
3449
/*                                                                           */
3450
/*  Revision History:                                                        */
3451
/*                                                                           */
3452
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
3453
/*         22 10 2008    100356         Draft                                */
3454
/*                                                                           */
3455
/*****************************************************************************/
3456
WORD32 ih264d_rel_display_frame(iv_obj_t *dec_hdl,
3457
                                void *pv_api_ip,
3458
                                void *pv_api_op)
3459
0
{
3460
0
3461
0
    ivd_rel_display_frame_ip_t *ps_rel_ip;
3462
0
    ivd_rel_display_frame_op_t *ps_rel_op;
3463
0
    UWORD32 buf_released = 0;
3464
0
3465
0
    UWORD32 u4_ts = -1;
3466
0
    dec_struct_t *ps_dec = dec_hdl->pv_codec_handle;
3467
0
3468
0
    ps_rel_ip = (ivd_rel_display_frame_ip_t *)pv_api_ip;
3469
0
    ps_rel_op = (ivd_rel_display_frame_op_t *)pv_api_op;
3470
0
    ps_rel_op->u4_error_code = 0;
3471
0
    u4_ts = ps_rel_ip->u4_disp_buf_id;
3472
0
3473
0
    if(0 == ps_dec->u4_share_disp_buf)
3474
0
    {
3475
0
        ps_dec->u4_disp_buf_mapping[u4_ts] = 0;
3476
0
        ps_dec->u4_disp_buf_to_be_freed[u4_ts] = 0;
3477
0
        return IV_SUCCESS;
3478
0
    }
3479
0
3480
0
    if(ps_dec->pv_pic_buf_mgr != NULL)
3481
0
    {
3482
0
        if(1 == ps_dec->u4_disp_buf_mapping[u4_ts])
3483
0
        {
3484
0
            ih264_buf_mgr_release((buf_mgr_t *)ps_dec->pv_pic_buf_mgr,
3485
0
                                  ps_rel_ip->u4_disp_buf_id,
3486
0
                                  BUF_MGR_IO);
3487
0
            ps_dec->u4_disp_buf_mapping[u4_ts] = 0;
3488
0
            buf_released = 1;
3489
0
        }
3490
0
    }
3491
0
3492
0
    if((1 == ps_dec->u4_share_disp_buf) && (0 == buf_released))
3493
0
        ps_dec->u4_disp_buf_to_be_freed[u4_ts] = 1;
3494
0
3495
0
    return IV_SUCCESS;
3496
0
}
3497
3498
/**
3499
 *******************************************************************************
3500
 *
3501
 * @brief
3502
 *  Sets degrade params
3503
 *
3504
 * @par Description:
3505
 *  Sets degrade params.
3506
 *  Refer to ih264d_ctl_degrade_ip_t definition for details
3507
 *
3508
 * @param[in] ps_codec_obj
3509
 *  Pointer to codec object at API level
3510
 *
3511
 * @param[in] pv_api_ip
3512
 *  Pointer to input argument structure
3513
 *
3514
 * @param[out] pv_api_op
3515
 *  Pointer to output argument structure
3516
 *
3517
 * @returns  Status
3518
 *
3519
 * @remarks
3520
 *
3521
 *
3522
 *******************************************************************************
3523
 */
3524
3525
WORD32 ih264d_set_degrade(iv_obj_t *ps_codec_obj,
3526
                          void *pv_api_ip,
3527
                          void *pv_api_op)
3528
0
{
3529
0
    ih264d_ctl_degrade_ip_t *ps_ip;
3530
0
    ih264d_ctl_degrade_op_t *ps_op;
3531
0
    dec_struct_t *ps_codec = (dec_struct_t *)ps_codec_obj->pv_codec_handle;
3532
0
3533
0
    ps_ip = (ih264d_ctl_degrade_ip_t *)pv_api_ip;
3534
0
    ps_op = (ih264d_ctl_degrade_op_t *)pv_api_op;
3535
0
3536
0
    ps_codec->i4_degrade_type = ps_ip->i4_degrade_type;
3537
0
    ps_codec->i4_nondegrade_interval = ps_ip->i4_nondegrade_interval;
3538
0
    ps_codec->i4_degrade_pics = ps_ip->i4_degrade_pics;
3539
0
3540
0
    ps_op->u4_error_code = 0;
3541
0
    ps_codec->i4_degrade_pic_cnt = 0;
3542
0
3543
0
    return IV_SUCCESS;
3544
0
}
3545
3546
WORD32 ih264d_get_frame_dimensions(iv_obj_t *dec_hdl,
3547
                                   void *pv_api_ip,
3548
                                   void *pv_api_op)
3549
0
{
3550
0
    ih264d_ctl_get_frame_dimensions_ip_t *ps_ip;
3551
0
    ih264d_ctl_get_frame_dimensions_op_t *ps_op;
3552
0
    dec_struct_t *ps_dec = dec_hdl->pv_codec_handle;
3553
0
    UWORD32 disp_wd, disp_ht, buffer_wd, buffer_ht, x_offset, y_offset;
3554
0
3555
0
    ps_ip = (ih264d_ctl_get_frame_dimensions_ip_t *)pv_api_ip;
3556
0
3557
0
    ps_op = (ih264d_ctl_get_frame_dimensions_op_t *)pv_api_op;
3558
0
    UNUSED(ps_ip);
3559
0
    if((NULL != ps_dec->ps_cur_sps) && (1 == (ps_dec->ps_cur_sps->u1_is_valid)))
3560
0
    {
3561
0
        disp_wd = ps_dec->u2_disp_width;
3562
0
        disp_ht = ps_dec->u2_disp_height;
3563
0
3564
0
        if(0 == ps_dec->u4_share_disp_buf)
3565
0
        {
3566
0
            buffer_wd = disp_wd;
3567
0
            buffer_ht = disp_ht;
3568
0
        }
3569
0
        else
3570
0
        {
3571
0
            buffer_wd = ps_dec->u2_frm_wd_y;
3572
0
            buffer_ht = ps_dec->u2_frm_ht_y;
3573
0
        }
3574
0
    }
3575
0
    else
3576
0
    {
3577
0
        disp_wd = 0;
3578
0
        disp_ht = 0;
3579
0
3580
0
        if(0 == ps_dec->u4_share_disp_buf)
3581
0
        {
3582
0
            buffer_wd = disp_wd;
3583
0
            buffer_ht = disp_ht;
3584
0
        }
3585
0
        else
3586
0
        {
3587
0
            buffer_wd = ALIGN16(disp_wd) + (PAD_LEN_Y_H << 1);
3588
0
            buffer_ht = ALIGN16(disp_ht) + (PAD_LEN_Y_V << 2);
3589
0
        }
3590
0
    }
3591
0
    if(ps_dec->u4_app_disp_width > buffer_wd)
3592
0
        buffer_wd = ps_dec->u4_app_disp_width;
3593
0
3594
0
    if(0 == ps_dec->u4_share_disp_buf)
3595
0
    {
3596
0
        x_offset = 0;
3597
0
        y_offset = 0;
3598
0
    }
3599
0
    else
3600
0
    {
3601
0
        y_offset = (PAD_LEN_Y_V << 1);
3602
0
        x_offset = PAD_LEN_Y_H;
3603
0
3604
0
        if((NULL != ps_dec->ps_sps) && (1 == (ps_dec->ps_sps->u1_is_valid))
3605
0
                        && (0 != ps_dec->u2_crop_offset_y))
3606
0
        {
3607
0
            y_offset += ps_dec->u2_crop_offset_y / ps_dec->u2_frm_wd_y;
3608
0
            x_offset += ps_dec->u2_crop_offset_y % ps_dec->u2_frm_wd_y;
3609
0
        }
3610
0
    }
3611
0
3612
0
    ps_op->u4_disp_wd[0] = disp_wd;
3613
0
    ps_op->u4_disp_ht[0] = disp_ht;
3614
0
    ps_op->u4_buffer_wd[0] = buffer_wd;
3615
0
    ps_op->u4_buffer_ht[0] = buffer_ht;
3616
0
    ps_op->u4_x_offset[0] = x_offset;
3617
0
    ps_op->u4_y_offset[0] = y_offset;
3618
0
3619
0
    ps_op->u4_disp_wd[1] = ps_op->u4_disp_wd[2] = ((ps_op->u4_disp_wd[0] + 1)
3620
0
                    >> 1);
3621
0
    ps_op->u4_disp_ht[1] = ps_op->u4_disp_ht[2] = ((ps_op->u4_disp_ht[0] + 1)
3622
0
                    >> 1);
3623
0
    ps_op->u4_buffer_wd[1] = ps_op->u4_buffer_wd[2] = (ps_op->u4_buffer_wd[0]
3624
0
                    >> 1);
3625
0
    ps_op->u4_buffer_ht[1] = ps_op->u4_buffer_ht[2] = (ps_op->u4_buffer_ht[0]
3626
0
                    >> 1);
3627
0
    ps_op->u4_x_offset[1] = ps_op->u4_x_offset[2] =
3628
0
                    (ps_op->u4_x_offset[0] >> 1);
3629
0
    ps_op->u4_y_offset[1] = ps_op->u4_y_offset[2] =
3630
0
                    (ps_op->u4_y_offset[0] >> 1);
3631
0
3632
0
    if((ps_dec->u1_chroma_format == IV_YUV_420SP_UV)
3633
0
                    || (ps_dec->u1_chroma_format == IV_YUV_420SP_VU))
3634
0
    {
3635
0
        ps_op->u4_disp_wd[2] = 0;
3636
0
        ps_op->u4_disp_ht[2] = 0;
3637
0
        ps_op->u4_buffer_wd[2] = 0;
3638
0
        ps_op->u4_buffer_ht[2] = 0;
3639
0
        ps_op->u4_x_offset[2] = 0;
3640
0
        ps_op->u4_y_offset[2] = 0;
3641
0
3642
0
        ps_op->u4_disp_wd[1] <<= 1;
3643
0
        ps_op->u4_buffer_wd[1] <<= 1;
3644
0
        ps_op->u4_x_offset[1] <<= 1;
3645
0
    }
3646
0
3647
0
    return IV_SUCCESS;
3648
0
3649
0
}
3650
3651
WORD32 ih264d_get_vui_params(iv_obj_t *dec_hdl,
3652
                             void *pv_api_ip,
3653
                             void *pv_api_op)
3654
13
{
3655
13
    ih264d_ctl_get_vui_params_ip_t *ps_ip;
3656
13
    ih264d_ctl_get_vui_params_op_t *ps_op;
3657
13
    dec_struct_t *ps_dec = dec_hdl->pv_codec_handle;
3658
13
    dec_seq_params_t *ps_sps;
3659
13
    vui_t *ps_vui;
3660
13
    WORD32 i;
3661
13
    UWORD32 u4_size;
3662
13
3663
13
    ps_ip = (ih264d_ctl_get_vui_params_ip_t *)pv_api_ip;
3664
13
    ps_op = (ih264d_ctl_get_vui_params_op_t *)pv_api_op;
3665
13
    UNUSED(ps_ip);
3666
13
3667
13
    u4_size = ps_op->u4_size;
3668
13
    memset(ps_op, 0, sizeof(ih264d_ctl_get_vui_params_op_t));
3669
13
    ps_op->u4_size = u4_size;
3670
13
3671
13
    if(NULL == ps_dec->ps_cur_sps)
3672
0
    {
3673
0
        ps_op->u4_error_code = ERROR_VUI_PARAMS_NOT_FOUND;
3674
0
        return IV_FAIL;
3675
0
    }
3676
13
3677
13
    ps_sps = ps_dec->ps_cur_sps;
3678
13
    if((0 == ps_sps->u1_is_valid)
3679
13
                    || (0 == ps_sps->u1_vui_parameters_present_flag))
3680
0
    {
3681
0
        ps_op->u4_error_code = ERROR_VUI_PARAMS_NOT_FOUND;
3682
0
        return IV_FAIL;
3683
0
    }
3684
13
3685
13
    ps_vui = &ps_sps->s_vui;
3686
13
3687
13
    ps_op->u1_aspect_ratio_idc              = ps_vui->u1_aspect_ratio_idc;
3688
13
    ps_op->u2_sar_width                     = ps_vui->u2_sar_width;
3689
13
    ps_op->u2_sar_height                    = ps_vui->u2_sar_height;
3690
13
    ps_op->u1_overscan_appropriate_flag     = ps_vui->u1_overscan_appropriate_flag;
3691
13
    ps_op->u1_video_format                  = ps_vui->u1_video_format;
3692
13
    ps_op->u1_video_full_range_flag         = ps_vui->u1_video_full_range_flag;
3693
13
    ps_op->u1_colour_primaries              = ps_vui->u1_colour_primaries;
3694
13
    ps_op->u1_tfr_chars                     = ps_vui->u1_tfr_chars;
3695
13
    ps_op->u1_matrix_coeffs                 = ps_vui->u1_matrix_coeffs;
3696
13
    ps_op->u1_cr_top_field                  = ps_vui->u1_cr_top_field;
3697
13
    ps_op->u1_cr_bottom_field               = ps_vui->u1_cr_bottom_field;
3698
13
    ps_op->u4_num_units_in_tick             = ps_vui->u4_num_units_in_tick;
3699
13
    ps_op->u4_time_scale                    = ps_vui->u4_time_scale;
3700
13
    ps_op->u1_fixed_frame_rate_flag         = ps_vui->u1_fixed_frame_rate_flag;
3701
13
    ps_op->u1_nal_hrd_params_present        = ps_vui->u1_nal_hrd_params_present;
3702
13
    ps_op->u1_vcl_hrd_params_present        = ps_vui->u1_vcl_hrd_params_present;
3703
13
    ps_op->u1_low_delay_hrd_flag            = ps_vui->u1_low_delay_hrd_flag;
3704
13
    ps_op->u1_pic_struct_present_flag       = ps_vui->u1_pic_struct_present_flag;
3705
13
    ps_op->u1_bitstream_restriction_flag    = ps_vui->u1_bitstream_restriction_flag;
3706
13
    ps_op->u1_mv_over_pic_boundaries_flag   = ps_vui->u1_mv_over_pic_boundaries_flag;
3707
13
    ps_op->u4_max_bytes_per_pic_denom       = ps_vui->u4_max_bytes_per_pic_denom;
3708
13
    ps_op->u4_max_bits_per_mb_denom         = ps_vui->u4_max_bits_per_mb_denom;
3709
13
    ps_op->u4_log2_max_mv_length_horz       = ps_vui->u4_log2_max_mv_length_horz;
3710
13
    ps_op->u4_log2_max_mv_length_vert       = ps_vui->u4_log2_max_mv_length_vert;
3711
13
    ps_op->u4_num_reorder_frames            = ps_vui->u4_num_reorder_frames;
3712
13
    ps_op->u4_max_dec_frame_buffering       = ps_vui->u4_max_dec_frame_buffering;
3713
13
3714
13
    return IV_SUCCESS;
3715
13
}
3716
3717
WORD32 ih264d_set_num_cores(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
3718
2
{
3719
2
    ih264d_ctl_set_num_cores_ip_t *ps_ip;
3720
2
    ih264d_ctl_set_num_cores_op_t *ps_op;
3721
2
    dec_struct_t *ps_dec = dec_hdl->pv_codec_handle;
3722
2
3723
2
    ps_ip = (ih264d_ctl_set_num_cores_ip_t *)pv_api_ip;
3724
2
    ps_op = (ih264d_ctl_set_num_cores_op_t *)pv_api_op;
3725
2
    ps_op->u4_error_code = 0;
3726
2
    ps_dec->u4_num_cores = ps_ip->u4_num_cores;
3727
2
    if(ps_dec->u4_num_cores == 1)
3728
0
    {
3729
0
        ps_dec->u1_separate_parse = 0;
3730
0
    }
3731
2
    else
3732
2
    {
3733
2
        ps_dec->u1_separate_parse = 1;
3734
2
    }
3735
2
3736
2
    /*using only upto three threads currently*/
3737
2
    if(ps_dec->u4_num_cores > 3)
3738
2
        ps_dec->u4_num_cores = 3;
3739
2
3740
2
    return IV_SUCCESS;
3741
2
}
3742
3743
void ih264d_fill_output_struct_from_context(dec_struct_t *ps_dec,
3744
                                            ivd_video_decode_op_t *ps_dec_op)
3745
13
{
3746
13
    if((ps_dec_op->u4_error_code & 0xff)
3747
13
                    != ERROR_DYNAMIC_RESOLUTION_NOT_SUPPORTED)
3748
13
    {
3749
13
        ps_dec_op->u4_pic_wd = (UWORD32)ps_dec->u2_disp_width;
3750
13
        ps_dec_op->u4_pic_ht = (UWORD32)ps_dec->u2_disp_height;
3751
13
    }
3752
13
    ps_dec_op->e_pic_type = ps_dec->i4_frametype;
3753
13
3754
13
    ps_dec_op->u4_new_seq = 0;
3755
13
    ps_dec_op->u4_output_present = ps_dec->u4_output_present;
3756
13
    ps_dec_op->u4_progressive_frame_flag =
3757
13
                    ps_dec->s_disp_op.u4_progressive_frame_flag;
3758
13
3759
13
    ps_dec_op->u4_is_ref_flag = 1;
3760
13
    if(ps_dec_op->u4_frame_decoded_flag)
3761
11
    {
3762
11
        if(ps_dec->ps_cur_slice->u1_nal_ref_idc == 0)
3763
0
            ps_dec_op->u4_is_ref_flag = 0;
3764
11
    }
3765
13
3766
13
    ps_dec_op->e_output_format = ps_dec->s_disp_op.e_output_format;
3767
13
    ps_dec_op->s_disp_frm_buf = ps_dec->s_disp_op.s_disp_frm_buf;
3768
13
    ps_dec_op->e4_fld_type = ps_dec->s_disp_op.e4_fld_type;
3769
13
    ps_dec_op->u4_ts = ps_dec->s_disp_op.u4_ts;
3770
13
    ps_dec_op->u4_disp_buf_id = ps_dec->s_disp_op.u4_disp_buf_id;
3771
13
}
3772
3773
/*****************************************************************************/
3774
/*                                                                           */
3775
/*  Function Name : ih264d_api_function                                      */
3776
/*                                                                           */
3777
/*  Description   :                                                          */
3778
/*                                                                           */
3779
/*  Inputs        :iv_obj_t decoder handle                                   */
3780
/*                :pv_api_ip pointer to input structure                      */
3781
/*                :pv_api_op pointer to output structure                     */
3782
/*  Outputs       :                                                          */
3783
/*  Returns       : void                                                     */
3784
/*                                                                           */
3785
/*  Issues        : none                                                     */
3786
/*                                                                           */
3787
/*  Revision History:                                                        */
3788
/*                                                                           */
3789
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
3790
/*         22 10 2008    100356         Draft                                */
3791
/*                                                                           */
3792
/*****************************************************************************/
3793
IV_API_CALL_STATUS_T ih264d_api_function(iv_obj_t *dec_hdl,
3794
                                              void *pv_api_ip,
3795
                                              void *pv_api_op)
3796
33
{
3797
33
    UWORD32 command;
3798
33
    UWORD32 *pu2_ptr_cmd;
3799
33
    UWORD32 u4_api_ret;
3800
33
    IV_API_CALL_STATUS_T e_status;
3801
33
    e_status = api_check_struct_sanity(dec_hdl, pv_api_ip, pv_api_op);
3802
33
3803
33
    if(e_status != IV_SUCCESS)
3804
0
    {
3805
0
        UWORD32 *ptr_err;
3806
0
3807
0
        ptr_err = (UWORD32 *)pv_api_op;
3808
0
        UNUSED(ptr_err);
3809
0
        H264_DEC_DEBUG_PRINT("error code = %d\n", *(ptr_err + 1));
3810
0
        return IV_FAIL;
3811
0
    }
3812
33
3813
33
    pu2_ptr_cmd = (UWORD32 *)pv_api_ip;
3814
33
    pu2_ptr_cmd++;
3815
33
3816
33
    command = *pu2_ptr_cmd;
3817
33
//    H264_DEC_DEBUG_PRINT("inside lib = %d\n",command);
3818
33
    switch(command)
3819
33
    {
3820
33
3821
33
        case IVD_CMD_CREATE:
3822
1
            u4_api_ret = ih264d_create(dec_hdl, (void *)pv_api_ip,
3823
1
                                     (void *)pv_api_op);
3824
1
            break;
3825
33
        case IVD_CMD_DELETE:
3826
1
            u4_api_ret = ih264d_delete(dec_hdl, (void *)pv_api_ip,
3827
1
                                     (void *)pv_api_op);
3828
1
            break;
3829
33
3830
33
        case IVD_CMD_VIDEO_DECODE:
3831
13
            u4_api_ret = ih264d_video_decode(dec_hdl, (void *)pv_api_ip,
3832
13
                                             (void *)pv_api_op);
3833
13
            break;
3834
33
3835
33
        case IVD_CMD_GET_DISPLAY_FRAME:
3836
0
            u4_api_ret = ih264d_get_display_frame(dec_hdl, (void *)pv_api_ip,
3837
0
                                                  (void *)pv_api_op);
3838
0
3839
0
            break;
3840
33
3841
33
        case IVD_CMD_SET_DISPLAY_FRAME:
3842
0
            u4_api_ret = ih264d_set_display_frame(dec_hdl, (void *)pv_api_ip,
3843
0
                                                  (void *)pv_api_op);
3844
0
3845
0
            break;
3846
33
3847
33
        case IVD_CMD_REL_DISPLAY_FRAME:
3848
0
            u4_api_ret = ih264d_rel_display_frame(dec_hdl, (void *)pv_api_ip,
3849
0
                                                  (void *)pv_api_op);
3850
0
            break;
3851
33
3852
33
        case IVD_CMD_VIDEO_CTL:
3853
18
            u4_api_ret = ih264d_ctl(dec_hdl, (void *)pv_api_ip,
3854
18
                                    (void *)pv_api_op);
3855
18
            break;
3856
33
        default:
3857
0
            u4_api_ret = IV_FAIL;
3858
0
            break;
3859
33
    }
3860
33
3861
33
    return u4_api_ret;
3862
33
}
/proc/self/cwd/external/libavc/decoder/ih264d_bitstrm.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
21
/*!
22
 **************************************************************************
23
 * \file ih264d_bitstrm.c
24
 *
25
 * \brief
26
 *    Bitstream parsing routines
27
 *
28
 * \date
29
 *    20/11/2002
30
 *
31
 * \author  AI
32
 **************************************************************************
33
 */
34
35
#include <stdlib.h>
36
#include "ih264_typedefs.h"
37
#include "ih264_macros.h"
38
#include "ih264_platform_macros.h"
39
#include "ih264d_bitstrm.h"
40
#include "ih264d_error_handler.h"
41
42
#include "ih264d_debug.h"
43
#include "ih264d_tables.h"
44
#include "ih264d_structs.h"
45
46
/*!
47
 **************************************************************************
48
 * \if Function name : ih264d_get_bit_h264 \endif
49
 *
50
 * \brief
51
 *    Read one bit from the bitstream.
52
 *
53
 *   This is a Bitstream processing function. It reads the
54
 *   bit currently pointed by the bit pointer in the
55
 *   buffer and advances the pointer by one. It returns
56
 *   the bit (0 or 1) in the form of an unsigned integer.
57
 *
58
 * \return
59
 *    Returns the next bit (0 or 1) in the bitstream.
60
 *
61
 **************************************************************************
62
 */
63
UWORD8 ih264d_get_bit_h264(dec_bit_stream_t *ps_stream)
64
36
{
65
36
    UWORD32 u4_code;
66
36
67
36
    GETBIT(u4_code, ps_stream->u4_ofst, ps_stream->pu4_buffer);
68
36
    return (u4_code);
69
36
}
70
71
/*!
72
 **************************************************************************
73
 * \if Function name : ih264d_get_bits_h264 \endif
74
 *
75
 * \brief
76
 *    Read specified number of bits from the bitstream.
77
 *
78
 *   This is a Bitstream processing function. It reads the
79
 *   number specified number of bits from the current bit
80
 *   position and advances the bit and byte pointers
81
 *   appropriately.
82
 *
83
 * \return
84
 *    An unsigned 32 bit integer with its least significant bits
85
 *    containing the bits in order of their occurence in the bitstream.
86
 *
87
 **************************************************************************
88
 */
89
90
UWORD32 ih264d_get_bits_h264(dec_bit_stream_t *ps_bitstrm, UWORD32 u4_num_bits)
91
66
{
92
66
    UWORD32 u4_code = 0;
93
66
    if(u4_num_bits)
94
66
        GETBITS(u4_code, ps_bitstrm->u4_ofst, ps_bitstrm->pu4_buffer, u4_num_bits);
95
66
    return (u4_code);
96
66
}
97
98
/*!
99
 **************************************************************************
100
 * \if Function name : ih264d_next_bits_h264 \endif
101
 *
102
 * \brief
103
 *    Peek specified number of bits from the bitstream.
104
 *
105
 *   This is a Bitstream processing function. It gets the
106
 *   specified number of bits from the buffer without
107
 *   altering the current pointers. It is equivalent to
108
 *   next_bits() function in the standard.
109
 *
110
 * \return
111
 *    An unsigned 32 bit integer with its least significant bits
112
 *    containing the bits in order of their occurence in the bitstream.
113
 **************************************************************************
114
 */
115
UWORD32 ih264d_next_bits_h264(dec_bit_stream_t *ps_bitstrm, UWORD32 u4_num_bits)
116
0
{
117
0
    UWORD32 u4_word_off = (ps_bitstrm->u4_ofst >> 5);
118
0
    UWORD32 u4_bit_off = ps_bitstrm->u4_ofst & 0x1F;
119
0
    UWORD32 *pu4_bitstream = ps_bitstrm->pu4_buffer;
120
0
    UWORD32 u4_bits = pu4_bitstream[u4_word_off++] << u4_bit_off;
121
0
122
0
    /*************************************************************************/
123
0
    /* Test if number of bits to be read exceeds the number of bits in the   */
124
0
    /* current word. If yes, read from the next word of the buffer, The bits */
125
0
    /* from both the words are concatenated to get next 32 bits in 'u4_bits' */
126
0
    /*************************************************************************/
127
0
    if(u4_bit_off > (INT_IN_BITS - u4_num_bits))
128
0
        u4_bits |= (pu4_bitstream[u4_word_off] >> (INT_IN_BITS - u4_bit_off));
129
0
130
0
    return ((u4_bits >> (INT_IN_BITS - u4_num_bits)));
131
0
}
132
133
/*!
134
 **************************************************************************
135
 * \if Function name : ih264d_flush_bits_h264 \endif
136
 *
137
 * \brief
138
 *    Flush specified number of bits from the bitstream.
139
 *
140
 *   This function flushes the specified number of bits (marks
141
 *   as read) from the buffer.
142
 *
143
 * \return
144
 *     A 8 bit unsigned integer with value
145
 *    '1' on successful flush
146
 *    '0' on failure.
147
 *
148
 **************************************************************************
149
 */
150
WORD32 ih264d_flush_bits_h264(dec_bit_stream_t *ps_bitstrm, WORD32 u4_num_bits)
151
0
{
152
0
    ps_bitstrm->u4_ofst += u4_num_bits;
153
0
154
0
    if(ps_bitstrm->u4_ofst > ps_bitstrm->u4_max_ofst)
155
0
    {
156
0
        return ERROR_EOB_FLUSHBITS_T;
157
0
    }
158
0
    return OK;
159
0
}
160
161
/*!
162
 **************************************************************************
163
 * \if Function name : ih264d_check_byte_aligned \endif
164
 *
165
 * \brief
166
 *    Checks whether the bit ps_bitstrm u4_ofst is at byte boundary.
167
 *
168
 * \param ps_bitstrm : Pointer to bitstream
169
 *
170
 * \return
171
 *    Returns 1 if bit ps_bitstrm u4_ofst is at byte alligned position else zero.
172
 **************************************************************************
173
 */
174
175
UWORD8 ih264d_check_byte_aligned(dec_bit_stream_t * ps_bitstrm)
176
0
{
177
0
    if(ps_bitstrm->u4_ofst & 0x07)
178
0
        return (0);
179
0
    else
180
0
        return (1);
181
0
}
/proc/self/cwd/external/libavc/decoder/ih264d_bitstrm.h
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
21
#ifndef _IH264D_BITSTRM_H_
22
#define _IH264D_BITSTRM_H_
23
/*!
24
 *************************************************************************
25
 * \file ih264d_bitstrm.h
26
 *
27
 * \brief
28
 *  Contains all the declarations of bitstream reading routines
29
 *
30
 * \date
31
 *    20/11/2002
32
 *
33
 * \author  AI
34
 *************************************************************************
35
 */
36
37
/* Includes */
38
#include <stdio.h>
39
#include <stdlib.h>
40
#include "ih264_typedefs.h"
41
#include "ih264_macros.h"
42
#include "ih264_platform_macros.h"
43
44
#define INT_IN_BYTES        4
45
894k
#define INT_IN_BITS         32
46
47
/* Based on level 1.2 of baseline profile */
48
/* 396[MAX_FS] * 128 * 1.5 [ChromaFormatParameter] / sizeof(UWORD32)
49
 i.e  396 * 128 * 1.5 / 4 = 19008 */
50
/* Based on level 3 of main profile */
51
/* 1620[MAX_FS] * 128 * 1.5 [ChromaFormatParameter] / sizeof(UWORD32)
52
 i.e  1620 * 128 * 1.5 / 4= 77760 */
53
#define SIZE_OF_BUFFER      77760
54
55
/* Structure for the ps_bitstrm */
56
typedef struct
57
{
58
    UWORD32 u4_ofst; /* Offset in the buffer for the current bit */
59
    UWORD32 *pu4_buffer; /* Bitstream Buffer  */
60
    UWORD32 u4_max_ofst; /* Position of the last bit read in the current buffer */
61
    void * pv_codec_handle; /* For Error Handling */
62
} dec_bit_stream_t;
63
64
/* To read the next bit */
65
UWORD8 ih264d_get_bit_h264(dec_bit_stream_t *);
66
67
/* To read the next specified number of bits */
68
UWORD32 ih264d_get_bits_h264(dec_bit_stream_t *, UWORD32);
69
70
/* To see the next specified number of bits */
71
UWORD32 ih264d_next_bits_h264(dec_bit_stream_t *, UWORD32);
72
73
/* To flush a specified number of bits*/
74
WORD32 ih264d_flush_bits_h264(dec_bit_stream_t *, WORD32);
75
76
/*!
77
 **************************************************************************
78
 * \if Function name : MoreRbspData \endif
79
 *
80
 * \brief
81
 *    Determines whether there is more data in RBSP or not.
82
 *
83
 * \param ps_bitstrm : Pointer to bitstream
84
 *
85
 * \return
86
 *    Returns 1 if there is more data in RBSP before rbsp_trailing_bits().
87
 *    Otherwise it returns FALSE.
88
 **************************************************************************
89
 */
90
91
#define MORE_RBSP_DATA(ps_bitstrm) \
92
5.06k
  (ps_bitstrm->u4_ofst < ps_bitstrm->u4_max_ofst)
93
#define EXCEED_OFFSET(ps_bitstrm) \
94
5.39k
  (ps_bitstrm->u4_ofst > ps_bitstrm->u4_max_ofst)
95
96
void GoToByteBoundary(dec_bit_stream_t * ps_bitstrm);
97
UWORD8 ih264d_check_byte_aligned(dec_bit_stream_t * ps_bitstrm);
98
99
/*****************************************************************************/
100
/* Define a macro for inlining of GETBIT:                                    */
101
/*****************************************************************************/
102
42.1k
#define   GETBIT(u4_code, u4_offset, pu4_bitstream)                         \
103
42.1k
{                                                                           \
104
42.1k
    UWORD32 *pu4_buf =  (pu4_bitstream);                                    \
105
42.1k
    UWORD32 u4_word_off = ((u4_offset) >> 5);                               \
106
42.1k
    UWORD32 u4_bit_off = (u4_offset) & 0x1F;                                \
107
42.1k
    u4_code = pu4_buf[u4_word_off] << u4_bit_off;                           \
108
42.1k
    (u4_offset)++;                                                          \
109
42.1k
    u4_code = (u4_code >> 31);                                              \
110
42.1k
}
111
112
113
114
/*****************************************************************************/
115
/* Define a macro for inlining of GETBITS: u4_no_bits shall not exceed 32    */
116
/*****************************************************************************/
117
221k
#define     GETBITS(u4_code, u4_offset, pu4_bitstream, u4_no_bits)          \
118
221k
{                                                                           \
119
221k
    UWORD32 *pu4_buf =  (pu4_bitstream);                                    \
120
221k
    UWORD32 u4_word_off = ((u4_offset) >> 5);                               \
121
221k
    UWORD32 u4_bit_off = (u4_offset) & 0x1F;                                \
122
221k
    u4_code = pu4_buf[u4_word_off++] << u4_bit_off;                         \
123
221k
                                                                            \
124
221k
    if(u4_bit_off)                                                          \
125
221k
        u4_code |= (pu4_buf[u4_word_off] >> (INT_IN_BITS - u4_bit_off));    \
126
221k
    u4_code = u4_code >> (INT_IN_BITS - u4_no_bits);                        \
127
221k
    (u4_offset) += u4_no_bits;                                              \
128
221k
}                                                                           \
129
                                                                            \
130
131
/*****************************************************************************/
132
/* Define a macro for inlining of NEXTBITS                                   */
133
/*****************************************************************************/
134
114k
#define     NEXTBITS(u4_word, u4_offset, pu4_bitstream, u4_no_bits)         \
135
114k
{                                                                           \
136
114k
    UWORD32 *pu4_buf =  (pu4_bitstream);                                    \
137
114k
    UWORD32 u4_word_off = ((u4_offset) >> 5);                               \
138
114k
    UWORD32 u4_bit_off = (u4_offset) & 0x1F;                                \
139
114k
    u4_word = pu4_buf[u4_word_off++] << u4_bit_off;                         \
140
114k
    if(u4_bit_off)                                                          \
141
114k
        u4_word |= (pu4_buf[u4_word_off] >> (INT_IN_BITS - u4_bit_off));    \
142
114k
    u4_word = u4_word >> (INT_IN_BITS - u4_no_bits);                        \
143
114k
}
144
/*****************************************************************************/
145
/* Define a macro for inlining of NEXTBITS_32                                */
146
/*****************************************************************************/
147
240k
#define     NEXTBITS_32(u4_word, u4_offset, pu4_bitstream)                  \
148
240k
{                                                                           \
149
240k
    UWORD32 *pu4_buf =  (pu4_bitstream);                                    \
150
240k
    UWORD32 u4_word_off = ((u4_offset) >> 5);                               \
151
240k
    UWORD32 u4_bit_off = (u4_offset) & 0x1F;                                \
152
240k
                                                                            \
153
240k
    u4_word = pu4_buf[u4_word_off++] << u4_bit_off;                         \
154
240k
    if(u4_bit_off)                                                          \
155
240k
    u4_word |= (pu4_buf[u4_word_off] >> (INT_IN_BITS - u4_bit_off));        \
156
240k
}
157
158
159
/*****************************************************************************/
160
/* Define a macro for inlining of FIND_ONE_IN_STREAM_32                      */
161
/*****************************************************************************/
162
219k
#define   FIND_ONE_IN_STREAM_32(u4_ldz, u4_offset, pu4_bitstream)           \
163
219k
{                                                                           \
164
219k
    UWORD32 u4_word;                                                        \
165
219k
    NEXTBITS_32(u4_word, u4_offset, pu4_bitstream);                         \
166
219k
    u4_ldz = CLZ(u4_word);                                     \
167
219k
    (u4_offset) += (u4_ldz + 1);                                            \
168
219k
}
169
170
/*****************************************************************************/
171
/* Define a macro for inlining of FIND_ONE_IN_STREAM_LEN                     */
172
/*****************************************************************************/
173
3.05k
#define   FIND_ONE_IN_STREAM_LEN(u4_ldz, u4_offset, pu4_bitstream, u4_len)  \
174
3.05k
{                                                                           \
175
3.05k
    UWORD32 u4_word;                                                        \
176
3.05k
    NEXTBITS_32(u4_word, u4_offset, pu4_bitstream);                         \
177
3.05k
    u4_ldz = CLZ(u4_word);                                     \
178
3.05k
    if(u4_ldz < u4_len)                                                     \
179
3.05k
    (u4_offset) += (u4_ldz + 1);                                            \
180
3.05k
    else                                                                    \
181
3.05k
    {                                                                       \
182
418
        u4_ldz = u4_len;                                                    \
183
418
        (u4_offset) += u4_ldz;                                              \
184
418
    }                                                                       \
185
3.05k
}
186
187
/*****************************************************************************/
188
/* Define a macro for inlining of FLUSHBITS                                  */
189
/*****************************************************************************/
190
114k
#define   FLUSHBITS(u4_offset, u4_no_bits)                                  \
191
114k
{                                                                           \
192
114k
        (u4_offset) += (u4_no_bits);                                        \
193
114k
}
194
195
#endif  /* _BITSTREAM_H_ */
/proc/self/cwd/external/libavc/decoder/ih264d_cabac.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/*!
21
 ***************************************************************************
22
 * \file ih264d_cabac.c
23
 *
24
 * \brief
25
 *    This file contains Binary decoding routines.
26
 *
27
 * \date
28
 *    04/02/2003
29
 *
30
 * \author  NS
31
 ***************************************************************************
32
 */
33
#include <string.h>
34
#include "ih264_typedefs.h"
35
#include "ih264_macros.h"
36
#include "ih264_platform_macros.h"
37
#include "ih264d_structs.h"
38
#include "ih264d_cabac.h"
39
#include "ih264d_bitstrm.h"
40
#include "ih264d_error_handler.h"
41
#include "ih264d_defs.h"
42
#include "ih264d_debug.h"
43
#include "ih264d_tables.h"
44
#include "ih264d_parse_cabac.h"
45
#include "ih264d_tables.h"
46
47
48
49
/*!
50
 **************************************************************************
51
 * \if Function name : ih264d_init_cabac_dec_envirnoment \endif
52
 *
53
 * \brief
54
 *    This function initializes CABAC decoding envirnoment. This function
55
 *    implements 9.3.3.2.3.1 of ISO/IEC14496-10.
56
 *
57
 * \return
58
 *    None
59
 *
60
 **************************************************************************
61
 */
62
WORD32 ih264d_init_cabac_dec_envirnoment(decoding_envirnoment_t * ps_cab_env,
63
                                       dec_bit_stream_t *ps_bitstrm)
64
0
{
65
0
    UWORD32 u4_code_int_val_ofst;
66
0
67
0
    ps_cab_env->u4_code_int_range = (HALF - 2) << 23;
68
0
    NEXTBITS(u4_code_int_val_ofst, ps_bitstrm->u4_ofst, ps_bitstrm->pu4_buffer,
69
0
             32);
70
0
    FLUSHBITS(ps_bitstrm->u4_ofst, 9)
71
0
72
0
    if(ps_bitstrm->u4_ofst > ps_bitstrm->u4_max_ofst)
73
0
        return ERROR_EOB_FLUSHBITS_T;
74
0
75
0
    ps_cab_env->u4_code_int_val_ofst = u4_code_int_val_ofst;
76
0
77
0
    /*brief description of the design adopted for CABAC*/
78
0
    /*according to the standard the u4_code_int_range needs to be initialized 0x 1FE(10 bits) and
79
0
     9 bits from the bit stream need to be read and into the u4_code_int_val_ofst.As and when the
80
0
     u4_code_int_range becomes less than 10 bits we need to renormalize and read from the bitstream*
81
0
82
0
     In the implemented design
83
0
     initially
84
0
85
0
     range_new = range <<23
86
0
     valOffset_new = valOffset << 23 + 23 bits(read from the bit stream)
87
0
88
0
     Thus we have read 23 more bits ahead of time.
89
0
90
0
     It can be mathematical proved that even with the modified range and u4_ofst the operations
91
0
     like comparison and subtraction needed for a bin decode are still valid(both in the regular case and the bypass case)
92
0
93
0
     As bins are decoded..we consume the bits that we have already read into the valOffset.The clz of Range
94
0
     gives us the number of bits we consumed of the 23 bits that we have read ahead of time.
95
0
96
0
     when the number bits we have consumed exceeds 23 ,we renormalize..and  we read from the bitstream again*/
97
0
98
0
RESET_BIN_COUNTS(ps_cab_env)
99
0
100
0
    return OK;
101
0
}
102
103
/*****************************************************************************/
104
/*                                                                           */
105
/*  Function Name : ih264d_init_cabac_contexts                                      */
106
/*                                                                           */
107
/*  Description   : This function initializes the cabac contexts             */
108
/*                  depending upon slice type and Init_Idc value.            */
109
/*  Inputs        : ps_dec, slice type                                       */
110
/*  Globals       : <Does it use any global variables?>                      */
111
/*  Outputs       :                                                          */
112
/*  Returns       : void                                                     */
113
/*                                                                           */
114
/*  Issues        : none                                                     */
115
/*                                                                           */
116
/*  Revision History:                                                        */
117
/*                                                                           */
118
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
119
/*         03 05 2005   100153)         Draft                                */
120
/*                                                                           */
121
/*****************************************************************************/
122
123
void ih264d_init_cabac_contexts(UWORD8 u1_slice_type, dec_struct_t * ps_dec)
124
0
{
125
0
126
0
    bin_ctxt_model_t *p_cabac_ctxt_table_t = ps_dec->p_cabac_ctxt_table_t;
127
0
    UWORD8 u1_qp_y = ps_dec->ps_cur_slice->u1_slice_qp;
128
0
    UWORD8 u1_cabac_init_Idc = 0;
129
0
130
0
    if(I_SLICE != u1_slice_type)
131
0
    {
132
0
        u1_cabac_init_Idc = ps_dec->ps_cur_slice->u1_cabac_init_idc;
133
0
    }
134
0
135
0
    {
136
0
        /* MAKING ps_dec->p_ctxt_inc_mb_map a scratch buffer */
137
0
        /* 0th entry of CtxtIncMbMap will be always be containing default values
138
0
         for CABAC context representing MB not available */
139
0
        ctxt_inc_mb_info_t *p_DefCtxt = ps_dec->p_ctxt_inc_mb_map - 1;
140
0
        UWORD8 *pu1_temp;
141
0
        WORD8 i;
142
0
        p_DefCtxt->u1_mb_type = CAB_SKIP;
143
0
144
0
        p_DefCtxt->u1_cbp = 0x0f;
145
0
        p_DefCtxt->u1_intra_chroma_pred_mode = 0;
146
0
147
0
        p_DefCtxt->u1_yuv_dc_csbp = 0x7;
148
0
149
0
        p_DefCtxt->u1_transform8x8_ctxt = 0;
150
0
151
0
        pu1_temp = (UWORD8*)p_DefCtxt->i1_ref_idx;
152
0
        for(i = 0; i < 4; i++, pu1_temp++)
153
0
            (*pu1_temp) = 0;
154
0
        pu1_temp = (UWORD8*)p_DefCtxt->u1_mv;
155
0
        for(i = 0; i < 16; i++, pu1_temp++)
156
0
            (*pu1_temp) = 0;
157
0
        ps_dec->ps_def_ctxt_mb_info = p_DefCtxt;
158
0
    }
159
0
160
0
    if(u1_slice_type == I_SLICE)
161
0
    {
162
0
        u1_cabac_init_Idc = 3;
163
0
        ps_dec->p_mb_type_t = p_cabac_ctxt_table_t + MB_TYPE_I_SLICE;
164
0
    }
165
0
    else if(u1_slice_type == P_SLICE)
166
0
    {
167
0
        ps_dec->p_mb_type_t = p_cabac_ctxt_table_t + MB_TYPE_P_SLICE;
168
0
        ps_dec->p_mb_skip_flag_t = p_cabac_ctxt_table_t + MB_SKIP_FLAG_P_SLICE;
169
0
        ps_dec->p_sub_mb_type_t = p_cabac_ctxt_table_t + SUB_MB_TYPE_P_SLICE;
170
0
    }
171
0
    else if(u1_slice_type == B_SLICE)
172
0
    {
173
0
        ps_dec->p_mb_type_t = p_cabac_ctxt_table_t + MB_TYPE_B_SLICE;
174
0
        ps_dec->p_mb_skip_flag_t = p_cabac_ctxt_table_t + MB_SKIP_FLAG_B_SLICE;
175
0
        ps_dec->p_sub_mb_type_t = p_cabac_ctxt_table_t + SUB_MB_TYPE_B_SLICE;
176
0
    }
177
0
    {
178
0
        bin_ctxt_model_t *p_cabac_ctxt_table_t_tmp = p_cabac_ctxt_table_t;
179
0
        if(ps_dec->ps_cur_slice->u1_field_pic_flag)
180
0
        {
181
0
            p_cabac_ctxt_table_t_tmp += SIGNIFICANT_COEFF_FLAG_FLD;
182
0
183
0
        }
184
0
        else
185
0
        {
186
0
            p_cabac_ctxt_table_t_tmp += SIGNIFICANT_COEFF_FLAG_FRAME;
187
0
        }
188
0
        {
189
0
            bin_ctxt_model_t * * p_significant_coeff_flag_t =
190
0
                            ps_dec->p_significant_coeff_flag_t;
191
0
            p_significant_coeff_flag_t[0] = p_cabac_ctxt_table_t_tmp
192
0
                            + SIG_COEFF_CTXT_CAT_0_OFFSET;
193
0
            p_significant_coeff_flag_t[1] = p_cabac_ctxt_table_t_tmp
194
0
                            + SIG_COEFF_CTXT_CAT_1_OFFSET;
195
0
            p_significant_coeff_flag_t[2] = p_cabac_ctxt_table_t_tmp
196
0
                            + SIG_COEFF_CTXT_CAT_2_OFFSET;
197
0
            p_significant_coeff_flag_t[3] = p_cabac_ctxt_table_t_tmp
198
0
                            + SIG_COEFF_CTXT_CAT_3_OFFSET;
199
0
            p_significant_coeff_flag_t[4] = p_cabac_ctxt_table_t_tmp
200
0
                            + SIG_COEFF_CTXT_CAT_4_OFFSET;
201
0
202
0
            p_significant_coeff_flag_t[5] = p_cabac_ctxt_table_t_tmp
203
0
                            + SIG_COEFF_CTXT_CAT_5_OFFSET;
204
0
205
0
        }
206
0
    }
207
0
208
0
    memcpy(p_cabac_ctxt_table_t,
209
0
           gau1_ih264d_cabac_ctxt_init_table[u1_cabac_init_Idc][u1_qp_y],
210
0
           NUM_CABAC_CTXTS * sizeof(bin_ctxt_model_t));
211
0
}
212
/*!
213
 **************************************************************************
214
 * \if Function name : ih264d_decode_bin \endif
215
 *
216
 * \brief
217
 *    This function implements decoding process of a decision as defined
218
 *    in 9.3.3.2.2.
219
 *
220
 * \return
221
 *    Returns symbol decoded.
222
 *
223
 * \note
224
 *    It is specified in 9.3.3.2.3.2 that, one of the input to this function
225
 *    is CtxIdx. CtxIdx is used to identify state and MPS of that context
226
 *    (Refer Fig 9.11 - Flowchart for encoding a decision). To suffice that
227
 *    here we pass a pointer bin_ctxt_model_t which contains these values.
228
 *
229
 **************************************************************************
230
 */
231
232
UWORD32 ih264d_decode_bin(UWORD32 u4_ctx_inc,
233
                          bin_ctxt_model_t *ps_src_bin_ctxt,
234
                          dec_bit_stream_t *ps_bitstrm,
235
                          decoding_envirnoment_t *ps_cab_env)
236
237
0
{
238
0
239
0
    UWORD32 u4_qnt_int_range, u4_code_int_range, u4_code_int_val_ofst,
240
0
                    u4_int_range_lps;
241
0
242
0
    UWORD32 u4_symbol, u4_mps_state;
243
0
244
0
    bin_ctxt_model_t *ps_bin_ctxt;
245
0
246
0
    UWORD32 table_lookup;
247
0
    const UWORD32 *pu4_table = (const UWORD32 *)ps_cab_env->cabac_table;
248
0
    UWORD32 u4_clz;
249
0
250
0
    ps_bin_ctxt = ps_src_bin_ctxt + u4_ctx_inc;
251
0
252
0
    u4_code_int_range = ps_cab_env->u4_code_int_range;
253
0
    u4_code_int_val_ofst = ps_cab_env->u4_code_int_val_ofst;
254
0
255
0
    u4_mps_state = (ps_bin_ctxt->u1_mps_state);
256
0
    u4_clz = CLZ(u4_code_int_range);
257
0
258
0
    u4_qnt_int_range = u4_code_int_range << u4_clz;
259
0
    u4_qnt_int_range = (u4_qnt_int_range >> 29) & 0x3;
260
0
261
0
    table_lookup = pu4_table[(u4_mps_state << 2) + u4_qnt_int_range];
262
0
    u4_int_range_lps = table_lookup & 0xff;
263
0
264
0
    u4_int_range_lps = u4_int_range_lps << (23 - u4_clz);
265
0
    u4_code_int_range = u4_code_int_range - u4_int_range_lps;
266
0
267
0
    u4_symbol = ((u4_mps_state >> 6) & 0x1);
268
0
269
0
    u4_mps_state = (table_lookup >> 8) & 0x7F;
270
0
271
0
    CHECK_IF_LPS(u4_code_int_range, u4_code_int_val_ofst, u4_symbol,
272
0
                 u4_int_range_lps, u4_mps_state, table_lookup)
273
0
274
0
    if(u4_code_int_range < ONE_RIGHT_SHIFTED_BY_8)
275
0
    {
276
0
        UWORD32 *pu4_buffer, u4_offset;
277
0
278
0
        pu4_buffer = ps_bitstrm->pu4_buffer;
279
0
        u4_offset = ps_bitstrm->u4_ofst;
280
0
281
0
        RENORM_RANGE_OFFSET(u4_code_int_range, u4_code_int_val_ofst, u4_offset,
282
0
                            pu4_buffer)
283
0
284
0
        ps_bitstrm->u4_ofst = u4_offset;
285
0
    }
286
0
287
0
    INC_BIN_COUNT(ps_cab_env)
288
0
289
0
    ps_cab_env->u4_code_int_val_ofst = u4_code_int_val_ofst;
290
0
    ps_cab_env->u4_code_int_range = u4_code_int_range;
291
0
    ps_bin_ctxt->u1_mps_state = u4_mps_state;
292
0
293
0
    return (u4_symbol);
294
0
}
295
296
/*!
297
 **************************************************************************
298
 * \if Function name : ih264d_decode_terminate \endif
299
 *
300
 * \brief
301
 *    This function implements decoding process of a termination as defined
302
 *    9.3.3.2.2.3 of ISO/IEC14496-10.
303
 *
304
 * \return
305
 *    Returns symbol decoded.
306
 *
307
 * \note
308
 *    This routine is called while decoding "end_of_skice_flag" and of the
309
 *    bin indicating PCM mode in MBType.
310
 *
311
 **************************************************************************
312
 */
313
UWORD8 ih264d_decode_terminate(decoding_envirnoment_t * ps_cab_env,
314
                               dec_bit_stream_t * ps_stream)
315
0
{
316
0
    UWORD32 u4_symbol;
317
0
    UWORD32 u4_code_int_val_ofst, u4_code_int_range;
318
0
    UWORD32 u4_clz;
319
0
320
0
    u4_code_int_range = ps_cab_env->u4_code_int_range;
321
0
    u4_code_int_val_ofst = ps_cab_env->u4_code_int_val_ofst;
322
0
323
0
    u4_clz = CLZ(u4_code_int_range);
324
0
    u4_code_int_range -= (2 << (23 - u4_clz));
325
0
326
0
    if(u4_code_int_val_ofst >= u4_code_int_range)
327
0
    {
328
0
        /* S=1 */
329
0
        u4_symbol = 1;
330
0
331
0
        {
332
0
333
0
            /*the u4_ofst needs to be updated before termination*/
334
0
            ps_stream->u4_ofst += u4_clz;
335
0
336
0
        }
337
0
338
0
    }
339
0
    else
340
0
    {
341
0
        /* S=0 */
342
0
        u4_symbol = 0;
343
0
344
0
        if(u4_code_int_range < ONE_RIGHT_SHIFTED_BY_8)
345
0
        {
346
0
            UWORD32 *pu4_buffer, u4_offset;
347
0
348
0
            pu4_buffer = ps_stream->pu4_buffer;
349
0
            u4_offset = ps_stream->u4_ofst;
350
0
351
0
            RENORM_RANGE_OFFSET(u4_code_int_range, u4_code_int_val_ofst, u4_offset,
352
0
                                pu4_buffer)
353
0
            ps_stream->u4_ofst = u4_offset;
354
0
        }
355
0
    }
356
0
357
0
    ps_cab_env->u4_code_int_range = u4_code_int_range;
358
0
    ps_cab_env->u4_code_int_val_ofst = u4_code_int_val_ofst;
359
0
360
0
    INC_BIN_COUNT(ps_cab_env)
361
0
362
0
    return (u4_symbol);
363
0
}
364
365
/*****************************************************************************/
366
/*                                                                           */
367
/*  Function Name : ih264d_decode_bins_tunary                                */
368
/*                                                                           */
369
/*  Description   : This function decodes bins in the case of TUNARY         */
370
/*                  binarization technique.valid_length is assumed  equal to 3 */
371
/*                  and u1_max_bins <= 4 in this functon.                                              */
372
/*  Inputs        : <What inputs does the function take?>                    */
373
/*  Globals       : <Does it use any global variables?>                      */
374
/*  Processing    : <Describe how the function operates - include algorithm  */
375
/*                  description>                                             */
376
/*  Outputs       : <What does the function produce?>                        */
377
/*  Returns       : <What does the function return?>                         */
378
/*                                                                           */
379
/*  Issues        :                                                          */
380
/*                                                                           */
381
/*  Revision History:                                                        */
382
/*                                                                           */
383
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
384
/*         20 11 2008   SH          Draft                                   */
385
/*                                                                           */
386
/*****************************************************************************/
387
388
UWORD32 ih264d_decode_bins_tunary(UWORD8 u1_max_bins,
389
                                  UWORD32 u4_ctx_inc,
390
                                  bin_ctxt_model_t *ps_src_bin_ctxt,
391
                                  dec_bit_stream_t *ps_bitstrm,
392
                                  decoding_envirnoment_t *ps_cab_env)
393
394
0
{
395
0
    UWORD32 u4_value;
396
0
    UWORD32 u4_symbol;
397
0
    UWORD8 u4_ctx_Inc;
398
0
    bin_ctxt_model_t *ps_bin_ctxt;
399
0
    UWORD32 u4_code_int_range, u4_code_int_val_ofst;
400
0
    const UWORD32 *pu4_table = (const UWORD32 *)ps_cab_env->cabac_table;
401
0
402
0
    u4_value = 0;
403
0
404
0
    /*u1_max_bins has to be less than or equal to 4, u1_max_bins <= 4 for  this function*/
405
0
406
0
    /*here the valid length is assumed to be equal to 3 ,so the calling function is expected
407
0
     to duplicate CtxInc if valid lenth is 2 and cmaxbin is greater than2*/
408
0
    u4_code_int_range = ps_cab_env->u4_code_int_range;
409
0
    u4_code_int_val_ofst = ps_cab_env->u4_code_int_val_ofst;
410
0
411
0
    do
412
0
    {
413
0
        u4_ctx_Inc = u4_ctx_inc & 0xF;
414
0
        u4_ctx_inc = u4_ctx_inc >> 4;
415
0
416
0
        ps_bin_ctxt = ps_src_bin_ctxt + u4_ctx_Inc;
417
0
418
0
        DECODE_ONE_BIN_MACRO(ps_bin_ctxt, u4_code_int_range, u4_code_int_val_ofst,
419
0
                             pu4_table, ps_bitstrm, u4_symbol)
420
0
421
0
        INC_BIN_COUNT(ps_cab_env);INC_DECISION_BINS(ps_cab_env);
422
0
423
0
        u4_value++;
424
0
    }
425
0
    while((u4_value < u1_max_bins) & (u4_symbol));
426
0
427
0
    u4_value = u4_value - 1 + u4_symbol;
428
0
429
0
    ps_cab_env->u4_code_int_range = u4_code_int_range;
430
0
    ps_cab_env->u4_code_int_val_ofst = u4_code_int_val_ofst;
431
0
432
0
    return (u4_value);
433
0
434
0
}
435
436
/*****************************************************************************/
437
/*                                                                           */
438
/*  Function Name : ih264d_decode_bins                                */
439
/*                                                                           */
440
/*  Description   : This function decodes bins in the case of MSB_FIRST_FLC  */
441
/*                  binarization technique.valid_length is always equal max_bins */
442
/*                  for MSB_FIRST_FLC. assumes  u1_max_bins <= 4               */
443
/*  Inputs        : <What inputs does the function take?>                    */
444
/*  Globals       : <Does it use any global variables?>                      */
445
/*  Processing    : <Describe how the function operates - include algorithm  */
446
/*                  description>                                             */
447
/*  Outputs       : <What does the function produce?>                        */
448
/*  Returns       : <What does the function return?>                         */
449
/*                                                                           */
450
/*  Issues        : <List any issues or problems with this function>         */
451
/*                                                                           */
452
/*  Revision History:                                                        */
453
/*                                                                           */
454
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
455
/*         20 11 2008   SH          Draft                                   */
456
/*                                                                           */
457
/*****************************************************************************/
458
459
UWORD32 ih264d_decode_bins(UWORD8 u1_max_bins,
460
                           UWORD32 u4_ctx_inc,
461
                           bin_ctxt_model_t *ps_src_bin_ctxt,
462
                           dec_bit_stream_t *ps_bitstrm,
463
                           decoding_envirnoment_t *ps_cab_env)
464
465
0
{
466
0
    UWORD32 u4_value;
467
0
    UWORD32 u4_symbol, i;
468
0
    UWORD32 u4_ctxt_inc;
469
0
    bin_ctxt_model_t *ps_bin_ctxt;
470
0
    UWORD32 u4_code_int_range, u4_code_int_val_ofst;
471
0
    const UWORD32 *pu4_table = (const UWORD32 *)ps_cab_env->cabac_table;
472
0
473
0
    i = 0;
474
0
475
0
    u4_value = 0;
476
0
477
0
    /*u1_max_bins has to be less than or equal to 4, u1_max_bins <= 4 for  this fucntion*/
478
0
    u4_code_int_range = ps_cab_env->u4_code_int_range;
479
0
    u4_code_int_val_ofst = ps_cab_env->u4_code_int_val_ofst;
480
0
481
0
    do
482
0
    {
483
0
        u4_ctxt_inc = u4_ctx_inc & 0xf;
484
0
        u4_ctx_inc = u4_ctx_inc >> 4;
485
0
486
0
        ps_bin_ctxt = ps_src_bin_ctxt + u4_ctxt_inc;
487
0
488
0
        DECODE_ONE_BIN_MACRO(ps_bin_ctxt, u4_code_int_range, u4_code_int_val_ofst,
489
0
                             pu4_table, ps_bitstrm, u4_symbol)
490
0
491
0
        INC_BIN_COUNT(ps_cab_env);INC_DECISION_BINS(ps_cab_env);
492
0
493
0
        u4_value = (u4_value << 1) | (u4_symbol);
494
0
495
0
        i++;
496
0
    }
497
0
    while(i < u1_max_bins);
498
0
499
0
    ps_cab_env->u4_code_int_range = u4_code_int_range;
500
0
    ps_cab_env->u4_code_int_val_ofst = u4_code_int_val_ofst;
501
0
502
0
    return (u4_value);
503
0
504
0
}
505
506
/*****************************************************************************/
507
/*                                                                           */
508
/*  Function Name : ih264d_decode_bins_unary                                */
509
/*                                                                           */
510
/*  Description   : This function decodes bins in the case of UNARY         */
511
/*                  binarization technique.here the valid length is taken to 5*/
512
/*                  and cmax is always greater than 9                       */
513
/*  Inputs        : <What inputs does the function take?>                    */
514
/*  Globals       : <Does it use any global variables?>                      */
515
/*  Processing    : <Describe how the function operates - include algorithm  */
516
/*                  description>                                             */
517
/*  Outputs       : <What does the function produce?>                        */
518
/*  Returns       : <What does the function return?>                         */
519
/*                                                                           */
520
/*  Issues        : <List any issues or problems with this function>         */
521
/*                                                                           */
522
/*  Revision History:                                                        */
523
/*                                                                           */
524
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
525
/*         20 11 2008   SH          Draft                                   */
526
/*                                                                           */
527
/*****************************************************************************/
528
UWORD32 ih264d_decode_bins_unary(UWORD8 u1_max_bins,
529
                                 UWORD32 u4_ctx_inc,
530
                                 bin_ctxt_model_t *ps_src_bin_ctxt,
531
                                 dec_bit_stream_t *ps_bitstrm,
532
                                 decoding_envirnoment_t *ps_cab_env)
533
0
{
534
0
    UWORD32 u4_value;
535
0
    UWORD32 u4_symbol;
536
0
    bin_ctxt_model_t *ps_bin_ctxt;
537
0
    UWORD32 u4_ctx_Inc;
538
0
    UWORD32 u4_code_int_range, u4_code_int_val_ofst;
539
0
    const UWORD32 *pu4_table = (const UWORD32 *)ps_cab_env->cabac_table;
540
0
541
0
    /* in this function the valid length for u4_ctx_inc is always taken to be,so if the
542
0
     the valid length is lessthan 5 the caller need to duplicate accordingly*/
543
0
544
0
    /*u1_max_bins is always greater or equal to 9 we have the check for u1_max_bins only after the 2 loop*/
545
0
    u4_value = 0;
546
0
    u4_code_int_range = ps_cab_env->u4_code_int_range;
547
0
    u4_code_int_val_ofst = ps_cab_env->u4_code_int_val_ofst;
548
0
549
0
    do
550
0
    {
551
0
        u4_ctx_Inc = u4_ctx_inc & 0xf;
552
0
        u4_ctx_inc = u4_ctx_inc >> 4;
553
0
554
0
        ps_bin_ctxt = ps_src_bin_ctxt + u4_ctx_Inc;
555
0
556
0
        DECODE_ONE_BIN_MACRO(ps_bin_ctxt, u4_code_int_range, u4_code_int_val_ofst,
557
0
                             pu4_table, ps_bitstrm, u4_symbol)
558
0
559
0
        INC_BIN_COUNT(ps_cab_env);INC_DECISION_BINS(ps_cab_env);
560
0
561
0
        u4_value++;
562
0
563
0
    }
564
0
    while(u4_symbol && u4_value < 4);
565
0
566
0
    if(u4_symbol && (u4_value < u1_max_bins))
567
0
    {
568
0
569
0
        u4_ctx_Inc = u4_ctx_inc & 0xf;
570
0
571
0
        ps_bin_ctxt = ps_src_bin_ctxt + u4_ctx_Inc;
572
0
573
0
        do
574
0
        {
575
0
576
0
            DECODE_ONE_BIN_MACRO(ps_bin_ctxt, u4_code_int_range, u4_code_int_val_ofst,
577
0
                                 pu4_table, ps_bitstrm, u4_symbol)
578
0
579
0
            INC_BIN_COUNT(ps_cab_env);INC_DECISION_BINS(ps_cab_env);
580
0
581
0
            u4_value++;
582
0
583
0
        }
584
0
        while(u4_symbol && (u4_value < u1_max_bins));
585
0
586
0
    }
587
0
588
0
    ps_cab_env->u4_code_int_range = u4_code_int_range;
589
0
    ps_cab_env->u4_code_int_val_ofst = u4_code_int_val_ofst;
590
0
591
0
    u4_value = u4_value - 1 + u4_symbol;
592
0
593
0
    return (u4_value);
594
0
595
0
}
596
597
/*****************************************************************************/
598
/*                                                                           */
599
/*  Function Name : ih264d_decode_bypass_bins_unary                                     */
600
/*                                                                           */
601
/*  Description   : This function is used in the case of UNARY coding       */
602
/*                                                                           */
603
/*                                                                           */
604
/*  Inputs        : <What inputs does the function take?>                    */
605
/*  Globals       : <Does it use any global variables?>                      */
606
/*  Processing    : <Describe how the function operates - include algorithm  */
607
/*                  description>                                             */
608
/*  Outputs       : <What does the function produce?>                        */
609
/*  Returns       : <What does the function return?>                         */
610
/*                                                                           */
611
/*  Issues        : <List any issues or problems with this function>         */
612
/*                                                                           */
613
/*  Revision History:                                                        */
614
/*                                                                           */
615
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
616
/*         13 10 2005   Ittiam          Draft                                */
617
/*                                                                           */
618
/*****************************************************************************/
619
620
UWORD32 ih264d_decode_bypass_bins_unary(decoding_envirnoment_t *ps_cab_env,
621
                                        dec_bit_stream_t *ps_bitstrm)
622
0
{
623
0
    UWORD32 u4_value;
624
0
    UWORD32 u4_bin;
625
0
    UWORD32 u4_code_int_val_ofst, u4_code_int_range;
626
0
627
0
    UWORD32 u1_max_bins;
628
0
629
0
    u4_code_int_val_ofst = ps_cab_env->u4_code_int_val_ofst;
630
0
    u4_code_int_range = ps_cab_env->u4_code_int_range;
631
0
632
0
    if(u4_code_int_range < ONE_RIGHT_SHIFTED_BY_9)
633
0
    {
634
0
        UWORD32 *pu4_buffer, u4_offset;
635
0
636
0
        pu4_buffer = ps_bitstrm->pu4_buffer;
637
0
        u4_offset = ps_bitstrm->u4_ofst;
638
0
639
0
        RENORM_RANGE_OFFSET(u4_code_int_range, u4_code_int_val_ofst, u4_offset,
640
0
                            pu4_buffer)
641
0
        ps_bitstrm->u4_ofst = u4_offset;
642
0
    }
643
0
644
0
    /*as it is called only form mvd*/
645
0
    u1_max_bins = 32;
646
0
    u4_value = 0;
647
0
648
0
    do
649
0
    {
650
0
        u4_value++;
651
0
652
0
        u4_code_int_range = u4_code_int_range >> 1;
653
0
        if(u4_code_int_val_ofst >= u4_code_int_range)
654
0
        {
655
0
            /* S=1 */
656
0
            u4_bin = 1;
657
0
            u4_code_int_val_ofst -= u4_code_int_range;
658
0
        }
659
0
        else
660
0
        {
661
0
            /* S=0 */
662
0
            u4_bin = 0;
663
0
        }
664
0
665
0
        INC_BIN_COUNT(ps_cab_env);INC_BYPASS_BINS(ps_cab_env);
666
0
667
0
        if(u4_code_int_range < ONE_RIGHT_SHIFTED_BY_9)
668
0
        {
669
0
            UWORD32 *pu4_buffer, u4_offset;
670
0
671
0
            pu4_buffer = ps_bitstrm->pu4_buffer;
672
0
            u4_offset = ps_bitstrm->u4_ofst;
673
0
674
0
            RENORM_RANGE_OFFSET(u4_code_int_range, u4_code_int_val_ofst, u4_offset,
675
0
                                pu4_buffer)
676
0
677
0
            ps_bitstrm->u4_ofst = u4_offset;
678
0
        }
679
0
680
0
    }
681
0
    while(u4_bin && (u4_value < u1_max_bins));
682
0
683
0
    ps_cab_env->u4_code_int_val_ofst = u4_code_int_val_ofst;
684
0
    ps_cab_env->u4_code_int_range = u4_code_int_range;
685
0
    u4_value = (u4_value - 1 + u4_bin);
686
0
687
0
return (u4_value);
688
0
}
689
690
/*****************************************************************************/
691
/*                                                                           */
692
/*  Function Name : ih264d_decode_bypass_bins                                     */
693
/*                                                                           */
694
/*  Description   : This function is used in the case of FLC coding       */
695
/*                                                                           */
696
/*                                                                           */
697
/*  Inputs        : <What inputs does the function take?>                    */
698
/*  Globals       : <Does it use any global variables?>                      */
699
/*  Processing    : <Describe how the function operates - include algorithm  */
700
/*                  description>                                             */
701
/*  Outputs       : <What does the function produce?>                        */
702
/*  Returns       : <What does the function return?>                         */
703
/*                                                                           */
704
/*  Issues        : <List any issues or problems with this function>         */
705
/*                                                                           */
706
/*  Revision History:                                                        */
707
/*                                                                           */
708
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
709
/*         13 10 2005   Ittiam          Draft                                */
710
/*                                                                           */
711
/*****************************************************************************/
712
713
UWORD32 ih264d_decode_bypass_bins(decoding_envirnoment_t *ps_cab_env,
714
                                  UWORD8 u1_max_bins,
715
                                  dec_bit_stream_t *ps_bitstrm)
716
0
{
717
0
    UWORD32 u4_bins;
718
0
    UWORD32 u4_bin;
719
0
    UWORD32 u4_code_int_val_ofst, u4_code_int_range;
720
0
721
0
    u4_bins = 0;
722
0
    u4_code_int_val_ofst = ps_cab_env->u4_code_int_val_ofst;
723
0
    u4_code_int_range = ps_cab_env->u4_code_int_range;
724
0
725
0
    if(u4_code_int_range < ONE_RIGHT_SHIFTED_BY_9)
726
0
    {
727
0
        UWORD32 *pu4_buffer, u4_offset;
728
0
729
0
        pu4_buffer = ps_bitstrm->pu4_buffer;
730
0
        u4_offset = ps_bitstrm->u4_ofst;
731
0
732
0
        RENORM_RANGE_OFFSET(u4_code_int_range, u4_code_int_val_ofst, u4_offset,
733
0
                            pu4_buffer)
734
0
        ps_bitstrm->u4_ofst = u4_offset;
735
0
    }
736
0
737
0
    do
738
0
    {
739
0
740
0
        u4_code_int_range = u4_code_int_range >> 1;
741
0
742
0
        if(u4_code_int_val_ofst >= u4_code_int_range)
743
0
        {
744
0
            /* S=1 */
745
0
            u4_bin = 1;
746
0
            u4_code_int_val_ofst -= u4_code_int_range;
747
0
        }
748
0
        else
749
0
        {
750
0
            /* S=0 */
751
0
            u4_bin = 0;
752
0
        }
753
0
754
0
        INC_BIN_COUNT(ps_cab_env);INC_BYPASS_BINS(ps_cab_env);
755
0
756
0
        u4_bins = ((u4_bins << 1) | u4_bin);
757
0
        u1_max_bins--;
758
0
759
0
        if(u4_code_int_range < ONE_RIGHT_SHIFTED_BY_9)
760
0
        {
761
0
            UWORD32 *pu4_buffer, u4_offset;
762
0
763
0
            pu4_buffer = ps_bitstrm->pu4_buffer;
764
0
            u4_offset = ps_bitstrm->u4_ofst;
765
0
766
0
            RENORM_RANGE_OFFSET(u4_code_int_range, u4_code_int_val_ofst, u4_offset,
767
0
                                pu4_buffer)
768
0
            ps_bitstrm->u4_ofst = u4_offset;
769
0
        }
770
0
771
0
    }
772
0
    while(u1_max_bins);
773
0
774
0
    ps_cab_env->u4_code_int_val_ofst = u4_code_int_val_ofst;
775
0
    ps_cab_env->u4_code_int_range = u4_code_int_range;
776
0
777
0
    return (u4_bins);
778
0
}
779
/proc/self/cwd/external/libavc/decoder/ih264d_cabac.h
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/*!
21
 ***************************************************************************
22
 * \file ih264d_cabac.h
23
 *
24
 * \brief
25
 *    This file contains declarations of Binary decoding routines and tables.
26
 *
27
 * \date
28
 *    04/02/2003
29
 *
30
 * \author  NS
31
 ***************************************************************************
32
 */
33
34
#ifndef _IH264D_CABAC_H_
35
#define _IH264D_CABAC_H_
36
37
#include "ih264_typedefs.h"
38
#include "ih264_macros.h"
39
#include "ih264_platform_macros.h"
40
#include "ih264d_bitstrm.h"
41
#include "ih264d_defs.h"
42
43
0
#define   B_BITS    10
44
45
0
#define   HALF      (1 << (B_BITS-1))
46
#define   QUARTER   (1 << (B_BITS-2))
47
48
#define CTXT_UNUSED   {0,64}
49
#define NUM_MB_SKIP_CTXT  6
50
#define NUM_MB_TYPE_CTXT  9
51
#define NUM_SUBMB_TYPE_CTXT 7
52
#define NUM_REF_IDX_CTXT  6
53
#define NUM_MB_QP_DELTA 4
54
#define NUM_PRED_MODE 6
55
#define NUM_MB_FIELD    3
56
#define NUM_CBP 12
57
#define NUM_CTX_MVD 14
58
59
/* Residual block cabac context parameters */
60
#define NUM_CTX_CAT 6
61
#define NUM_LUMA_CTX_CAT 3
62
#define NUM_CTX_CODED_BLOCK 4
63
/* Luma CtxSigCoeff + CtxLastCoeff = 15 + 15 = 30 */
64
#define NUM_LUMA_CTX_SIG_COEF 30
65
/* Chroma DC CtxSigCoeff + CtxLastCoeff = 3 + 3 = 6 */
66
#define NUM_CTX_CHROMA_DC_SIG_COEF 6
67
/* Chroma AC CtxSigCoeff + CtxLastCoeff = 14 + 14 = 28 */
68
#define NUM_CTX_CHROMA_AC_SIG_COEF 28
69
#define NUM_CTX_ABS_LEVEL 10
70
71
1
#define LUMA_DC_CTXCAT    0
72
1
#define LUMA_AC_CTXCAT    1
73
1
#define LUMA_4X4_CTXCAT   2
74
1
#define CHROMA_DC_CTXCAT  3
75
1
#define CHROMA_AC_CTXCAT  4
76
1
#define LUMA_8X8_CTXCAT   5
77
78
/*****************************************************************************/
79
/* Constant Macros                                                           */
80
/*****************************************************************************/
81
1
#define NUM_CABAC_CTXTS 460
82
#define QP_RANGE        52
83
#define NUM_CAB_INIT_IDC_PLUS_ONE 4
84
0
#define LAST_COEFF_CTXT_MINUS_SIG_COEFF_CTXT 61
85
0
#define LAST_COEFF_CTXT_MINUS_SIG_COEFF_CTXT_8X8 15
86
87
/*bits 0 to 5 :state
88
 bit 6:mps*/
89
typedef struct
90
{
91
    UWORD8 u1_mps_state; /* state number */
92
} bin_ctxt_model_t;
93
94
typedef struct
95
96
{
97
    /* Neighbour availability Variables needed to get CtxtInc, for CABAC */
98
    UWORD8 u1_mb_type; /** macroblock type: I/P/B/SI/SP */
99
    UWORD8 u1_cbp; /** Coded Block Pattern */
100
    UWORD8 u1_intra_chroma_pred_mode;
101
102
    /*************************************************************************/
103
    /*               Arrangnment of DC CSBP                                  */
104
    /*        bits:  b7  b6  b5  b4  b3  b2  b1  b0                          */
105
    /*        CSBP:   x   x   x   x   x  Vdc Udc Ydc                         */
106
    /*************************************************************************/
107
    UWORD8 u1_yuv_dc_csbp;
108
    WORD8 i1_ref_idx[4];
109
    UWORD8 u1_mv[4][4];
110
    UWORD8 u1_transform8x8_ctxt;
111
} ctxt_inc_mb_info_t;
112
113
0
#define ONE_RIGHT_SHIFTED_BY_8 1<<8
114
0
#define ONE_RIGHT_SHIFTED_BY_9    1<<9
115
0
#define ONE_RIGHT_SHIFTED_BY_14 1<<14
116
typedef struct
117
{
118
    UWORD32 u4_code_int_range;
119
    UWORD32 u4_code_int_val_ofst;
120
    const void *cabac_table;
121
    void * pv_codec_handle; /* For Error Handling */
122
} decoding_envirnoment_t;
123
124
WORD32 ih264d_init_cabac_dec_envirnoment(decoding_envirnoment_t * ps_cab_env,
125
                                       dec_bit_stream_t *ps_bitstrm);
126
127
UWORD32 ih264d_decode_bin(UWORD32 u4_ctx_inc,
128
                          bin_ctxt_model_t *ps_bin_ctxt,
129
                          dec_bit_stream_t *ps_bitstrm,
130
                          decoding_envirnoment_t *ps_cab_env);
131
UWORD8 ih264d_decode_terminate(decoding_envirnoment_t * ps_cab_env,
132
                               dec_bit_stream_t * ps_bitstrm);
133
134
UWORD32 ih264d_decode_bins_tunary(UWORD8 u1_max_bins,
135
                                  UWORD32 u4_ctx_inc,
136
                                  bin_ctxt_model_t *ps_src_bin_ctxt,
137
                                  dec_bit_stream_t *ps_bitstrm,
138
                                  decoding_envirnoment_t *ps_cab_env);
139
140
UWORD32 ih264d_decode_bins(UWORD8 u1_max_bins,
141
                           UWORD32 u4_ctx_inc,
142
                           bin_ctxt_model_t *ps_src_bin_ctxt,
143
                           dec_bit_stream_t *ps_bitstrm,
144
                           decoding_envirnoment_t *ps_cab_env);
145
UWORD32 ih264d_decode_bins_unary(UWORD8 u1_max_bins,
146
                                 UWORD32 u4_ctx_inc,
147
                                 bin_ctxt_model_t *ps_src_bin_ctxt,
148
                                 dec_bit_stream_t *ps_bitstrm,
149
                                 decoding_envirnoment_t *ps_cab_env);
150
151
UWORD32 ih264d_decode_bypass_bins_unary(decoding_envirnoment_t *ps_cab_env,
152
                                        dec_bit_stream_t *ps_bitstrm);
153
154
UWORD32 ih264d_decode_bypass_bins(decoding_envirnoment_t *ps_cab_env,
155
                                  UWORD8 u1_max_bins,
156
                                  dec_bit_stream_t *ps_bitstrm);
157
158
/*****************************************************************************/
159
/* Function Macros                                                           */
160
/*****************************************************************************/
161
162
/*****************************************************************************/
163
/* Defining a macro for renormalization*/
164
/*****************************************************************************/
165
166
/*we renormalize every time the number bits(which are read ahead of time) we have
167
 consumed in the u4_ofst exceeds 23*/
168
169
#define RENORM_RANGE_OFFSET(u4_codeIntRange_m,u4_codeIntValOffset_m,u4_offset_m,pu4_buffer_m) \
170
0
  {                                                                                         \
171
0
    UWORD32 read_bits_m,u4_clz_m  ;                                                         \
172
0
    u4_clz_m = CLZ(u4_codeIntRange_m);                                                  \
173
0
    NEXTBITS(read_bits_m,(u4_offset_m+23),pu4_buffer_m,u4_clz_m)                            \
174
0
    FLUSHBITS(u4_offset_m,(u4_clz_m))                                                       \
175
0
    u4_codeIntRange_m = u4_codeIntRange_m << u4_clz_m;                                      \
176
0
    u4_codeIntValOffset_m = (u4_codeIntValOffset_m << u4_clz_m) | read_bits_m;              \
177
0
  }
178
179
/*****************************************************************************/
180
/* Defining a macro for checking if the symbol is MPS*/
181
/*****************************************************************************/
182
183
#define CHECK_IF_LPS(u4_codeIntRange_m,u4_codeIntValOffset_m,u4_symbol_m,                   \
184
0
                    u4_codeIntRangeLPS_m,u1_mps_state_m,table_lookup_m)                     \
185
0
{                                                                                         \
186
0
  if(u4_codeIntValOffset_m >= u4_codeIntRange_m)                                            \
187
0
  {                                                                                         \
188
0
      u4_symbol_m = 1 - u4_symbol_m;                                                        \
189
0
      u4_codeIntValOffset_m -= u4_codeIntRange_m;                                           \
190
0
      u4_codeIntRange_m = u4_codeIntRangeLPS_m;                                             \
191
0
      u1_mps_state_m = (table_lookup_m >> 15) & 0x7F;                                       \
192
0
  }                                                                                         \
193
0
}
194
195
/*!
196
 **************************************************************************
197
 * \if Function name : DECODE_ONE_BIN_MACRO \endif
198
 *
199
 * \brief
200
 *    This function implements decoding process of a decision as defined
201
 *    in 9.3.3.2.2.
202
 *
203
 * \return
204
 *    Returns symbol decoded.
205
 *
206
 * \note
207
 *    It is specified in 9.3.3.2.3.2 that, one of the input to this function
208
 *    is CtxIdx. CtxIdx is used to identify state and MPS of that context
209
 *    (Refer Fig 9.11 - Flowchart for encoding a decision). To suffice that
210
 *    here we pass a pointer bin_ctxt_model_t which contains these values.
211
 *
212
 **************************************************************************
213
 */
214
215
#define DECODE_ONE_BIN_MACRO(p_binCtxt_arg ,u4_code_int_range,u4_code_int_val_ofst,       \
216
                     pu4_table_arg,                                                \
217
0
                     p_DecBitStream_arg,u4_symbol)                                           \
218
0
{                                                                                       \
219
0
    bin_ctxt_model_t *p_binCtxt_m = (bin_ctxt_model_t *) p_binCtxt_arg;                           \
220
0
    dec_bit_stream_t *p_DecBitStream_m = (dec_bit_stream_t *) p_DecBitStream_arg;                 \
221
0
    const UWORD32 *pu4_table_m = (const UWORD32 *) pu4_table_arg;                         \
222
0
                                                                                        \
223
0
    UWORD32 u4_quantCodeIntRange_m,u4_codeIntRangeLPS_m;                                    \
224
0
    UWORD32 u1_mps_state_m;                                                               \
225
0
    UWORD32 table_lookup_m;                                                               \
226
0
    UWORD32 u4_clz_m;                                                                     \
227
0
                                                                                        \
228
0
    u1_mps_state_m = (p_binCtxt_m->u1_mps_state);                                           \
229
0
    u4_clz_m = CLZ(u4_code_int_range);                                                  \
230
0
    u4_quantCodeIntRange_m = u4_code_int_range << u4_clz_m;                                   \
231
0
    u4_quantCodeIntRange_m = (u4_quantCodeIntRange_m >> 29) & 0x3;                          \
232
0
    table_lookup_m = pu4_table_m[(u1_mps_state_m << 2)+u4_quantCodeIntRange_m];                 \
233
0
    u4_codeIntRangeLPS_m = table_lookup_m & 0xff;                                           \
234
0
                                                                                        \
235
0
    u4_codeIntRangeLPS_m = u4_codeIntRangeLPS_m << (23 - u4_clz_m);                           \
236
0
    u4_code_int_range = u4_code_int_range - u4_codeIntRangeLPS_m;                             \
237
0
    u4_symbol = ((u1_mps_state_m>> 6) & 0x1);                                             \
238
0
    /*if mps*/                                                                          \
239
0
    u1_mps_state_m = (table_lookup_m >> 8) & 0x7F;                                          \
240
0
    if(u4_code_int_val_ofst >= u4_code_int_range)                                          \
241
0
  {                                                                                     \
242
0
                                                                                        \
243
0
    u4_symbol = 1 - u4_symbol;                                                          \
244
0
    u4_code_int_val_ofst -= u4_code_int_range;                                             \
245
0
    u4_code_int_range = u4_codeIntRangeLPS_m;                                               \
246
0
    u1_mps_state_m = (table_lookup_m >> 15) & 0x7F;                                         \
247
0
  }                                                                                     \
248
0
    if(u4_code_int_range < ONE_RIGHT_SHIFTED_BY_8)                                        \
249
0
    {                                                                                   \
250
0
        UWORD32 *pu4_buffer,u4_offset;                                                  \
251
0
        UWORD32 read_bits,u4_clz_m  ;                                                     \
252
0
                                                                                        \
253
0
        pu4_buffer = p_DecBitStream_m->pu4_buffer;                                         \
254
0
        u4_offset = p_DecBitStream_m->u4_ofst;                                          \
255
0
        u4_clz_m = CLZ(u4_code_int_range);                                              \
256
0
        NEXTBITS(read_bits,(u4_offset+23),pu4_buffer,u4_clz_m)                            \
257
0
        FLUSHBITS(u4_offset,(u4_clz_m))                                                   \
258
0
        u4_code_int_range = u4_code_int_range << u4_clz_m;                                    \
259
0
        u4_code_int_val_ofst= (u4_code_int_val_ofst << u4_clz_m) | read_bits;               \
260
0
                                                                                        \
261
0
                                                                                        \
262
0
        p_DecBitStream_m->u4_ofst = u4_offset;                                          \
263
0
    }                                                                                   \
264
0
    p_binCtxt_m->u1_mps_state = u1_mps_state_m;                                             \
265
0
}
266
267
#endif  /*  _IH264D_CABAC_H_ */
/proc/self/cwd/external/libavc/decoder/ih264d_compute_bs.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
21
#include "ih264_typedefs.h"
22
#include "ih264_macros.h"
23
#include "ih264_platform_macros.h"
24
#include "ih264d_structs.h"
25
#include "ih264d_defs.h"
26
#include "ih264d_deblocking.h"
27
#include "string.h"
28
#include "ih264d_debug.h"
29
#include "ih264d_tables.h"
30
31
UWORD16 ih264d_update_csbp_8x8(UWORD16 u2_luma_csbp)
32
0
{
33
0
    UWORD16 u2_mod_csbp;
34
0
35
0
    u2_mod_csbp = u2_luma_csbp;
36
0
37
0
    if(u2_mod_csbp & 0x0033)
38
0
    {
39
0
        u2_mod_csbp |= 0x0033;
40
0
    }
41
0
42
0
    if(u2_mod_csbp & 0x00CC)
43
0
    {
44
0
        u2_mod_csbp |= 0x00CC;
45
0
    }
46
0
47
0
    if(u2_mod_csbp & 0x3300)
48
0
    {
49
0
        u2_mod_csbp |= 0x3300;
50
0
    }
51
0
52
0
    if(u2_mod_csbp & 0xCC00)
53
0
    {
54
0
        u2_mod_csbp |= 0xCC00;
55
0
    }
56
0
57
0
    return u2_mod_csbp;
58
0
}
59
60
/*****************************************************************************/
61
/*                                                                           */
62
/*  Function Name : ih264d_fill_bs2_horz_vert                                       */
63
/*                                                                           */
64
/*  Description   : This function fills boundray strength (=2) for all horz  */
65
/*                  and vert edges of current mb based on coded sub block    */
66
/*                  pattern of current, top and left mb                      */
67
/*  Inputs        :                                                          */
68
/*                  pu4_bs : Base pointer of  BS table which gets updated    */
69
/*                  u4_left_mb_csbp : left mb's coded sub block pattern      */
70
/*                  u4_top_mb_csbp : top mb's coded sub block pattern        */
71
/*                  u4_cur_mb_csbp : current mb's coded sub block pattern    */
72
/*                                                                           */
73
/*  Globals       : <Does it use any global variables?>                      */
74
/*  Processing    :                                                          */
75
/*                                                                           */
76
/*              csbp for each 4x4 block in a mb is bit packet in reverse     */
77
/*              raster scan order for each mb as shown below:                */
78
/*              15|14|13|12|11|10|9|8|7|6|5|4|3|2|1|0.                       */
79
/*                                                                           */
80
/*              BS=2 for a 4x4 edge if any of adjacent blocks forming edge   */
81
/*              are coded. Keeping this in mind, bs=2 for all horz and vert  */
82
/*              edges can be derived using  a lookup table for each edge     */
83
/*              after "ORing" the csbp values as follows:                    */
84
/*              (C means current Mb, T means top mb and L means left mb)     */
85
/*                                                                           */
86
/*              All Horz edges:                                              */
87
/*              15C|14C|13C|12C|11C|10C|9C|8C|7C|6C|5C|4C|3C |2C |1C |0C     */
88
/*  (or with)   11C|10C| 9C| 8C| 7C|6C |5C|4C|3C|2C|1C|0C|15T|14T|13T|12T    */
89
/*              -----BS[3]-----|----BS[2]----|---BS[1]---|----BS[0]-----|    */
90
/*                                                                           */
91
/*              All Vert edges:                                              */
92
/*              15C|14C|13C|12C|11C|10C|9C| 8C|7C|6C|5C|4C|3C |2C |1C |0C    */
93
/*  (or with)   14C|13C|12C|15L|10C| 9C|8C|11L|6C|5C|4C|7L|2C |1C |0C |3L    */
94
/*              Do 4x4 transpose of resulting pattern to get vertBS[4]-BS[7] */
95
/*                                                                           */
96
/*  Outputs       : <What does the function produce?>                        */
97
/*  Returns       : <What does the function return?>                         */
98
/*                                                                           */
99
/*  Issues        : <List any issues or problems with this function>         */
100
/*                                                                           */
101
/*  Revision History:                                                        */
102
/*                                                                           */
103
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
104
/*         16 10 2008   Jay             Draft                                */
105
/*                                                                           */
106
/*****************************************************************************/
107
0
#define CSBP_LEFT_BLOCK_MASK 0x1111
108
0
#define CSBP_RIGHT_BLOCK_MASK 0x8888
109
110
void ih264d_fill_bs2_horz_vert(UWORD32 *pu4_bs, /* Base pointer of BS table */
111
                               WORD32 u4_left_mb_csbp, /* csbp of left mb */
112
                               WORD32 u4_top_mb_csbp, /* csbp of top mb */
113
                               WORD32 u4_cur_mb_csbp, /* csbp of current mb */
114
                               const UWORD32 *pu4_packed_bs2, const UWORD16 *pu2_4x4_v2h_reorder)
115
0
{
116
0
    /*************************************************************************/
117
0
    /*u4_nbr_horz_csbp=11C|10C|9C|8C|7C|6C|5C|4C|3C|2C|1C|0C|15T|14T|13T|12T */
118
0
    /*************************************************************************/
119
0
    UWORD32 u4_nbr_horz_csbp = (u4_cur_mb_csbp << 4) | (u4_top_mb_csbp >> 12);
120
0
    UWORD32 u4_horz_bs2_dec = u4_cur_mb_csbp | u4_nbr_horz_csbp;
121
0
122
0
    /*************************************************************************/
123
0
    /*u4_left_mb_masked_csbp = 15L|0|0|0|11L|0|0|0|7L|0|0|0|3L|0|0|0         */
124
0
    /*************************************************************************/
125
0
    UWORD32 u4_left_mb_masked_csbp = u4_left_mb_csbp & CSBP_RIGHT_BLOCK_MASK;
126
0
127
0
    /*************************************************************************/
128
0
    /*u4_cur_mb_masked_csbp =14C|13C|12C|x|10C|9C|8C|x|6C|5C|4C|x|2C|1C|0C|x */
129
0
    /*************************************************************************/
130
0
    UWORD32 u4_cur_mb_masked_csbp = (u4_cur_mb_csbp << 1)
131
0
                    & (~CSBP_LEFT_BLOCK_MASK);
132
0
133
0
    /*************************************************************************/
134
0
    /*u4_nbr_vert_csbp=14C|13C|12C|15L|10C|9C|8C|11L|6C|5C|4C|7L|2C|1C|0C|3L */
135
0
    /*************************************************************************/
136
0
    UWORD32 u4_nbr_vert_csbp = (u4_cur_mb_masked_csbp)
137
0
                    | (u4_left_mb_masked_csbp >> 3);
138
0
139
0
    UWORD32 u4_vert_bs2_dec = u4_cur_mb_csbp | u4_nbr_vert_csbp;
140
0
141
0
    UWORD32 u4_reordered_vert_bs2_dec, u4_temp;
142
0
143
0
    PROFILE_DISABLE_BOUNDARY_STRENGTH()
144
0
145
0
    /*************************************************************************/
146
0
    /* Fill horz edges (0,1,2,3) boundary strengths 2 using look up table    */
147
0
    /*************************************************************************/
148
0
    pu4_bs[0] = pu4_packed_bs2[u4_horz_bs2_dec & 0xF];
149
0
    pu4_bs[1] = pu4_packed_bs2[(u4_horz_bs2_dec >> 4) & 0xF];
150
0
    pu4_bs[2] = pu4_packed_bs2[(u4_horz_bs2_dec >> 8) & 0xF];
151
0
    pu4_bs[3] = pu4_packed_bs2[(u4_horz_bs2_dec >> 12) & 0xF];
152
0
153
0
    /*************************************************************************/
154
0
    /* Do 4x4 tranpose of u4_vert_bs2_dec by using look up table for reorder */
155
0
    /*************************************************************************/
156
0
    u4_reordered_vert_bs2_dec = pu2_4x4_v2h_reorder[u4_vert_bs2_dec & 0xF];
157
0
    u4_temp = pu2_4x4_v2h_reorder[(u4_vert_bs2_dec >> 4) & 0xF];
158
0
    u4_reordered_vert_bs2_dec |= (u4_temp << 1);
159
0
    u4_temp = pu2_4x4_v2h_reorder[(u4_vert_bs2_dec >> 8) & 0xF];
160
0
    u4_reordered_vert_bs2_dec |= (u4_temp << 2);
161
0
    u4_temp = pu2_4x4_v2h_reorder[(u4_vert_bs2_dec >> 12) & 0xF];
162
0
    u4_reordered_vert_bs2_dec |= (u4_temp << 3);
163
0
164
0
    /*************************************************************************/
165
0
    /* Fill vert edges (4,5,6,7) boundary strengths 2 using look up table    */
166
0
    /*************************************************************************/
167
0
    pu4_bs[4] = pu4_packed_bs2[u4_reordered_vert_bs2_dec & 0xF];
168
0
    pu4_bs[5] = pu4_packed_bs2[(u4_reordered_vert_bs2_dec >> 4) & 0xF];
169
0
    pu4_bs[6] = pu4_packed_bs2[(u4_reordered_vert_bs2_dec >> 8) & 0xF];
170
0
    pu4_bs[7] = pu4_packed_bs2[(u4_reordered_vert_bs2_dec >> 12) & 0xF];
171
0
}
172
173
/*****************************************************************************/
174
/*                                                                           */
175
/*  Function Name : ih264d_fill_bs1_16x16mb_pslice                                  */
176
/*                                                                           */
177
/*  Description   : This function fills boundray strength (=1) for those     */
178
/*                  horz and vert mb edges of 16x16mb which are set to 0 by  */
179
/*                  ih264d_fill_bs2_horz_vert. This function is used for p slices   */
180
/*                                                                           */
181
/*  Inputs        : <What inputs does the function take?>                    */
182
/*  Globals       : <Does it use any global variables?>                      */
183
/*  Processing    : If any motion vector component of adjacent 4x4 blocks    */
184
/*                  differs by more than 1 integer pel or if reference       */
185
/*                  pictures are different, Bs is set to 1.                  */
186
/*                                                                           */
187
/*  Outputs       : <What does the function produce?>                        */
188
/*  Returns       : <What does the function return?>                         */
189
/*                                                                           */
190
/*  Issues        : <List any issues or problems with this function>         */
191
/*                                                                           */
192
/*  Revision History:                                                        */
193
/*                                                                           */
194
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
195
/*         16 10 2008   Jay             Draft                                */
196
/*                                                                           */
197
/*****************************************************************************/
198
void ih264d_fill_bs1_16x16mb_pslice(mv_pred_t *ps_cur_mv_pred,
199
                                    mv_pred_t *ps_top_mv_pred,
200
                                    void **ppv_map_ref_idx_to_poc,
201
                                    UWORD32 *pu4_bs_table, /* pointer to the BsTable array */
202
                                    mv_pred_t *ps_leftmost_mv_pred,
203
                                    neighbouradd_t *ps_left_addr,
204
                                    void **u4_pic_addrress, /* picture address for BS calc */
205
                                    WORD32 i4_ver_mvlimit)
206
0
{
207
0
    WORD16 i2_q_mv0, i2_q_mv1;
208
0
    WORD16 i2_p_mv0, i2_p_mv1;
209
0
    void *pv_cur_pic_addr0, *pv_cur_pic_addr1;
210
0
    void *pv_nbr_pic_addr0, *pv_nbr_pic_addr1;
211
0
    void **ppv_map_ref_idx_to_poc_l0; //,*ppv_map_ref_idx_to_poc_l1;
212
0
    UWORD32 i;
213
0
    UWORD32 u4_bs_horz = pu4_bs_table[0];
214
0
    UWORD32 u4_bs_vert = pu4_bs_table[4];
215
0
216
0
    PROFILE_DISABLE_BOUNDARY_STRENGTH()
217
0
218
0
    ppv_map_ref_idx_to_poc_l0 = ppv_map_ref_idx_to_poc;
219
0
220
0
    i2_q_mv0 = ps_cur_mv_pred->i2_mv[0];
221
0
    i2_q_mv1 = ps_cur_mv_pred->i2_mv[1];
222
0
    pv_cur_pic_addr0 = ppv_map_ref_idx_to_poc_l0[ps_cur_mv_pred->i1_ref_frame[0]];
223
0
    pv_cur_pic_addr1 = 0;
224
0
225
0
    /*********************************/
226
0
    /* Computing Bs for the top edge */
227
0
    /*********************************/
228
0
    for(i = 0; i < 4; i++, ps_top_mv_pred++)
229
0
    {
230
0
        UWORD32 u4_idx = 24 - (i << 3);
231
0
232
0
        /*********************************/
233
0
        /* check if Bs is already set    */
234
0
        /*********************************/
235
0
        if(!((u4_bs_horz >> u4_idx) & 0xf))
236
0
        {
237
0
            /************************************************************/
238
0
            /* If Bs is not set, use left edge and current edge mvs and */
239
0
            /* reference pictures addresses to evaluate Bs==1           */
240
0
            /************************************************************/
241
0
            UWORD32 u4_bs_temp1;
242
0
            UWORD32 u4_bs;
243
0
244
0
            /*********************************************************/
245
0
            /* If any motion vector component differs by more than 1 */
246
0
            /* integer pel or if reference pictures are different Bs */
247
0
            /* is set to 1. Note that this condition shall be met for*/
248
0
            /* both (fwd-fwd,bwd-bwd) and (fwd-bwd,bwd-fwd) direction*/
249
0
            /*********************************************************/
250
0
            i2_p_mv0 = ps_top_mv_pred->i2_mv[0];
251
0
            i2_p_mv1 = ps_top_mv_pred->i2_mv[1];
252
0
            pv_nbr_pic_addr0 = u4_pic_addrress[i & 2];
253
0
            pv_nbr_pic_addr1 = u4_pic_addrress[1 + (i & 2)];
254
0
255
0
            u4_bs_temp1 = ((ABS((i2_p_mv0 - i2_q_mv0)) >= 4) ||
256
0
                           (ABS((i2_p_mv1 - i2_q_mv1)) >= i4_ver_mvlimit));
257
0
258
0
            u4_bs = ((pv_cur_pic_addr0 != pv_nbr_pic_addr0)
259
0
                            || (pv_cur_pic_addr1 != pv_nbr_pic_addr1)
260
0
                            || u4_bs_temp1);
261
0
262
0
            u4_bs_horz |= (u4_bs << u4_idx);
263
0
        }
264
0
    }
265
0
    pu4_bs_table[0] = u4_bs_horz;
266
0
267
0
    /***********************************/
268
0
    /* Computing Bs for the left edge  */
269
0
    /***********************************/
270
0
    for(i = 0; i < 4; i++, ps_leftmost_mv_pred += 4)
271
0
    {
272
0
        UWORD32 u4_idx = 24 - (i << 3);
273
0
274
0
        /*********************************/
275
0
        /* check if Bs is already set    */
276
0
        /*********************************/
277
0
        if(!((u4_bs_vert >> u4_idx) & 0xf))
278
0
        {
279
0
            /****************************************************/
280
0
            /* If Bs is not set, evalaute conditions for Bs=1   */
281
0
            /****************************************************/
282
0
            UWORD32 u4_bs_temp1;
283
0
            UWORD32 u4_bs;
284
0
            /*********************************************************/
285
0
            /* If any motion vector component differs by more than 1 */
286
0
            /* integer pel or if reference pictures are different Bs */
287
0
            /* is set to 1. Note that this condition shall be met for*/
288
0
            /* both (fwd-fwd,bwd-bwd) and (fwd-bwd,bwd-fwd) direction*/
289
0
            /*********************************************************/
290
0
291
0
            i2_p_mv0 = ps_leftmost_mv_pred->i2_mv[0];
292
0
            i2_p_mv1 = ps_leftmost_mv_pred->i2_mv[1];
293
0
            pv_nbr_pic_addr0 = ps_left_addr->u4_add[i & 2];
294
0
            pv_nbr_pic_addr1 = ps_left_addr->u4_add[1 + (i & 2)];
295
0
296
0
            u4_bs_temp1 =
297
0
                            ((ABS((i2_p_mv0 - i2_q_mv0))
298
0
                                            >= 4)
299
0
                                            | (ABS((i2_p_mv1 - i2_q_mv1))
300
0
                                                            >= i4_ver_mvlimit));
301
0
302
0
            u4_bs = ((pv_cur_pic_addr0 != pv_nbr_pic_addr0)
303
0
                            || (pv_cur_pic_addr1 != pv_nbr_pic_addr1)
304
0
                            || u4_bs_temp1);
305
0
306
0
            u4_bs_vert |= (u4_bs << u4_idx);
307
0
        }
308
0
    }
309
0
    pu4_bs_table[4] = u4_bs_vert;
310
0
311
0
    return;
312
0
}
313
314
/*****************************************************************************/
315
/*                                                                           */
316
/*  Function Name : ih264d_fill_bs1_non16x16mb_pslice                               */
317
/*                                                                           */
318
/*  Description   : This function fills boundray strength (=1) for those     */
319
/*                  horz and vert edges of non16x16mb which are set to 0 by  */
320
/*                  ih264d_fill_bs2_horz_vert. This function is used for p slices   */
321
/*                                                                           */
322
/*  Inputs        : <What inputs does the function take?>                    */
323
/*  Globals       : <Does it use any global variables?>                      */
324
/*  Processing    : If any motion vector component of adjacent 4x4 blocks    */
325
/*                  differs by more than 1 integer pel or if reference       */
326
/*                  pictures are different, Bs is set to 1.                  */
327
/*                                                                           */
328
/*  Outputs       : <What does the function produce?>                        */
329
/*  Returns       : <What does the function return?>                         */
330
/*                                                                           */
331
/*  Issues        : <List any issues or problems with this function>         */
332
/*                                                                           */
333
/*  Revision History:                                                        */
334
/*                                                                           */
335
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
336
/*         16 10 2008   Jay             Draft                                */
337
/*                                                                           */
338
/*****************************************************************************/
339
void ih264d_fill_bs1_non16x16mb_pslice(mv_pred_t *ps_cur_mv_pred,
340
                                       mv_pred_t *ps_top_mv_pred,
341
                                       void **ppv_map_ref_idx_to_poc,
342
                                       UWORD32 *pu4_bs_table, /* pointer to the BsTable array */
343
                                       mv_pred_t *ps_leftmost_mv_pred,
344
                                       neighbouradd_t *ps_left_addr,
345
                                       void **u4_pic_addrress,
346
                                       WORD32 i4_ver_mvlimit)
347
0
{
348
0
    UWORD32 edge;
349
0
    void **ppv_map_ref_idx_to_poc_l0; //,*ppv_map_ref_idx_to_poc_l1;
350
0
351
0
    PROFILE_DISABLE_BOUNDARY_STRENGTH()
352
0
353
0
    ppv_map_ref_idx_to_poc_l0 = ppv_map_ref_idx_to_poc;
354
0
355
0
356
0
    for(edge = 0; edge < 4; edge++, ps_top_mv_pred = ps_cur_mv_pred - 4)
357
0
    {
358
0
        /*********************************************************************/
359
0
        /* Each iteration of this loop fills the four BS values of one HORIZ */
360
0
        /* edge and one BS value for each of the four VERT edges.            */
361
0
        /*********************************************************************/
362
0
        WORD32 i;
363
0
        UWORD32 u4_vert_idx = 24 - (edge << 3);
364
0
        UWORD32 u4_bs_horz = pu4_bs_table[edge];
365
0
        mv_pred_t *ps_left_mv_pred = ps_leftmost_mv_pred + (edge << 2);
366
0
367
0
        for(i = 0; i < 4; i++, ps_top_mv_pred++, ps_cur_mv_pred++)
368
0
        {
369
0
            WORD16 i2_cur_mv0, i2_cur_mv1;
370
0
            WORD8 i1_cur_ref0;
371
0
            void *pv_cur_pic_addr0, *pv_cur_pic_addr1 = 0;
372
0
            void *pv_nbr_pic_addr0, *pv_nbr_pic_addr1;
373
0
374
0
            /******************************************************/
375
0
            /* Each iteration of this inner loop computes a HORIZ */
376
0
            /* and a VERT BS value for a 4x4 block                */
377
0
            /******************************************************/
378
0
            UWORD32 u4_bs_vert = (pu4_bs_table[i + 4] >> u4_vert_idx) & 0xf;
379
0
            UWORD32 u4_horz_idx = 24 - (i << 3);
380
0
381
0
            /*****************************************************/
382
0
            /* check if vert Bs for this block is already set    */
383
0
            /*****************************************************/
384
0
            if(!u4_bs_vert)
385
0
            {
386
0
                WORD16 i2_left_mv0, i2_left_mv1;
387
0
                /************************************************************/
388
0
                /* If Bs is not set, use left edge and current edge mvs and */
389
0
                /* reference pictures addresses to evaluate Bs==1           */
390
0
                /************************************************************/
391
0
                i2_left_mv0 = ps_left_mv_pred->i2_mv[0];
392
0
                i2_left_mv1 = ps_left_mv_pred->i2_mv[1];
393
0
394
0
                i2_cur_mv0 = ps_cur_mv_pred->i2_mv[0];
395
0
                i2_cur_mv1 = ps_cur_mv_pred->i2_mv[1];
396
0
397
0
                i1_cur_ref0 = ps_cur_mv_pred->i1_ref_frame[0];
398
0
399
0
                pv_cur_pic_addr0 = ppv_map_ref_idx_to_poc_l0[i1_cur_ref0];
400
0
                if(i)
401
0
                {
402
0
                    WORD8 i1_left_ref0 = ps_left_mv_pred->i1_ref_frame[0];
403
0
                    pv_nbr_pic_addr0 = ppv_map_ref_idx_to_poc_l0[i1_left_ref0];
404
0
                    pv_nbr_pic_addr1 = 0;
405
0
                }
406
0
                else
407
0
                {
408
0
                    pv_nbr_pic_addr0 = ps_left_addr->u4_add[edge & 2];
409
0
                    pv_nbr_pic_addr1 = ps_left_addr->u4_add[1 + (edge & 2)];
410
0
                }
411
0
412
0
                {
413
0
                    UWORD32 u4_bs_temp1;
414
0
                    /*********************************************************/
415
0
                    /* If any motion vector component differs by more than 1 */
416
0
                    /* integer pel or if reference pictures are different Bs */
417
0
                    /* is set to 1. Note that this condition shall be met for*/
418
0
                    /* both (fwd-fwd,bwd-bwd) and (fwd-bwd,bwd-fwd) direction*/
419
0
                    /*********************************************************/
420
0
421
0
                    u4_bs_temp1 =
422
0
                                    ((ABS((i2_left_mv0 - i2_cur_mv0))
423
0
                                                    >= 4)
424
0
                                                    | (ABS((i2_left_mv1
425
0
                                                                    - i2_cur_mv1))
426
0
                                                                    >= i4_ver_mvlimit));
427
0
428
0
                    u4_bs_vert = ((pv_nbr_pic_addr0 != pv_cur_pic_addr0)
429
0
                                    || (pv_nbr_pic_addr1 != pv_cur_pic_addr1)
430
0
                                    || u4_bs_temp1);
431
0
432
0
                    pu4_bs_table[i + 4] |= (u4_bs_vert << u4_vert_idx);
433
0
                }
434
0
            }
435
0
436
0
            /*****************************************************/
437
0
            /* check if horz Bs for this block is already set    */
438
0
            /*****************************************************/
439
0
            if(!((u4_bs_horz >> u4_horz_idx) & 0xf))
440
0
            {
441
0
                WORD16 i2_top_mv0, i2_top_mv1;
442
0
                /************************************************************/
443
0
                /* If Bs is not set, use top edge and current edge mvs and  */
444
0
                /* reference pictures addresses to evaluate Bs==1           */
445
0
                /************************************************************/
446
0
                i2_cur_mv0 = ps_cur_mv_pred->i2_mv[0];
447
0
                i2_cur_mv1 = ps_cur_mv_pred->i2_mv[1];
448
0
449
0
                i1_cur_ref0 = ps_cur_mv_pred->i1_ref_frame[0];
450
0
451
0
                i2_top_mv0 = ps_top_mv_pred->i2_mv[0];
452
0
                i2_top_mv1 = ps_top_mv_pred->i2_mv[1];
453
0
454
0
                pv_cur_pic_addr0 = ppv_map_ref_idx_to_poc_l0[i1_cur_ref0];
455
0
                if(edge)
456
0
                {
457
0
                    WORD8 i1_top_ref0 = ps_top_mv_pred->i1_ref_frame[0];
458
0
                    pv_nbr_pic_addr0 = ppv_map_ref_idx_to_poc_l0[i1_top_ref0];
459
0
                    pv_nbr_pic_addr1 = 0;
460
0
                }
461
0
                else
462
0
                {
463
0
                    pv_nbr_pic_addr0 = u4_pic_addrress[i & 2];
464
0
                    pv_nbr_pic_addr1 = u4_pic_addrress[1 + (i & 2)];
465
0
                }
466
0
467
0
                {
468
0
                    UWORD32 u4_bs_temp1;
469
0
                    UWORD32 u4_bs;
470
0
                    /*********************************************************/
471
0
                    /* If any motion vector component differs by more than 1 */
472
0
                    /* integer pel or if reference pictures are different Bs */
473
0
                    /* is set to 1. Note that this condition shall be met for*/
474
0
                    /* both (fwd-fwd,bwd-bwd) and (fwd-bwd,bwd-fwd) direction*/
475
0
                    /*********************************************************/
476
0
477
0
                    u4_bs_temp1 =
478
0
                                    ((ABS((i2_top_mv0 - i2_cur_mv0))
479
0
                                                    >= 4)
480
0
                                                    | (ABS((i2_top_mv1
481
0
                                                                    - i2_cur_mv1))
482
0
                                                                    >= i4_ver_mvlimit));
483
0
484
0
                    u4_bs = ((pv_nbr_pic_addr0 != pv_cur_pic_addr0)
485
0
                                    || (pv_nbr_pic_addr1 != pv_cur_pic_addr1)
486
0
                                    || u4_bs_temp1);
487
0
488
0
                    u4_bs_horz |= (u4_bs << u4_horz_idx);
489
0
                }
490
0
            }
491
0
492
0
            ps_left_mv_pred = ps_cur_mv_pred;
493
0
        }
494
0
495
0
        pu4_bs_table[edge] = u4_bs_horz;
496
0
    }
497
0
}
498
499
/*****************************************************************************/
500
/*                                                                           */
501
/*  Function Name : ih264d_fill_bs1_16x16mb_bslice                                  */
502
/*                                                                           */
503
/*  Description   : This function fills boundray strength (=1) for those     */
504
/*                  horz and vert mb edges of 16x16mb which are set to 0 by  */
505
/*                  ih264d_fill_bs2_horz_vert. This function is used for b slices   */
506
/*                                                                           */
507
/*  Inputs        : <What inputs does the function take?>                    */
508
/*  Globals       : <Does it use any global variables?>                      */
509
/*  Processing    : If any motion vector component of adjacent 4x4 blocks    */
510
/*                  differs by more than 1 integer pel or if reference       */
511
/*                  pictures are different, Bs is set to 1.                  */
512
/*                                                                           */
513
/*  Outputs       : <What does the function produce?>                        */
514
/*  Returns       : <What does the function return?>                         */
515
/*                                                                           */
516
/*  Issues        : <List any issues or problems with this function>         */
517
/*                                                                           */
518
/*  Revision History:                                                        */
519
/*                                                                           */
520
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
521
/*         16 10 2008   Jay             Draft                                */
522
/*                                                                           */
523
/*****************************************************************************/
524
void ih264d_fill_bs1_16x16mb_bslice(mv_pred_t *ps_cur_mv_pred,
525
                                    mv_pred_t *ps_top_mv_pred,
526
                                    void **ppv_map_ref_idx_to_poc,
527
                                    UWORD32 *pu4_bs_table, /* pointer to the BsTable array */
528
                                    mv_pred_t *ps_leftmost_mv_pred,
529
                                    neighbouradd_t *ps_left_addr,
530
                                    void **u4_pic_addrress,
531
                                    WORD32 i4_ver_mvlimit)
532
0
{
533
0
    WORD16 i2_q_mv0, i2_q_mv1, i2_q_mv2, i2_q_mv3;
534
0
    WORD16 i2_p_mv0, i2_p_mv1, i2_p_mv2, i2_p_mv3;
535
0
    void *pv_cur_pic_addr0, *pv_cur_pic_addr1;
536
0
    void *pv_nbr_pic_addr0, *pv_nbr_pic_addr1;
537
0
    void **ppv_map_ref_idx_to_poc_l0, **ppv_map_ref_idx_to_poc_l1;
538
0
    UWORD32 i;
539
0
    UWORD32 u4_bs_horz = pu4_bs_table[0];
540
0
    UWORD32 u4_bs_vert = pu4_bs_table[4];
541
0
542
0
    PROFILE_DISABLE_BOUNDARY_STRENGTH()
543
0
544
0
    ppv_map_ref_idx_to_poc_l0 = ppv_map_ref_idx_to_poc;
545
0
    ppv_map_ref_idx_to_poc_l1 = ppv_map_ref_idx_to_poc + POC_LIST_L0_TO_L1_DIFF;
546
0
    i2_q_mv0 = ps_cur_mv_pred->i2_mv[0];
547
0
    i2_q_mv1 = ps_cur_mv_pred->i2_mv[1];
548
0
    i2_q_mv2 = ps_cur_mv_pred->i2_mv[2];
549
0
    i2_q_mv3 = ps_cur_mv_pred->i2_mv[3];
550
0
    pv_cur_pic_addr0 = ppv_map_ref_idx_to_poc_l0[ps_cur_mv_pred->i1_ref_frame[0]];
551
0
    pv_cur_pic_addr1 = ppv_map_ref_idx_to_poc_l1[ps_cur_mv_pred->i1_ref_frame[1]];
552
0
553
0
    /*********************************/
554
0
    /* Computing Bs for the top edge */
555
0
    /*********************************/
556
0
    for(i = 0; i < 4; i++, ps_top_mv_pred++)
557
0
    {
558
0
        UWORD32 u4_idx = 24 - (i << 3);
559
0
560
0
        /*********************************/
561
0
        /* check if Bs is already set    */
562
0
        /*********************************/
563
0
        if(!((u4_bs_horz >> u4_idx) & 0xf))
564
0
        {
565
0
            /************************************************************/
566
0
            /* If Bs is not set, use left edge and current edge mvs and */
567
0
            /* reference pictures addresses to evaluate Bs==1           */
568
0
            /************************************************************/
569
0
            UWORD32 u4_bs_temp1, u4_bs_temp2;
570
0
            UWORD32 u4_bs;
571
0
572
0
            /*********************************************************/
573
0
            /* If any motion vector component differs by more than 1 */
574
0
            /* integer pel or if reference pictures are different Bs */
575
0
            /* is set to 1. Note that this condition shall be met for*/
576
0
            /* both (fwd-fwd,bwd-bwd) and (fwd-bwd,bwd-fwd) direction*/
577
0
            /*********************************************************/
578
0
            i2_p_mv0 = ps_top_mv_pred->i2_mv[0];
579
0
            i2_p_mv1 = ps_top_mv_pred->i2_mv[1];
580
0
            i2_p_mv2 = ps_top_mv_pred->i2_mv[2];
581
0
            i2_p_mv3 = ps_top_mv_pred->i2_mv[3];
582
0
            pv_nbr_pic_addr0 = u4_pic_addrress[i & 2];
583
0
            pv_nbr_pic_addr1 = u4_pic_addrress[1 + (i & 2)];
584
0
585
0
            u4_bs_temp1 =
586
0
                            ((ABS((i2_p_mv0 - i2_q_mv0))
587
0
                                            >= 4)
588
0
                                            | (ABS((i2_p_mv1 - i2_q_mv1))
589
0
                                                            >= i4_ver_mvlimit)
590
0
                                            | (ABS((i2_p_mv2 - i2_q_mv2))
591
0
                                                            >= 4)
592
0
                                            | (ABS((i2_p_mv3 - i2_q_mv3))
593
0
                                                            >= i4_ver_mvlimit));
594
0
595
0
            u4_bs_temp2 =
596
0
                            ((ABS((i2_p_mv0 - i2_q_mv2))
597
0
                                            >= 4)
598
0
                                            | (ABS((i2_p_mv1 - i2_q_mv3))
599
0
                                                            >= i4_ver_mvlimit)
600
0
                                            | (ABS((i2_p_mv2 - i2_q_mv0))
601
0
                                                            >= 4)
602
0
                                            | (ABS((i2_p_mv3 - i2_q_mv1))
603
0
                                                            >= i4_ver_mvlimit));
604
0
605
0
            u4_bs = ((pv_cur_pic_addr0 != pv_nbr_pic_addr0)
606
0
                            || (pv_cur_pic_addr1 != pv_nbr_pic_addr1)
607
0
                            || u4_bs_temp1)
608
0
                            && ((pv_cur_pic_addr0 != pv_nbr_pic_addr1)
609
0
                                            || (pv_cur_pic_addr1
610
0
                                                            != pv_nbr_pic_addr0)
611
0
                                            || u4_bs_temp2);
612
0
613
0
            u4_bs_horz |= (u4_bs << u4_idx);
614
0
        }
615
0
    }
616
0
    pu4_bs_table[0] = u4_bs_horz;
617
0
618
0
    /***********************************/
619
0
    /* Computing Bs for the left edge  */
620
0
    /***********************************/
621
0
    for(i = 0; i < 4; i++, ps_leftmost_mv_pred += 4)
622
0
    {
623
0
        UWORD32 u4_idx = 24 - (i << 3);
624
0
625
0
        /*********************************/
626
0
        /* check if Bs is already set    */
627
0
        /*********************************/
628
0
        if(!((u4_bs_vert >> u4_idx) & 0xf))
629
0
        {
630
0
            /****************************************************/
631
0
            /* If Bs is not set, evalaute conditions for Bs=1   */
632
0
            /****************************************************/
633
0
            UWORD32 u4_bs_temp1, u4_bs_temp2;
634
0
            UWORD32 u4_bs;
635
0
            /*********************************************************/
636
0
            /* If any motion vector component differs by more than 1 */
637
0
            /* integer pel or if reference pictures are different Bs */
638
0
            /* is set to 1. Note that this condition shall be met for*/
639
0
            /* both (fwd-fwd,bwd-bwd) and (fwd-bwd,bwd-fwd) direction*/
640
0
            /*********************************************************/
641
0
642
0
            i2_p_mv0 = ps_leftmost_mv_pred->i2_mv[0];
643
0
            i2_p_mv1 = ps_leftmost_mv_pred->i2_mv[1];
644
0
            i2_p_mv2 = ps_leftmost_mv_pred->i2_mv[2];
645
0
            i2_p_mv3 = ps_leftmost_mv_pred->i2_mv[3];
646
0
            pv_nbr_pic_addr0 = ps_left_addr->u4_add[i & 2];
647
0
            pv_nbr_pic_addr1 = ps_left_addr->u4_add[1 + (i & 2)];
648
0
649
0
            u4_bs_temp1 =
650
0
                            ((ABS((i2_p_mv0 - i2_q_mv0))
651
0
                                            >= 4)
652
0
                                            | (ABS((i2_p_mv1 - i2_q_mv1))
653
0
                                                            >= i4_ver_mvlimit)
654
0
                                            | (ABS((i2_p_mv2 - i2_q_mv2))
655
0
                                                            >= 4)
656
0
                                            | (ABS((i2_p_mv3 - i2_q_mv3))
657
0
                                                            >= i4_ver_mvlimit));
658
0
659
0
            u4_bs_temp2 =
660
0
                            ((ABS((i2_p_mv0 - i2_q_mv2))
661
0
                                            >= 4)
662
0
                                            | (ABS((i2_p_mv1 - i2_q_mv3))
663
0
                                                            >= i4_ver_mvlimit)
664
0
                                            | (ABS((i2_p_mv2 - i2_q_mv0))
665
0
                                                            >= 4)
666
0
                                            | (ABS((i2_p_mv3 - i2_q_mv1))
667
0
                                                            >= i4_ver_mvlimit));
668
0
669
0
            u4_bs = ((pv_cur_pic_addr0 != pv_nbr_pic_addr0)
670
0
                            || (pv_cur_pic_addr1 != pv_nbr_pic_addr1)
671
0
                            || u4_bs_temp1)
672
0
                            && ((pv_cur_pic_addr0 != pv_nbr_pic_addr1)
673
0
                                            || (pv_cur_pic_addr1
674
0
                                                            != pv_nbr_pic_addr0)
675
0
                                            || u4_bs_temp2);
676
0
677
0
            u4_bs_vert |= (u4_bs << u4_idx);
678
0
        }
679
0
    }
680
0
    pu4_bs_table[4] = u4_bs_vert;
681
0
682
0
    return;
683
0
}
684
685
/*****************************************************************************/
686
/*                                                                           */
687
/*  Function Name : ih264d_fill_bs1_non16x16mb_bslice                               */
688
/*                                                                           */
689
/*  Description   : This function fills boundray strength (=1) for those     */
690
/*                  horz and vert edges of non16x16mb which are set to 0 by  */
691
/*                  ih264d_fill_bs2_horz_vert. This function is used for b slices   */
692
/*                                                                           */
693
/*  Inputs        : <What inputs does the function take?>                    */
694
/*  Globals       : <Does it use any global variables?>                      */
695
/*  Processing    : If any motion vector component of adjacent 4x4 blocks    */
696
/*                  differs by more than 1 integer pel or if reference       */
697
/*                  pictures are different, Bs is set to 1.                  */
698
/*                                                                           */
699
/*  Outputs       : <What does the function produce?>                        */
700
/*  Returns       : <What does the function return?>                         */
701
/*                                                                           */
702
/*  Issues        : <List any issues or problems with this function>         */
703
/*                                                                           */
704
/*  Revision History:                                                        */
705
/*                                                                           */
706
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
707
/*         16 10 2008   Jay             Draft                                */
708
/*                                                                           */
709
/*****************************************************************************/
710
void ih264d_fill_bs1_non16x16mb_bslice(mv_pred_t *ps_cur_mv_pred,
711
                                       mv_pred_t *ps_top_mv_pred,
712
                                       void **ppv_map_ref_idx_to_poc,
713
                                       UWORD32 *pu4_bs_table, /* pointer to the BsTable array */
714
                                       mv_pred_t *ps_leftmost_mv_pred,
715
                                       neighbouradd_t *ps_left_addr,
716
                                       void **u4_pic_addrress,
717
                                       WORD32 i4_ver_mvlimit)
718
0
{
719
0
    UWORD32 edge;
720
0
    void **ppv_map_ref_idx_to_poc_l0, **ppv_map_ref_idx_to_poc_l1;
721
0
    ppv_map_ref_idx_to_poc_l0 = ppv_map_ref_idx_to_poc;
722
0
    ppv_map_ref_idx_to_poc_l1 = ppv_map_ref_idx_to_poc + POC_LIST_L0_TO_L1_DIFF;
723
0
724
0
    PROFILE_DISABLE_BOUNDARY_STRENGTH()
725
0
726
0
    for(edge = 0; edge < 4; edge++, ps_top_mv_pred = ps_cur_mv_pred - 4)
727
0
    {
728
0
        /*********************************************************************/
729
0
        /* Each iteration of this loop fills the four BS values of one HORIZ */
730
0
        /* edge and one BS value for each of the four VERT edges.            */
731
0
        /*********************************************************************/
732
0
        WORD32 i;
733
0
        UWORD32 u4_vert_idx = 24 - (edge << 3);
734
0
        UWORD32 u4_bs_horz = pu4_bs_table[edge];
735
0
        mv_pred_t *ps_left_mv_pred = ps_leftmost_mv_pred + (edge << 2);
736
0
737
0
        for(i = 0; i < 4; i++, ps_top_mv_pred++, ps_cur_mv_pred++)
738
0
        {
739
0
            WORD16 i2_cur_mv0, i2_cur_mv1, i16_curMv2, i16_curMv3;
740
0
            WORD8 i1_cur_ref0, i1_cur_ref1;
741
0
            void *pv_cur_pic_addr0, *pv_cur_pic_addr1;
742
0
            void *pv_nbr_pic_addr0, *pv_nbr_pic_addr1;
743
0
744
0
            /******************************************************/
745
0
            /* Each iteration of this inner loop computes a HORIZ */
746
0
            /* and a VERT BS value for a 4x4 block                */
747
0
            /******************************************************/
748
0
            UWORD32 u4_bs_vert = (pu4_bs_table[i + 4] >> u4_vert_idx) & 0xf;
749
0
            UWORD32 u4_horz_idx = 24 - (i << 3);
750
0
751
0
            /*****************************************************/
752
0
            /* check if vert Bs for this block is already set    */
753
0
            /*****************************************************/
754
0
            if(!u4_bs_vert)
755
0
            {
756
0
                WORD16 i2_left_mv0, i2_left_mv1, i2_left_mv2, i2_left_mv3;
757
0
                /************************************************************/
758
0
                /* If Bs is not set, use left edge and current edge mvs and */
759
0
                /* reference pictures addresses to evaluate Bs==1           */
760
0
                /************************************************************/
761
0
                i2_left_mv0 = ps_left_mv_pred->i2_mv[0];
762
0
                i2_left_mv1 = ps_left_mv_pred->i2_mv[1];
763
0
                i2_left_mv2 = ps_left_mv_pred->i2_mv[2];
764
0
                i2_left_mv3 = ps_left_mv_pred->i2_mv[3];
765
0
766
0
                i2_cur_mv0 = ps_cur_mv_pred->i2_mv[0];
767
0
                i2_cur_mv1 = ps_cur_mv_pred->i2_mv[1];
768
0
                i16_curMv2 = ps_cur_mv_pred->i2_mv[2];
769
0
                i16_curMv3 = ps_cur_mv_pred->i2_mv[3];
770
0
                i1_cur_ref0 = ps_cur_mv_pred->i1_ref_frame[0];
771
0
                i1_cur_ref1 = ps_cur_mv_pred->i1_ref_frame[1];
772
0
                pv_cur_pic_addr0 = ppv_map_ref_idx_to_poc_l0[i1_cur_ref0];
773
0
                pv_cur_pic_addr1 = ppv_map_ref_idx_to_poc_l1[i1_cur_ref1];
774
0
775
0
                if(i)
776
0
                {
777
0
                    WORD8 i1_left_ref0, i1_left_ref1;
778
0
                    i1_left_ref0 = ps_left_mv_pred->i1_ref_frame[0];
779
0
                    i1_left_ref1 = ps_left_mv_pred->i1_ref_frame[1];
780
0
                    pv_nbr_pic_addr0 = ppv_map_ref_idx_to_poc_l0[i1_left_ref0];
781
0
                    pv_nbr_pic_addr1 = ppv_map_ref_idx_to_poc_l1[i1_left_ref1];
782
0
                }
783
0
                else
784
0
                {
785
0
                    pv_nbr_pic_addr0 = ps_left_addr->u4_add[edge & 2];
786
0
                    pv_nbr_pic_addr1 = ps_left_addr->u4_add[1 + (edge & 2)];
787
0
                }
788
0
789
0
                {
790
0
                    UWORD32 u4_bs_temp1, u4_bs_temp2;
791
0
                    /*********************************************************/
792
0
                    /* If any motion vector component differs by more than 1 */
793
0
                    /* integer pel or if reference pictures are different Bs */
794
0
                    /* is set to 1. Note that this condition shall be met for*/
795
0
                    /* both (fwd-fwd,bwd-bwd) and (fwd-bwd,bwd-fwd) direction*/
796
0
                    /*********************************************************/
797
0
798
0
                    u4_bs_temp1 =
799
0
                                    ((ABS((i2_left_mv0 - i2_cur_mv0))
800
0
                                                    >= 4)
801
0
                                                    | (ABS((i2_left_mv1
802
0
                                                                    - i2_cur_mv1))
803
0
                                                                    >= i4_ver_mvlimit)
804
0
                                                    | (ABS((i2_left_mv2
805
0
                                                                    - i16_curMv2))
806
0
                                                                    >= 4)
807
0
                                                    | (ABS((i2_left_mv3
808
0
                                                                    - i16_curMv3))
809
0
                                                                    >= i4_ver_mvlimit));
810
0
811
0
                    u4_bs_temp2 =
812
0
                                    ((ABS((i2_left_mv0 - i16_curMv2))
813
0
                                                    >= 4)
814
0
                                                    | (ABS((i2_left_mv1
815
0
                                                                    - i16_curMv3))
816
0
                                                                    >= i4_ver_mvlimit)
817
0
                                                    | (ABS((i2_left_mv2
818
0
                                                                    - i2_cur_mv0))
819
0
                                                                    >= 4)
820
0
                                                    | (ABS((i2_left_mv3
821
0
                                                                    - i2_cur_mv1))
822
0
                                                                    >= i4_ver_mvlimit));
823
0
824
0
                    u4_bs_vert =
825
0
                                    ((pv_nbr_pic_addr0 != pv_cur_pic_addr0)
826
0
                                                    || (pv_nbr_pic_addr1
827
0
                                                                    != pv_cur_pic_addr1)
828
0
                                                    || u4_bs_temp1)
829
0
                                                    && ((pv_nbr_pic_addr0
830
0
                                                                    != pv_cur_pic_addr1)
831
0
                                                                    || (pv_nbr_pic_addr1
832
0
                                                                                    != pv_cur_pic_addr0)
833
0
                                                                    || u4_bs_temp2);
834
0
835
0
                    pu4_bs_table[i + 4] |= (u4_bs_vert << u4_vert_idx);
836
0
                }
837
0
            }
838
0
839
0
            /*****************************************************/
840
0
            /* check if horz Bs for this block is already set    */
841
0
            /*****************************************************/
842
0
            if(!((u4_bs_horz >> u4_horz_idx) & 0xf))
843
0
            {
844
0
                WORD16 i2_top_mv0, i2_top_mv1, i16_topMv2, i16_topMv3;
845
0
                /************************************************************/
846
0
                /* If Bs is not set, use top edge and current edge mvs and  */
847
0
                /* reference pictures addresses to evaluate Bs==1           */
848
0
                /************************************************************/
849
0
                i2_cur_mv0 = ps_cur_mv_pred->i2_mv[0];
850
0
                i2_cur_mv1 = ps_cur_mv_pred->i2_mv[1];
851
0
                i16_curMv2 = ps_cur_mv_pred->i2_mv[2];
852
0
                i16_curMv3 = ps_cur_mv_pred->i2_mv[3];
853
0
                i1_cur_ref0 = ps_cur_mv_pred->i1_ref_frame[0];
854
0
                i1_cur_ref1 = ps_cur_mv_pred->i1_ref_frame[1];
855
0
856
0
                i2_top_mv0 = ps_top_mv_pred->i2_mv[0];
857
0
                i2_top_mv1 = ps_top_mv_pred->i2_mv[1];
858
0
                i16_topMv2 = ps_top_mv_pred->i2_mv[2];
859
0
                i16_topMv3 = ps_top_mv_pred->i2_mv[3];
860
0
                pv_cur_pic_addr0 = ppv_map_ref_idx_to_poc_l0[i1_cur_ref0];
861
0
                pv_cur_pic_addr1 = ppv_map_ref_idx_to_poc_l1[i1_cur_ref1];
862
0
                if(edge)
863
0
                {
864
0
                    WORD8 i1_top_ref0, i1_top_ref1;
865
0
                    i1_top_ref0 = ps_top_mv_pred->i1_ref_frame[0];
866
0
                    i1_top_ref1 = ps_top_mv_pred->i1_ref_frame[1];
867
0
                    pv_nbr_pic_addr0 = ppv_map_ref_idx_to_poc_l0[i1_top_ref0];
868
0
                    pv_nbr_pic_addr1 = ppv_map_ref_idx_to_poc_l1[i1_top_ref1];
869
0
                }
870
0
                else
871
0
                {
872
0
                    pv_nbr_pic_addr0 = u4_pic_addrress[i & 2];
873
0
                    pv_nbr_pic_addr1 = u4_pic_addrress[1 + (i & 2)];
874
0
                }
875
0
876
0
                {
877
0
                    UWORD32 u4_bs_temp1, u4_bs_temp2;
878
0
                    UWORD32 u4_bs;
879
0
                    /*********************************************************/
880
0
                    /* If any motion vector component differs by more than 1 */
881
0
                    /* integer pel or if reference pictures are different Bs */
882
0
                    /* is set to 1. Note that this condition shall be met for*/
883
0
                    /* both (fwd-fwd,bwd-bwd) and (fwd-bwd,bwd-fwd) direction*/
884
0
                    /*********************************************************/
885
0
886
0
                    u4_bs_temp1 =
887
0
                                    ((ABS((i2_top_mv0 - i2_cur_mv0))
888
0
                                                    >= 4)
889
0
                                                    | (ABS((i2_top_mv1
890
0
                                                                    - i2_cur_mv1))
891
0
                                                                    >= i4_ver_mvlimit)
892
0
                                                    | (ABS((i16_topMv2
893
0
                                                                    - i16_curMv2))
894
0
                                                                    >= 4)
895
0
                                                    | (ABS((i16_topMv3
896
0
                                                                    - i16_curMv3))
897
0
                                                                    >= i4_ver_mvlimit));
898
0
899
0
                    u4_bs_temp2 =
900
0
                                    ((ABS((i2_top_mv0 - i16_curMv2))
901
0
                                                    >= 4)
902
0
                                                    | (ABS((i2_top_mv1
903
0
                                                                    - i16_curMv3))
904
0
                                                                    >= i4_ver_mvlimit)
905
0
                                                    | (ABS((i16_topMv2
906
0
                                                                    - i2_cur_mv0))
907
0
                                                                    >= 4)
908
0
                                                    | (ABS((i16_topMv3
909
0
                                                                    - i2_cur_mv1))
910
0
                                                                    >= i4_ver_mvlimit));
911
0
912
0
                    u4_bs =
913
0
                                    ((pv_nbr_pic_addr0 != pv_cur_pic_addr0)
914
0
                                                    || (pv_nbr_pic_addr1
915
0
                                                                    != pv_cur_pic_addr1)
916
0
                                                    || u4_bs_temp1)
917
0
                                                    && ((pv_nbr_pic_addr0
918
0
                                                                    != pv_cur_pic_addr1)
919
0
                                                                    || (pv_nbr_pic_addr1
920
0
                                                                                    != pv_cur_pic_addr0)
921
0
                                                                    || u4_bs_temp2);
922
0
923
0
                    u4_bs_horz |= (u4_bs << u4_horz_idx);
924
0
                }
925
0
            }
926
0
927
0
            ps_left_mv_pred = ps_cur_mv_pred;
928
0
        }
929
0
930
0
        pu4_bs_table[edge] = u4_bs_horz;
931
0
    }
932
0
}
933
934
/*****************************************************************************/
935
/*                                                                           */
936
/*  Function Name : ih264d_fill_bs_xtra_left_edge_cur_fld                           */
937
/*                                                                           */
938
/*  Description   : This function fills boundray strength (= 2 or 1) for     */
939
/*                  xtra left mb edge when cur mb is field and left mb is    */
940
/*                  frame.                                                   */
941
/*  Inputs        :                                                          */
942
/*                                                                           */
943
/*  Globals       : <Does it use any global variables?>                      */
944
/*  Processing    :                                                          */
945
/*                                                                           */
946
/*                                                                           */
947
/*  Outputs       : <What does the function produce?>                        */
948
/*  Returns       : <What does the function return?>                         */
949
/*                                                                           */
950
/*  Issues        : <List any issues or problems with this function>         */
951
/*                                                                           */
952
/*  Revision History:                                                        */
953
/*                                                                           */
954
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
955
/*         16 10 2008   Jay             Draft                                */
956
/*                                                                           */
957
/*****************************************************************************/
958
void ih264d_fill_bs_xtra_left_edge_cur_fld(UWORD32 *pu4_bs, /* Base pointer of BS table */
959
                                           WORD32 u4_left_mb_t_csbp, /* left mbpair's top csbp   */
960
                                           WORD32 u4_left_mb_b_csbp, /* left mbpair's bottom csbp*/
961
                                           WORD32 u4_cur_mb_csbp, /* csbp of current mb */
962
                                           UWORD32 u4_cur_mb_top /* is top or bottom mb */
963
964
                                           )
965
0
{
966
0
    const UWORD32 *pu4_packed_bs = (const UWORD32 *)gau4_ih264d_packed_bs2;
967
0
    UWORD32 u4_cur, u4_left, u4_or;
968
0
    UNUSED(u4_cur_mb_top);
969
0
970
0
    PROFILE_DISABLE_BOUNDARY_STRENGTH()
971
0
972
0
    u4_left_mb_t_csbp = ((u4_left_mb_t_csbp & 0x0008) >> 3)
973
0
                    + ((u4_left_mb_t_csbp & 0x0080) >> 6)
974
0
                    + ((u4_left_mb_t_csbp & 0x0800) >> 9)
975
0
                    + ((u4_left_mb_t_csbp & 0x8000) >> 12);
976
0
977
0
    u4_left_mb_b_csbp = ((u4_left_mb_b_csbp & 0x0008) << 1)
978
0
                    + ((u4_left_mb_b_csbp & 0x0080) >> 2)
979
0
                    + ((u4_left_mb_b_csbp & 0x0800) >> 5)
980
0
                    + ((u4_left_mb_b_csbp & 0x8000) >> 8);
981
0
982
0
    /*********************************************************************/
983
0
    /* u4_cur = 0|0|0|0|0|0|0|0|12C|12C|8C|8C|4C|4C|0C|0C                */
984
0
    /*********************************************************************/
985
0
    u4_cur = (u4_cur_mb_csbp & 0x0001) + ((u4_cur_mb_csbp & 0x0001) << 1)
986
0
                    + ((u4_cur_mb_csbp & 0x0010) >> 2)
987
0
                    + ((u4_cur_mb_csbp & 0x0010) >> 1)
988
0
                    + ((u4_cur_mb_csbp & 0x0100) >> 4)
989
0
                    + ((u4_cur_mb_csbp & 0x0100) >> 3)
990
0
                    + ((u4_cur_mb_csbp & 0x1000) >> 6)
991
0
                    + ((u4_cur_mb_csbp & 0x1000) >> 5);
992
0
993
0
    /*********************************************************************/
994
0
    /* u4_left =0|0|0|0|0|0|0|0|15Lb|11Lb|7Lb|3Lb|15Lt|11Lt|7Lt|3Lt      */
995
0
    /*********************************************************************/
996
0
    u4_left = u4_left_mb_t_csbp + u4_left_mb_b_csbp;
997
0
998
0
    u4_or = (u4_cur | u4_left);
999
0
    /*********************************************************************/
1000
0
    /* Fill vert edges (4,9) boundary strengths  using look up table     */
1001
0
    /*********************************************************************/
1002
0
    pu4_packed_bs += 16;
1003
0
    pu4_bs[4] = pu4_packed_bs[u4_or & 0xF];
1004
0
    pu4_bs[9] = pu4_packed_bs[(u4_or >> 4)];
1005
0
}
1006
1007
/*****************************************************************************/
1008
/*                                                                           */
1009
/*  Function Name : ih264d_fill_bs_xtra_left_edge_cur_frm                           */
1010
/*                                                                           */
1011
/*  Description   : This function fills boundray strength (= 2 or 1) for     */
1012
/*                  xtra left mb edge when cur mb is frame and left mb is    */
1013
/*                  field.                                                   */
1014
/*  Inputs        :                                                          */
1015
/*                                                                           */
1016
/*  Globals       : <Does it use any global variables?>                      */
1017
/*  Processing    :                                                          */
1018
/*                                                                           */
1019
/*                                                                           */
1020
/*  Outputs       : <What does the function produce?>                        */
1021
/*  Returns       : <What does the function return?>                         */
1022
/*                                                                           */
1023
/*  Issues        : <List any issues or problems with this function>         */
1024
/*                                                                           */
1025
/*  Revision History:                                                        */
1026
/*                                                                           */
1027
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1028
/*         16 10 2008   Jay             Draft                                */
1029
/*                                                                           */
1030
/*****************************************************************************/
1031
void ih264d_fill_bs_xtra_left_edge_cur_frm(UWORD32 *pu4_bs, /* Base pointer of BS table */
1032
                                           WORD32 u4_left_mb_t_csbp, /* left mbpair's top csbp   */
1033
                                           WORD32 u4_left_mb_b_csbp, /* left mbpair's bottom csbp*/
1034
                                           WORD32 u4_cur_mb_csbp, /* csbp of current mb */
1035
                                           UWORD32 u4_cur_mb_bot /* is top or bottom mb */
1036
1037
                                           )
1038
0
{
1039
0
    const UWORD32 *pu4_packed_bs = (const UWORD32 *)gau4_ih264d_packed_bs2;
1040
0
    UWORD32 u4_cur, u4_left, u4_or;
1041
0
    UWORD32 u4_right_shift = (u4_cur_mb_bot << 3);
1042
0
1043
0
    PROFILE_DISABLE_BOUNDARY_STRENGTH()
1044
0
1045
0
    u4_left_mb_t_csbp >>= u4_right_shift;
1046
0
    u4_left_mb_b_csbp >>= u4_right_shift;
1047
0
1048
0
    u4_left_mb_t_csbp = ((u4_left_mb_t_csbp & 0x08) >> 3)
1049
0
                    + ((u4_left_mb_t_csbp & 0x08) >> 2)
1050
0
                    + ((u4_left_mb_t_csbp & 0x80) >> 5)
1051
0
                    + ((u4_left_mb_t_csbp & 0x80) >> 4);
1052
0
1053
0
    u4_left_mb_b_csbp = ((u4_left_mb_b_csbp & 0x08) << 1)
1054
0
                    + ((u4_left_mb_b_csbp & 0x08) << 2)
1055
0
                    + ((u4_left_mb_b_csbp & 0x80) >> 1)
1056
0
                    + ((u4_left_mb_b_csbp & 0x80));
1057
0
1058
0
    u4_cur = ((u4_cur_mb_csbp & 0x0001)) + ((u4_cur_mb_csbp & 0x0010) >> 3)
1059
0
                    + ((u4_cur_mb_csbp & 0x0100) >> 6)
1060
0
                    + ((u4_cur_mb_csbp & 0x1000) >> 9);
1061
0
1062
0
    u4_cur += (u4_cur << 4);
1063
0
1064
0
    u4_left = u4_left_mb_t_csbp + u4_left_mb_b_csbp;
1065
0
1066
0
    u4_or = (u4_cur | u4_left);
1067
0
    /*********************************************************************/
1068
0
    /* Fill vert edges (4,9) boundary strengths  using look up table     */
1069
0
    /*********************************************************************/
1070
0
    pu4_packed_bs += 16;
1071
0
    pu4_bs[4] = pu4_packed_bs[u4_or & 0xF];
1072
0
    pu4_bs[9] = pu4_packed_bs[(u4_or >> 4)];
1073
0
}
1074
1075
/*****************************************************************************/
1076
/*                                                                           */
1077
/*  Function Name : ih264d_fill_bs_xtra_top_edge                                    */
1078
/*                                                                           */
1079
/*  Description   : This function fills boundray strength (= 2 or 1) for     */
1080
/*                  xtra top mb edge when cur mb is top mb of frame mb pair  */
1081
/*                  and top mbpair is field coded.                           */
1082
/*  Inputs        :                                                          */
1083
/*                                                                           */
1084
/*  Globals       : <Does it use any global variables?>                      */
1085
/*  Processing    :                                                          */
1086
/*                                                                           */
1087
/*                                                                           */
1088
/*  Outputs       : <What does the function produce?>                        */
1089
/*  Returns       : <What does the function return?>                         */
1090
/*                                                                           */
1091
/*  Issues        : <List any issues or problems with this function>         */
1092
/*                                                                           */
1093
/*  Revision History:                                                        */
1094
/*                                                                           */
1095
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1096
/*         16 10 2008   Jay             Draft                                */
1097
/*                                                                           */
1098
/*****************************************************************************/
1099
void ih264d_fill_bs_xtra_top_edge(UWORD32 *pu4_bs, /* Base pointer of BS table */
1100
                                  WORD32 u4_topmb_t_csbp, /* top mbpair's top csbp   */
1101
                                  WORD32 u4_topmb_b_csbp, /* top mbpair's bottom csbp*/
1102
                                  WORD32 u4_cur_mb_csbp /* csbp of current mb */
1103
1104
                                  )
1105
0
{
1106
0
    const UWORD32 *pu4_packed_bs = (const UWORD32 *)gau4_ih264d_packed_bs2;
1107
0
    UWORD32 u4_or;
1108
0
1109
0
    u4_cur_mb_csbp &= 0xf;
1110
0
    u4_topmb_t_csbp >>= 12;
1111
0
    u4_topmb_b_csbp >>= 12;
1112
0
1113
0
    u4_or = (u4_cur_mb_csbp | u4_topmb_t_csbp);
1114
0
    /*********************************************************************/
1115
0
    /* Fill vert edges (0,8) boundary strengths  using look up table     */
1116
0
    /*********************************************************************/
1117
0
    pu4_packed_bs += 16;
1118
0
    pu4_bs[8] = pu4_packed_bs[u4_or];
1119
0
1120
0
    u4_or = (u4_cur_mb_csbp | u4_topmb_b_csbp);
1121
0
    pu4_bs[0] = pu4_packed_bs[u4_or];
1122
0
}
1123
1124
/*****************************************************************************/
1125
/*                                                                           */
1126
/*  Function Name : ih264d_compute_bs_non_mbaff                                        */
1127
/*                                                                           */
1128
/*  Description   : This function computes the pointers of left,top & current*/
1129
/*                : Nnz, MvPred & deblk_mb_t and supplies to FillBs function for*/
1130
/*                : Boundary Strength Calculation                            */
1131
/*  Inputs        : <What inputs does the function take?>                    */
1132
/*  Processing    : This functions calls deblock MB in the MB increment order*/
1133
/*                                                                           */
1134
/*  Outputs       : Produces the Boundary Strength for Current Mb            */
1135
/*  Returns       : None                                                     */
1136
/*                                                                           */
1137
/*  Revision History:                                                        */
1138
/*                                                                           */
1139
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1140
/*                      ITTIAM                                               */
1141
/*****************************************************************************/
1142
1143
void ih264d_compute_bs_non_mbaff(dec_struct_t * ps_dec,
1144
                                 dec_mb_info_t * ps_cur_mb_info,
1145
                                 const UWORD16 u2_mbxn_mb)
1146
0
{
1147
0
    /* Mvpred and Nnz for top and Courrent */
1148
0
    mv_pred_t *ps_cur_mv_pred, *ps_top_mv_pred = NULL, *ps_left_mv_pred;
1149
0
    /* deblk_mb_t Params */
1150
0
    deblk_mb_t *ps_cur_mb_params; /*< Parameters of current MacroBlock */
1151
0
    deblkmb_neighbour_t *ps_deblk_top_mb;
1152
0
1153
0
    /* Reference Index to POC mapping*/
1154
0
    void ** apv_map_ref_idx_to_poc;
1155
0
    UWORD32 u4_leftmbtype;
1156
0
1157
0
    UWORD16 u2_left_csbp, u2_top_csbp, u2_cur_csbp;
1158
0
1159
0
    /* Set of flags */
1160
0
    UWORD32 u4_cur_mb_intra, u1_top_mb_typ, u4_cur_mb_fld;
1161
0
    UWORD32 u1_cur_mb_type;
1162
0
    UWORD32 * pu4_bs_table;
1163
0
1164
0
    /* Neighbour availability */
1165
0
    /* Initialization */
1166
0
    const UWORD32 u2_mbx = ps_cur_mb_info->u2_mbx;
1167
0
    const UWORD32 u2_mby = ps_cur_mb_info->u2_mby;
1168
0
    const UWORD32 u1_pingpong = u2_mbx & 0x01;
1169
0
1170
0
    PROFILE_DISABLE_BOUNDARY_STRENGTH()
1171
0
1172
0
    ps_deblk_top_mb = ps_dec->ps_deblk_top_mb + u2_mbx;
1173
0
1174
0
1175
0
    /* Pointer assignment for Current DeblkMB, Current Mv Pred  */
1176
0
    ps_cur_mb_params = ps_dec->ps_deblk_mbn + u2_mbxn_mb;
1177
0
    ps_cur_mv_pred = ps_dec->ps_mv_cur + (u2_mbxn_mb << 4);
1178
0
1179
0
    apv_map_ref_idx_to_poc = ps_dec->ppv_map_ref_idx_to_poc + 1;
1180
0
    u1_cur_mb_type = ps_cur_mb_params->u1_mb_type;
1181
0
    u1_top_mb_typ = ps_deblk_top_mb->u1_mb_type;
1182
0
    ps_deblk_top_mb->u1_mb_type = u1_cur_mb_type;
1183
0
1184
0
    {
1185
0
        UWORD8 mb_qp_temp;
1186
0
1187
0
        ps_cur_mb_params->u1_topmb_qp = ps_deblk_top_mb->u1_mb_qp;
1188
0
        ps_deblk_top_mb->u1_mb_qp = ps_cur_mb_params->u1_mb_qp;
1189
0
1190
0
        ps_cur_mb_params->u1_left_mb_qp = ps_dec->deblk_left_mb[1].u1_mb_qp;
1191
0
        ps_dec->deblk_left_mb[1].u1_mb_qp = ps_cur_mb_params->u1_mb_qp;
1192
0
1193
0
    }
1194
0
1195
0
    /* if no deblocking required for current Mb then continue */
1196
0
    /* Check next Mbs   in Mb group                           */
1197
0
    if(ps_cur_mb_params->u1_deblocking_mode & MB_DISABLE_FILTERING)
1198
0
    {
1199
0
        void ** pu4_map_ref_idx_to_poc_l1 = apv_map_ref_idx_to_poc +
1200
0
        POC_LIST_L0_TO_L1_DIFF;
1201
0
        {
1202
0
            /* Store Parameter for Top MvPred refernce frame Address */
1203
0
1204
0
            void ** ppv_top_mv_pred_addr = ps_cur_mb_info->ps_curmb->u4_pic_addrress;
1205
0
            WORD8 * p1_refTop0 = (ps_cur_mv_pred + 12)->i1_ref_frame;
1206
0
            WORD8 * p1_refTop1 = (ps_cur_mv_pred + 14)->i1_ref_frame;
1207
0
1208
0
            /* Store Left addresses for Next Mb   */
1209
0
            void ** ppv_left_mv_pred_addr =
1210
0
                            ps_dec->ps_left_mvpred_addr[!u1_pingpong][1].u4_add;
1211
0
            WORD8 * p1_refleft0 = (ps_cur_mv_pred + 3)->i1_ref_frame;
1212
0
1213
0
1214
0
            ppv_top_mv_pred_addr[0] = apv_map_ref_idx_to_poc[p1_refTop0[0]];
1215
0
            ppv_top_mv_pred_addr[1] = pu4_map_ref_idx_to_poc_l1[p1_refTop0[1]];
1216
0
1217
0
            ppv_left_mv_pred_addr[2] = apv_map_ref_idx_to_poc[p1_refTop1[0]];
1218
0
            ppv_top_mv_pred_addr[2] = apv_map_ref_idx_to_poc[p1_refTop1[0]];
1219
0
            ppv_left_mv_pred_addr[3] = pu4_map_ref_idx_to_poc_l1[p1_refTop1[1]];
1220
0
            ppv_top_mv_pred_addr[3] = pu4_map_ref_idx_to_poc_l1[p1_refTop1[1]];
1221
0
1222
0
            ppv_left_mv_pred_addr[0] = apv_map_ref_idx_to_poc[p1_refleft0[0]];
1223
0
            ppv_left_mv_pred_addr[1] = pu4_map_ref_idx_to_poc_l1[p1_refleft0[1]];
1224
0
            //}
1225
0
            /* Storing the leftMbtype for next Mb */
1226
0
            ps_dec->deblk_left_mb[1].u1_mb_type = ps_cur_mb_params->u1_mb_type;
1227
0
        }
1228
0
1229
0
        return;
1230
0
    }
1231
0
1232
0
    /* Flag for extra left Edge */
1233
0
    ps_cur_mb_params->u1_single_call = 1;
1234
0
1235
0
    /* Update the Left deblk_mb_t and Left MvPred Parameters           */
1236
0
    if(!u2_mbx)
1237
0
    {
1238
0
        u4_leftmbtype = 0;
1239
0
1240
0
        /* Initialize the ps_left_mv_pred with Junk but Valid Location */
1241
0
        /* to avoid invalid memory access                           */
1242
0
        /* this is read only pointer                                */
1243
0
        ps_left_mv_pred = ps_dec->ps_mv_cur + 3;
1244
0
    }
1245
0
    else
1246
0
    {
1247
0
        u4_leftmbtype = ps_dec->deblk_left_mb[1].u1_mb_type;
1248
0
1249
0
        /* Come to Left Most Edge of the MB */
1250
0
        ps_left_mv_pred = (u2_mbxn_mb) ?
1251
0
                        ps_dec->ps_mv_cur + ((u2_mbxn_mb - 1) << 4) + 3 :
1252
0
                        ps_dec->ps_mv_left + 3;
1253
0
    }
1254
0
1255
0
    if(!u2_mby)
1256
0
        u1_top_mb_typ = 0;
1257
0
1258
0
    /* MvPred Pointer Calculation */
1259
0
    /* CHANGED CODE */
1260
0
    ps_top_mv_pred = ps_cur_mv_pred - (ps_dec->u2_frm_wd_in_mbs << 4) + 12;
1261
0
1262
0
    u4_cur_mb_intra = u1_cur_mb_type & D_INTRA_MB;
1263
0
    u4_cur_mb_fld = !!(u1_cur_mb_type & D_FLD_MB);
1264
0
    /* Compute BS function */
1265
0
    pu4_bs_table = ps_cur_mb_params->u4_bs_table;
1266
0
1267
0
    u2_cur_csbp = ps_cur_mb_info->ps_curmb->u2_luma_csbp;
1268
0
    u2_left_csbp = ps_cur_mb_info->ps_left_mb->u2_luma_csbp;
1269
0
    u2_top_csbp = ps_cur_mb_info->ps_top_mb->u2_luma_csbp;
1270
0
    /* Compute BS function */
1271
0
    if(ps_dec->ps_cur_sps->u1_profile_idc == HIGH_PROFILE_IDC)
1272
0
    {
1273
0
        if(ps_cur_mb_info->u1_tran_form8x8 == 1)
1274
0
        {
1275
0
            u2_cur_csbp = ih264d_update_csbp_8x8(
1276
0
                            ps_cur_mb_info->ps_curmb->u2_luma_csbp);
1277
0
        }
1278
0
1279
0
        if(ps_cur_mb_info->ps_left_mb->u1_tran_form8x8 == 1)
1280
0
        {
1281
0
            u2_left_csbp = ih264d_update_csbp_8x8(
1282
0
                            ps_cur_mb_info->ps_left_mb->u2_luma_csbp);
1283
0
        }
1284
0
1285
0
        if(ps_cur_mb_info->ps_top_mb->u1_tran_form8x8 == 1)
1286
0
        {
1287
0
            u2_top_csbp = ih264d_update_csbp_8x8(
1288
0
                            ps_cur_mb_info->ps_top_mb->u2_luma_csbp);
1289
0
        }
1290
0
    }
1291
0
    if(u4_cur_mb_intra)
1292
0
    {
1293
0
1294
0
        pu4_bs_table[4] = 0x04040404;
1295
0
        pu4_bs_table[0] = u4_cur_mb_fld ? 0x03030303 : 0x04040404;
1296
0
        pu4_bs_table[1] = 0x03030303;
1297
0
        pu4_bs_table[2] = 0x03030303;
1298
0
        pu4_bs_table[3] = 0x03030303;
1299
0
        pu4_bs_table[5] = 0x03030303;
1300
0
        pu4_bs_table[6] = 0x03030303;
1301
0
        pu4_bs_table[7] = 0x03030303;
1302
0
    }
1303
0
    else
1304
0
    {
1305
0
        UWORD32 u4_is_non16x16 = !!(u1_cur_mb_type & D_PRED_NON_16x16);
1306
0
        UWORD32 u4_is_b = ps_dec->u1_B;
1307
0
1308
0
        ih264d_fill_bs2_horz_vert(
1309
0
                        pu4_bs_table, u2_left_csbp, u2_top_csbp, u2_cur_csbp,
1310
0
                        (const UWORD32 *)(gau4_ih264d_packed_bs2),
1311
0
                        (const UWORD16 *)(gau2_ih264d_4x4_v2h_reorder));
1312
0
1313
0
        if(u4_leftmbtype & D_INTRA_MB)
1314
0
            pu4_bs_table[4] = 0x04040404;
1315
0
1316
0
        if(u1_top_mb_typ & D_INTRA_MB)
1317
0
            pu4_bs_table[0] = u4_cur_mb_fld ? 0x03030303 : 0x04040404;
1318
0
1319
0
        ps_dec->pf_fill_bs1[u4_is_b][u4_is_non16x16](
1320
0
                        ps_cur_mv_pred, ps_top_mv_pred, apv_map_ref_idx_to_poc,
1321
0
                        pu4_bs_table, ps_left_mv_pred,
1322
0
                        &(ps_dec->ps_left_mvpred_addr[u1_pingpong][1]),
1323
0
                        ps_cur_mb_info->ps_top_mb->u4_pic_addrress,
1324
0
                        (4 >> u4_cur_mb_fld));
1325
0
    }
1326
0
1327
0
    {
1328
0
        void ** pu4_map_ref_idx_to_poc_l1 = apv_map_ref_idx_to_poc +
1329
0
        POC_LIST_L0_TO_L1_DIFF;
1330
0
        {
1331
0
            /* Store Parameter for Top MvPred refernce frame Address */
1332
0
1333
0
            void ** ppv_top_mv_pred_addr = ps_cur_mb_info->ps_curmb->u4_pic_addrress;
1334
0
            WORD8 * p1_refTop0 = (ps_cur_mv_pred + 12)->i1_ref_frame;
1335
0
            WORD8 * p1_refTop1 = (ps_cur_mv_pred + 14)->i1_ref_frame;
1336
0
1337
0
            /* Store Left addresses for Next Mb   */
1338
0
            void ** ppv_left_mv_pred_addr =
1339
0
                            ps_dec->ps_left_mvpred_addr[!u1_pingpong][1].u4_add;
1340
0
            WORD8 * p1_refleft0 = (ps_cur_mv_pred + 3)->i1_ref_frame;
1341
0
1342
0
            ppv_top_mv_pred_addr[0] = apv_map_ref_idx_to_poc[p1_refTop0[0]];
1343
0
            ppv_top_mv_pred_addr[1] = pu4_map_ref_idx_to_poc_l1[p1_refTop0[1]];
1344
0
1345
0
            ppv_left_mv_pred_addr[2] = apv_map_ref_idx_to_poc[p1_refTop1[0]];
1346
0
            ppv_top_mv_pred_addr[2] = apv_map_ref_idx_to_poc[p1_refTop1[0]];
1347
0
            ppv_left_mv_pred_addr[3] = pu4_map_ref_idx_to_poc_l1[p1_refTop1[1]];
1348
0
            ppv_top_mv_pred_addr[3] = pu4_map_ref_idx_to_poc_l1[p1_refTop1[1]];
1349
0
1350
0
            ppv_left_mv_pred_addr[0] = apv_map_ref_idx_to_poc[p1_refleft0[0]];
1351
0
            ppv_left_mv_pred_addr[1] = pu4_map_ref_idx_to_poc_l1[p1_refleft0[1]];
1352
0
1353
0
            /* Storing the leftMbtype for next Mb */
1354
0
            ps_dec->deblk_left_mb[1].u1_mb_type = ps_cur_mb_params->u1_mb_type;
1355
0
1356
0
        }
1357
0
    }
1358
0
1359
0
    /* For transform 8x8 disable deblocking of the intrernal edges of a 8x8 block */
1360
0
    if(ps_cur_mb_info->u1_tran_form8x8)
1361
0
    {
1362
0
        pu4_bs_table[1] = 0;
1363
0
        pu4_bs_table[3] = 0;
1364
0
        pu4_bs_table[5] = 0;
1365
0
        pu4_bs_table[7] = 0;
1366
0
    }
1367
0
}
1368
1369
/*****************************************************************************/
1370
/*                                                                           */
1371
/*  Function Name : ih264d_compute_bs_mbaff                                           */
1372
/*                                                                           */
1373
/*  Description   : This function computes the pointers of left,top & current*/
1374
/*                : Nnz, MvPred & deblk_mb_t and supplies to FillBs function for*/
1375
/*                : Boundary Strength Calculation                            */
1376
/*  Inputs        : <What inputs does the function take?>                    */
1377
/*  Processing    : This functions calls deblock MB in the MB increment order*/
1378
/*                                                                           */
1379
/*  Outputs       : Produces the Boundary Strength for Current Mb            */
1380
/*  Returns       : None                                                     */
1381
/*                                                                           */
1382
/*  Revision History:                                                        */
1383
/*                                                                           */
1384
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1385
/*                      ITTIAM                                               */
1386
/*****************************************************************************/
1387
1388
void ih264d_compute_bs_mbaff(dec_struct_t * ps_dec,
1389
                             dec_mb_info_t * ps_cur_mb_info,
1390
                             const UWORD16 u2_mbxn_mb)
1391
0
{
1392
0
    /* Mvpred and Nnz for top and Courrent */
1393
0
    mv_pred_t *ps_cur_mv_pred, *ps_top_mv_pred = NULL, *ps_left_mv_pred;
1394
0
    /* deblk_mb_t Params */
1395
0
    deblk_mb_t *ps_cur_mb_params; /*< Parameters of current MacroBlock */
1396
0
    neighbouradd_t * ps_left_ngbr;
1397
0
    deblkmb_neighbour_t *ps_deblk_top_mb;
1398
0
    /* Reference Index to POC mapping*/
1399
0
    void ** apv_map_ref_idx_to_poc;
1400
0
1401
0
    UWORD32 u4_leftmbtype;
1402
0
1403
0
1404
0
    UWORD16 u2_left_csbp, u2_top_csbp, u2_cur_csbp;
1405
0
1406
0
    /* Set of flags */
1407
0
    UWORD32 u4_cur_mb_intra, u4_cur_mb_fld, u4_top_mb_fld, u1_top_mb_typ, u4_left_mb_fld;
1408
0
    UWORD32 u1_cur_mb_type;
1409
0
    UWORD32 * pu4_bs_table;
1410
0
    const UWORD32 u4_bot_mb = (1 - ps_cur_mb_info->u1_topmb);
1411
0
    /* Initialization */
1412
0
    const UWORD32 u2_mbx = ps_cur_mb_info->u2_mbx;
1413
0
    const UWORD32 u2_mby = ps_cur_mb_info->u2_mby;
1414
0
    /* Load From u1_pingpong and Store in !u1_pingpong */
1415
0
    const UWORD32 u1_pingpong = u2_mbx & 0x01;
1416
0
1417
0
    PROFILE_DISABLE_BOUNDARY_STRENGTH()
1418
0
1419
0
    ps_deblk_top_mb = ps_dec->ps_deblk_top_mb + (u2_mbx << 1);
1420
0
1421
0
1422
0
    /************************************************/
1423
0
    /* Initialize the left Mb type                  */
1424
0
    /* Left MvPred                                  */
1425
0
    /************************************************/
1426
0
1427
0
    if(!u2_mbx)
1428
0
    {
1429
0
        /************************************************************/
1430
0
        /* Initialize the ps_left_mv_pred with Junk but Valid Location */
1431
0
        /* to avoid invalid memory access                       */
1432
0
        /* this is read only pointer                                */
1433
0
        /************************************************************/
1434
0
        ps_left_mv_pred = ps_dec->ps_mv_cur + 16;
1435
0
    }
1436
0
    else
1437
0
    {
1438
0
        /* Come to Left Most Edge of the MB */
1439
0
        ps_left_mv_pred = (u2_mbxn_mb) ?
1440
0
                        ps_dec->ps_mv_cur + ((u2_mbxn_mb - 1) << 5) + 3 :
1441
0
                        ps_dec->ps_mv_left + 3;
1442
0
1443
0
        ps_left_mv_pred += (u4_bot_mb << 4);
1444
0
    }
1445
0
1446
0
    u4_leftmbtype = ps_dec->deblk_left_mb[u4_bot_mb].u1_mb_type;
1447
0
1448
0
    ps_left_ngbr = &(ps_dec->ps_left_mvpred_addr[u1_pingpong][u4_bot_mb]);
1449
0
1450
0
    /************************************************/
1451
0
    /* Pointer Assignment for Current Mb Parameters */
1452
0
    /* Pointer Assignment for Current MvPred        */
1453
0
    /************************************************/
1454
0
    ps_cur_mb_params = ps_dec->ps_deblk_mbn + (u2_mbxn_mb << 1) + u4_bot_mb;
1455
0
    u1_cur_mb_type = ps_cur_mb_params->u1_mb_type;
1456
0
1457
0
    ps_cur_mv_pred = ps_dec->ps_mv_cur + (u2_mbxn_mb << 5);
1458
0
    ps_cur_mv_pred += (u4_bot_mb << 4);
1459
0
1460
0
    /********************************************/
1461
0
    /* Pointer Assignment for Top Mb Parameters */
1462
0
    /* Pointer Assignment for Top MvPred and    */
1463
0
    /* Pointer Assignment for Top Nnz           */
1464
0
    /********************************************/
1465
0
1466
0
    /* CHANGED CODE */
1467
0
    ps_top_mv_pred = ps_cur_mv_pred - (ps_dec->u2_frm_wd_in_mbs << 5) + 12;
1468
0
1469
0
    u4_cur_mb_fld = !!(u1_cur_mb_type & D_FLD_MB);
1470
0
    u4_left_mb_fld = !!(ps_dec->deblk_left_mb[0].u1_mb_type & D_FLD_MB);
1471
0
1472
0
    if(u4_left_mb_fld != u4_cur_mb_fld)
1473
0
    {
1474
0
        /* Flag for extra left Edge */
1475
0
        ps_cur_mb_params->u1_single_call = 0;
1476
0
1477
0
        if(u4_bot_mb)
1478
0
        {
1479
0
            ps_left_ngbr--;
1480
0
            ps_left_mv_pred -= 16;
1481
0
        }
1482
0
    }
1483
0
    else
1484
0
        ps_cur_mb_params->u1_single_call = 1;
1485
0
1486
0
    apv_map_ref_idx_to_poc = ps_dec->ppv_map_ref_idx_to_poc + 1;
1487
0
    if(u4_cur_mb_fld)
1488
0
    {
1489
0
        if(u4_bot_mb)
1490
0
        {
1491
0
            apv_map_ref_idx_to_poc += BOT_LIST_FLD_L0;
1492
0
        }
1493
0
        else
1494
0
        {
1495
0
            apv_map_ref_idx_to_poc += TOP_LIST_FLD_L0;
1496
0
        }
1497
0
    }
1498
0
1499
0
    /**********************************************************/
1500
0
    /* if no deblocking required for current Mb then continue */
1501
0
    /**********************************************************/
1502
0
    if(ps_cur_mb_params->u1_deblocking_mode & MB_DISABLE_FILTERING)
1503
0
    {
1504
0
        void ** pu4_map_ref_idx_to_poc_l1 = apv_map_ref_idx_to_poc +
1505
0
        POC_LIST_L0_TO_L1_DIFF;
1506
0
1507
0
        {
1508
0
            /* Store Parameter for Top MvPred refernce frame Address */
1509
0
1510
0
            void ** ppv_top_mv_pred_addr = ps_cur_mb_info->ps_curmb->u4_pic_addrress;
1511
0
            void ** ppv_left_mv_pred_addr =
1512
0
                            ps_dec->ps_left_mvpred_addr[!u1_pingpong][u4_bot_mb].u4_add;
1513
0
            WORD8 * p1_refTop0 = (ps_cur_mv_pred + 12)->i1_ref_frame;
1514
0
            WORD8 * p1_refTop1 = (ps_cur_mv_pred + 14)->i1_ref_frame;
1515
0
            WORD8 * p1_refLeft0 = (ps_cur_mv_pred + 3)->i1_ref_frame;
1516
0
            ppv_top_mv_pred_addr[0] = apv_map_ref_idx_to_poc[p1_refTop0[0]];
1517
0
            ppv_top_mv_pred_addr[1] = pu4_map_ref_idx_to_poc_l1[p1_refTop0[1]];
1518
0
            ppv_left_mv_pred_addr[2] = apv_map_ref_idx_to_poc[p1_refTop1[0]];
1519
0
            ppv_top_mv_pred_addr[2] = apv_map_ref_idx_to_poc[p1_refTop1[0]];
1520
0
            ppv_left_mv_pred_addr[3] = pu4_map_ref_idx_to_poc_l1[p1_refTop1[1]];
1521
0
            ppv_top_mv_pred_addr[3] = pu4_map_ref_idx_to_poc_l1[p1_refTop1[1]];
1522
0
            ppv_left_mv_pred_addr[0] = apv_map_ref_idx_to_poc[p1_refLeft0[0]];
1523
0
            ppv_left_mv_pred_addr[1] = pu4_map_ref_idx_to_poc_l1[p1_refLeft0[1]];
1524
0
        }
1525
0
        if(u4_bot_mb)
1526
0
        {
1527
0
            /* store The Left Mb Type*/
1528
0
            ps_dec->deblk_left_mb[0].u1_mb_type =
1529
0
                            (ps_cur_mb_params - 1)->u1_mb_type;
1530
0
            ps_dec->deblk_left_mb[1].u1_mb_type = ps_cur_mb_params->u1_mb_type;
1531
0
1532
0
        }
1533
0
        ps_deblk_top_mb[u4_bot_mb].u1_mb_type = u1_cur_mb_type;
1534
0
        return;
1535
0
    }
1536
0
1537
0
    if(u2_mby)
1538
0
    {
1539
0
        u1_top_mb_typ = ps_deblk_top_mb[1].u1_mb_type;
1540
0
        u4_top_mb_fld = !!(u1_top_mb_typ & D_FLD_MB);
1541
0
1542
0
        if(!u4_bot_mb)
1543
0
        {
1544
0
            if(u4_top_mb_fld & u4_cur_mb_fld)
1545
0
                u1_top_mb_typ = ps_deblk_top_mb[0].u1_mb_type;
1546
0
            else
1547
0
            {
1548
0
                ps_top_mv_pred += 16;
1549
0
            }
1550
0
        }
1551
0
    }
1552
0
    else
1553
0
    {
1554
0
        u4_top_mb_fld = u4_cur_mb_fld;
1555
0
        u1_top_mb_typ = 0;
1556
0
    }
1557
0
1558
0
    if(u4_bot_mb & !u4_cur_mb_fld)
1559
0
    {
1560
0
        u1_top_mb_typ = ps_deblk_top_mb[0].u1_mb_type;
1561
0
        u4_top_mb_fld = u4_cur_mb_fld;
1562
0
        ps_top_mv_pred = ps_cur_mv_pred - 4;
1563
0
    }
1564
0
1565
0
    pu4_bs_table = ps_cur_mb_params->u4_bs_table;
1566
0
    u4_cur_mb_intra = u1_cur_mb_type & D_INTRA_MB;
1567
0
1568
0
    u2_cur_csbp = ps_cur_mb_info->ps_curmb->u2_luma_csbp;
1569
0
    u2_left_csbp = ps_cur_mb_info->ps_left_mb->u2_luma_csbp;
1570
0
    u2_top_csbp = ps_cur_mb_info->ps_top_mb->u2_luma_csbp;
1571
0
    /* Compute BS function */
1572
0
    if(ps_dec->ps_cur_sps->u1_profile_idc == HIGH_PROFILE_IDC)
1573
0
    {
1574
0
1575
0
        if(ps_cur_mb_info->u1_tran_form8x8 == 1)
1576
0
        {
1577
0
            u2_cur_csbp = ih264d_update_csbp_8x8(
1578
0
                            ps_cur_mb_info->ps_curmb->u2_luma_csbp);
1579
0
        }
1580
0
1581
0
        if(ps_cur_mb_info->ps_left_mb->u1_tran_form8x8 == 1)
1582
0
        {
1583
0
            u2_left_csbp = ih264d_update_csbp_8x8(
1584
0
                            ps_cur_mb_info->ps_left_mb->u2_luma_csbp);
1585
0
        }
1586
0
1587
0
        if(ps_cur_mb_info->ps_top_mb->u1_tran_form8x8 == 1)
1588
0
        {
1589
0
            u2_top_csbp = ih264d_update_csbp_8x8(
1590
0
                            ps_cur_mb_info->ps_top_mb->u2_luma_csbp);
1591
0
        }
1592
0
    }
1593
0
    if(u4_cur_mb_intra)
1594
0
    {
1595
0
1596
0
        pu4_bs_table[4] = 0x04040404;
1597
0
        if((0 == u4_cur_mb_fld) && (0 == u4_top_mb_fld))
1598
0
        {
1599
0
            pu4_bs_table[0] = 0x04040404;
1600
0
        }
1601
0
        else
1602
0
        {
1603
0
            pu4_bs_table[0] = 0x03030303;
1604
0
        }
1605
0
1606
0
        pu4_bs_table[1] = 0x03030303;
1607
0
        pu4_bs_table[2] = 0x03030303;
1608
0
        pu4_bs_table[3] = 0x03030303;
1609
0
        pu4_bs_table[5] = 0x03030303;
1610
0
        pu4_bs_table[6] = 0x03030303;
1611
0
        pu4_bs_table[7] = 0x03030303;
1612
0
1613
0
        /*********************************************************************/
1614
0
        /* Fill Bs of xtra top and left edge unconditionally to avoid checks */
1615
0
        /*********************************************************************/
1616
0
        pu4_bs_table[8] = 0x03030303;
1617
0
        pu4_bs_table[9] = 0x04040404;
1618
0
    }
1619
0
    else
1620
0
    {
1621
0
        UWORD32 u4_is_non16x16 = !!(u1_cur_mb_type & D_PRED_NON_16x16);
1622
0
        UWORD32 u4_is_b = ps_dec->u1_B;
1623
0
1624
0
        ih264d_fill_bs2_horz_vert(
1625
0
                        pu4_bs_table, u2_left_csbp, u2_top_csbp, u2_cur_csbp,
1626
0
                        (const UWORD32 *)(gau4_ih264d_packed_bs2),
1627
0
                        (const UWORD16 *)(gau2_ih264d_4x4_v2h_reorder));
1628
0
1629
0
        if(u4_leftmbtype & D_INTRA_MB)
1630
0
            pu4_bs_table[4] = 0x04040404;
1631
0
1632
0
        if(u1_top_mb_typ & D_INTRA_MB)
1633
0
            pu4_bs_table[0] = u4_cur_mb_fld ? 0x03030303 : 0x04040404;
1634
0
        else if(u4_cur_mb_fld != u4_top_mb_fld)
1635
0
        {
1636
0
            /****************************************************/
1637
0
            /* Setting BS for mixed mode edge=1 when (Bs!=2)    */
1638
0
            /****************************************************/
1639
0
            pu4_bs_table[0] = (pu4_bs_table[0] >> 1) + 0x01010101;
1640
0
        }
1641
0
1642
0
        {
1643
0
            /* Call to Compute Boundary Strength for Extra Left Edge */
1644
0
            if(u2_mbx
1645
0
                            && !(ps_cur_mb_params->u1_deblocking_mode
1646
0
                                            & MB_DISABLE_LEFT_EDGE))
1647
0
            {
1648
0
                if(u4_cur_mb_fld != u4_left_mb_fld)
1649
0
                {
1650
0
                    UWORD32 u4_left_mb_t_csbp =
1651
0
                                    ps_cur_mb_info->ps_left_mb[0].u2_luma_csbp;
1652
0
                    UWORD32 u4_left_mb_b_csbp =
1653
0
                                    ps_cur_mb_info->ps_left_mb[1].u2_luma_csbp;
1654
0
                    if(1 == ps_cur_mb_info->ps_left_mb[0].u1_tran_form8x8)
1655
0
                    {
1656
0
                        u4_left_mb_t_csbp = (UWORD32)ih264d_update_csbp_8x8(
1657
0
                                        (UWORD16)u4_left_mb_t_csbp);
1658
0
                    }
1659
0
1660
0
                    if(1 == ps_cur_mb_info->ps_left_mb[1].u1_tran_form8x8)
1661
0
                    {
1662
0
                        u4_left_mb_b_csbp = (UWORD32)ih264d_update_csbp_8x8(
1663
0
                                        (UWORD16)u4_left_mb_b_csbp);
1664
0
                    }
1665
0
                    ps_dec->pf_fill_bs_xtra_left_edge[u4_cur_mb_fld](
1666
0
                                    pu4_bs_table, u4_left_mb_t_csbp,
1667
0
                                    u4_left_mb_b_csbp, u2_cur_csbp, u4_bot_mb);
1668
0
1669
0
                    if(ps_dec->deblk_left_mb[0].u1_mb_type & D_INTRA_MB)
1670
0
                        pu4_bs_table[4] = 0x04040404;
1671
0
1672
0
                    if(ps_dec->deblk_left_mb[1].u1_mb_type & D_INTRA_MB)
1673
0
                        pu4_bs_table[9] = 0x04040404;
1674
0
1675
0
                }
1676
0
            }
1677
0
            /* Call to Compute Boundary Strength for Extra Top Edge */
1678
0
            if(u2_mby
1679
0
                            && !(ps_cur_mb_params->u1_deblocking_mode
1680
0
                                            & MB_DISABLE_TOP_EDGE))
1681
0
            {
1682
0
                if((((!u4_bot_mb) & (!u4_cur_mb_fld)) && u4_top_mb_fld))
1683
0
                {
1684
0
                    UWORD32 u4_topmb_t_csbp =
1685
0
                                    ps_cur_mb_info->ps_top_mb[-1].u2_luma_csbp;
1686
0
                    UWORD32 u4_topmb_b_csbp =
1687
0
                                    ps_cur_mb_info->ps_top_mb[0].u2_luma_csbp;
1688
0
                    if(1 == ps_cur_mb_info->ps_top_mb[-1].u1_tran_form8x8)
1689
0
                    {
1690
0
                        u4_topmb_t_csbp = (UWORD32)ih264d_update_csbp_8x8(
1691
0
                                        (UWORD16)u4_topmb_t_csbp);
1692
0
                    }
1693
0
1694
0
                    if(1 == ps_cur_mb_info->ps_top_mb[0].u1_tran_form8x8)
1695
0
                    {
1696
0
                        u4_topmb_b_csbp = (UWORD32)ih264d_update_csbp_8x8(
1697
0
                                        (UWORD16)u4_topmb_b_csbp);
1698
0
                    }
1699
0
                    ih264d_fill_bs_xtra_top_edge(pu4_bs_table, u4_topmb_t_csbp,
1700
0
                                                 u4_topmb_b_csbp, u2_cur_csbp);
1701
0
1702
0
                    if(ps_deblk_top_mb[0].u1_mb_type & D_INTRA_MB)
1703
0
                        pu4_bs_table[8] = 0x03030303;
1704
0
1705
0
                    if(ps_deblk_top_mb[1].u1_mb_type & D_INTRA_MB)
1706
0
                        pu4_bs_table[0] = 0x03030303;
1707
0
                }
1708
0
            }
1709
0
        }
1710
0
1711
0
        ps_dec->pf_fill_bs1[u4_is_b][u4_is_non16x16](
1712
0
                        ps_cur_mv_pred, ps_top_mv_pred, apv_map_ref_idx_to_poc,
1713
0
                        pu4_bs_table, ps_left_mv_pred, ps_left_ngbr,
1714
0
                        ps_cur_mb_info->ps_top_mb->u4_pic_addrress,
1715
0
                        (4 >> u4_cur_mb_fld));
1716
0
    }
1717
0
1718
0
    {
1719
0
        void ** pu4_map_ref_idx_to_poc_l1 = apv_map_ref_idx_to_poc +
1720
0
        POC_LIST_L0_TO_L1_DIFF;
1721
0
1722
0
        {
1723
0
            /* Store Parameter for Top MvPred refernce frame Address */
1724
0
            void ** ppv_top_mv_pred_addr = ps_cur_mb_info->ps_curmb->u4_pic_addrress;
1725
0
            void ** ppv_left_mv_pred_addr =
1726
0
                            ps_dec->ps_left_mvpred_addr[!u1_pingpong][u4_bot_mb].u4_add;
1727
0
            WORD8 * p1_refTop0 = (ps_cur_mv_pred + 12)->i1_ref_frame;
1728
0
            WORD8 * p1_refTop1 = (ps_cur_mv_pred + 14)->i1_ref_frame;
1729
0
            WORD8 * p1_refLeft0 = (ps_cur_mv_pred + 3)->i1_ref_frame;
1730
0
            ppv_top_mv_pred_addr[0] = apv_map_ref_idx_to_poc[p1_refTop0[0]];
1731
0
            ppv_top_mv_pred_addr[1] = pu4_map_ref_idx_to_poc_l1[p1_refTop0[1]];
1732
0
            ppv_left_mv_pred_addr[2] = apv_map_ref_idx_to_poc[p1_refTop1[0]];
1733
0
            ppv_top_mv_pred_addr[2] = apv_map_ref_idx_to_poc[p1_refTop1[0]];
1734
0
            ppv_left_mv_pred_addr[3] = pu4_map_ref_idx_to_poc_l1[p1_refTop1[1]];
1735
0
            ppv_top_mv_pred_addr[3] = pu4_map_ref_idx_to_poc_l1[p1_refTop1[1]];
1736
0
            ppv_left_mv_pred_addr[0] = apv_map_ref_idx_to_poc[p1_refLeft0[0]];
1737
0
            ppv_left_mv_pred_addr[1] = pu4_map_ref_idx_to_poc_l1[p1_refLeft0[1]];
1738
0
        }
1739
0
        if(u4_bot_mb)
1740
0
        {
1741
0
            /* store The Left Mb Type*/
1742
0
            ps_dec->deblk_left_mb[0].u1_mb_type =
1743
0
                            (ps_cur_mb_params - 1)->u1_mb_type;
1744
0
            ps_dec->deblk_left_mb[1].u1_mb_type = ps_cur_mb_params->u1_mb_type;
1745
0
1746
0
        }
1747
0
        ps_deblk_top_mb[u4_bot_mb].u1_mb_type = u1_cur_mb_type;
1748
0
    }
1749
0
    /* For transform 8x8 disable deblocking of the intrernal edges of a 8x8 block */
1750
0
    if(ps_cur_mb_info->u1_tran_form8x8)
1751
0
    {
1752
0
        pu4_bs_table[1] = 0;
1753
0
        pu4_bs_table[3] = 0;
1754
0
        pu4_bs_table[5] = 0;
1755
0
        pu4_bs_table[7] = 0;
1756
0
    }
1757
0
1758
0
}
1759
1760
1761
1762
/*!
1763
 **************************************************************************
1764
 * \if Function name : ih264d_fill_bs_for_mb \endif
1765
 *
1766
 * \brief
1767
 *    Determines the boundary strength (Bs), for the complete MB. Bs is
1768
 *    determined for each block boundary between two neighbouring 4x4
1769
 *    luma blocks, then packed in a UWORD32, first Bs placed in MSB and
1770
 *    so on.  Such packed Bs values for all 8 edges are kept in an array.
1771
 *
1772
 * \return
1773
 *    Returns the packed boundary strength(Bs)  MSB -> LSB Bs0|Bs1|Bs2|Bs3
1774
 *
1775
 **************************************************************************
1776
 */
1777
1778
void ih264d_fill_bs_for_mb(deblk_mb_t * ps_cur_mb_params,
1779
                           deblk_mb_t * ps_top_mb_params,
1780
                           deblk_mb_t * ps_left_mb_params,
1781
                           mv_pred_t *ps_cur_mv_pred,
1782
                           mv_pred_t *ps_top_mv_pred,
1783
                           UWORD8 *puc_cur_nnz,
1784
                           UWORD8 *puc_top_nnz,
1785
                           void **ppv_map_ref_idx_to_poc,
1786
                           UWORD32 ui_mbAff,
1787
                           UWORD32 ui_bs_table[], /* pointer to the BsTable array */
1788
                           mv_pred_t *ps_leftmost_mv_pred,
1789
                           neighbouradd_t *ps_left_addr,
1790
                           neighbouradd_t *ps_top_add)
1791
0
{
1792
0
    UWORD32 u4_bs_horz = 0;
1793
0
    UWORD8 edge, u1_top_intra = 0, u1_left_intra = 0;
1794
0
    mv_pred_t *ps_left_mv_pred;
1795
0
    WORD16 i2_cur_mv0, i2_cur_mv1, i16_curMv2, i16_curMv3;
1796
0
    WORD16 i2_left_mv0, i2_left_mv1, i2_left_mv2, i2_left_mv3;
1797
0
    WORD16 i2_top_mv0, i2_top_mv1, i16_topMv2, i16_topMv3;
1798
0
    WORD8 i1_cur_ref0, i1_cur_ref1, i1_left_ref0, i1_left_ref1, i1_top_ref0, i1_top_ref1;
1799
0
    UWORD8 uc_cur_nnz, uc_left_nnz, uc_top_nnz, u1_mb_type, uc_Bslice;
1800
0
    void **ppv_map_ref_idx_to_poc_l0, **ppv_map_ref_idx_to_poc_l1;
1801
0
    UWORD8 uc_temp;
1802
0
    UWORD8 uc_cur_mb_fld, uc_top_mb_fld;
1803
0
    UWORD32 c_mv_limit;
1804
0
1805
0
    u1_mb_type = ps_cur_mb_params->u1_mb_type;
1806
0
    uc_Bslice = u1_mb_type & D_B_SLICE;
1807
0
    ppv_map_ref_idx_to_poc_l0 = ppv_map_ref_idx_to_poc;
1808
0
    ppv_map_ref_idx_to_poc_l1 = ppv_map_ref_idx_to_poc + POC_LIST_L0_TO_L1_DIFF;
1809
0
1810
0
    ps_top_mb_params = ps_top_mb_params ? ps_top_mb_params : ps_cur_mb_params;
1811
0
    u1_top_intra = ps_top_mb_params->u1_mb_type & D_INTRA_MB;
1812
0
    u1_left_intra = ps_left_mb_params->u1_mb_type & D_INTRA_MB;
1813
0
1814
0
    ui_bs_table[4] = 0x04040404; //Default for INTRA MB Boundary edges.
1815
0
    uc_cur_mb_fld = (ps_cur_mb_params->u1_mb_type & D_FLD_MB) >> 7;
1816
0
    uc_top_mb_fld = (ps_top_mb_params->u1_mb_type & D_FLD_MB) >> 7;
1817
0
1818
0
    c_mv_limit = 4 >> uc_cur_mb_fld;
1819
0
    if((0 == uc_cur_mb_fld) && (0 == uc_top_mb_fld))
1820
0
    {
1821
0
        ui_bs_table[0] = 0x04040404;
1822
0
    }
1823
0
    else
1824
0
    {
1825
0
        ui_bs_table[0] = 0x03030303;
1826
0
    }
1827
0
1828
0
    for(edge = 0; edge < 4;
1829
0
                    edge++, ps_top_mv_pred = ps_cur_mv_pred - 4, puc_top_nnz =
1830
0
                                    puc_cur_nnz - 4)
1831
0
    {
1832
0
        //Each iteration of this loop fills the four BS values of one HORIZ edge and
1833
0
        //one BS value for each of the four VERT edges.
1834
0
        WORD8 i = 0;
1835
0
        UWORD8 uc_bs_horiz, uc_bs_vert;
1836
0
        UWORD32 ui_cnd;
1837
0
        void *ui_ref_pic_addr[4];
1838
0
        UWORD8 uc_mixed_mode_edge;
1839
0
1840
0
        uc_mixed_mode_edge = 0;
1841
0
1842
0
        uc_temp = (ui_mbAff << 4) + 13;
1843
0
1844
0
        uc_cur_nnz = *(puc_cur_nnz - uc_temp);
1845
0
        ps_left_mv_pred = ps_leftmost_mv_pred + (edge << 2);
1846
0
1847
0
        for(i = 0; i < 4; i++, ps_top_mv_pred++, ps_cur_mv_pred++)
1848
0
        {
1849
0
            //Each iteration of this inner loop computes a HORIZ
1850
0
            //and a VERT BS value for a 4x4 block
1851
0
1852
0
            uc_left_nnz = uc_cur_nnz;
1853
0
            uc_cur_nnz = *puc_cur_nnz++;
1854
0
            uc_top_nnz = *puc_top_nnz++;
1855
0
1856
0
            //VERT edge is assigned BS values first
1857
0
            ui_cnd = !(uc_left_nnz || uc_cur_nnz);
1858
0
            uc_bs_vert = 2;
1859
0
1860
0
            if(ui_cnd)
1861
0
            {
1862
0
                i2_left_mv0 = ps_left_mv_pred->i2_mv[0];
1863
0
                i2_left_mv1 = ps_left_mv_pred->i2_mv[1];
1864
0
                i2_left_mv2 = ps_left_mv_pred->i2_mv[2];
1865
0
                i2_left_mv3 = ps_left_mv_pred->i2_mv[3];
1866
0
1867
0
                i2_cur_mv0 = ps_cur_mv_pred->i2_mv[0];
1868
0
                i2_cur_mv1 = ps_cur_mv_pred->i2_mv[1];
1869
0
                i16_curMv2 = ps_cur_mv_pred->i2_mv[2];
1870
0
                i16_curMv3 = ps_cur_mv_pred->i2_mv[3];
1871
0
                i1_cur_ref0 = ps_cur_mv_pred->i1_ref_frame[0];
1872
0
                i1_cur_ref1 = ps_cur_mv_pred->i1_ref_frame[1];
1873
0
                ui_ref_pic_addr[2] = ppv_map_ref_idx_to_poc_l0[i1_cur_ref0];
1874
0
                ui_ref_pic_addr[3] = ppv_map_ref_idx_to_poc_l1[i1_cur_ref1];
1875
0
1876
0
                if(i)
1877
0
                {
1878
0
                    i1_left_ref0 = ps_left_mv_pred->i1_ref_frame[0];
1879
0
                    i1_left_ref1 = ps_left_mv_pred->i1_ref_frame[1];
1880
0
                    ui_ref_pic_addr[0] = ppv_map_ref_idx_to_poc_l0[i1_left_ref0];
1881
0
                    ui_ref_pic_addr[1] = ppv_map_ref_idx_to_poc_l1[i1_left_ref1];
1882
0
                }
1883
0
                else
1884
0
                {
1885
0
                    ui_ref_pic_addr[0] = ps_left_addr->u4_add[edge & 2];
1886
0
                    ui_ref_pic_addr[1] = ps_left_addr->u4_add[1 + (edge & 2)];
1887
0
                }
1888
0
                if(!uc_Bslice)
1889
0
                {
1890
0
                    uc_bs_vert =
1891
0
                                    (ui_ref_pic_addr[0] != ui_ref_pic_addr[2])
1892
0
                                                    | (ABS((i2_left_mv0
1893
0
                                                                    - i2_cur_mv0))
1894
0
                                                                    >= 4)
1895
0
                                                    | (ABS((i2_left_mv1
1896
0
                                                                    - i2_cur_mv1))
1897
0
                                                                    >= (UWORD8)c_mv_limit);
1898
0
                }
1899
0
                else
1900
0
                {
1901
0
                    UWORD8 uc_bs_temp1, uc_bs_temp2;
1902
0
1903
0
                    uc_bs_vert = 1;
1904
0
1905
0
                    uc_bs_temp1 =
1906
0
                                    ((ABS((i2_left_mv0 - i2_cur_mv0))
1907
0
                                                    >= 4)
1908
0
                                                    | (ABS((i2_left_mv1
1909
0
                                                                    - i2_cur_mv1))
1910
0
                                                                    >= (UWORD8)c_mv_limit)
1911
0
                                                    | (ABS((i2_left_mv2
1912
0
                                                                    - i16_curMv2))
1913
0
                                                                    >= 4)
1914
0
                                                    | (ABS((i2_left_mv3
1915
0
                                                                    - i16_curMv3))
1916
0
                                                                    >= (UWORD8)c_mv_limit));
1917
0
1918
0
                    uc_bs_temp2 =
1919
0
                                    ((ABS((i2_left_mv0 - i16_curMv2))
1920
0
                                                    >= 4)
1921
0
                                                    | (ABS((i2_left_mv1
1922
0
                                                                    - i16_curMv3))
1923
0
                                                                    >= (UWORD8)c_mv_limit)
1924
0
                                                    | (ABS((i2_left_mv2
1925
0
                                                                    - i2_cur_mv0))
1926
0
                                                                    >= 4)
1927
0
                                                    | (ABS((i2_left_mv3
1928
0
                                                                    - i2_cur_mv1))
1929
0
                                                                    >= (UWORD8)c_mv_limit));
1930
0
1931
0
                    uc_bs_vert =
1932
0
                                    (((ui_ref_pic_addr[0] != ui_ref_pic_addr[2])
1933
0
                                                    || (ui_ref_pic_addr[1]
1934
0
                                                                    != ui_ref_pic_addr[3]))
1935
0
                                                    || (uc_bs_temp1))
1936
0
                                                    && (((ui_ref_pic_addr[0]
1937
0
                                                                    != ui_ref_pic_addr[3])
1938
0
                                                                    || (ui_ref_pic_addr[1]
1939
0
                                                                                    != ui_ref_pic_addr[2]))
1940
0
                                                                    || (uc_bs_temp2));
1941
0
1942
0
                }
1943
0
            }
1944
0
            //Fill the VERT BS, only if valid i.e.,
1945
0
            //if it is a non-edge OR it is an edge, which is not yet filled
1946
0
            uc_bs_vert = (!i && u1_left_intra) ? 4 : uc_bs_vert;
1947
0
            ui_bs_table[i + 4] = (ui_bs_table[i + 4] << 8) | uc_bs_vert;
1948
0
1949
0
            //HORIZ edge is assigned BS values next
1950
0
            ui_cnd = !(uc_top_nnz || uc_cur_nnz);
1951
0
            uc_bs_horiz = 2;
1952
0
1953
0
            if(ui_cnd)
1954
0
            {
1955
0
                uc_mixed_mode_edge =
1956
0
                                (0 == edge) ? (uc_top_mb_fld != uc_cur_mb_fld) : 0;
1957
0
                ui_cnd = 1 - uc_mixed_mode_edge;
1958
0
                uc_bs_horiz = uc_mixed_mode_edge;
1959
0
            }
1960
0
1961
0
            if(ui_cnd)
1962
0
            {
1963
0
                i2_cur_mv0 = ps_cur_mv_pred->i2_mv[0];
1964
0
                i2_cur_mv1 = ps_cur_mv_pred->i2_mv[1];
1965
0
                i16_curMv2 = ps_cur_mv_pred->i2_mv[2];
1966
0
                i16_curMv3 = ps_cur_mv_pred->i2_mv[3];
1967
0
                i1_cur_ref0 = ps_cur_mv_pred->i1_ref_frame[0];
1968
0
                i1_cur_ref1 = ps_cur_mv_pred->i1_ref_frame[1];
1969
0
1970
0
                i2_top_mv0 = ps_top_mv_pred->i2_mv[0];
1971
0
                i2_top_mv1 = ps_top_mv_pred->i2_mv[1];
1972
0
                i16_topMv2 = ps_top_mv_pred->i2_mv[2];
1973
0
                i16_topMv3 = ps_top_mv_pred->i2_mv[3];
1974
0
                ui_ref_pic_addr[2] = ppv_map_ref_idx_to_poc_l0[i1_cur_ref0];
1975
0
                ui_ref_pic_addr[3] = ppv_map_ref_idx_to_poc_l1[i1_cur_ref1];
1976
0
                if(edge)
1977
0
                {
1978
0
                    i1_top_ref0 = ps_top_mv_pred->i1_ref_frame[0];
1979
0
                    i1_top_ref1 = ps_top_mv_pred->i1_ref_frame[1];
1980
0
                    ui_ref_pic_addr[0] = ppv_map_ref_idx_to_poc_l0[i1_top_ref0];
1981
0
                    ui_ref_pic_addr[1] = ppv_map_ref_idx_to_poc_l1[i1_top_ref1];
1982
0
                }
1983
0
                else
1984
0
                {
1985
0
                    ui_ref_pic_addr[0] = ps_top_add->u4_add[i & 2];
1986
0
                    ui_ref_pic_addr[1] = ps_top_add->u4_add[1 + (i & 2)];
1987
0
                }
1988
0
                if(!uc_Bslice)
1989
0
                {
1990
0
                    uc_bs_horiz =
1991
0
                                    (ui_ref_pic_addr[0] != ui_ref_pic_addr[2])
1992
0
                                                    | (ABS((i2_top_mv0
1993
0
                                                                    - i2_cur_mv0))
1994
0
                                                                    >= 4)
1995
0
                                                    | (ABS((i2_top_mv1
1996
0
                                                                    - i2_cur_mv1))
1997
0
                                                                    >= (UWORD8)c_mv_limit);
1998
0
                }
1999
0
                else
2000
0
                {
2001
0
                    UWORD8 uc_bs_temp1, uc_bs_temp2;
2002
0
2003
0
                    uc_bs_horiz = 1;
2004
0
2005
0
                    uc_bs_temp1 =
2006
0
                                    ((ABS((i2_top_mv0 - i2_cur_mv0))
2007
0
                                                    >= 4)
2008
0
                                                    | (ABS((i2_top_mv1
2009
0
                                                                    - i2_cur_mv1))
2010
0
                                                                    >= (UWORD8)c_mv_limit)
2011
0
                                                    | (ABS((i16_topMv2
2012
0
                                                                    - i16_curMv2))
2013
0
                                                                    >= 4)
2014
0
                                                    | (ABS((i16_topMv3
2015
0
                                                                    - i16_curMv3))
2016
0
                                                                    >= (UWORD8)c_mv_limit));
2017
0
2018
0
                    uc_bs_temp2 =
2019
0
                                    ((ABS((i2_top_mv0 - i16_curMv2))
2020
0
                                                    >= 4)
2021
0
                                                    | (ABS((i2_top_mv1
2022
0
                                                                    - i16_curMv3))
2023
0
                                                                    >= (UWORD8)c_mv_limit)
2024
0
                                                    | (ABS((i16_topMv2
2025
0
                                                                    - i2_cur_mv0))
2026
0
                                                                    >= 4)
2027
0
                                                    | (ABS((i16_topMv3
2028
0
                                                                    - i2_cur_mv1))
2029
0
                                                                    >= (UWORD8)c_mv_limit));
2030
0
2031
0
                    uc_bs_horiz =
2032
0
                                    (((ui_ref_pic_addr[0] != ui_ref_pic_addr[2])
2033
0
                                                    || (ui_ref_pic_addr[1]
2034
0
                                                                    != ui_ref_pic_addr[3]))
2035
0
                                                    || (uc_bs_temp1))
2036
0
                                                    && (((ui_ref_pic_addr[0]
2037
0
                                                                    != ui_ref_pic_addr[3])
2038
0
                                                                    || (ui_ref_pic_addr[1]
2039
0
                                                                                    != ui_ref_pic_addr[2]))
2040
0
                                                                    || (uc_bs_temp2));
2041
0
2042
0
                }
2043
0
            }
2044
0
            ps_left_mv_pred = ps_cur_mv_pred;
2045
0
            u4_bs_horz = (u4_bs_horz << 8) + uc_bs_horiz;
2046
0
        }
2047
0
        //Fill the HORIZ BS, only if valid i.e.,
2048
0
        //if it is a non-edge OR it is an edge, which is not yet filled
2049
0
        if(edge || (!edge && !u1_top_intra))
2050
0
            ui_bs_table[edge] = u4_bs_horz;
2051
0
    }
2052
0
}
2053
2054
/*!
2055
 **************************************************************************
2056
 * \if Function name : ih264d_fill_bs_for_extra_left_edge \endif
2057
 *
2058
 * \brief
2059
 *    Fills the boundary strength (Bs), for the top extra edge. ock
2060
 *
2061
 * \return
2062
 *    Returns the packed boundary strength(Bs)  MSB -> LSB Bs0|Bs1|Bs2|Bs3
2063
 *
2064
 **************************************************************************
2065
 */
2066
void ih264d_fill_bs_for_extra_left_edge(deblk_mb_t *ps_cur_deblk_mb,
2067
                                        deblk_mb_t *ps_leftDeblkMb,
2068
                                        UWORD8* puc_cur_nnz,
2069
                                        UWORD8 uc_botMb)
2070
0
{
2071
0
    /* Set the Flag in uc_deblocking_mode variable of current MB*/
2072
0
    /* for mixed mode edge*/
2073
0
    ps_cur_deblk_mb->u1_single_call = 0;
2074
0
2075
0
    if(ps_cur_deblk_mb->u1_mb_type & D_INTRA_MB)
2076
0
    {
2077
0
        ps_cur_deblk_mb->u4_bs_table[4] = 0x04040404;
2078
0
        ps_cur_deblk_mb->u4_bs_table[9] = 0x04040404;
2079
0
    }
2080
0
    else if((ps_leftDeblkMb->u1_mb_type & D_INTRA_MB)
2081
0
                    && ((ps_leftDeblkMb + 1)->u1_mb_type & D_INTRA_MB))
2082
0
    {
2083
0
        ps_cur_deblk_mb->u4_bs_table[4] = 0x04040404;
2084
0
        ps_cur_deblk_mb->u4_bs_table[9] = 0x04040404;
2085
0
    }
2086
0
    else
2087
0
    {
2088
0
        /* Get strengths of left MB edge */
2089
0
        UWORD32 u4_bs;
2090
0
        UWORD8 uc_Bs;
2091
0
        WORD32 i;
2092
0
        UWORD32 ui_curMbFld;
2093
0
        UWORD8 *puc_left_nnz;
2094
0
        UWORD32 ui_bs_left_edge[2];
2095
0
2096
0
        ui_curMbFld = (ps_cur_deblk_mb->u1_mb_type & D_FLD_MB) >> 7;
2097
0
2098
0
        puc_left_nnz = puc_cur_nnz - 29;
2099
0
        if((ui_curMbFld == 0) && uc_botMb)
2100
0
        {
2101
0
            puc_left_nnz -= 8;
2102
0
        }
2103
0
        else if(ui_curMbFld && uc_botMb)
2104
0
        {
2105
0
            puc_left_nnz -= 16;
2106
0
        }
2107
0
2108
0
        if(ui_curMbFld)
2109
0
        {
2110
0
            if(ps_leftDeblkMb->u1_mb_type & D_INTRA_MB)
2111
0
            {
2112
0
                ui_bs_left_edge[0] = 0x04040404;
2113
0
                puc_left_nnz += 16;
2114
0
                puc_cur_nnz += 8;
2115
0
            }
2116
0
            else
2117
0
            {
2118
0
                u4_bs = 0;
2119
0
                for(i = 4; i > 0; i--)
2120
0
                {
2121
0
                    uc_Bs = ((*puc_cur_nnz || *puc_left_nnz)) ? 2 : 1;
2122
0
                    u4_bs = (u4_bs << 8) | uc_Bs;
2123
0
                    puc_left_nnz += 4;
2124
0
                    if(i & 0x01)
2125
0
                        puc_cur_nnz += 4;
2126
0
                }
2127
0
                ui_bs_left_edge[0] = u4_bs;
2128
0
            }
2129
0
2130
0
            if((ps_leftDeblkMb + 1)->u1_mb_type & D_INTRA_MB)
2131
0
            {
2132
0
                ui_bs_left_edge[1] = 0x04040404;
2133
0
            }
2134
0
            else
2135
0
            {
2136
0
                u4_bs = 0;
2137
0
                for(i = 4; i > 0; i--)
2138
0
                {
2139
0
                    uc_Bs = ((*puc_cur_nnz || *puc_left_nnz)) ? 2 : 1;
2140
0
                    u4_bs = (u4_bs << 8) | uc_Bs;
2141
0
                    puc_left_nnz += 4;
2142
0
                    if(i & 0x01)
2143
0
                        puc_cur_nnz += 4;
2144
0
                }
2145
0
                ui_bs_left_edge[1] = u4_bs;
2146
0
            }
2147
0
        }
2148
0
        else
2149
0
        {
2150
0
            UWORD8 *puc_curNnzB, *puc_leftNnzB;
2151
0
            puc_curNnzB = puc_cur_nnz;
2152
0
            puc_leftNnzB = puc_left_nnz + 16;
2153
0
            if(ps_leftDeblkMb->u1_mb_type & D_INTRA_MB)
2154
0
            {
2155
0
                ui_bs_left_edge[0] = 0x04040404;
2156
0
            }
2157
0
            else
2158
0
            {
2159
0
                u4_bs = 0;
2160
0
                for(i = 4; i > 0; i--, puc_cur_nnz += 4)
2161
0
                {
2162
0
                    uc_Bs = ((*puc_cur_nnz || *puc_left_nnz)) ? 2 : 1;
2163
0
                    u4_bs = (u4_bs << 8) | uc_Bs;
2164
0
                    if(i & 0x01)
2165
0
                        puc_left_nnz += 4;
2166
0
                }
2167
0
                ui_bs_left_edge[0] = u4_bs;
2168
0
            }
2169
0
2170
0
            if((ps_leftDeblkMb + 1)->u1_mb_type & D_INTRA_MB)
2171
0
            {
2172
0
                ui_bs_left_edge[1] = 0x04040404;
2173
0
            }
2174
0
            else
2175
0
            {
2176
0
                u4_bs = 0;
2177
0
                for(i = 4; i > 0; i--, puc_curNnzB += 4)
2178
0
                {
2179
0
                    uc_Bs = ((*puc_curNnzB || *puc_leftNnzB)) ? 2 : 1;
2180
0
                    u4_bs = (u4_bs << 8) | uc_Bs;
2181
0
                    if(i & 0x01)
2182
0
                        puc_leftNnzB += 4;
2183
0
                }
2184
0
                ui_bs_left_edge[1] = u4_bs;
2185
0
            }
2186
0
        }
2187
0
        /* Copy The Values in Cur Deblk Mb Parameters */
2188
0
        ps_cur_deblk_mb->u4_bs_table[4] = ui_bs_left_edge[0];
2189
0
        ps_cur_deblk_mb->u4_bs_table[9] = ui_bs_left_edge[1];
2190
0
    }
2191
0
2192
0
}
2193
2194
/*!
2195
 **************************************************************************
2196
 * \if Function name : ih264d_fill_bs_for_extra_top_edge \endif
2197
 *
2198
 * \brief
2199
 *    Fills the boundary strength (Bs), for the top extra edge. ock
2200
 *
2201
 * \return
2202
 *    Returns the packed boundary strength(Bs)  MSB -> LSB Bs0|Bs1|Bs2|Bs3
2203
 *
2204
 **************************************************************************
2205
 */
2206
void ih264d_fill_bs_for_extra_top_edge(deblk_mb_t *ps_cur_mb_params,
2207
                                       UWORD8 u1_Edge0_mb_typ,
2208
                                       UWORD8 u1_Edge1_mb_typ,
2209
                                       UWORD8 *pu1_curNnz,
2210
                                       UWORD8 *pu1_topNnz)
2211
0
{
2212
0
    UWORD32 u4_bs;
2213
0
    UWORD8 uc_Bs;
2214
0
    WORD32 i;
2215
0
    UWORD8 *pu1_cur_nnz_tmp;
2216
0
    UWORD8 *pu1_top_nnz_tmp;
2217
0
    UWORD8 u1_top_edge;
2218
0
    UWORD8 u1_top_mb_type;
2219
0
    for(u1_top_edge = 0; u1_top_edge < 2; u1_top_edge++)
2220
0
    {
2221
0
        u1_top_mb_type = u1_top_edge ? u1_Edge1_mb_typ : u1_Edge0_mb_typ;
2222
0
        pu1_cur_nnz_tmp = pu1_curNnz;
2223
0
        pu1_top_nnz_tmp = pu1_topNnz + (u1_top_edge << 2);
2224
0
2225
0
        if((ps_cur_mb_params->u1_mb_type & D_INTRA_MB)
2226
0
                        + (u1_top_mb_type & D_INTRA_MB))
2227
0
        {
2228
0
            u4_bs = 0x03030303;
2229
0
        }
2230
0
        else
2231
0
        {
2232
0
            u4_bs = 0;
2233
0
            for(i = 4; i > 0; i--, pu1_cur_nnz_tmp += 1, pu1_top_nnz_tmp += 1)
2234
0
            {
2235
0
                uc_Bs = ((*pu1_cur_nnz_tmp || *pu1_top_nnz_tmp)) ? 2 : 1;
2236
0
                u4_bs = (u4_bs << 8) | uc_Bs;
2237
0
            }
2238
0
        }
2239
0
        if(u1_top_edge)
2240
0
            ps_cur_mb_params->u4_bs_table[0] = u4_bs;
2241
0
        else
2242
0
            ps_cur_mb_params->u4_bs_table[8] = u4_bs;
2243
0
    }
2244
0
}
2245
2246
2247
void ih264d_fill_bs_mbedge_4(dec_struct_t * ps_dec,
2248
                             dec_mb_info_t * ps_cur_mb_info,
2249
                             const UWORD16 u2_mbxn_mb)
2250
0
{
2251
0
2252
0
    /* deblk_mb_t Params */
2253
0
    deblk_mb_t *ps_cur_mb_params; /*< Parameters of current MacroBlock */
2254
0
    deblkmb_neighbour_t *ps_deblk_top_mb;
2255
0
    UWORD32 * pu4_bs_table;
2256
0
    UWORD8 u1_cur_mb_type;
2257
0
2258
0
    /* Neighbour availability */
2259
0
    /* Initialization */
2260
0
    const UWORD32 u2_mbx = ps_cur_mb_info->u2_mbx;
2261
0
    const UWORD32 u2_mby = ps_cur_mb_info->u2_mby;
2262
0
    const UWORD32 u1_pingpong = u2_mbx & 0x01;
2263
0
    ps_deblk_top_mb = ps_dec->ps_deblk_top_mb + u2_mbx;
2264
0
2265
0
2266
0
    /* Pointer assignment for Current DeblkMB, Current Mv Pred  */
2267
0
    ps_cur_mb_params = ps_dec->ps_deblk_mbn + u2_mbxn_mb;
2268
0
2269
0
    u1_cur_mb_type = ps_cur_mb_params->u1_mb_type;
2270
0
2271
0
    ps_deblk_top_mb->u1_mb_type = u1_cur_mb_type;
2272
0
2273
0
    {
2274
0
        UWORD8 mb_qp_temp;
2275
0
2276
0
        ps_cur_mb_params->u1_topmb_qp = ps_deblk_top_mb->u1_mb_qp;
2277
0
        ps_deblk_top_mb->u1_mb_qp = ps_cur_mb_params->u1_mb_qp;
2278
0
2279
0
        ps_cur_mb_params->u1_left_mb_qp = ps_dec->deblk_left_mb[1].u1_mb_qp;
2280
0
        ps_dec->deblk_left_mb[1].u1_mb_qp = ps_cur_mb_params->u1_mb_qp;
2281
0
2282
0
    }
2283
0
2284
0
    ps_cur_mb_params->u1_single_call = 1;
2285
0
2286
0
    ps_dec->deblk_left_mb[1].u1_mb_type = ps_cur_mb_params->u1_mb_type;
2287
0
    /* if no deblocking required for current Mb then continue */
2288
0
    /* Check next Mbs   in Mb group                           */
2289
0
    if(ps_cur_mb_params->u1_deblocking_mode & MB_DISABLE_FILTERING)
2290
0
    {
2291
0
        /* Storing the leftMbtype for next Mb */
2292
0
        return;
2293
0
    }
2294
0
2295
0
    /* Compute BS function */
2296
0
    pu4_bs_table = ps_cur_mb_params->u4_bs_table;
2297
0
2298
0
    pu4_bs_table[4] = 0x04040404;
2299
0
    pu4_bs_table[0] = 0x04040404;
2300
0
    pu4_bs_table[1] = 0;
2301
0
    pu4_bs_table[2] = 0;
2302
0
    pu4_bs_table[3] = 0;
2303
0
    pu4_bs_table[5] = 0;
2304
0
    pu4_bs_table[6] = 0;
2305
0
    pu4_bs_table[7] = 0;
2306
0
2307
0
}
2308
2309
void ih264d_fill_bs_mbedge_2(dec_struct_t * ps_dec,
2310
                             dec_mb_info_t * ps_cur_mb_info,
2311
                             const UWORD16 u2_mbxn_mb)
2312
0
{
2313
0
2314
0
    /* deblk_mb_t Params */
2315
0
    deblk_mb_t *ps_cur_mb_params; /*< Parameters of current MacroBlock */
2316
0
    deblkmb_neighbour_t *ps_deblk_top_mb;
2317
0
    UWORD32 * pu4_bs_table;
2318
0
    UWORD8 u1_cur_mb_type;
2319
0
2320
0
    /* Neighbour availability */
2321
0
    /* Initialization */
2322
0
    const UWORD32 u2_mbx = ps_cur_mb_info->u2_mbx;
2323
0
    const UWORD32 u2_mby = ps_cur_mb_info->u2_mby;
2324
0
    const UWORD32 u1_pingpong = u2_mbx & 0x01;
2325
0
    ps_deblk_top_mb = ps_dec->ps_deblk_top_mb + u2_mbx;
2326
0
2327
0
2328
0
    /* Pointer assignment for Current DeblkMB, Current Mv Pred  */
2329
0
    ps_cur_mb_params = ps_dec->ps_deblk_mbn + u2_mbxn_mb;
2330
0
2331
0
    u1_cur_mb_type = ps_cur_mb_params->u1_mb_type;
2332
0
2333
0
    ps_deblk_top_mb->u1_mb_type = u1_cur_mb_type;
2334
0
2335
0
    {
2336
0
        UWORD8 mb_qp_temp;
2337
0
2338
0
        ps_cur_mb_params->u1_topmb_qp = ps_deblk_top_mb->u1_mb_qp;
2339
0
        ps_deblk_top_mb->u1_mb_qp = ps_cur_mb_params->u1_mb_qp;
2340
0
2341
0
        ps_cur_mb_params->u1_left_mb_qp = ps_dec->deblk_left_mb[1].u1_mb_qp;
2342
0
        ps_dec->deblk_left_mb[1].u1_mb_qp = ps_cur_mb_params->u1_mb_qp;
2343
0
2344
0
    }
2345
0
2346
0
    ps_cur_mb_params->u1_single_call = 1;
2347
0
2348
0
    ps_dec->deblk_left_mb[1].u1_mb_type = ps_cur_mb_params->u1_mb_type;
2349
0
    /* if no deblocking required for current Mb then continue */
2350
0
    /* Check next Mbs   in Mb group                           */
2351
0
    if(ps_cur_mb_params->u1_deblocking_mode & MB_DISABLE_FILTERING)
2352
0
    {
2353
0
        /* Storing the leftMbtype for next Mb */
2354
0
        return;
2355
0
    }
2356
0
2357
0
    /* Compute BS function */
2358
0
    pu4_bs_table = ps_cur_mb_params->u4_bs_table;
2359
0
2360
0
    {
2361
0
        UWORD32 top_mb_csbp, left_mb_csbp, cur_mb_csbp;
2362
0
        UWORD32 top_edge, left_edge;
2363
0
2364
0
        top_mb_csbp = ps_cur_mb_info->ps_top_mb->u2_luma_csbp;
2365
0
        left_mb_csbp = ps_cur_mb_info->ps_left_mb->u2_luma_csbp;
2366
0
        cur_mb_csbp = ps_cur_mb_info->ps_curmb->u2_luma_csbp;
2367
0
2368
0
        top_mb_csbp = top_mb_csbp >> 12;
2369
0
        top_edge = top_mb_csbp | (cur_mb_csbp & 0xf);
2370
0
2371
0
        if(top_edge)
2372
0
            pu4_bs_table[0] = 0x02020202;
2373
0
        else
2374
0
            pu4_bs_table[0] = 0;
2375
0
2376
0
        cur_mb_csbp = cur_mb_csbp & CSBP_LEFT_BLOCK_MASK;
2377
0
        left_mb_csbp = left_mb_csbp & CSBP_RIGHT_BLOCK_MASK;
2378
0
2379
0
        left_edge = cur_mb_csbp | left_mb_csbp;
2380
0
2381
0
        if(left_edge)
2382
0
            pu4_bs_table[4] = 0x02020202;
2383
0
        else
2384
0
            pu4_bs_table[4] = 0;
2385
0
2386
0
        pu4_bs_table[1] = 0;
2387
0
        pu4_bs_table[2] = 0;
2388
0
        pu4_bs_table[3] = 0;
2389
0
        pu4_bs_table[5] = 0;
2390
0
        pu4_bs_table[6] = 0;
2391
0
        pu4_bs_table[7] = 0;
2392
0
    }
2393
0
2394
0
}
/proc/self/cwd/external/libavc/decoder/ih264d_deblocking.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
21
#include <string.h>
22
23
#include "ih264_typedefs.h"
24
#include "iv.h"
25
#include "ivd.h"
26
#include "ih264_macros.h"
27
#include "ih264_platform_macros.h"
28
#include "ih264d_debug.h"
29
#include "ih264d_defs.h"
30
#include "ih264d_defs.h"
31
#include "ih264d_structs.h"
32
#include "ih264d_deblocking.h"
33
#include "ih264d_mb_utils.h"
34
#include "ih264d_error_handler.h"
35
#include "ih264d_utils.h"
36
37
38
#include "ih264d_defs.h"
39
#include "ih264d_format_conv.h"
40
#include "ih264d_deblocking.h"
41
#include "ih264d_tables.h"
42
43
/*!
44
 *************************************************************************
45
 * \file ih264d_deblocking.c
46
 *
47
 * \brief
48
 *    Decoder specific deblocking routines
49
 *
50
 * \author AI
51
 *************************************************************************
52
 */
53
54
/*!
55
 **************************************************************************
56
 * \if Function name : HorizonPad \endif
57
 *
58
 * \brief
59
 *    Does the Horizontal padding on a whole pic.
60
 *
61
 * \return
62
 *    None
63
 **************************************************************************
64
 */
65
66
/*!
67
 **************************************************************************
68
 * \if Function name : FilterBoundaryLeft \endif
69
 *
70
 * \brief
71
 *    Filters MacroBlock Left Boundary egdes.
72
 *
73
 * \return
74
 *    None
75
 **************************************************************************
76
 */
77
void ih264d_filter_boundary_left_nonmbaff(dec_struct_t *ps_dec,
78
                                          tfr_ctxt_t * ps_tfr_cxt,
79
                                          WORD8 i1_cb_qp_idx_ofst,
80
                                          WORD8 i1_cr_qp_idx_ofst,
81
                                          deblk_mb_t * ps_cur_mb,
82
                                          WORD32 i4_strd_y,
83
                                          WORD32 i4_strd_uv,
84
                                          deblk_mb_t * ps_left_mb,
85
                                          UWORD32 pu4_bs_tab[],
86
                                          UWORD8 u1_cur_fld)
87
4.84k
{
88
4.84k
    UWORD8 *pu1_y, *pu1_u, *pu1_v;
89
4.84k
    WORD32 uc_tmp, qp_avg;
90
4.84k
    WORD32 alpha_u = 0, beta_u = 0, alpha_v = 0, beta_v = 0;
91
4.84k
    WORD32 alpha_y = 0, beta_y = 0;
92
4.84k
93
4.84k
    WORD32 idx_b_u, idx_a_u, idx_b_v, idx_a_v;
94
4.84k
    WORD32 idx_b_y, idx_a_y;
95
4.84k
96
4.84k
    UWORD32 u4_bs_val;
97
4.84k
98
4.84k
    UWORD8 *pu1_cliptab_u, *pu1_cliptab_v, *pu1_cliptab_y;
99
4.84k
100
4.84k
    UWORD8 u1_double_cl = !ps_cur_mb->u1_single_call;
101
4.84k
    WORD32 ofst_a = ps_cur_mb->i1_slice_alpha_c0_offset;
102
4.84k
    WORD32 ofst_b = ps_cur_mb->i1_slice_beta_offset;
103
4.84k
104
4.84k
    PROFILE_DISABLE_DEBLK()
105
4.84k
106
4.84k
    pu1_y = ps_tfr_cxt->pu1_mb_y;
107
4.84k
    pu1_u = ps_tfr_cxt->pu1_mb_u;
108
4.84k
    pu1_v = ps_tfr_cxt->pu1_mb_v;
109
4.84k
110
4.84k
    /* LUMA values */
111
4.84k
    /* Deblock rounding change */
112
4.84k
    qp_avg =
113
4.84k
                    (UWORD8)((ps_cur_mb->u1_left_mb_qp + ps_cur_mb->u1_mb_qp + 1)
114
4.84k
                                    >> 1);
115
4.84k
116
4.84k
    idx_a_y = qp_avg + ofst_a;
117
4.84k
    alpha_y = gau1_ih264d_alpha_table[12 + idx_a_y];
118
4.84k
    idx_b_y = qp_avg + ofst_b;
119
4.84k
    beta_y = gau1_ih264d_beta_table[12 + idx_b_y];
120
4.84k
121
4.84k
    /* Chroma cb values */
122
4.84k
    {
123
4.84k
        WORD32 mb_qp1, mb_qp2;
124
4.84k
        mb_qp1 = (ps_cur_mb->u1_left_mb_qp + i1_cb_qp_idx_ofst);
125
4.84k
        mb_qp2 = (ps_cur_mb->u1_mb_qp + i1_cb_qp_idx_ofst);
126
4.84k
        qp_avg = (UWORD8)((gau1_ih264d_qp_scale_cr[12 + mb_qp1]
127
4.84k
                        + gau1_ih264d_qp_scale_cr[12 + mb_qp2] + 1) >> 1);
128
4.84k
    }
129
4.84k
    idx_a_u = qp_avg + ofst_a;
130
4.84k
    alpha_u = gau1_ih264d_alpha_table[12 + idx_a_u];
131
4.84k
    idx_b_u = qp_avg + ofst_b;
132
4.84k
    beta_u = gau1_ih264d_beta_table[12 + idx_b_u];
133
4.84k
    /* Chroma cr values */
134
4.84k
    {
135
4.84k
        WORD32 mb_qp1, mb_qp2;
136
4.84k
        mb_qp1 = (ps_cur_mb->u1_left_mb_qp + i1_cr_qp_idx_ofst);
137
4.84k
        mb_qp2 = (ps_cur_mb->u1_mb_qp + i1_cr_qp_idx_ofst);
138
4.84k
        qp_avg = (UWORD8)((gau1_ih264d_qp_scale_cr[12 + mb_qp1]
139
4.84k
                        + gau1_ih264d_qp_scale_cr[12 + mb_qp2] + 1) >> 1);
140
4.84k
    }
141
4.84k
    idx_a_v = qp_avg + ofst_a;
142
4.84k
    alpha_v = gau1_ih264d_alpha_table[12 + idx_a_v];
143
4.84k
    idx_b_v = qp_avg + ofst_b;
144
4.84k
    beta_v = gau1_ih264d_beta_table[12 + idx_b_v];
145
4.84k
146
4.84k
    if(u1_double_cl == 0)
147
4.84k
    {
148
4.84k
        u4_bs_val = pu4_bs_tab[4];
149
4.84k
150
4.84k
        if(0x04040404 == u4_bs_val)
151
4.84k
        {
152
4.84k
            ps_dec->pf_deblk_luma_vert_bs4(pu1_y, i4_strd_y, alpha_y, beta_y);
153
4.84k
            ps_dec->pf_deblk_chroma_vert_bs4(pu1_u, i4_strd_uv, alpha_u,
154
4.84k
                                             beta_u, alpha_v, beta_v);
155
4.84k
        }
156
0
        else
157
0
        {
158
0
            if(u4_bs_val)
159
0
            {
160
0
161
0
                pu1_cliptab_y = (UWORD8 *)&gau1_ih264d_clip_table[12 + idx_a_y];
162
0
                pu1_cliptab_u = (UWORD8 *)&gau1_ih264d_clip_table[12 + idx_a_u];
163
0
                pu1_cliptab_v = (UWORD8 *)&gau1_ih264d_clip_table[12 + idx_a_v];
164
0
                ps_dec->pf_deblk_luma_vert_bslt4(pu1_y, i4_strd_y, alpha_y,
165
0
                                                 beta_y, u4_bs_val,
166
0
                                                 pu1_cliptab_y);
167
0
                ps_dec->pf_deblk_chroma_vert_bslt4(pu1_u, i4_strd_uv, alpha_u,
168
0
                                                   beta_u, alpha_v, beta_v,
169
0
                                                   u4_bs_val, pu1_cliptab_u,
170
0
                                                   pu1_cliptab_v);
171
0
172
0
            }
173
0
        }
174
4.84k
175
4.84k
    }
176
0
    else
177
0
    {
178
0
179
0
        i4_strd_y <<= (!u1_cur_fld);
180
0
        u4_bs_val = pu4_bs_tab[4];
181
0
        i4_strd_uv <<= (!u1_cur_fld);
182
0
183
0
        if(0x04040404 == u4_bs_val)
184
0
        {
185
0
186
0
            ps_dec->pf_deblk_luma_vert_bs4_mbaff(pu1_y, i4_strd_y, alpha_y,
187
0
                                                 beta_y);
188
0
            ps_dec->pf_deblk_chroma_vert_bs4_mbaff(pu1_u, i4_strd_uv, alpha_u,
189
0
                                                   beta_u, alpha_v, beta_v);
190
0
191
0
        }
192
0
        else
193
0
        {
194
0
            if(u4_bs_val)
195
0
            {
196
0
197
0
                pu1_cliptab_y = (UWORD8 *)&gau1_ih264d_clip_table[12 + idx_a_y];
198
0
                pu1_cliptab_u = (UWORD8 *)&gau1_ih264d_clip_table[12 + idx_a_u];
199
0
                pu1_cliptab_v = (UWORD8 *)&gau1_ih264d_clip_table[12 + idx_a_v];
200
0
201
0
                ps_dec->pf_deblk_luma_vert_bslt4_mbaff(pu1_y, i4_strd_y,
202
0
                                                       alpha_y, beta_y,
203
0
                                                       u4_bs_val,
204
0
                                                       pu1_cliptab_y);
205
0
                ps_dec->pf_deblk_chroma_vert_bslt4_mbaff(pu1_u, i4_strd_uv,
206
0
                                                         alpha_u, beta_u,
207
0
                                                         alpha_v, beta_v,
208
0
                                                         u4_bs_val,
209
0
                                                         pu1_cliptab_u,
210
0
                                                         pu1_cliptab_v);
211
0
            }
212
0
        }
213
0
214
0
        {
215
0
216
0
            UWORD16 u2_shift = (i4_strd_y >> 1) << (u1_cur_fld ? 4 : 0);
217
0
            pu1_y += u2_shift;
218
0
            u2_shift = (i4_strd_uv >> 1) << (u1_cur_fld ? 3 : 0);
219
0
            pu1_u += u2_shift;
220
0
            pu1_v += u2_shift;
221
0
        }
222
0
223
0
        qp_avg = (((ps_left_mb + 1)->u1_mb_qp + ps_cur_mb->u1_mb_qp + 1) >> 1);
224
0
225
0
        idx_a_y = qp_avg + ofst_a;
226
0
        alpha_y = gau1_ih264d_alpha_table[12 + idx_a_y];
227
0
        idx_b_y = qp_avg + ofst_b;
228
0
        beta_y = gau1_ih264d_beta_table[12 + idx_b_y];
229
0
        u4_bs_val = pu4_bs_tab[9];
230
0
231
0
        {
232
0
            WORD32 mb_qp1, mb_qp2;
233
0
            mb_qp1 = ((ps_left_mb + 1)->u1_mb_qp + i1_cb_qp_idx_ofst);
234
0
            mb_qp2 = (ps_cur_mb->u1_mb_qp + i1_cb_qp_idx_ofst);
235
0
            qp_avg = (UWORD8)((gau1_ih264d_qp_scale_cr[12 + mb_qp1]
236
0
                            + gau1_ih264d_qp_scale_cr[12 + mb_qp2] + 1) >> 1);
237
0
        }
238
0
        idx_a_u = qp_avg + ofst_a;
239
0
        alpha_u = gau1_ih264d_alpha_table[12 + idx_a_u];
240
0
        idx_b_u = qp_avg + ofst_b;
241
0
        beta_u = gau1_ih264d_beta_table[12 + idx_b_u];
242
0
        u4_bs_val = pu4_bs_tab[9];
243
0
        {
244
0
            WORD32 mb_qp1, mb_qp2;
245
0
            mb_qp1 = ((ps_left_mb + 1)->u1_mb_qp + i1_cr_qp_idx_ofst);
246
0
            mb_qp2 = (ps_cur_mb->u1_mb_qp + i1_cr_qp_idx_ofst);
247
0
            qp_avg = (UWORD8)((gau1_ih264d_qp_scale_cr[12 + mb_qp1]
248
0
                            + gau1_ih264d_qp_scale_cr[12 + mb_qp2] + 1) >> 1);
249
0
        }
250
0
        idx_a_v = qp_avg + ofst_a;
251
0
        alpha_v = gau1_ih264d_alpha_table[12 + idx_a_v];
252
0
        idx_b_v = qp_avg + ofst_b;
253
0
        beta_v = gau1_ih264d_beta_table[12 + idx_b_v];
254
0
255
0
        if(0x04040404 == u4_bs_val)
256
0
        {
257
0
            ps_dec->pf_deblk_luma_vert_bs4_mbaff(pu1_y, i4_strd_y, alpha_y,
258
0
                                                 beta_y);
259
0
            ps_dec->pf_deblk_chroma_vert_bs4_mbaff(pu1_u, i4_strd_uv, alpha_u,
260
0
                                                   beta_u, alpha_v, beta_v);
261
0
262
0
        }
263
0
        else
264
0
        {
265
0
            if(u4_bs_val)
266
0
            {
267
0
268
0
                pu1_cliptab_y = (UWORD8 *)&gau1_ih264d_clip_table[12 + idx_a_y];
269
0
                pu1_cliptab_u = (UWORD8 *)&gau1_ih264d_clip_table[12 + idx_a_u];
270
0
                pu1_cliptab_v = (UWORD8 *)&gau1_ih264d_clip_table[12 + idx_a_v];
271
0
272
0
                ps_dec->pf_deblk_luma_vert_bslt4_mbaff(pu1_y, i4_strd_y,
273
0
                                                       alpha_y, beta_y,
274
0
                                                       u4_bs_val,
275
0
                                                       pu1_cliptab_y);
276
0
                ps_dec->pf_deblk_chroma_vert_bslt4_mbaff(pu1_u, i4_strd_uv,
277
0
                                                         alpha_u, beta_u,
278
0
                                                         alpha_v, beta_v,
279
0
                                                         u4_bs_val,
280
0
                                                         pu1_cliptab_u,
281
0
                                                         pu1_cliptab_v);
282
0
283
0
            }
284
0
        }
285
0
    }
286
4.84k
287
4.84k
}
288
289
/*!
290
 **************************************************************************
291
 * \if Function name : FilterBoundaryTop \endif
292
 *
293
 * \brief
294
 *    Filters MacroBlock Top Boundary egdes.
295
 *
296
 * \return
297
 *    None
298
 **************************************************************************
299
 */
300
301
void ih264d_filter_boundary_top_nonmbaff(dec_struct_t *ps_dec,
302
                                         tfr_ctxt_t * ps_tfr_cxt,
303
                                         WORD8 i1_cb_qp_idx_ofst,
304
                                         WORD8 i1_cr_qp_idx_ofst,
305
                                         deblk_mb_t * ps_cur_mb,
306
                                         WORD32 i4_strd_y,
307
                                         WORD32 i4_strd_uv,
308
                                         deblk_mb_t * ps_top_mb,
309
                                         UWORD32 u4_bs)
310
4.80k
{
311
4.80k
    UWORD8 *pu1_y, *pu1_u;
312
4.80k
    WORD32 alpha_u = 0, beta_u = 0, alpha_v = 0, beta_v = 0;
313
4.80k
    WORD32 alpha_y = 0, beta_y = 0;
314
4.80k
    WORD32 qp_avg;
315
4.80k
    WORD32 idx_b_u, idx_a_u, idx_b_v, idx_a_v;
316
4.80k
    WORD32 idx_b_y, idx_a_y;
317
4.80k
    UWORD16 uc_tmp;
318
4.80k
319
4.80k
    UWORD8 *pu1_cliptab_u, *pu1_cliptab_v, *pu1_cliptab_y;
320
4.80k
    WORD32 ofst_a = ps_cur_mb->i1_slice_alpha_c0_offset;
321
4.80k
    WORD32 ofst_b = ps_cur_mb->i1_slice_beta_offset;
322
4.80k
323
4.80k
    UNUSED(ps_top_mb);
324
4.80k
    /* LUMA values */
325
4.80k
    /* Deblock rounding change */
326
4.80k
    uc_tmp = ((ps_cur_mb->u1_topmb_qp + ps_cur_mb->u1_mb_qp + 1) >> 1);
327
4.80k
    qp_avg = (UWORD8)uc_tmp;
328
4.80k
    idx_a_y = qp_avg + ofst_a;
329
4.80k
    alpha_y = gau1_ih264d_alpha_table[12 + idx_a_y];
330
4.80k
    idx_b_y = qp_avg + ofst_b;
331
4.80k
    beta_y = gau1_ih264d_beta_table[12 + idx_b_y];
332
4.80k
    pu1_y = ps_tfr_cxt->pu1_mb_y;
333
4.80k
334
4.80k
    /* CHROMA cb values */
335
4.80k
    {
336
4.80k
        WORD32 mb_qp1, mb_qp2;
337
4.80k
        mb_qp1 = (ps_cur_mb->u1_topmb_qp + i1_cb_qp_idx_ofst);
338
4.80k
        mb_qp2 = (ps_cur_mb->u1_mb_qp + i1_cb_qp_idx_ofst);
339
4.80k
        qp_avg = (UWORD8)((gau1_ih264d_qp_scale_cr[12 + mb_qp1]
340
4.80k
                        + gau1_ih264d_qp_scale_cr[12 + mb_qp2] + 1) >> 1);
341
4.80k
    }
342
4.80k
343
4.80k
    idx_a_u = qp_avg + ofst_a;
344
4.80k
    alpha_u = gau1_ih264d_alpha_table[12 + idx_a_u];
345
4.80k
    idx_b_u = qp_avg + ofst_b;
346
4.80k
    beta_u = gau1_ih264d_beta_table[12 + idx_b_u];
347
4.80k
    /* CHROMA cr values */
348
4.80k
    {
349
4.80k
        WORD32 mb_qp1, mb_qp2;
350
4.80k
        mb_qp1 = (ps_cur_mb->u1_topmb_qp + i1_cr_qp_idx_ofst);
351
4.80k
        mb_qp2 = (ps_cur_mb->u1_mb_qp + i1_cr_qp_idx_ofst);
352
4.80k
        qp_avg = (UWORD8)((gau1_ih264d_qp_scale_cr[12 + mb_qp1]
353
4.80k
                        + gau1_ih264d_qp_scale_cr[12 + mb_qp2] + 1) >> 1);
354
4.80k
    }
355
4.80k
356
4.80k
    idx_a_v = qp_avg + ofst_a;
357
4.80k
    alpha_v = gau1_ih264d_alpha_table[12 + idx_a_v];
358
4.80k
    idx_b_v = qp_avg + ofst_b;
359
4.80k
    beta_v = gau1_ih264d_beta_table[12 + idx_b_v];
360
4.80k
    pu1_u = ps_tfr_cxt->pu1_mb_u;
361
4.80k
362
4.80k
    if(u4_bs == 0x04040404)
363
4.80k
    {
364
4.80k
        /* Code specific to the assembly module */
365
4.80k
366
4.80k
        ps_dec->pf_deblk_luma_horz_bs4(pu1_y, i4_strd_y, alpha_y, beta_y);
367
4.80k
        ps_dec->pf_deblk_chroma_horz_bs4(pu1_u, i4_strd_uv, alpha_u, beta_u,
368
4.80k
                                         alpha_v, beta_v);
369
4.80k
    }
370
0
    else
371
0
    {
372
0
        if(u4_bs)
373
0
        {
374
0
375
0
            pu1_cliptab_y = (UWORD8 *)&gau1_ih264d_clip_table[12 + idx_a_y];
376
0
            pu1_cliptab_u =
377
0
                            (UWORD8 *)&gau1_ih264d_clip_table[12 + idx_a_u];
378
0
            pu1_cliptab_v =
379
0
                            (UWORD8 *)&gau1_ih264d_clip_table[12 + idx_a_v];
380
0
381
0
            ps_dec->pf_deblk_luma_horz_bslt4(pu1_y, i4_strd_y, alpha_y, beta_y,
382
0
                                             u4_bs, pu1_cliptab_y);
383
0
            ps_dec->pf_deblk_chroma_horz_bslt4(pu1_u, i4_strd_uv, alpha_u,
384
0
                                               beta_u, alpha_v, beta_v,
385
0
                                               u4_bs, pu1_cliptab_u,
386
0
                                               pu1_cliptab_v);
387
0
388
0
        }
389
0
    }
390
4.80k
391
4.80k
}
392
393
void ih264d_deblock_mb_nonmbaff(dec_struct_t *ps_dec,
394
                                tfr_ctxt_t * ps_tfr_cxt,
395
                                WORD8 i1_cb_qp_idx_ofst,
396
                                WORD8 i1_cr_qp_idx_ofst,
397
                                WORD32 i4_strd_y,
398
                                WORD32 i4_strd_uv )
399
5.06k
{
400
5.06k
    UWORD8 *pu1_y, *pu1_u;
401
5.06k
    UWORD32 u4_bs;
402
5.06k
403
5.06k
    WORD32 alpha, beta, alpha_u, beta_u, alpha_v, beta_v;
404
5.06k
405
5.06k
    UWORD8 *pu1_cliptab_u;
406
5.06k
    UWORD8 *pu1_cliptab_v;
407
5.06k
    UWORD8 *pu1_cliptab_y;
408
5.06k
409
5.06k
    UWORD32 * pu4_bs_tab;
410
5.06k
    WORD32 idx_a_y, idx_a_u, idx_a_v;
411
5.06k
    UWORD32 u4_deb_mode, u4_mbs_next;
412
5.06k
    UWORD32 u4_image_wd_mb;
413
5.06k
    deblk_mb_t *ps_top_mb,*ps_left_mb,*ps_cur_mb;
414
5.06k
415
5.06k
    PROFILE_DISABLE_DEBLK()
416
5.06k
    /* Return from here to switch off deblocking */
417
5.06k
418
5.06k
    u4_image_wd_mb = ps_dec->u2_frm_wd_in_mbs;
419
5.06k
420
5.06k
    ps_cur_mb = ps_dec->ps_cur_deblk_mb;
421
5.06k
    pu4_bs_tab = ps_cur_mb->u4_bs_table;
422
5.06k
    u4_deb_mode = ps_cur_mb->u1_deblocking_mode;
423
5.06k
     if(!(u4_deb_mode & MB_DISABLE_FILTERING))
424
5.06k
     {
425
5.06k
426
5.06k
         if(ps_dec->u4_deblk_mb_x)
427
4.84k
         {
428
4.84k
             ps_left_mb = ps_cur_mb - 1;
429
4.84k
430
4.84k
         }
431
220
         else
432
220
         {
433
220
             ps_left_mb = NULL;
434
220
435
220
         }
436
5.06k
         if(ps_dec->u4_deblk_mb_y != 0)
437
4.80k
         {
438
4.80k
             ps_top_mb = ps_cur_mb - (u4_image_wd_mb);
439
4.80k
         }
440
253
         else
441
253
         {
442
253
             ps_top_mb = NULL;
443
253
         }
444
5.06k
445
5.06k
         if(u4_deb_mode & MB_DISABLE_LEFT_EDGE)
446
5.06k
             ps_left_mb = NULL;
447
5.06k
         if(u4_deb_mode & MB_DISABLE_TOP_EDGE)
448
5.06k
             ps_top_mb = NULL;
449
5.06k
450
5.06k
        /*---------------------------------------------------------------------*/
451
5.06k
        /* Filter wrt Left edge                                                */
452
5.06k
        /* except                                                              */
453
5.06k
        /*      - Left Egde is Picture Boundary                                */
454
5.06k
        /*      - Left Egde is part of Slice Boundary and Deblocking           */
455
5.06k
        /*        parameters of slice disable Filtering of Slice Boundary Edges*/
456
5.06k
        /*---------------------------------------------------------------------*/
457
5.06k
        if(ps_left_mb)
458
4.84k
            ih264d_filter_boundary_left_nonmbaff(ps_dec, ps_tfr_cxt,
459
4.84k
                                                 i1_cb_qp_idx_ofst,
460
4.84k
                                                 i1_cr_qp_idx_ofst, ps_cur_mb,
461
4.84k
                                                 i4_strd_y, i4_strd_uv, ps_left_mb,
462
4.84k
                                                 pu4_bs_tab, 0);
463
5.06k
464
5.06k
        /*--------------------------------------------------------------------*/
465
5.06k
        /* Filter wrt Other Vertical Edges                                    */
466
5.06k
        /*--------------------------------------------------------------------*/
467
5.06k
        {
468
5.06k
            WORD32 ofst_a, ofst_b, idx_b_y, idx_b_u,
469
5.06k
                            idx_b_v;
470
5.06k
            WORD32 qp_avg, qp_avg_u, qp_avg_v;
471
5.06k
            ofst_a = ps_cur_mb->i1_slice_alpha_c0_offset;
472
5.06k
            ofst_b = ps_cur_mb->i1_slice_beta_offset;
473
5.06k
474
5.06k
            qp_avg = ps_cur_mb->u1_mb_qp;
475
5.06k
476
5.06k
            idx_a_y = qp_avg + ofst_a;
477
5.06k
            alpha = gau1_ih264d_alpha_table[12 + idx_a_y];
478
5.06k
            idx_b_y = qp_avg + ofst_b;
479
5.06k
            beta = gau1_ih264d_beta_table[12 + idx_b_y];
480
5.06k
481
5.06k
            /* CHROMA values */
482
5.06k
            /* CHROMA Cb values */
483
5.06k
            qp_avg_u = (qp_avg + i1_cb_qp_idx_ofst);
484
5.06k
            qp_avg_u = gau1_ih264d_qp_scale_cr[12 + qp_avg_u];
485
5.06k
            idx_a_u = qp_avg_u + ofst_a;
486
5.06k
            alpha_u = gau1_ih264d_alpha_table[12 + idx_a_u];
487
5.06k
            idx_b_u = qp_avg_u + ofst_b;
488
5.06k
            beta_u = gau1_ih264d_beta_table[12 + idx_b_u];
489
5.06k
            /* CHROMA Cr values */
490
5.06k
            qp_avg_v = (qp_avg + i1_cr_qp_idx_ofst);
491
5.06k
            qp_avg_v = gau1_ih264d_qp_scale_cr[12 + qp_avg_v];
492
5.06k
            idx_a_v = qp_avg_v + ofst_a;
493
5.06k
            alpha_v = gau1_ih264d_alpha_table[12 + idx_a_v];
494
5.06k
            idx_b_v = qp_avg_v + ofst_b;
495
5.06k
            beta_v = gau1_ih264d_beta_table[12 + idx_b_v];
496
5.06k
        }
497
5.06k
498
5.06k
        pu1_cliptab_y = (UWORD8 *)&gau1_ih264d_clip_table[12 + idx_a_y]; //this for Luma
499
5.06k
        pu1_cliptab_u = (UWORD8 *)&gau1_ih264d_clip_table[12 + idx_a_u]; //this for chroma
500
5.06k
        pu1_cliptab_v = (UWORD8 *)&gau1_ih264d_clip_table[12 + idx_a_v]; //this for chroma
501
5.06k
502
5.06k
        //edge=1
503
5.06k
504
5.06k
505
5.06k
        u4_bs = pu4_bs_tab[5];
506
5.06k
        pu1_y = ps_tfr_cxt->pu1_mb_y;
507
5.06k
        pu1_u = ps_tfr_cxt->pu1_mb_u;
508
5.06k
509
5.06k
        if(u4_bs)
510
5.06k
        {
511
5.06k
512
5.06k
            ps_dec->pf_deblk_luma_vert_bslt4(pu1_y + 4, i4_strd_y, alpha, beta,
513
5.06k
                                             u4_bs, pu1_cliptab_y);
514
5.06k
515
5.06k
        }
516
5.06k
        //edge=2
517
5.06k
518
5.06k
        u4_bs = pu4_bs_tab[6];
519
5.06k
        if(u4_bs)
520
5.06k
        {
521
5.06k
            ps_dec->pf_deblk_luma_vert_bslt4(pu1_y + 8, i4_strd_y, alpha, beta,
522
5.06k
                                             u4_bs, pu1_cliptab_y);
523
5.06k
            ps_dec->pf_deblk_chroma_vert_bslt4(pu1_u + 4 * YUV420SP_FACTOR,
524
5.06k
                                               i4_strd_uv, alpha_u, beta_u,
525
5.06k
                                               alpha_v, beta_v, u4_bs,
526
5.06k
                                               pu1_cliptab_u, pu1_cliptab_v);
527
5.06k
528
5.06k
        }
529
5.06k
        //edge=3
530
5.06k
531
5.06k
        u4_bs = pu4_bs_tab[7];
532
5.06k
        if(u4_bs)
533
5.06k
        {
534
5.06k
            ps_dec->pf_deblk_luma_vert_bslt4(pu1_y + 12, i4_strd_y, alpha, beta,
535
5.06k
                                             u4_bs, pu1_cliptab_y);
536
5.06k
537
5.06k
        }
538
5.06k
539
5.06k
        /*--------------------------------------------------------------------*/
540
5.06k
        /* Filter wrt Top edge                                                */
541
5.06k
        /* except                                                             */
542
5.06k
        /*      - Top Egde is Picture Boundary                                */
543
5.06k
        /*      - Top Egde is part of Slice Boundary and Deblocking           */
544
5.06k
        /*        parameters of slice disable Filtering of Slice Boundary Edges*/
545
5.06k
        /*--------------------------------------------------------------------*/
546
5.06k
        if(ps_top_mb)
547
4.80k
        {
548
4.80k
            /** if top MB and MB AFF and cur MB is frame and top is field then  */
549
4.80k
            /*  one extra top edge needs to be deblocked                        */
550
4.80k
551
4.80k
            ih264d_filter_boundary_top_nonmbaff(ps_dec, ps_tfr_cxt,
552
4.80k
                                                i1_cb_qp_idx_ofst,
553
4.80k
                                                i1_cr_qp_idx_ofst, ps_cur_mb,
554
4.80k
                                                i4_strd_y, i4_strd_uv, ps_top_mb,
555
4.80k
                                                pu4_bs_tab[0]);
556
4.80k
557
4.80k
        }
558
5.06k
559
5.06k
        /*--------------------------------------------------------------------*/
560
5.06k
        /* Filter wrt Other Horizontal Edges                                  */
561
5.06k
        /*--------------------------------------------------------------------*/
562
5.06k
563
5.06k
        //edge1
564
5.06k
        u4_bs = pu4_bs_tab[1];
565
5.06k
566
5.06k
        if(u4_bs)
567
5.06k
        {
568
5.06k
            ps_dec->pf_deblk_luma_horz_bslt4(pu1_y + (i4_strd_y << 2), i4_strd_y,
569
5.06k
                                             alpha, beta, u4_bs, pu1_cliptab_y);
570
5.06k
571
5.06k
        }
572
5.06k
        //edge2
573
5.06k
        u4_bs = pu4_bs_tab[2];
574
5.06k
575
5.06k
        if(u4_bs)
576
5.06k
        {
577
5.06k
578
5.06k
            ps_dec->pf_deblk_luma_horz_bslt4(pu1_y + (i4_strd_y << 3), i4_strd_y,
579
5.06k
                                             alpha, beta, u4_bs, pu1_cliptab_y);
580
5.06k
            ps_dec->pf_deblk_chroma_horz_bslt4(pu1_u + (i4_strd_uv << 2),
581
5.06k
                                               i4_strd_uv, alpha_u, beta_u,
582
5.06k
                                               alpha_v, beta_v, u4_bs,
583
5.06k
                                               pu1_cliptab_u, pu1_cliptab_v);
584
5.06k
585
5.06k
        }
586
5.06k
        //edge3
587
5.06k
        u4_bs = pu4_bs_tab[3];
588
5.06k
        if(u4_bs)
589
5.06k
        {
590
5.06k
            ps_dec->pf_deblk_luma_horz_bslt4(
591
5.06k
                            (pu1_y + (i4_strd_y << 3) + (i4_strd_y << 2)),
592
5.06k
                            i4_strd_y, alpha, beta, u4_bs, pu1_cliptab_y);
593
5.06k
594
5.06k
        }
595
5.06k
     }
596
5.06k
597
5.06k
     ps_dec->u4_deblk_mb_x++;
598
5.06k
     ps_dec->ps_cur_deblk_mb++;
599
5.06k
     ps_dec->u4_cur_deblk_mb_num++;
600
5.06k
     u4_mbs_next = u4_image_wd_mb - ps_dec->u4_deblk_mb_x;
601
5.06k
602
5.06k
     ps_tfr_cxt->pu1_mb_y += 16;
603
5.06k
     ps_tfr_cxt->pu1_mb_u += 8 * YUV420SP_FACTOR;
604
5.06k
     ps_tfr_cxt->pu1_mb_v += 8;
605
5.06k
606
5.06k
     if(!u4_mbs_next)
607
220
     {
608
220
         ps_tfr_cxt->pu1_mb_y += ps_tfr_cxt->u4_y_inc;
609
220
         ps_tfr_cxt->pu1_mb_u += ps_tfr_cxt->u4_uv_inc;
610
220
         ps_tfr_cxt->pu1_mb_v += ps_tfr_cxt->u4_uv_inc;
611
220
         ps_dec->u4_deblk_mb_y++;
612
220
         ps_dec->u4_deblk_mb_x = 0;
613
220
     }
614
5.06k
615
5.06k
}
616
617
/**************************************************************************
618
 *
619
 *  Function Name : ih264d_init_deblk_tfr_ctxt
620
 *
621
 *  Description   : This function is called once per deblockpicture call
622
 *                  This sets up the transfer address contexts
623
 *
624
 *  Revision History:
625
 *
626
 *         DD MM YYYY   Author(s)       Changes (Describe the changes made)
627
 *         14 06 2005   SWRN            Draft
628
 **************************************************************************/
629
void ih264d_init_deblk_tfr_ctxt(dec_struct_t * ps_dec,
630
                                pad_mgr_t *ps_pad_mgr,
631
                                tfr_ctxt_t *ps_tfr_cxt,
632
                                UWORD16 u2_image_wd_mb,
633
                                UWORD8 u1_mbaff)
634
33
{
635
33
636
33
    UWORD32 i4_wd_y;
637
33
    UWORD32 i4_wd_uv;
638
33
    UWORD8 u1_field_pic_flag = ps_dec->ps_cur_slice->u1_field_pic_flag; /*< Field u4_flag  */
639
33
    UNUSED(u2_image_wd_mb);
640
33
    ps_tfr_cxt->pu1_src_y = ps_dec->s_cur_pic.pu1_buf1 - 4;
641
33
    ps_tfr_cxt->pu1_src_u = ps_dec->s_cur_pic.pu1_buf2 - 4;
642
33
    ps_tfr_cxt->pu1_src_v = ps_dec->s_cur_pic.pu1_buf3 - 4;
643
33
    ps_tfr_cxt->pu1_dest_y = ps_tfr_cxt->pu1_src_y;
644
33
    ps_tfr_cxt->pu1_dest_u = ps_tfr_cxt->pu1_src_u;
645
33
    ps_tfr_cxt->pu1_dest_v = ps_tfr_cxt->pu1_src_v;
646
33
647
33
    ps_tfr_cxt->pu1_mb_y = ps_tfr_cxt->pu1_src_y + 4;
648
33
    ps_tfr_cxt->pu1_mb_u = ps_tfr_cxt->pu1_src_u + 4;
649
33
    ps_tfr_cxt->pu1_mb_v = ps_tfr_cxt->pu1_src_v + 4;
650
33
651
33
    i4_wd_y = ps_dec->u2_frm_wd_y << u1_field_pic_flag;
652
33
    i4_wd_uv = ps_dec->u2_frm_wd_uv << u1_field_pic_flag;
653
33
    ps_tfr_cxt->u4_y_inc = ((i4_wd_y << u1_mbaff) * 16
654
33
                    - (ps_dec->u2_frm_wd_in_mbs << 4));
655
33
656
33
    ps_tfr_cxt->u4_uv_inc = (i4_wd_uv << u1_mbaff) * 8
657
33
                    - (ps_dec->u2_frm_wd_in_mbs << 4);
658
33
659
33
    /* padding related initialisations */
660
33
    if(ps_dec->ps_cur_slice->u1_nal_ref_idc)
661
33
    {
662
33
        ps_pad_mgr->u1_vert_pad_top = !(ps_dec->ps_cur_slice->u1_field_pic_flag
663
33
                        && ps_dec->ps_cur_slice->u1_bottom_field_flag);
664
33
        ps_pad_mgr->u1_vert_pad_bot =
665
33
                        ((!ps_dec->ps_cur_slice->u1_field_pic_flag)
666
33
                                        || ps_dec->ps_cur_slice->u1_bottom_field_flag);
667
33
        ps_pad_mgr->u1_horz_pad = 1;
668
33
    }
669
0
    else
670
0
    {
671
0
        ps_pad_mgr->u1_horz_pad = 0;
672
0
        ps_pad_mgr->u1_vert_pad_top = 0;
673
0
        ps_pad_mgr->u1_vert_pad_bot = 0;
674
0
    }
675
33
}
676
677
/*****************************************************************************/
678
/*                                                                           */
679
/*  Function Name : ih264d_deblock_picture_mbaff                                     */
680
/*                                                                           */
681
/*  Description   : This function carries out deblocking on a whole picture  */
682
/*                  with MBAFF                                               */
683
/*                                                                           */
684
/*  Inputs        : <What inputs does the function take?>                    */
685
/*  Processing    : This functions calls deblock MB in the MB increment order*/
686
/*                                                                           */
687
/*  Outputs       : Produces the deblocked picture                           */
688
/*  Returns       : None                                                     */
689
/*                                                                           */
690
/*  Revision History:                                                        */
691
/*                                                                           */
692
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
693
/*         17 02 2005   NS              Creation                             */
694
/*         14 06 2005   SWRN            clean-up                             */
695
/*****************************************************************************/
696
697
void ih264d_deblock_picture_mbaff(dec_struct_t * ps_dec)
698
0
{
699
0
    WORD16 i2_mb_x, i2_mb_y;
700
0
    deblk_mb_t *ps_cur_mb;
701
0
    deblk_mb_t *ps_top_mb;
702
0
    deblk_mb_t *ps_left_mb;
703
0
704
0
    UWORD8 u1_vert_pad_top = 1;
705
0
    UWORD8 u1_cur_fld, u1_top_fld, u1_left_fld;
706
0
    UWORD8 u1_first_row;
707
0
708
0
    UWORD8 * pu1_deb_y, *pu1_deb_u, *pu1_deb_v;
709
0
    UWORD8 u1_deb_mode, u1_extra_top_edge;
710
0
    WORD32 i4_wd_y, i4_wd_uv;
711
0
712
0
    UWORD8 u1_field_pic_flag = ps_dec->ps_cur_slice->u1_field_pic_flag; /*< Field u4_flag                       */
713
0
    UWORD8 u1_bottom_field_flag = ps_dec->ps_cur_slice->u1_bottom_field_flag; /*< Bottom field u4_flag*/
714
0
715
0
    /**************************************************/
716
0
    /* one time loads from ps_dec which will be used  */
717
0
    /* frequently throughout the deblocking procedure */
718
0
    /**************************************************/
719
0
    pad_mgr_t * ps_pad_mgr = &ps_dec->s_pad_mgr;
720
0
    tfr_ctxt_t s_tfr_ctxt;
721
0
    tfr_ctxt_t * ps_tfr_cxt = &s_tfr_ctxt;
722
0
723
0
    UWORD16 u2_image_wd_mb = ps_dec->u2_frm_wd_in_mbs;
724
0
    UWORD16 u2_image_ht_mb = ps_dec->u2_frm_ht_in_mbs;
725
0
    UWORD8 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
726
0
    WORD8 i1_cb_qp_idx_ofst = ps_dec->ps_cur_pps->i1_chroma_qp_index_offset;
727
0
    WORD8 i1_cr_qp_idx_ofst =
728
0
                    ps_dec->ps_cur_pps->i1_second_chroma_qp_index_offset;
729
0
730
0
    /* Set up Parameter for  DMA transfer */
731
0
    ih264d_init_deblk_tfr_ctxt(ps_dec, ps_pad_mgr, ps_tfr_cxt, u2_image_wd_mb,
732
0
                               u1_mbaff);
733
0
734
0
    /* Pic level Initialisations */
735
0
    i2_mb_y = u2_image_ht_mb;
736
0
    i2_mb_x = 0;
737
0
    u1_extra_top_edge = 0;
738
0
739
0
    u1_first_row = 1;
740
0
741
0
    i4_wd_y = ps_dec->u2_frm_wd_y << u1_field_pic_flag;
742
0
    i4_wd_uv = ps_dec->u2_frm_wd_uv << u1_field_pic_flag;
743
0
    /* Initial filling of the buffers with deblocking data */
744
0
745
0
    pu1_deb_y = ps_tfr_cxt->pu1_mb_y;
746
0
    pu1_deb_u = ps_tfr_cxt->pu1_mb_u;
747
0
    pu1_deb_v = ps_tfr_cxt->pu1_mb_v;
748
0
    ps_cur_mb = ps_dec->ps_deblk_pic;
749
0
750
0
    if(ps_dec->u4_app_disable_deblk_frm == 0)
751
0
    {
752
0
        {
753
0
754
0
            while(i2_mb_y > 0)
755
0
            {
756
0
                do
757
0
                {
758
0
759
0
                    u1_deb_mode = ps_cur_mb->u1_deblocking_mode;
760
0
                    if(!(u1_deb_mode & MB_DISABLE_FILTERING))
761
0
                    {
762
0
                        ps_tfr_cxt->pu1_mb_y = pu1_deb_y;
763
0
                        ps_tfr_cxt->pu1_mb_u = pu1_deb_u;
764
0
                        ps_tfr_cxt->pu1_mb_v = pu1_deb_v;
765
0
766
0
                        u1_cur_fld = (ps_cur_mb->u1_mb_type & D_FLD_MB) >> 7;
767
0
                        u1_cur_fld &= 1;
768
0
                        if(i2_mb_x)
769
0
                        {
770
0
                            ps_left_mb = ps_cur_mb - 2;
771
0
                        }
772
0
                        else
773
0
                        {
774
0
                            ps_left_mb = NULL;
775
0
                        }
776
0
                        if(!u1_first_row)
777
0
                        {
778
0
                            ps_top_mb = ps_cur_mb - (u2_image_wd_mb << 1) + 1;
779
0
                            u1_top_fld = (ps_top_mb->u1_mb_type & D_FLD_MB)
780
0
                                            >> 7;
781
0
                        }
782
0
                        else
783
0
                        {
784
0
                            ps_top_mb = NULL;
785
0
                            u1_top_fld = 0;
786
0
                        }
787
0
788
0
                        if((!u1_first_row) & u1_top_fld & u1_cur_fld)
789
0
                            ps_top_mb--;
790
0
791
0
                        /********************************************************/
792
0
                        /* if top MB and MB AFF and cur MB is frame and top is  */
793
0
                        /* field, then one extra top edge needs to be deblocked */
794
0
                        /********************************************************/
795
0
                        u1_extra_top_edge = (!u1_cur_fld) & u1_top_fld;
796
0
797
0
                        if(u1_deb_mode & MB_DISABLE_LEFT_EDGE)
798
0
                            ps_left_mb = NULL;
799
0
                        if(u1_deb_mode & MB_DISABLE_TOP_EDGE)
800
0
                            ps_top_mb = NULL;
801
0
802
0
                        ih264d_deblock_mb_mbaff(ps_dec, ps_tfr_cxt,
803
0
                                                i1_cb_qp_idx_ofst,
804
0
                                                i1_cr_qp_idx_ofst, ps_cur_mb,
805
0
                                                i4_wd_y, i4_wd_uv, ps_top_mb,
806
0
                                                ps_left_mb, u1_cur_fld,
807
0
                                                u1_extra_top_edge);
808
0
                    }
809
0
810
0
                    ps_cur_mb++;
811
0
812
0
                    u1_deb_mode = ps_cur_mb->u1_deblocking_mode;
813
0
                    if(!(u1_deb_mode & MB_DISABLE_FILTERING))
814
0
                    {
815
0
                        ps_tfr_cxt->pu1_mb_y = pu1_deb_y;
816
0
                        ps_tfr_cxt->pu1_mb_u = pu1_deb_u;
817
0
                        ps_tfr_cxt->pu1_mb_v = pu1_deb_v;
818
0
819
0
                        u1_cur_fld = (ps_cur_mb->u1_mb_type & D_FLD_MB) >> 7;
820
0
                        u1_cur_fld &= 1;
821
0
                        if(i2_mb_x)
822
0
                        {
823
0
                            ps_left_mb = ps_cur_mb - 2;
824
0
                            u1_left_fld = (ps_left_mb->u1_mb_type & D_FLD_MB)
825
0
                                            >> 7;
826
0
                        }
827
0
                        else
828
0
                        {
829
0
                            ps_left_mb = NULL;
830
0
                            u1_left_fld = u1_cur_fld;
831
0
                        }
832
0
                        if(!u1_first_row)
833
0
                        {
834
0
                            ps_top_mb = ps_cur_mb - (u2_image_wd_mb << 1);
835
0
                        }
836
0
                        else
837
0
                        {
838
0
                            ps_top_mb = NULL;
839
0
                        }
840
0
841
0
                        {
842
0
                            UWORD8 u1_row_shift_y = 0, u1_row_shift_uv = 0;
843
0
                            if(!u1_cur_fld)
844
0
                            {
845
0
                                ps_top_mb = ps_cur_mb - 1;
846
0
                                u1_top_fld = (ps_top_mb->u1_mb_type & D_FLD_MB)
847
0
                                                >> 7;
848
0
                                u1_row_shift_y = 4;
849
0
                                u1_row_shift_uv = 3;
850
0
                            }
851
0
                            ps_tfr_cxt->pu1_mb_y += i4_wd_y << u1_row_shift_y;
852
0
                            ps_tfr_cxt->pu1_mb_u +=
853
0
                                            (i4_wd_uv << u1_row_shift_uv);
854
0
                            ps_tfr_cxt->pu1_mb_v += i4_wd_uv << u1_row_shift_uv;
855
0
                        }
856
0
857
0
                        /* point to A if top else A+1 */
858
0
                        if(u1_left_fld ^ u1_cur_fld)
859
0
                            ps_left_mb--;
860
0
861
0
                        /********************************************************/
862
0
                        /* if top MB and MB AFF and cur MB is frame and top is  */
863
0
                        /* field, then one extra top edge needs to be deblocked */
864
0
                        /********************************************************/
865
0
                        u1_extra_top_edge = 0;
866
0
867
0
                        if(u1_deb_mode & MB_DISABLE_LEFT_EDGE)
868
0
                            ps_left_mb = NULL;
869
0
                        if(u1_deb_mode & MB_DISABLE_TOP_EDGE)
870
0
                            ps_top_mb = NULL;
871
0
872
0
                        ih264d_deblock_mb_mbaff(ps_dec, ps_tfr_cxt,
873
0
                                                i1_cb_qp_idx_ofst,
874
0
                                                i1_cr_qp_idx_ofst, ps_cur_mb,
875
0
                                                i4_wd_y, i4_wd_uv, ps_top_mb,
876
0
                                                ps_left_mb, u1_cur_fld,
877
0
                                                u1_extra_top_edge);
878
0
                    }
879
0
880
0
                    ps_cur_mb++;
881
0
                    i2_mb_x++;
882
0
883
0
                    pu1_deb_y += 16;
884
0
                    pu1_deb_u += 8 * YUV420SP_FACTOR;
885
0
                    pu1_deb_v += 8;
886
0
887
0
                }
888
0
                while(u2_image_wd_mb > i2_mb_x);
889
0
890
0
                pu1_deb_y += ps_tfr_cxt->u4_y_inc;
891
0
                pu1_deb_u += ps_tfr_cxt->u4_uv_inc;
892
0
                pu1_deb_v += ps_tfr_cxt->u4_uv_inc;
893
0
894
0
                i2_mb_x = 0;
895
0
                i2_mb_y -= 2;
896
0
897
0
                u1_first_row = 0;
898
0
899
0
            }
900
0
        }
901
0
902
0
    }
903
0
    //Padd the Picture
904
0
    //Horizontal Padd
905
0
906
0
    if(ps_pad_mgr->u1_horz_pad)
907
0
    {
908
0
        UWORD32 u1_field_pic_flag = ps_dec->ps_cur_slice->u1_field_pic_flag;
909
0
        ps_dec->pf_pad_left_luma(ps_tfr_cxt->pu1_src_y + 4,
910
0
                                 ps_dec->u2_frm_wd_y << u1_field_pic_flag,
911
0
                                 ps_dec->u2_pic_ht >> u1_field_pic_flag,
912
0
                                 PAD_LEN_Y_H);
913
0
        ps_dec->pf_pad_right_luma(
914
0
                        ps_tfr_cxt->pu1_src_y + 4
915
0
                                        + (ps_dec->u2_frm_wd_in_mbs << 4),
916
0
                        ps_dec->u2_frm_wd_y << u1_field_pic_flag,
917
0
                        ps_dec->u2_pic_ht >> u1_field_pic_flag, PAD_LEN_Y_H);
918
0
919
0
        ps_dec->pf_pad_left_chroma(ps_tfr_cxt->pu1_src_u + 4,
920
0
                                   ps_dec->u2_frm_wd_uv << u1_field_pic_flag,
921
0
                                   (ps_dec->u2_pic_ht / 2) >> u1_field_pic_flag,
922
0
                                   PAD_LEN_UV_H * YUV420SP_FACTOR);
923
0
        ps_dec->pf_pad_right_chroma(
924
0
                        ps_tfr_cxt->pu1_src_u + 4
925
0
                                        + (ps_dec->u2_frm_wd_in_mbs << 4),
926
0
                        ps_dec->u2_frm_wd_uv << u1_field_pic_flag,
927
0
                        (ps_dec->u2_pic_ht / 2) >> u1_field_pic_flag,
928
0
                        PAD_LEN_UV_H * YUV420SP_FACTOR);
929
0
930
0
    }
931
0
932
0
//Vertical Padd Top
933
0
    if(ps_pad_mgr->u1_vert_pad_top)
934
0
    {
935
0
        ps_dec->pf_pad_top(ps_dec->ps_cur_pic->pu1_buf1 - PAD_LEN_Y_H,
936
0
                           ps_dec->u2_frm_wd_y, ps_dec->u2_frm_wd_y,
937
0
                           ps_pad_mgr->u1_pad_len_y_v);
938
0
        ps_dec->pf_pad_top(
939
0
                        ps_dec->ps_cur_pic->pu1_buf2
940
0
                                        - PAD_LEN_UV_H * YUV420SP_FACTOR,
941
0
                        ps_dec->u2_frm_wd_uv, ps_dec->u2_frm_wd_uv,
942
0
                        ps_pad_mgr->u1_pad_len_cr_v);
943
0
        ps_pad_mgr->u1_vert_pad_top = 0;
944
0
    }
945
0
946
0
//Vertical Padd Bottom
947
0
    if(ps_pad_mgr->u1_vert_pad_bot)
948
0
    {
949
0
950
0
        UWORD8 *pu1_buf;
951
0
        pu1_buf = ps_dec->ps_cur_pic->pu1_buf1 - PAD_LEN_Y_H;
952
0
        pu1_buf += ps_dec->u2_pic_ht * ps_dec->u2_frm_wd_y;
953
0
        ps_dec->pf_pad_bottom(pu1_buf, ps_dec->u2_frm_wd_y, ps_dec->u2_frm_wd_y,
954
0
                              ps_pad_mgr->u1_pad_len_y_v);
955
0
        pu1_buf = ps_dec->ps_cur_pic->pu1_buf2 - PAD_LEN_UV_H * YUV420SP_FACTOR;
956
0
        pu1_buf += (ps_dec->u2_pic_ht >> 1) * ps_dec->u2_frm_wd_uv;
957
0
958
0
        ps_dec->pf_pad_bottom(pu1_buf, ps_dec->u2_frm_wd_uv,
959
0
                              ps_dec->u2_frm_wd_uv,
960
0
                              ps_pad_mgr->u1_pad_len_cr_v);
961
0
962
0
    }
963
0
}
964
965
/*****************************************************************************/
966
/*                                                                           */
967
/*  Function Name : ih264d_deblock_picture_non_mbaff                                  */
968
/*                                                                           */
969
/*  Description   : This function carries out deblocking on a whole picture  */
970
/*                  without MBAFF                                            */
971
/*                                                                           */
972
/*  Inputs        : <What inputs does the function take?>                    */
973
/*  Processing    : This functions calls deblock MB in the MB increment order*/
974
/*                                                                           */
975
/*  Outputs       : Produces the deblocked picture                           */
976
/*  Returns       : None                                                     */
977
/*                                                                           */
978
/*  Revision History:                                                        */
979
/*                                                                           */
980
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
981
/*         17 02 2005   NS              Creation                             */
982
/*         14 06 2005   SWRN            clean-up                             */
983
/*****************************************************************************/
984
985
void ih264d_deblock_picture_non_mbaff(dec_struct_t * ps_dec)
986
0
{
987
0
    deblk_mb_t *ps_cur_mb;
988
0
989
0
    UWORD8 u1_vert_pad_top = 1;
990
0
991
0
    UWORD8 u1_deb_mode;
992
0
    WORD32 i4_wd_y, i4_wd_uv;
993
0
994
0
    UWORD8 u1_field_pic_flag = ps_dec->ps_cur_slice->u1_field_pic_flag; /*< Field u4_flag                       */
995
0
    UWORD8 u1_bottom_field_flag = ps_dec->ps_cur_slice->u1_bottom_field_flag; /*< Bottom field u4_flag */
996
0
997
0
    /**************************************************/
998
0
    /* one time loads from ps_dec which will be used  */
999
0
    /* frequently throughout the deblocking procedure */
1000
0
    /**************************************************/
1001
0
    pad_mgr_t * ps_pad_mgr = &ps_dec->s_pad_mgr;
1002
0
    tfr_ctxt_t s_tfr_ctxt;
1003
0
    tfr_ctxt_t * ps_tfr_cxt = &s_tfr_ctxt; // = &ps_dec->s_tran_addrecon;
1004
0
1005
0
    UWORD16 u2_image_wd_mb = ps_dec->u2_frm_wd_in_mbs;
1006
0
    UWORD16 u2_image_ht_mb = ps_dec->u2_frm_ht_in_mbs;
1007
0
    WORD8 i1_cb_qp_idx_ofst = ps_dec->ps_cur_pps->i1_chroma_qp_index_offset;
1008
0
    WORD8 i1_cr_qp_idx_ofst =
1009
0
                    ps_dec->ps_cur_pps->i1_second_chroma_qp_index_offset;
1010
0
1011
0
    /* Set up Parameter for  DMA transfer */
1012
0
    ih264d_init_deblk_tfr_ctxt(ps_dec, ps_pad_mgr, ps_tfr_cxt, u2_image_wd_mb,
1013
0
                               0);
1014
0
1015
0
    /* Pic level Initialisations */
1016
0
1017
0
1018
0
1019
0
    i4_wd_y = ps_dec->u2_frm_wd_y << u1_field_pic_flag;
1020
0
    i4_wd_uv = ps_dec->u2_frm_wd_uv << u1_field_pic_flag;
1021
0
    /* Initial filling of the buffers with deblocking data */
1022
0
1023
0
    ps_cur_mb = ps_dec->ps_deblk_pic;
1024
0
1025
0
    if(ps_dec->u4_app_disable_deblk_frm == 0)
1026
0
    {
1027
0
        if(ps_dec->ps_cur_sps->u1_mb_aff_flag == 1)
1028
0
        {
1029
0
            while( ps_dec->u4_deblk_mb_y < u2_image_ht_mb)
1030
0
            {
1031
0
                ih264d_deblock_mb_nonmbaff(ps_dec, ps_tfr_cxt,
1032
0
                                           i1_cb_qp_idx_ofst,
1033
0
                                           i1_cr_qp_idx_ofst,
1034
0
                                           i4_wd_y, i4_wd_uv);
1035
0
                ps_cur_mb++;
1036
0
            }
1037
0
        }
1038
0
1039
0
    }
1040
0
1041
0
    //Padd the Picture
1042
0
    //Horizontal Padd
1043
0
    if(ps_pad_mgr->u1_horz_pad)
1044
0
    {
1045
0
        UWORD32 u1_field_pic_flag = ps_dec->ps_cur_slice->u1_field_pic_flag;
1046
0
        ps_dec->pf_pad_left_luma(ps_tfr_cxt->pu1_src_y + 4,
1047
0
                                 ps_dec->u2_frm_wd_y << u1_field_pic_flag,
1048
0
                                 ps_dec->u2_pic_ht >> u1_field_pic_flag,
1049
0
                                 PAD_LEN_Y_H);
1050
0
        ps_dec->pf_pad_right_luma(
1051
0
                        ps_tfr_cxt->pu1_src_y + 4
1052
0
                                        + (ps_dec->u2_frm_wd_in_mbs << 4),
1053
0
                        ps_dec->u2_frm_wd_y << u1_field_pic_flag,
1054
0
                        ps_dec->u2_pic_ht >> u1_field_pic_flag, PAD_LEN_Y_H);
1055
0
1056
0
        ps_dec->pf_pad_left_chroma(ps_tfr_cxt->pu1_src_u + 4,
1057
0
                                   ps_dec->u2_frm_wd_uv << u1_field_pic_flag,
1058
0
                                   (ps_dec->u2_pic_ht / 2) >> u1_field_pic_flag,
1059
0
                                   PAD_LEN_UV_H * YUV420SP_FACTOR);
1060
0
        ps_dec->pf_pad_right_chroma(
1061
0
                        ps_tfr_cxt->pu1_src_u + 4
1062
0
                                        + (ps_dec->u2_frm_wd_in_mbs << 4),
1063
0
                        ps_dec->u2_frm_wd_uv << u1_field_pic_flag,
1064
0
                        (ps_dec->u2_pic_ht / 2) >> u1_field_pic_flag,
1065
0
                        PAD_LEN_UV_H * YUV420SP_FACTOR);
1066
0
1067
0
    }
1068
0
1069
0
//Vertical Padd Top
1070
0
    if(ps_pad_mgr->u1_vert_pad_top)
1071
0
    {
1072
0
        ps_dec->pf_pad_top(ps_dec->ps_cur_pic->pu1_buf1 - PAD_LEN_Y_H,
1073
0
                           ps_dec->u2_frm_wd_y, ps_dec->u2_frm_wd_y,
1074
0
                           ps_pad_mgr->u1_pad_len_y_v);
1075
0
        ps_dec->pf_pad_top(
1076
0
                        ps_dec->ps_cur_pic->pu1_buf2
1077
0
                                        - PAD_LEN_UV_H * YUV420SP_FACTOR,
1078
0
                        ps_dec->u2_frm_wd_uv, ps_dec->u2_frm_wd_uv,
1079
0
                        ps_pad_mgr->u1_pad_len_cr_v);
1080
0
        ps_pad_mgr->u1_vert_pad_top = 0;
1081
0
    }
1082
0
1083
0
//Vertical Padd Bottom
1084
0
    if(ps_pad_mgr->u1_vert_pad_bot)
1085
0
    {
1086
0
1087
0
        UWORD8 *pu1_buf;
1088
0
        pu1_buf = ps_dec->ps_cur_pic->pu1_buf1 - PAD_LEN_Y_H;
1089
0
        pu1_buf += ps_dec->u2_pic_ht * ps_dec->u2_frm_wd_y;
1090
0
        ps_dec->pf_pad_bottom(pu1_buf, ps_dec->u2_frm_wd_y, ps_dec->u2_frm_wd_y,
1091
0
                              ps_pad_mgr->u1_pad_len_y_v);
1092
0
        pu1_buf = ps_dec->ps_cur_pic->pu1_buf2 - PAD_LEN_UV_H * YUV420SP_FACTOR;
1093
0
        pu1_buf += (ps_dec->u2_pic_ht >> 1) * ps_dec->u2_frm_wd_uv;
1094
0
1095
0
        ps_dec->pf_pad_bottom(pu1_buf, ps_dec->u2_frm_wd_uv,
1096
0
                              ps_dec->u2_frm_wd_uv,
1097
0
                              ps_pad_mgr->u1_pad_len_cr_v);
1098
0
1099
0
    }
1100
0
}
1101
1102
void ih264d_deblock_picture_progressive(dec_struct_t * ps_dec)
1103
11
{
1104
11
    deblk_mb_t *ps_cur_mb;
1105
11
1106
11
    UWORD8 u1_vert_pad_top = 1;
1107
11
    UWORD8 u1_mbs_next;
1108
11
    UWORD8 u1_deb_mode;
1109
11
    WORD32 i4_wd_y, i4_wd_uv;
1110
11
1111
11
1112
11
    /**************************************************/
1113
11
    /* one time loads from ps_dec which will be used  */
1114
11
    /* frequently throughout the deblocking procedure */
1115
11
    /**************************************************/
1116
11
    pad_mgr_t * ps_pad_mgr = &ps_dec->s_pad_mgr;
1117
11
1118
11
    tfr_ctxt_t s_tfr_ctxt;
1119
11
    tfr_ctxt_t * ps_tfr_cxt = &s_tfr_ctxt; // = &ps_dec->s_tran_addrecon;
1120
11
    UWORD16 u2_image_wd_mb = ps_dec->u2_frm_wd_in_mbs;
1121
11
    UWORD16 u2_image_ht_mb = ps_dec->u2_frm_ht_in_mbs;
1122
11
    UWORD8 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
1123
11
1124
11
    WORD8 i1_cb_qp_idx_ofst = ps_dec->ps_cur_pps->i1_chroma_qp_index_offset;
1125
11
    WORD8 i1_cr_qp_idx_ofst =
1126
11
                    ps_dec->ps_cur_pps->i1_second_chroma_qp_index_offset;
1127
11
1128
11
    /* Set up Parameter for  deblocking */
1129
11
    ih264d_init_deblk_tfr_ctxt(ps_dec, ps_pad_mgr, ps_tfr_cxt, u2_image_wd_mb,
1130
11
                               0);
1131
11
1132
11
    /* Pic level Initialisations */
1133
11
1134
11
    i4_wd_y = ps_dec->u2_frm_wd_y;
1135
11
    i4_wd_uv = ps_dec->u2_frm_wd_uv;
1136
11
    /* Initial filling of the buffers with deblocking data */
1137
11
    ps_cur_mb = ps_dec->ps_deblk_pic;
1138
11
1139
11
    if(ps_dec->u4_app_disable_deblk_frm == 0)
1140
11
    {
1141
11
        if(ps_dec->ps_cur_sps->u1_mb_aff_flag == 1)
1142
0
        {
1143
0
            while( ps_dec->u4_deblk_mb_y < u2_image_ht_mb)
1144
0
            {
1145
0
                ih264d_deblock_mb_nonmbaff(ps_dec, ps_tfr_cxt,
1146
0
                                           i1_cb_qp_idx_ofst,
1147
0
                                           i1_cr_qp_idx_ofst,
1148
0
                                           i4_wd_y, i4_wd_uv);
1149
0
                ps_cur_mb++;
1150
0
            }
1151
0
        }
1152
11
1153
11
    }
1154
11
1155
11
    //Padd the Picture
1156
11
    //Horizontal Padd
1157
11
    if(ps_pad_mgr->u1_horz_pad)
1158
11
    {
1159
11
        UWORD32 u1_field_pic_flag = ps_dec->ps_cur_slice->u1_field_pic_flag;
1160
11
        ps_dec->pf_pad_left_luma(ps_tfr_cxt->pu1_src_y + 4,
1161
11
                                 ps_dec->u2_frm_wd_y << u1_field_pic_flag,
1162
11
                                 ps_dec->u2_pic_ht >> u1_field_pic_flag,
1163
11
                                 PAD_LEN_Y_H);
1164
11
        ps_dec->pf_pad_right_luma(
1165
11
                        ps_tfr_cxt->pu1_src_y + 4
1166
11
                                        + (ps_dec->u2_frm_wd_in_mbs << 4),
1167
11
                        ps_dec->u2_frm_wd_y << u1_field_pic_flag,
1168
11
                        ps_dec->u2_pic_ht >> u1_field_pic_flag, PAD_LEN_Y_H);
1169
11
1170
11
        ps_dec->pf_pad_left_chroma(ps_tfr_cxt->pu1_src_u + 4,
1171
11
                                   ps_dec->u2_frm_wd_uv << u1_field_pic_flag,
1172
11
                                   (ps_dec->u2_pic_ht / 2) >> u1_field_pic_flag,
1173
11
                                   PAD_LEN_UV_H * YUV420SP_FACTOR);
1174
11
        ps_dec->pf_pad_right_chroma(
1175
11
                        ps_tfr_cxt->pu1_src_u + 4
1176
11
                                        + (ps_dec->u2_frm_wd_in_mbs << 4),
1177
11
                        ps_dec->u2_frm_wd_uv << u1_field_pic_flag,
1178
11
                        (ps_dec->u2_pic_ht / 2) >> u1_field_pic_flag,
1179
11
                        PAD_LEN_UV_H * YUV420SP_FACTOR);
1180
11
1181
11
    }
1182
11
1183
11
//Vertical Padd Top
1184
11
    if(ps_pad_mgr->u1_vert_pad_top)
1185
11
    {
1186
11
        ps_dec->pf_pad_top(ps_dec->ps_cur_pic->pu1_buf1 - PAD_LEN_Y_H,
1187
11
                           ps_dec->u2_frm_wd_y, ps_dec->u2_frm_wd_y,
1188
11
                           ps_pad_mgr->u1_pad_len_y_v);
1189
11
        ps_dec->pf_pad_top(
1190
11
                        ps_dec->ps_cur_pic->pu1_buf2
1191
11
                                        - PAD_LEN_UV_H * YUV420SP_FACTOR,
1192
11
                        ps_dec->u2_frm_wd_uv, ps_dec->u2_frm_wd_uv,
1193
11
                        ps_pad_mgr->u1_pad_len_cr_v);
1194
11
1195
11
    }
1196
11
1197
11
//Vertical Padd Bottom
1198
11
    if(ps_pad_mgr->u1_vert_pad_bot)
1199
11
    {
1200
11
1201
11
        UWORD8 *pu1_buf;
1202
11
        pu1_buf = ps_dec->ps_cur_pic->pu1_buf1 - PAD_LEN_Y_H;
1203
11
        pu1_buf += ps_dec->u2_pic_ht * ps_dec->u2_frm_wd_y;
1204
11
        ps_dec->pf_pad_bottom(pu1_buf, ps_dec->u2_frm_wd_y, ps_dec->u2_frm_wd_y,
1205
11
                              ps_pad_mgr->u1_pad_len_y_v);
1206
11
        pu1_buf = ps_dec->ps_cur_pic->pu1_buf2 - PAD_LEN_UV_H * YUV420SP_FACTOR;
1207
11
        pu1_buf += (ps_dec->u2_pic_ht >> 1) * ps_dec->u2_frm_wd_uv;
1208
11
1209
11
        ps_dec->pf_pad_bottom(pu1_buf, ps_dec->u2_frm_wd_uv,
1210
11
                              ps_dec->u2_frm_wd_uv,
1211
11
                              ps_pad_mgr->u1_pad_len_cr_v);
1212
11
1213
11
    }
1214
11
}
1215
1216
/*!
1217
 **************************************************************************
1218
 * \if Function name : ih264d_set_deblocking_parameters \endif
1219
 *
1220
 * \brief
1221
 *    Sets the deblocking parameters of the macroblock
1222
 *
1223
 * \return
1224
 *    0 on Success and Error code otherwise
1225
 *
1226
 * \note
1227
 *   Given the neighbour availablity information, and the deblocking
1228
 *   parameters of the slice,this function will set the deblocking
1229
 *   mode of the macroblock.
1230
 **************************************************************************
1231
 */
1232
1233
WORD8 ih264d_set_deblocking_parameters(deblk_mb_t * ps_cur_mb,
1234
                                       dec_slice_params_t * ps_slice,
1235
                                       UWORD8 u1_mb_ngbr_availablity,
1236
                                       UWORD8 u1_mb_field_decoding_flag)
1237
5.06k
{
1238
5.06k
    /*------------------------------------------------------------------*/
1239
5.06k
    /* Set the deblocking parameters                                  */
1240
5.06k
    /*------------------------------------------------------------------*/
1241
5.06k
    ps_cur_mb->i1_slice_alpha_c0_offset = ps_slice->i1_slice_alpha_c0_offset;
1242
5.06k
    ps_cur_mb->i1_slice_beta_offset = ps_slice->i1_slice_beta_offset;
1243
5.06k
    ps_cur_mb->u1_mb_type = (u1_mb_field_decoding_flag << 7);
1244
5.06k
1245
5.06k
    switch(ps_slice->u1_disable_dblk_filter_idc)
1246
5.06k
    {
1247
5.06k
        case DBLK_ENABLED:
1248
5.06k
            ps_cur_mb->u1_deblocking_mode = MB_ENABLE_FILTERING;
1249
5.06k
            break;
1250
5.06k
        case DBLK_DISABLED:
1251
0
            ps_cur_mb->u1_deblocking_mode = MB_DISABLE_FILTERING;
1252
0
            break;
1253
5.06k
        case SLICE_BOUNDARY_DBLK_DISABLED:
1254
0
        {
1255
0
            ps_cur_mb->u1_deblocking_mode = MB_ENABLE_FILTERING;
1256
0
            if(!(u1_mb_ngbr_availablity & LEFT_MB_AVAILABLE_MASK))
1257
0
                ps_cur_mb->u1_deblocking_mode |= MB_DISABLE_LEFT_EDGE;
1258
0
            if(!(u1_mb_ngbr_availablity & TOP_MB_AVAILABLE_MASK))
1259
0
                ps_cur_mb->u1_deblocking_mode |= MB_DISABLE_TOP_EDGE;
1260
0
            break;
1261
5.06k
        }
1262
5.06k
    }
1263
5.06k
1264
5.06k
    return (0);
1265
5.06k
}
1266
1267
void ih264d_copy_intra_pred_line(dec_struct_t *ps_dec,
1268
                                 dec_mb_info_t *ps_cur_mb_info,
1269
                                 UWORD32 nmb_index)
1270
5.06k
{
1271
5.06k
    UWORD8 *pu1_mb_last_row, u1_mb_field_decoding_flag;
1272
5.06k
    UWORD32 u4_recWidth, u4_recwidth_cr;
1273
5.06k
1274
5.06k
    u1_mb_field_decoding_flag = ps_cur_mb_info->u1_mb_field_decodingflag;
1275
5.06k
1276
5.06k
    u4_recWidth = ps_dec->u2_frm_wd_y << u1_mb_field_decoding_flag;
1277
5.06k
    u4_recwidth_cr = ps_dec->u2_frm_wd_uv << u1_mb_field_decoding_flag;
1278
5.06k
1279
5.06k
    pu1_mb_last_row = ps_dec->ps_frame_buf_ip_recon->pu1_dest_y
1280
5.06k
                    + (u4_recWidth * (MB_SIZE - 1));
1281
5.06k
    pu1_mb_last_row += MB_SIZE * nmb_index;
1282
5.06k
    MEMCPY_16BYTES(ps_dec->pu1_cur_y_intra_pred_line, pu1_mb_last_row);
1283
5.06k
1284
5.06k
    pu1_mb_last_row = ps_dec->ps_frame_buf_ip_recon->pu1_dest_u
1285
5.06k
                    + (u4_recwidth_cr * (BLK8x8SIZE - 1));
1286
5.06k
    pu1_mb_last_row += BLK8x8SIZE * nmb_index * YUV420SP_FACTOR;
1287
5.06k
1288
5.06k
    MEMCPY_16BYTES(ps_dec->pu1_cur_u_intra_pred_line, pu1_mb_last_row);
1289
5.06k
1290
5.06k
    ps_dec->pu1_cur_y_intra_pred_line = ps_dec->pu1_cur_y_intra_pred_line_base
1291
5.06k
                    + (MB_SIZE * (ps_cur_mb_info->u2_mbx + 1));
1292
5.06k
    ps_dec->pu1_cur_u_intra_pred_line = ps_dec->pu1_cur_u_intra_pred_line_base
1293
5.06k
                    + (BLK8x8SIZE * (ps_cur_mb_info->u2_mbx + 1))
1294
5.06k
                                    * YUV420SP_FACTOR;
1295
5.06k
    ps_dec->pu1_cur_v_intra_pred_line = ps_dec->pu1_cur_v_intra_pred_line_base
1296
5.06k
                    + (BLK8x8SIZE * (ps_cur_mb_info->u2_mbx + 1));
1297
5.06k
1298
5.06k
    if(ps_cur_mb_info->u2_mbx == (ps_dec->u2_frm_wd_in_mbs - 1))
1299
220
    {
1300
220
        UWORD8* pu1_temp;
1301
220
1302
220
        ps_dec->pu1_cur_y_intra_pred_line =
1303
220
                        ps_dec->pu1_cur_y_intra_pred_line_base;
1304
220
        ps_dec->pu1_cur_u_intra_pred_line =
1305
220
                        ps_dec->pu1_cur_u_intra_pred_line_base;
1306
220
        ps_dec->pu1_cur_v_intra_pred_line =
1307
220
                        ps_dec->pu1_cur_v_intra_pred_line_base;
1308
220
1309
220
        /*swap current and previous rows*/
1310
220
        pu1_temp = ps_dec->pu1_cur_y_intra_pred_line;
1311
220
        ps_dec->pu1_cur_y_intra_pred_line = ps_dec->pu1_prev_y_intra_pred_line;
1312
220
        ps_dec->pu1_prev_y_intra_pred_line = pu1_temp;
1313
220
1314
220
        pu1_temp = ps_dec->pu1_cur_u_intra_pred_line;
1315
220
        ps_dec->pu1_cur_u_intra_pred_line = ps_dec->pu1_prev_u_intra_pred_line;
1316
220
        ps_dec->pu1_prev_u_intra_pred_line = pu1_temp;
1317
220
1318
220
        pu1_temp = ps_dec->pu1_cur_v_intra_pred_line;
1319
220
        ps_dec->pu1_cur_v_intra_pred_line = ps_dec->pu1_prev_v_intra_pred_line;
1320
220
        ps_dec->pu1_prev_v_intra_pred_line = pu1_temp;
1321
220
1322
220
        ps_dec->pu1_cur_y_intra_pred_line_base =
1323
220
                        ps_dec->pu1_cur_y_intra_pred_line;
1324
220
        ps_dec->pu1_cur_u_intra_pred_line_base =
1325
220
                        ps_dec->pu1_cur_u_intra_pred_line;
1326
220
        ps_dec->pu1_cur_v_intra_pred_line_base =
1327
220
                        ps_dec->pu1_cur_v_intra_pred_line;
1328
220
1329
220
1330
220
1331
220
1332
220
1333
220
    }
1334
5.06k
1335
5.06k
}
1336
1337
1338
void ih264d_filter_boundary_left_mbaff(dec_struct_t *ps_dec,
1339
                                       tfr_ctxt_t * ps_tfr_cxt,
1340
                                       WORD8 i1_cb_qp_idx_ofst,
1341
                                       WORD8 i1_cr_qp_idx_ofst,
1342
                                       deblk_mb_t * ps_cur_mb,
1343
                                       WORD32 i4_strd_y,
1344
                                       WORD32 i4_strd_uv,
1345
                                       deblk_mb_t * ps_left_mb, /* Neighbouring MB parameters   */
1346
                                       UWORD32 pu4_bs_tab[], /* pointer to the BsTable array */
1347
                                       UWORD8 u1_cur_fld)
1348
0
{
1349
0
    UWORD8 *pu1_y, *pu1_u, *pu1_v;
1350
0
    UWORD8 uc_tmp, qp_avg;
1351
0
    WORD32 alpha_u = 0, beta_u = 0, alpha_v = 0, beta_v = 0;
1352
0
    WORD32 alpha_y = 0, beta_y = 0;
1353
0
1354
0
    WORD32 idx_b_u, idx_a_u, idx_b_v, idx_a_v;
1355
0
    WORD32 idx_b_y, idx_a_y;
1356
0
1357
0
    UWORD32 u4_bs_val;
1358
0
1359
0
    UWORD8 *pu1_cliptab_u, *pu1_cliptab_v, *pu1_cliptab_y;
1360
0
1361
0
    UWORD8 u1_double_cl = !ps_cur_mb->u1_single_call;
1362
0
    WORD32 ofst_a = ps_cur_mb->i1_slice_alpha_c0_offset;
1363
0
    WORD32 ofst_b = ps_cur_mb->i1_slice_beta_offset;
1364
0
1365
0
    PROFILE_DISABLE_DEBLK()
1366
0
1367
0
    pu1_y = ps_tfr_cxt->pu1_mb_y;
1368
0
    pu1_u = ps_tfr_cxt->pu1_mb_u;
1369
0
    pu1_v = ps_tfr_cxt->pu1_mb_v;
1370
0
1371
0
    /* LUMA values */
1372
0
    /* Deblock rounding change */
1373
0
    uc_tmp = (UWORD8)((ps_left_mb->u1_mb_qp + ps_cur_mb->u1_mb_qp + 1) >> 1);
1374
0
    qp_avg = uc_tmp;
1375
0
    idx_a_y = qp_avg + ofst_a;
1376
0
    alpha_y = gau1_ih264d_alpha_table[12 + idx_a_y];
1377
0
    idx_b_y = qp_avg + ofst_b;
1378
0
    beta_y = gau1_ih264d_beta_table[12 + idx_b_y];
1379
0
1380
0
    /* Chroma cb values */
1381
0
    {
1382
0
        WORD32 mb_qp1, mb_qp2;
1383
0
        mb_qp1 = (ps_left_mb->u1_mb_qp + i1_cb_qp_idx_ofst);
1384
0
        mb_qp2 = (ps_cur_mb->u1_mb_qp + i1_cb_qp_idx_ofst);
1385
0
        qp_avg = (UWORD8)((gau1_ih264d_qp_scale_cr[12 + mb_qp1]
1386
0
                        + gau1_ih264d_qp_scale_cr[12 + mb_qp2] + 1) >> 1);
1387
0
    }
1388
0
    idx_a_u = qp_avg + ofst_a;
1389
0
    alpha_u = gau1_ih264d_alpha_table[12 + idx_a_u];
1390
0
    idx_b_u = qp_avg + ofst_b;
1391
0
    beta_u = gau1_ih264d_beta_table[12 + idx_b_u];
1392
0
1393
0
    /* Chroma cr values */
1394
0
    {
1395
0
        WORD32 mb_qp1, mb_qp2;
1396
0
        mb_qp1 = (ps_left_mb->u1_mb_qp + i1_cr_qp_idx_ofst);
1397
0
        mb_qp2 = (ps_cur_mb->u1_mb_qp + i1_cr_qp_idx_ofst);
1398
0
        qp_avg = (UWORD8)((gau1_ih264d_qp_scale_cr[12 + mb_qp1]
1399
0
                        + gau1_ih264d_qp_scale_cr[12 + mb_qp2] + 1) >> 1);
1400
0
    }
1401
0
    idx_a_v = qp_avg + ofst_a;
1402
0
    alpha_v = gau1_ih264d_alpha_table[12 + idx_a_v];
1403
0
    idx_b_v = qp_avg + ofst_b;
1404
0
    beta_v = gau1_ih264d_beta_table[12 + idx_b_v];
1405
0
1406
0
    if(u1_double_cl == 0)
1407
0
    {
1408
0
        u4_bs_val = pu4_bs_tab[4];
1409
0
1410
0
        if(0x04040404 == u4_bs_val)
1411
0
        {
1412
0
            ps_dec->pf_deblk_luma_vert_bs4(pu1_y, i4_strd_y, alpha_y, beta_y);
1413
0
            ps_dec->pf_deblk_chroma_vert_bs4(pu1_u, i4_strd_uv, alpha_u,
1414
0
                                             beta_u, alpha_v, beta_v);
1415
0
1416
0
        }
1417
0
        else
1418
0
        {
1419
0
            if(u4_bs_val)
1420
0
            {
1421
0
1422
0
                pu1_cliptab_y = (UWORD8 *)&gau1_ih264d_clip_table[12
1423
0
                                + idx_a_y];
1424
0
                pu1_cliptab_u = (UWORD8 *)&gau1_ih264d_clip_table[12
1425
0
                                + idx_a_u];
1426
0
                pu1_cliptab_v = (UWORD8 *)&gau1_ih264d_clip_table[12
1427
0
                                + idx_a_v];
1428
0
1429
0
                ps_dec->pf_deblk_luma_vert_bslt4(pu1_y, i4_strd_y, alpha_y,
1430
0
                                                 beta_y, u4_bs_val,
1431
0
                                                 pu1_cliptab_y);
1432
0
                ps_dec->pf_deblk_chroma_vert_bslt4(pu1_u, i4_strd_uv, alpha_u,
1433
0
                                                   beta_u, alpha_v, beta_v,
1434
0
                                                   u4_bs_val, pu1_cliptab_u,
1435
0
                                                   pu1_cliptab_v);
1436
0
1437
0
            }
1438
0
        }
1439
0
1440
0
    }
1441
0
    else
1442
0
    {
1443
0
1444
0
        i4_strd_y <<= (!u1_cur_fld);
1445
0
        u4_bs_val = pu4_bs_tab[4];
1446
0
        i4_strd_uv <<= (!u1_cur_fld);
1447
0
1448
0
        if(0x04040404 == u4_bs_val)
1449
0
        {
1450
0
            ps_dec->pf_deblk_luma_vert_bs4_mbaff(pu1_y, i4_strd_y, alpha_y,
1451
0
                                                 beta_y);
1452
0
            ps_dec->pf_deblk_chroma_vert_bs4_mbaff(pu1_u, i4_strd_uv, alpha_u,
1453
0
                                                   beta_u, alpha_v, beta_v);
1454
0
        }
1455
0
        else
1456
0
        {
1457
0
            if(u4_bs_val)
1458
0
            {
1459
0
1460
0
                pu1_cliptab_y = (UWORD8 *)&gau1_ih264d_clip_table[12 + idx_a_y];
1461
0
                pu1_cliptab_u = (UWORD8 *)&gau1_ih264d_clip_table[12 + idx_a_u];
1462
0
                pu1_cliptab_v = (UWORD8 *)&gau1_ih264d_clip_table[12 + idx_a_v];
1463
0
                ps_dec->pf_deblk_luma_vert_bslt4_mbaff(pu1_y, i4_strd_y,
1464
0
                                                       alpha_y, beta_y,
1465
0
                                                       u4_bs_val,
1466
0
                                                       pu1_cliptab_y);
1467
0
                ps_dec->pf_deblk_chroma_vert_bslt4_mbaff(pu1_u, i4_strd_uv,
1468
0
                                                         alpha_u, beta_u,
1469
0
                                                         alpha_v, beta_v,
1470
0
                                                         u4_bs_val,
1471
0
                                                         pu1_cliptab_u,
1472
0
                                                         pu1_cliptab_v);
1473
0
1474
0
            }
1475
0
        }
1476
0
1477
0
        {
1478
0
1479
0
            UWORD16 u2_shift = (i4_strd_y >> 1) << (u1_cur_fld ? 4 : 0);
1480
0
            pu1_y += u2_shift;
1481
0
            u2_shift = (i4_strd_uv >> 1) << (u1_cur_fld ? 3 : 0);
1482
0
            pu1_u += u2_shift;
1483
0
            pu1_v += u2_shift;
1484
0
        }
1485
0
1486
0
        uc_tmp = (((ps_left_mb + 1)->u1_mb_qp + ps_cur_mb->u1_mb_qp + 1) >> 1);
1487
0
        qp_avg = uc_tmp;
1488
0
        idx_a_y = qp_avg + ofst_a;
1489
0
        alpha_y = gau1_ih264d_alpha_table[12 + idx_a_y];
1490
0
        idx_b_y = qp_avg + ofst_b;
1491
0
        beta_y = gau1_ih264d_beta_table[12 + idx_b_y];
1492
0
        u4_bs_val = pu4_bs_tab[9];
1493
0
1494
0
        {
1495
0
            WORD32 mb_qp1, mb_qp2;
1496
0
            mb_qp1 = ((ps_left_mb + 1)->u1_mb_qp + i1_cb_qp_idx_ofst);
1497
0
            mb_qp2 = (ps_cur_mb->u1_mb_qp + i1_cb_qp_idx_ofst);
1498
0
            qp_avg = (UWORD8)((gau1_ih264d_qp_scale_cr[12 + mb_qp1]
1499
0
                            + gau1_ih264d_qp_scale_cr[12 + mb_qp2] + 1) >> 1);
1500
0
        }
1501
0
        idx_a_u = qp_avg + ofst_a;
1502
0
        alpha_u = gau1_ih264d_alpha_table[12 + idx_a_u];
1503
0
        idx_b_u = qp_avg + ofst_b;
1504
0
        beta_u = gau1_ih264d_beta_table[12 + idx_b_u];
1505
0
        u4_bs_val = pu4_bs_tab[9];
1506
0
        {
1507
0
            WORD32 mb_qp1, mb_qp2;
1508
0
            mb_qp1 = ((ps_left_mb + 1)->u1_mb_qp + i1_cr_qp_idx_ofst);
1509
0
            mb_qp2 = (ps_cur_mb->u1_mb_qp + i1_cr_qp_idx_ofst);
1510
0
            qp_avg = (UWORD8)((gau1_ih264d_qp_scale_cr[12 + mb_qp1]
1511
0
                            + gau1_ih264d_qp_scale_cr[12 + mb_qp2] + 1) >> 1);
1512
0
        }
1513
0
        idx_a_v = qp_avg + ofst_a;
1514
0
        alpha_v = gau1_ih264d_alpha_table[12 + idx_a_v];
1515
0
        idx_b_v = qp_avg + ofst_b;
1516
0
        beta_v = gau1_ih264d_beta_table[12 + idx_b_v];
1517
0
1518
0
        if(0x04040404 == u4_bs_val)
1519
0
        {
1520
0
            ps_dec->pf_deblk_luma_vert_bs4_mbaff(pu1_y, i4_strd_y, alpha_y,
1521
0
                                                 beta_y);
1522
0
            ps_dec->pf_deblk_chroma_vert_bs4_mbaff(pu1_u, i4_strd_uv, alpha_u,
1523
0
                                                   beta_u, alpha_v, beta_v);
1524
0
1525
0
        }
1526
0
        else
1527
0
        {
1528
0
            if(u4_bs_val)
1529
0
            {
1530
0
1531
0
                pu1_cliptab_y = (UWORD8 *)&gau1_ih264d_clip_table[12 + idx_a_y];
1532
0
                pu1_cliptab_u = (UWORD8 *)&gau1_ih264d_clip_table[12 + idx_a_u];
1533
0
                pu1_cliptab_v = (UWORD8 *)&gau1_ih264d_clip_table[12 + idx_a_v];
1534
0
1535
0
                ps_dec->pf_deblk_luma_vert_bslt4_mbaff(pu1_y, i4_strd_y,
1536
0
                                                       alpha_y, beta_y,
1537
0
                                                       u4_bs_val,
1538
0
                                                       pu1_cliptab_y);
1539
0
                ps_dec->pf_deblk_chroma_vert_bslt4_mbaff(pu1_u, i4_strd_uv,
1540
0
                                                         alpha_u, beta_u,
1541
0
                                                         alpha_v, beta_v,
1542
0
                                                         u4_bs_val,
1543
0
                                                         pu1_cliptab_u,
1544
0
                                                         pu1_cliptab_v);
1545
0
1546
0
            }
1547
0
        }
1548
0
    }
1549
0
1550
0
}
1551
1552
void ih264d_filter_boundary_topmbaff(dec_struct_t *ps_dec,
1553
                                     tfr_ctxt_t * ps_tfr_cxt,
1554
                                     WORD8 i1_cb_qp_idx_ofst,
1555
                                     WORD8 i1_cr_qp_idx_ofst,
1556
                                     deblk_mb_t * ps_cur_mb,
1557
                                     WORD32 i4_strd_y,
1558
                                     WORD32 i4_strd_uv,
1559
                                     deblk_mb_t * ps_top_mb,
1560
                                     UWORD32 u4_bs)
1561
0
{
1562
0
    UWORD8 *pu1_y, *pu1_u;
1563
0
    WORD32 alpha_u = 0, beta_u = 0, alpha_v = 0, beta_v = 0;
1564
0
    WORD32 alpha_y = 0, beta_y = 0;
1565
0
    WORD32 qp_avg;
1566
0
    WORD32 idx_b_u, idx_a_u, idx_b_v, idx_a_v;
1567
0
    WORD32 idx_b_y, idx_a_y;
1568
0
    UWORD16 uc_tmp;
1569
0
1570
0
    UWORD8 *pu1_cliptab_u, *pu1_cliptab_v, *pu1_cliptab_y;
1571
0
    WORD32 ofst_a = ps_cur_mb->i1_slice_alpha_c0_offset;
1572
0
    WORD32 ofst_b = ps_cur_mb->i1_slice_beta_offset;
1573
0
1574
0
    /* LUMA values */
1575
0
    /* Deblock rounding change */
1576
0
    uc_tmp = ((ps_top_mb->u1_mb_qp + ps_cur_mb->u1_mb_qp + 1) >> 1);
1577
0
    qp_avg = (UWORD8)uc_tmp;
1578
0
    idx_a_y = qp_avg + ofst_a;
1579
0
    alpha_y = gau1_ih264d_alpha_table[12 + idx_a_y];
1580
0
    idx_b_y = qp_avg + ofst_b;
1581
0
    beta_y = gau1_ih264d_beta_table[12 + idx_b_y];
1582
0
    pu1_y = ps_tfr_cxt->pu1_mb_y;
1583
0
1584
0
    /* CHROMA cb values */
1585
0
    {
1586
0
        WORD32 mb_qp1, mb_qp2;
1587
0
        mb_qp1 = (ps_top_mb->u1_mb_qp + i1_cb_qp_idx_ofst);
1588
0
        mb_qp2 = (ps_cur_mb->u1_mb_qp + i1_cb_qp_idx_ofst);
1589
0
        qp_avg = (UWORD8)((gau1_ih264d_qp_scale_cr[12 + mb_qp1]
1590
0
                        + gau1_ih264d_qp_scale_cr[12 + mb_qp2] + 1) >> 1);
1591
0
    }
1592
0
1593
0
    idx_a_u = qp_avg + ofst_a;
1594
0
    alpha_u = gau1_ih264d_alpha_table[12 + idx_a_u];
1595
0
    idx_b_u = qp_avg + ofst_b;
1596
0
    beta_u = gau1_ih264d_beta_table[12 + idx_b_u];
1597
0
    /* CHROMA cr values */
1598
0
    {
1599
0
        WORD32 mb_qp1, mb_qp2;
1600
0
        mb_qp1 = (ps_top_mb->u1_mb_qp + i1_cr_qp_idx_ofst);
1601
0
        mb_qp2 = (ps_cur_mb->u1_mb_qp + i1_cr_qp_idx_ofst);
1602
0
        qp_avg = (UWORD8)((gau1_ih264d_qp_scale_cr[12 + mb_qp1]
1603
0
                        + gau1_ih264d_qp_scale_cr[12 + mb_qp2] + 1) >> 1);
1604
0
    }
1605
0
1606
0
    idx_a_v = qp_avg + ofst_a;
1607
0
    alpha_v = gau1_ih264d_alpha_table[12 + idx_a_v];
1608
0
    idx_b_v = qp_avg + ofst_b;
1609
0
    beta_v = gau1_ih264d_beta_table[12 + idx_b_v];
1610
0
    pu1_u = ps_tfr_cxt->pu1_mb_u;
1611
0
1612
0
    if(u4_bs == 0x04040404)
1613
0
    {
1614
0
        /* Code specific to the assembly module */
1615
0
        ps_dec->pf_deblk_luma_horz_bs4(pu1_y, i4_strd_y, alpha_y, beta_y);
1616
0
        ps_dec->pf_deblk_chroma_horz_bs4(pu1_u, i4_strd_uv, alpha_u, beta_u,
1617
0
                                         alpha_v, beta_v);
1618
0
1619
0
    }
1620
0
    else
1621
0
    {
1622
0
        if(u4_bs)
1623
0
        {
1624
0
1625
0
            pu1_cliptab_y = (UWORD8 *)&gau1_ih264d_clip_table[12 + idx_a_y];
1626
0
            pu1_cliptab_u =
1627
0
                            (UWORD8 *)&gau1_ih264d_clip_table[12 + idx_a_u];
1628
0
            pu1_cliptab_v =
1629
0
                            (UWORD8 *)&gau1_ih264d_clip_table[12 + idx_a_v];
1630
0
1631
0
            ps_dec->pf_deblk_luma_horz_bslt4(pu1_y, i4_strd_y, alpha_y, beta_y,
1632
0
                                             u4_bs, pu1_cliptab_y);
1633
0
            ps_dec->pf_deblk_chroma_horz_bslt4(pu1_u, i4_strd_uv, alpha_u,
1634
0
                                               beta_u, alpha_v, beta_v,
1635
0
                                               u4_bs, pu1_cliptab_u,
1636
0
                                               pu1_cliptab_v);
1637
0
1638
0
        }
1639
0
    }
1640
0
1641
0
}
1642
1643
void ih264d_deblock_mb_mbaff(dec_struct_t *ps_dec,
1644
                             tfr_ctxt_t * ps_tfr_cxt,
1645
                             WORD8 i1_cb_qp_idx_ofst,
1646
                             WORD8 i1_cr_qp_idx_ofst,
1647
                             deblk_mb_t * ps_cur_mb,
1648
                             WORD32 i4_strd_y,
1649
                             WORD32 i4_strd_uv,
1650
                             deblk_mb_t * ps_top_mb,
1651
                             deblk_mb_t * ps_left_mb,
1652
                             UWORD8 u1_cur_fld,
1653
                             UWORD8 u1_extra_top_edge)
1654
0
{
1655
0
    UWORD8 *pu1_y, *pu1_u;
1656
0
    UWORD32 u4_bs;
1657
0
//  WORD8  edge;
1658
0
    WORD32 alpha, beta, alpha_u, beta_u, alpha_v, beta_v;
1659
0
1660
0
    UWORD8 *pu1_cliptab_u;
1661
0
    UWORD8 *pu1_cliptab_v;
1662
0
    UWORD8 *pu1_cliptab_y;
1663
0
1664
0
    UWORD32 * pu4_bs_tab = ps_cur_mb->u4_bs_table;
1665
0
    WORD32 idx_a_y, idx_a_u, idx_a_v;
1666
0
    /* Return from here to switch off deblocking */
1667
0
    PROFILE_DISABLE_DEBLK()
1668
0
1669
0
    i4_strd_y <<= u1_cur_fld;
1670
0
    i4_strd_uv <<= u1_cur_fld;
1671
0
    /*--------------------------------------------------------------------*/
1672
0
    /* Filter wrt Left edge                                               */
1673
0
    /* except                                                             */
1674
0
    /*      - Left Egde is Picture Boundary                               */
1675
0
    /*      - Left Egde is part of Slice Boundary and Deblocking          */
1676
0
    /*        parameters of slice disable Filtering of Slice Boundary Edges*/
1677
0
    /*--------------------------------------------------------------------*/
1678
0
    if(ps_left_mb)
1679
0
        ih264d_filter_boundary_left_mbaff(ps_dec, ps_tfr_cxt, i1_cb_qp_idx_ofst,
1680
0
                                          i1_cr_qp_idx_ofst, ps_cur_mb,
1681
0
                                          i4_strd_y, i4_strd_uv, ps_left_mb,
1682
0
                                          pu4_bs_tab, u1_cur_fld);
1683
0
1684
0
    /*--------------------------------------------------------------------*/
1685
0
    /* Filter wrt Other Vertical Edges                                    */
1686
0
    /*--------------------------------------------------------------------*/
1687
0
    {
1688
0
        WORD32 ofst_a, ofst_b, idx_b_y, idx_b_u,
1689
0
                        idx_b_v;
1690
0
        WORD32 qp_avg, qp_avg_u, qp_avg_v;
1691
0
        ofst_a = ps_cur_mb->i1_slice_alpha_c0_offset;
1692
0
        ofst_b = ps_cur_mb->i1_slice_beta_offset;
1693
0
        qp_avg = ps_cur_mb->u1_mb_qp;
1694
0
        idx_a_y = qp_avg + ofst_a;
1695
0
        alpha = gau1_ih264d_alpha_table[12 + idx_a_y];
1696
0
        idx_b_y = qp_avg + ofst_b;
1697
0
        beta = gau1_ih264d_beta_table[12 + idx_b_y];
1698
0
1699
0
        /* CHROMA Cb values */
1700
0
        qp_avg_u = (qp_avg + i1_cb_qp_idx_ofst);
1701
0
        qp_avg_u = gau1_ih264d_qp_scale_cr[12 + qp_avg_u];
1702
0
        idx_a_u = qp_avg_u + ofst_a;
1703
0
        alpha_u = gau1_ih264d_alpha_table[12 + idx_a_u];
1704
0
        idx_b_u = qp_avg_u + ofst_b;
1705
0
        beta_u = gau1_ih264d_beta_table[12 + idx_b_u];
1706
0
        /* CHROMA Cr values */
1707
0
        qp_avg_v = (qp_avg + i1_cr_qp_idx_ofst);
1708
0
        qp_avg_v = gau1_ih264d_qp_scale_cr[12 + qp_avg_v];
1709
0
        idx_a_v = qp_avg_v + ofst_a;
1710
0
        alpha_v = gau1_ih264d_alpha_table[12 + idx_a_v];
1711
0
        idx_b_v = qp_avg_v + ofst_b;
1712
0
        beta_v = gau1_ih264d_beta_table[12 + idx_b_v];
1713
0
    }
1714
0
1715
0
    //STARTL4_FILTER_VERT;
1716
0
1717
0
    pu1_cliptab_y = (UWORD8 *)&gau1_ih264d_clip_table[12 + idx_a_y]; //this for Luma
1718
0
    pu1_cliptab_u = (UWORD8 *)&gau1_ih264d_clip_table[12 + idx_a_u]; //this for chroma
1719
0
    pu1_cliptab_v = (UWORD8 *)&gau1_ih264d_clip_table[12 + idx_a_v]; //this for chroma
1720
0
1721
0
    //edge=1
1722
0
1723
0
1724
0
    u4_bs = pu4_bs_tab[5];
1725
0
    pu1_y = ps_tfr_cxt->pu1_mb_y;
1726
0
    pu1_u = ps_tfr_cxt->pu1_mb_u;
1727
0
1728
0
    if(u4_bs)
1729
0
    {
1730
0
1731
0
        ps_dec->pf_deblk_luma_vert_bslt4(pu1_y + 4, i4_strd_y, alpha, beta,
1732
0
                                         u4_bs, pu1_cliptab_y);
1733
0
1734
0
    }
1735
0
    //edge=2
1736
0
1737
0
    u4_bs = pu4_bs_tab[6];
1738
0
    if(u4_bs)
1739
0
    {
1740
0
1741
0
        ps_dec->pf_deblk_luma_vert_bslt4(pu1_y + 8, i4_strd_y, alpha, beta,
1742
0
                                         u4_bs, pu1_cliptab_y);
1743
0
        ps_dec->pf_deblk_chroma_vert_bslt4(pu1_u + 4 * YUV420SP_FACTOR,
1744
0
                                           i4_strd_uv, alpha_u, beta_u,
1745
0
                                           alpha_v, beta_v, u4_bs,
1746
0
                                           pu1_cliptab_u, pu1_cliptab_v);
1747
0
    }
1748
0
    //edge=3
1749
0
1750
0
    u4_bs = pu4_bs_tab[7];
1751
0
    if(u4_bs)
1752
0
    {
1753
0
1754
0
        ps_dec->pf_deblk_luma_vert_bslt4(pu1_y + 12, i4_strd_y, alpha, beta,
1755
0
                                         u4_bs, pu1_cliptab_y);
1756
0
1757
0
    }
1758
0
1759
0
    /*--------------------------------------------------------------------*/
1760
0
    /* Filter wrt Top edge                                                */
1761
0
    /* except                                                             */
1762
0
    /*      - Top Egde is Picture Boundary                                */
1763
0
    /*      - Top Egde is part of Slice Boundary and Deblocking           */
1764
0
    /*        parameters of slice disable Filtering of Slice Boundary Edges*/
1765
0
    /*--------------------------------------------------------------------*/
1766
0
    if(ps_top_mb)
1767
0
    {
1768
0
        /** if top MB and MB AFF and cur MB is frame and top is field then  */
1769
0
        /*  one extra top edge needs to be deblocked                        */
1770
0
        if(u1_extra_top_edge)
1771
0
        {
1772
0
            ih264d_filter_boundary_topmbaff(ps_dec, ps_tfr_cxt,
1773
0
                                            i1_cb_qp_idx_ofst,
1774
0
                                            i1_cr_qp_idx_ofst, ps_cur_mb,
1775
0
                                            (UWORD16)(i4_strd_y << 1),
1776
0
                                            (UWORD16)(i4_strd_uv << 1),
1777
0
                                            ps_top_mb - 1, pu4_bs_tab[8]);
1778
0
            ps_tfr_cxt->pu1_mb_y += i4_strd_y;
1779
0
            ps_tfr_cxt->pu1_mb_u += i4_strd_uv;
1780
0
            ps_tfr_cxt->pu1_mb_v += i4_strd_uv;
1781
0
1782
0
            ih264d_filter_boundary_topmbaff(ps_dec, ps_tfr_cxt,
1783
0
                                            i1_cb_qp_idx_ofst,
1784
0
                                            i1_cr_qp_idx_ofst, ps_cur_mb,
1785
0
                                            (UWORD16)(i4_strd_y << 1),
1786
0
                                            (UWORD16)(i4_strd_uv << 1),
1787
0
                                            ps_top_mb, pu4_bs_tab[0]);
1788
0
            ps_tfr_cxt->pu1_mb_y -= i4_strd_y;
1789
0
            ps_tfr_cxt->pu1_mb_u -= i4_strd_uv;
1790
0
            ps_tfr_cxt->pu1_mb_v -= i4_strd_uv;
1791
0
        }
1792
0
        else
1793
0
        {
1794
0
            ih264d_filter_boundary_topmbaff(ps_dec, ps_tfr_cxt,
1795
0
                                            i1_cb_qp_idx_ofst,
1796
0
                                            i1_cr_qp_idx_ofst, ps_cur_mb,
1797
0
                                            i4_strd_y, i4_strd_uv, ps_top_mb,
1798
0
                                            pu4_bs_tab[0]);
1799
0
        }
1800
0
    }
1801
0
1802
0
    /*--------------------------------------------------------------------*/
1803
0
    /* Filter wrt Other Horizontal Edges                                  */
1804
0
    /*--------------------------------------------------------------------*/
1805
0
1806
0
    //edge1
1807
0
    u4_bs = pu4_bs_tab[1];
1808
0
1809
0
    if(u4_bs)
1810
0
    {
1811
0
        ps_dec->pf_deblk_luma_horz_bslt4(pu1_y + (i4_strd_y << 2), i4_strd_y,
1812
0
                                         alpha, beta, u4_bs, pu1_cliptab_y);
1813
0
1814
0
    }
1815
0
    //edge2
1816
0
    u4_bs = pu4_bs_tab[2];
1817
0
1818
0
    if(u4_bs)
1819
0
    {
1820
0
1821
0
        ps_dec->pf_deblk_luma_horz_bslt4(pu1_y + (i4_strd_y << 3), i4_strd_y,
1822
0
                                         alpha, beta, u4_bs, pu1_cliptab_y);
1823
0
        ps_dec->pf_deblk_chroma_horz_bslt4(pu1_u + (i4_strd_uv << 2),
1824
0
                                           i4_strd_uv, alpha_u, beta_u,
1825
0
                                           alpha_v, beta_v, u4_bs,
1826
0
                                           pu1_cliptab_u, pu1_cliptab_v);
1827
0
1828
0
    }
1829
0
    //edge3
1830
0
    u4_bs = pu4_bs_tab[3];
1831
0
    if(u4_bs)
1832
0
    {
1833
0
1834
0
        ps_dec->pf_deblk_luma_horz_bslt4(
1835
0
                        (pu1_y + (i4_strd_y << 3) + (i4_strd_y << 2)),
1836
0
                        i4_strd_y, alpha, beta, u4_bs, pu1_cliptab_y);
1837
0
1838
0
    }
1839
0
1840
0
}
1841
/proc/self/cwd/external/libavc/decoder/ih264d_debug.h
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
#ifndef _IH264D_DEBUG_H_
21
#define _IH264D_DEBUG_H_
22
23
/*!
24
 **************************************************************************
25
 * \file ih264d_debug.h
26
 *
27
 * \brief
28
 *    Contains declarations used for debugging
29
 *
30
 * \date
31
 *    2/12/2002
32
 *
33
 * \author  AI
34
 **************************************************************************
35
 */
36
#ifdef DEBUG_DEC
37
#define H264_DEC_DEBUG_PRINT(...) printf("\n[H264_DEBUG] %s/%d:: ", __FUNCTION__, __LINE__);printf(__VA_ARGS__)
38
#else //DEBUG_DEC
39
37
#define H264_DEC_DEBUG_PRINT(...) {}
40
#endif //DEBUG_DEC
41
#define   STRENGTH_DEBLOCKING         0 //sanjeev
42
#define DEBUG_RECONSTRUCT_LUMA    0
43
#define DEBUG_RECONSTRUCT_CHROMA  0
44
45
#define DEBUG_IDCT                0
46
#define DEBUG_LUMA_IDCT           0
47
#define DEBUG_REF_IDCT            0
48
49
#define BIN_BIT_RATIO             0
50
#define MB_PART_HIST              0
51
52
#define MB_INTRA_PREDICTION       1
53
54
#ifdef WIN32
55
#define CHK_PURIFY                0
56
#else
57
#define CHK_PURIFY                0
58
#endif
59
60
#if MB_INTRA_PREDICTION
61
#define MB_INTRA_CHROMA_PREDICTION_ON 1
62
#define MB_INTRA_4x4_PREDICTION_ON    1
63
#define MB_INTRA_16x16_PREDICTION_ON  1
64
#endif
65
66
#define   TRACE                   0
67
#define   DEBUG_CABAC             0
68
#define   DEBUG_ABS_MVD           0
69
#define   DEBUG_INTRA_PRED_MODES  0
70
#define   DEBUG_DEBLOCKING        0
71
72
#define COPYTHECONTEXT(s,val)
73
#define PRINT_TRACE
74
#define PRINT_TRACE_CAB
75
#define SWITCHOFFTRACE
76
#define SWITCHONTRACE
77
#define SWITCHOFFTRACECABAC
78
#define SWITCHONTRACECABAC
79
80
#define INC_BIN_COUNT(ps_cab_env)
81
#define INC_DECISION_BINS(ps_cab_env)
82
#define INC_BYPASS_BINS(ps_cab_env)
83
#define INC_SYM_COUNT(ps_cab_env)
84
#define PRINT_BIN_BIT_RATIO(ps_dec)
85
#define RESET_BIN_COUNTS(ps_cab_env)
86
87
88
#ifdef PROFILE_DIS_DEBLK
89
#define PROFILE_DISABLE_DEBLK() return;
90
#else
91
9.90k
#define PROFILE_DISABLE_DEBLK() ;
92
#endif
93
94
#ifdef PROFILE_DIS_IQ_IT_RECON
95
#define PROFILE_DISABLE_IQ_IT_RECON()   if (0)
96
#define PROFILE_DISABLE_IQ_IT_RECON_RETURN()   return;
97
#else
98
72.8k
#define PROFILE_DISABLE_IQ_IT_RECON() ;
99
0
#define PROFILE_DISABLE_IQ_IT_RECON_RETURN() ;
100
#endif
101
102
#ifdef PROFILE_DIS_INTRA_PRED
103
#define PROFILE_DISABLE_INTRA_PRED() if (0)
104
#else
105
93.9k
#define PROFILE_DISABLE_INTRA_PRED() ;
106
#endif
107
108
#ifdef PROFILE_DIS_UNPACK
109
#define PROFILE_DISABLE_UNPACK_LUMA() return 0;
110
#define PROFILE_DISABLE_UNPACK_CHROMA() return ;
111
#else
112
39.5k
#define PROFILE_DISABLE_UNPACK_LUMA() ;
113
9.43k
#define PROFILE_DISABLE_UNPACK_CHROMA() ;
114
#endif
115
116
#ifdef PROFILE_DIS_INTER_PRED
117
#define PROFILE_DISABLE_INTER_PRED() return;
118
#else
119
0
#define PROFILE_DISABLE_INTER_PRED() ;
120
#endif
121
122
#ifdef PROFILE_DIS_BOUNDARY_STRENGTH
123
#define PROFILE_DISABLE_BOUNDARY_STRENGTH() return;
124
#else
125
5.06k
#define PROFILE_DISABLE_BOUNDARY_STRENGTH() ;
126
#endif
127
128
#ifdef PROFILE_DIS_MB_PART_INFO
129
#define PROFILE_DISABLE_MB_PART_INFO() return 0;
130
#else
131
0
#define PROFILE_DISABLE_MB_PART_INFO() ;
132
#endif
133
134
#endif /* _IH264D_DEBUG_H_ */
135
/proc/self/cwd/external/libavc/decoder/ih264d_defs.h
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
#ifndef _IH264D_DEFS_H_
21
#define _IH264D_DEFS_H_
22
23
/**
24
 ************************************************************************
25
 * \file ih264d_defs.h
26
 *
27
 * \brief
28
 *    Type definitions used in the code
29
 *
30
 * \date
31
 *    19/11/2002
32
 *
33
 * \author  Sriram Sethuraman
34
 *
35
 ************************************************************************
36
 */
37
2
#define H264_MAX_FRAME_WIDTH                4080
38
1
#define H264_MAX_FRAME_HEIGHT               4080
39
1
#define H264_MAX_FRAME_SIZE                 (4096 * 2048)
40
41
1
#define H264_MIN_FRAME_WIDTH                16
42
1
#define H264_MIN_FRAME_HEIGHT               16
43
44
13
#define FMT_CONV_NUM_ROWS       16
45
46
/** Bit manipulation macros */
47
206k
#define CHECKBIT(a,i) ((a) &  (1 << i))
48
0
#define CLEARBIT(a,i) ((a) &= ~(1 << i))
49
50
/** Macro to convert a integer to a boolean value */
51
36.1k
#define BOOLEAN(x) (!!(x))
52
53
/** Arithmetic operations */
54
55
#define MOD(x,y) ((x)%(y))
55
55
#define DIV(x,y) ((x)/(y))
56
#define MUL(x,y) ((x)*(y))
57
0
#define SIGN_POW2_DIV(x, y) (((x) < 0) ? (-((-(x)) >> (y))) : ((x) >> (y)))
58
59
5.06k
#define MB_ENABLE_FILTERING           0x00
60
10.1k
#define MB_DISABLE_FILTERING          0x01
61
5.06k
#define MB_DISABLE_TOP_EDGE           0x02
62
5.06k
#define MB_DISABLE_LEFT_EDGE          0x04
63
64
/** Maximum number of reference pics */
65
1.36k
#define MAX_REF_BUFS    32
66
6
#define MAX_DISP_BUFS_NEW 64
67
#define MAX_FRAMES              16
68
69
#define INVALID_FRAME_NUM       0x0fffffff
70
11
#define GAP_FRAME_NUM           0x1fffffff
71
72
/** macros for reference picture lists, refIdx to POC mapping */
73
// 1 extra entry into reference picture lists for refIdx = -1.
74
// this entry is always 0. this saves conditional checks in
75
// FillBs modules.
76
5.06k
#define POC_LIST_L0_TO_L1_DIFF  (( 2*MAX_FRAMES) + 1)
77
#define POC_LIST_L0_TO_L1_DIFF_1  ((MAX_FRAMES) + 1)
78
79
0
#define FRM_LIST_L0             0                                               //0
80
0
#define FRM_LIST_L1             1 * POC_LIST_L0_TO_L1_DIFF//FRM_LIST_L0 + POC_LIST_L0_TO_L1_DIFF        //0+33                  //(1 * POC_LIST_L0_TO_L1_DIFF)
81
0
#define TOP_LIST_FLD_L0         2 * POC_LIST_L0_TO_L1_DIFF//FRM_LIST_L1 + POC_LIST_L0_TO_L1_DIFF        //0+33+33                   //(2 * POC_LIST_L0_TO_L1_DIFF)
82
0
#define TOP_LIST_FLD_L1         3 * POC_LIST_L0_TO_L1_DIFF//TOP_LIST_FLD_L0 + POC_LIST_L0_TO_L1_DIFF_1  //0+33+33+17                //(3 * POC_LIST_L0_TO_L1_DIFF)
83
0
#define BOT_LIST_FLD_L0         4 * POC_LIST_L0_TO_L1_DIFF//TOP_LIST_FLD_L1 + POC_LIST_L0_TO_L1_DIFF_1  //0+33+33+17+17
84
0
#define BOT_LIST_FLD_L1         5 * POC_LIST_L0_TO_L1_DIFF//BOT_LIST_FLD_L0 + POC_LIST_L0_TO_L1_DIFF_1  //0+33+33+17+17+17
85
1
#define TOTAL_LIST_ENTRIES      6 * POC_LIST_L0_TO_L1_DIFF//BOT_LIST_FLD_L1 + POC_LIST_L0_TO_L1_DIFF_1  //0+33+33+17+17+17+17
86
#define PAD_MV_BANK_ROW             64
87
6
#define OFFSET_MV_BANK_ROW          ((PAD_MV_BANK_ROW)>>1)
88
#define PAD_PUC_CURNNZ              32
89
#define OFFSET_PUC_CURNNZ           (PAD_PUC_CURNNZ)
90
13
#define PAD_MAP_IDX_POC             (1)
91
#define OFFSET_MAP_IDX_POC          (1)
92
93
1
#define OFFSET_MAP_IDX_POC          (1)
94
95
13
#define NAL_REF_IDC(nal_first_byte)       ((nal_first_byte >> 5) & 0x3)
96
13
#define NAL_FORBIDDEN_BIT(nal_first_byte) (nal_first_byte>>7)
97
13
#define NAL_UNIT_TYPE(nal_first_byte)     (nal_first_byte & 0x1F)
98
99
#define INT_PIC_TYPE_I        (0x00)
100
101
#define YIELD_CNT_THRESHOLD  8
102
103
104
139k
#define OK        0
105
#define END       1
106
#define NOT_OK    -1
107
108
/* For 420SP */
109
96.7k
#define YUV420SP_FACTOR 2
110
111
/*To prevent buffer overflow access; in case the size of nal unit is
112
 *  greater than the allocated buffer size*/
113
1
#define EXTRA_BS_OFFSET 16*16*2
114
115
/**
116
 ***************************************************************************
117
 * Enum to hold various mem records being request
118
 ****************************************************************************
119
 */
120
enum
121
{
122
    /**
123
     * Codec Object at API level
124
     */
125
    MEM_REC_IV_OBJ,
126
127
    /**
128
     * Codec context
129
     */
130
    MEM_REC_CODEC,
131
132
    /**
133
     * Bitstream buffer which holds emulation prevention removed bytes
134
     */
135
    MEM_REC_BITSBUF,
136
137
    /**
138
     * Buffer to hold  coeff data
139
     */
140
    MEM_REC_COEFF_DATA,
141
142
    /**
143
     * Motion vector bank
144
     */
145
    MEM_REC_MVBANK,
146
147
    /**
148
     * Holds mem records passed to the codec.
149
     */
150
    MEM_REC_BACKUP,
151
152
    /**
153
     * Holds SPS
154
     */
155
    MEM_REC_SPS,
156
157
    /**
158
     * Holds PPS
159
     */
160
    MEM_REC_PPS,
161
162
    /**
163
     * Holds Slice Headers
164
     */
165
    MEM_REC_SLICE_HDR,
166
167
    /**
168
     * Holds thread handles
169
     */
170
    MEM_REC_THREAD_HANDLE,
171
172
    /**
173
     * Contains i4_status map indicating parse i4_status per MB basis
174
     */
175
    MEM_REC_PARSE_MAP,
176
177
    /**
178
     * Contains i4_status map indicating processing i4_status per MB basis
179
     */
180
    MEM_REC_PROC_MAP,
181
182
    /**
183
     * Contains slice number info for each MB
184
     */
185
186
    MEM_REC_SLICE_NUM_MAP,
187
188
    /**
189
     * Holds dpb manager context
190
     */
191
    MEM_REC_DPB_MGR,
192
193
    /**
194
     * Holds neighbors' info
195
     */
196
    MEM_REC_NEIGHBOR_INFO,
197
198
    /**
199
     * Holds neighbors' info
200
     */
201
    MEM_REC_PRED_INFO,
202
203
204
    /**
205
     * Holds inter pred inforamation on packed format info
206
     */
207
    MEM_REC_PRED_INFO_PKD,
208
    /**
209
     * Holds neighbors' info
210
     */
211
    MEM_REC_MB_INFO,
212
213
    /**
214
     * Holds deblock Mb info structure frame level)
215
     */
216
    MEM_REC_DEBLK_MB_INFO,
217
218
    /**
219
     * Holds  reference picture buffers in non-shared mode
220
     */
221
    MEM_REC_REF_PIC,
222
223
    /**
224
     * Holds  some misc intermediate_buffers
225
     */
226
    MEM_REC_EXTRA_MEM,
227
228
    /**
229
     * Holds  some misc intermediate_buffers
230
     */
231
    MEM_REC_INTERNAL_SCRATCH,
232
233
    /**
234
     * Holds  some misc intermediate_buffers
235
     */
236
    MEM_REC_INTERNAL_PERSIST,
237
238
    /* holds structures related to picture buffer manager*/
239
    MEM_REC_PIC_BUF_MGR,
240
241
    /*holds structure related to MV buffer manager*/
242
    MEM_REC_MV_BUF_MGR,
243
244
    /**
245
     * Place holder to compute number of memory records.
246
     */
247
    MEM_REC_CNT
248
/* Do not add anything below */
249
};
250
251
#ifdef DEBLOCK_THREAD
252
#define H264_MUTEX_LOCK(lock) ithread_mutex_lock(lock)
253
#define H264_MUTEX_UNLOCK(lock) ithread_mutex_unlock(lock)
254
#else //DEBLOCK_THREAD
255
#define H264_MUTEX_LOCK(lock)
256
#define H264_MUTEX_UNLOCK(lock)
257
258
#define DEBUG_THREADS_PRINTF(...)
259
#define DEBUG_PERF_PRINTF(...)
260
261
/** Profile Types*/
262
0
#define BASE_PROFILE_IDC    66
263
1
#define MAIN_PROFILE_IDC    77
264
0
#define EXTENDED_PROFILE_IDC    88
265
5.07k
#define HIGH_PROFILE_IDC   100
266
267
268
#define MB_SIZE             16
269
#define BLK8x8SIZE           8
270
#define BLK_SIZE             4
271
#define NUM_BLKS_PER_MB     24
272
#define NUM_LUM_BLKS_PER_MB 16
273
0
#define LUM_BLK              0
274
0
#define CHROM_BLK            1
275
#define NUM_PELS_IN_MB      64
276
277
/* Level Types */
278
0
#define H264_LEVEL_1_0     10
279
0
#define H264_LEVEL_1_1     11
280
0
#define H264_LEVEL_1_2     12
281
0
#define H264_LEVEL_1_3     13
282
0
#define H264_LEVEL_2_0     20
283
0
#define H264_LEVEL_2_1     21
284
0
#define H264_LEVEL_2_2     22
285
0
#define H264_LEVEL_3_0     30
286
1
#define H264_LEVEL_3_1     31
287
0
#define H264_LEVEL_3_2     32
288
0
#define H264_LEVEL_4_0     40
289
0
#define H264_LEVEL_4_1     41
290
0
#define H264_LEVEL_4_2     42
291
0
#define H264_LEVEL_5_0     50
292
0
#define H264_LEVEL_5_1     51
293
294
0
#define MAX_MBS_LEVEL_51 36864
295
0
#define MAX_MBS_LEVEL_50 22080
296
0
#define MAX_MBS_LEVEL_42 8704
297
0
#define MAX_MBS_LEVEL_41 8192
298
0
#define MAX_MBS_LEVEL_40 8192
299
0
#define MAX_MBS_LEVEL_32 5120
300
1
#define MAX_MBS_LEVEL_31 3600
301
0
#define MAX_MBS_LEVEL_30 1620
302
0
#define MAX_MBS_LEVEL_22 1620
303
0
#define MAX_MBS_LEVEL_21 792
304
0
#define MAX_MBS_LEVEL_20 396
305
0
#define MAX_MBS_LEVEL_13 396
306
0
#define MAX_MBS_LEVEL_12 396
307
0
#define MAX_MBS_LEVEL_11 396
308
0
#define MAX_MBS_LEVEL_10 99
309
310
/** NAL Types */
311
22
#define SLICE_NAL                       1
312
0
#define SLICE_DATA_PARTITION_A_NAL      2
313
0
#define SLICE_DATA_PARTITION_B_NAL      3
314
0
#define SLICE_DATA_PARTITION_C_NAL      4
315
88
#define IDR_SLICE_NAL                   5
316
0
#define SEI_NAL                         6
317
1
#define SEQ_PARAM_NAL                   7
318
1
#define PIC_PARAM_NAL                   8
319
0
#define ACCESS_UNIT_DELIMITER_RBSP      9
320
#define END_OF_SEQ_RBSP                 10
321
0
#define END_OF_STREAM_RBSP              11
322
0
#define FILLER_DATA_NAL                 12
323
324
/** Entropy coding modes */
325
2.18k
#define CAVLC  0
326
0
#define CABAC  1
327
328
/** Picture Types */
329
0
#define I_PIC       0
330
#define IP_PIC      1
331
#define IPB_PIC     2
332
0
#define SI_PIC      3
333
#define SIP_PIC     4
334
0
#define ISI_PIC     5
335
#define ISI_PSP_PIC 6
336
#define ALL_PIC     7
337
338
/* Frame or field picture type */
339
11
#define FRM_PIC         0x00
340
11
#define TOP_FLD         0x01
341
11
#define BOT_FLD         0x02
342
0
#define COMP_FLD_PAIR   0x03 /* TOP_FLD | BOT_FLD */
343
0
#define AFRM_PIC        0x04
344
11
#define TOP_REF         0x08
345
11
#define BOT_REF         0x10
346
0
#define PIC_MASK        0x03
347
#define NON_EXISTING    0xff
348
349
/* field picture type for display */
350
#define DISP_TOP_FLD    0x00
351
#define DISP_BOT_FLD    0x01
352
353
/** Slice Types */
354
11
#define P_SLICE  0
355
297
#define B_SLICE  1
356
495
#define I_SLICE  2
357
0
#define SP_SLICE 3
358
0
#define SI_SLICE 4
359
360
/* Definition for picture skip */
361
13
#define SKIP_NONE  (0x0)
362
11
#define I_SLC_BIT  (0x1)
363
11
#define P_SLC_BIT  (0x2)
364
11
#define B_SLC_BIT  (0x4)
365
366
/** Macros used for Deblocking */
367
0
#define D_INTER_MB        0
368
10.1k
#define D_INTRA_MB        1
369
0
#define D_PRED_NON_16x16  2
370
0
#define D_B_SLICE         4
371
#define D_B_SUBMB         6 //D_B_SLICE | D_PRED_NON_16x16 | D_INTER_MB
372
5.06k
#define D_FLD_MB          0x80
373
374
/** Macros for Cabac checks */
375
/** MbType */
376
/** |x|x|I_PCM|SKIP|
377
 |S|Inter/Intra|P/B|NON-BD16x16/BD16x16,I16x16/I4x4| */
378
#define CAB_INTRA         0x00 /* 0000 00xx */
379
#define CAB_INTER         0x04 /* 0000 01xx */
380
0
#define CAB_I4x4          0x00 /* 0000 00x0 */
381
0
#define CAB_I16x16        0x01 /* 0000 00x1 */
382
0
#define CAB_BD16x16       0x04 /* 0000 0100 */
383
0
#define CAB_NON_BD16x16   0x05 /* 0000 0101 */
384
0
#define CAB_P             0x07 /* 0000 0111 */
385
0
#define CAB_SI4x4         0x08 /* 0000 10x0 */
386
#define CAB_SI16x16       0x09 /* 0000 10x1 */
387
0
#define CAB_SKIP_MASK     0x10 /* 0001 0000 */
388
1
#define CAB_SKIP          0x10 /* 0001 0000 */
389
0
#define CAB_P_SKIP        0x16 /* 0001 x11x */
390
0
#define CAB_B_SKIP        0x14 /* 0001 x100 */
391
0
#define CAB_BD16x16_MASK  0x07 /* 0000 0111 */
392
0
#define CAB_INTRA_MASK    0x04 /* 0000 0100 */
393
0
#define CAB_I_PCM         0x20 /* 001x xxxx */
394
395
/**< Binarization types for CABAC */
396
/* |x|x|x|x|MSB_FIRST_FLC|FLC|TUNARY|UNARY| */
397
#define UNARY           1
398
#define TUNARY          2
399
#define FLC             4
400
#define MSB_FIRST_FLC   12
401
402
/** Macroblock Types */
403
39.9k
#define I_4x4_MB    0
404
2.81k
#define I_16x16_MB  1
405
0
#define P_MB        2
406
0
#define B_MB        3
407
#define SI_MB       4
408
#define SP_MB       5
409
0
#define I_PCM_MB    6
410
411
#define SI4x4_MB 0xFF
412
413
/** Intra luma 16x16 and chroma 8x8 prediction modes */
414
#define NUM_INTRA_PRED_MODES  4
415
#define VERT    0
416
#define HORIZ   1
417
693
#define DC      2
418
#define PLANE   3
419
176
#define NOT_VALID -1
420
1.61k
#define DC_DC_DC_DC   0x02020202 /*packed 4 bytes used in Decode Intra Mb*/
421
422
/** Intra luma 4x4 prediction modes */
423
#define NUM_INTRA4x4_PRED_MODES 9
424
425
/** VERT, HORIZ, DC are applicable to 4x4 as well */
426
/** D - Down; U - Up; L - Left; R - Right */
427
#define DIAG_DL   3
428
#define DIAG_DR   4
429
#define VERT_R    5
430
#define HORIZ_D   6
431
#define VERT_L    7
432
#define HORIZ_U   8
433
434
/** P_MB prediction modes */
435
#define NUM_INTER_MB_PRED_MODES 5
436
0
#define PRED_16x16  0
437
0
#define PRED_16x8   1
438
0
#define PRED_8x16   2
439
0
#define PRED_8x8    3
440
0
#define PRED_8x8R0  4
441
#define MAGIC_16x16 5
442
10.1k
#define MB_SKIP     255
443
444
/* P_MB submb modes */
445
0
#define P_L0_8x8    0
446
#define P_L0_8x4    1
447
#define P_L0_4x8    2
448
#define P_L0_4x4    3
449
450
/* B_MB submb modes */
451
0
#define B_DIRECT_8x8    0
452
#define B_L0_8x8        1
453
#define B_L1_8x8        2
454
0
#define B_BI_8x8        3
455
#define B_L0_8x4        4
456
#define B_L0_4x8        5
457
#define B_L1_8x4        6
458
#define B_L1_4x8        7
459
#define B_BI_8x4        8
460
#define B_BI_4x8        9
461
#define B_L0_4x4        10
462
#define B_L1_4x4        11
463
#define B_BI_4x4        12
464
465
/** B_MB prediction modes */
466
0
#define B_8x8    22
467
#define PRED_INVALID  -1
468
0
#define B_DIRECT  0
469
0
#define PRED_L0   1
470
0
#define PRED_L1   2
471
0
#define BI_PRED   3
472
#define B_DIRECT_BI_PRED  23
473
#define B_DIRECT_PRED_L0  24
474
#define B_DIRECT_PRED_L1  25
475
0
#define B_DIRECT_SPATIAL  26
476
477
#define B_DIRECT8x8_BI_PRED  13
478
#define B_DIRECT8x8_PRED_L0  14
479
#define B_DIRECT8x8_PRED_L1  15
480
481
#define ONE_TO_ONE  0
482
#define FRM_TO_FLD  1
483
#define FLD_TO_FRM  2
484
485
/** Inter Sub MB Pred modes */
486
#define NUM_INTER_SUBMB_PRED_MODES 4
487
#define SUBMB_8x8    0
488
#define SUBMB_8x4    1
489
#define SUBMB_4x8    2
490
#define SUBMB_4x4    3
491
492
/** Coded Block Pattern - Chroma */
493
18.7k
#define CBPC_ALLZERO    0
494
6.56k
#define CBPC_ACZERO     1
495
2.18k
#define CBPC_NONZERO    2
496
497
/** Index for accessing the left MB in the MV predictor array */
498
0
#define LEFT  0
499
/** Index for accessing the top MB in the MV predictor array */
500
0
#define TOP   1
501
/** Index for accessing the top right MB in the MV predictor array */
502
0
#define TOP_R 2
503
/** Index for accessing the top Left MB in the MV predictor array */
504
#define TOP_L 3
505
506
/** Maximum number of Sequence Parameter sets */
507
3
#define MAX_NUM_SEQ_PARAMS 32
508
509
/** Maximum number of Picture Parameter sets */
510
3
#define MAX_NUM_PIC_PARAMS 256
511
512
2
#define MASK_ERR_SEQ_SET_ID   (0xFFFFFFE0)
513
12
#define MASK_ERR_PIC_SET_ID   (0xFFFFFF00)
514
515
1
#define MAX_PIC_ORDER_CNT_TYPE    2
516
517
1
#define MAX_BITS_IN_FRAME_NUM     16
518
1
#define MAX_BITS_IN_POC_LSB       16
519
520
3
#define H264_MAX_REF_PICS         16
521
2
#define H264_MAX_REF_IDX          32
522
1
#define MAX_WEIGHT_BIPRED_IDC     2
523
0
#define MAX_CABAC_INIT_IDC        2
524
525
2
#define H264_DEFAULT_NUM_CORES 1
526
2
#define DEFAULT_SEPARATE_PARSE (H264_DEFAULT_NUM_CORES == 2)? 1 :0
527
528
/** Maximum number of Slice groups */
529
#define MAX_NUM_SLICE_GROUPS 8
530
#define MAX_NUM_REF_FRAMES_OFFSET 255
531
532
/** Deblocking modes for a slice */
533
11
#define SLICE_BOUNDARY_DBLK_DISABLED  2
534
0
#define DBLK_DISABLED                 1
535
5.06k
#define DBLK_ENABLED                  0
536
22
#define MIN_DBLK_FIL_OFF              -12
537
22
#define MAX_DBLK_FIL_OFF              12
538
539
/** Width of the predictor buffers used for MC */
540
20.2k
#define MB_SIZE             16
541
20.2k
#define BLK8x8SIZE          8
542
57.8k
#define BLK_SIZE             4
543
#define NUM_BLKS_PER_MB     24
544
#define NUM_LUM_BLKS_PER_MB 16
545
546
50.6k
#define SUB_BLK_WIDTH                 4
547
#define SUB_SUB_BLK_SIZE              4 /* 2x2 pixel i4_size */
548
5.09k
#define SUB_BLK_SIZE                  ((SUB_BLK_WIDTH) * (SUB_BLK_WIDTH))
549
3
#define MB_LUM_SIZE                   256
550
4.37k
#define MB_CHROM_SIZE                 64
551
552
/**< Width to pad the luminance frame buff    */
553
/**< Height to pad the luminance frame buff   */
554
/**< Width to pad the chrominance frame buff  */
555
/**< Height to pad the chrominance frame buff */
556
557
60
#define PAD_LEN_Y_H                   32
558
6
#define PAD_LEN_Y_V                   20
559
56
#define PAD_LEN_UV_H                  16
560
2
#define PAD_LEN_UV_V                  8
561
562
8
#define PAD_MV_BANK_ROW             64
563
564
/**< Maimum u4_ofst by which the Mvs could point outside the frame buffers
565
 horizontally in the left and vertically in the top direction */
566
#define MAX_OFFSET_OUTSIDE_X_FRM      -20
567
#define MAX_OFFSET_OUTSIDE_Y_FRM      -20
568
#define MAX_OFFSET_OUTSIDE_UV_FRM     -8
569
570
/** UVLC parsing macros */
571
0
#define   UEV     1
572
#define   SEV     2
573
0
#define   TEV     3
574
575
/** Defines for Boolean values */
576
#ifndef TRUE
577
13
#define TRUE    1
578
22
#define FALSE   0
579
#endif
580
581
255
#define UNUSED_FOR_REF 0
582
44
#define IS_SHORT_TERM  1
583
0
#define IS_LONG_TERM   2
584
585
/** Defines for which field gets displayed first */
586
5.69k
#define MAX_FRAMES              16
587
384
#define INVALID_FRAME_NUM       0x0fffffff
588
10
#define DO_NOT_DISP             254
589
#define DISP_FLD_FIRST_UNDEF  0
590
#define DISP_TOP_FLD_FIRST   1
591
#define DISP_BOT_FLD_FIRST   2
592
593
/** Misc error resilience requirements*/
594
0
#define MASK_LOG2_WEIGHT_DENOM      0xFFFFFFF8
595
0
#define MASK_PRED_WEIGHT_OFFSET     0xFFFFFF00
596
0
#define MAX_REDUNDANT_PIC_CNT       127
597
598
599
600
#endif //DEBLOCK_THREAD
601
602
40.2k
#define NUM_COEFFS_IN_4x4BLK 16
603
604
605
0
#define MEMSET_16BYTES(pu4_start,value)                         \
606
0
{                                                               \
607
0
    memset(pu4_start,value,16);                                 \
608
0
}
609
610
10.1k
#define MEMCPY_16BYTES(dst,src)                                 \
611
10.1k
{                                                               \
612
10.1k
    memcpy(dst,src,16);                                         \
613
10.1k
}
614
615
616
#endif /*_IH264D_DEFS_H_*/
/proc/self/cwd/external/libavc/decoder/ih264d_dpb_manager.h
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
#ifndef _IH264D_DPB_MANAGER_H_
21
#define _IH264D_DPB_MANAGER_H_
22
/*!
23
***************************************************************************
24
* \file ih264d_dpb_manager.h
25
*
26
* \brief
27
*    Decoded Picture Buffer Manager Include File
28
*
29
* Detailed_description
30
*
31
* \date
32
*    19-12-2002
33
*
34
* \author  Sriram Sethuraman
35
***************************************************************************
36
*/
37
#include "ih264_typedefs.h"
38
#include "ih264_macros.h"
39
#include "ih264_platform_macros.h"
40
#include "ih264d_bitstrm.h"
41
#include "ih264d_defs.h"
42
43
0
#define END_OF_MMCO                 0
44
0
#define MARK_ST_PICNUM_AS_NONREF    1
45
0
#define MARK_LT_INDEX_AS_NONREF     2
46
0
#define MARK_ST_PICNUM_AS_LT_INDEX  3
47
0
#define SET_MAX_LT_INDEX            4
48
0
#define RESET_REF_PICTURES          5
49
0
#define SET_LT_INDEX                6
50
#define RESET_NONREF_PICTURES       7
51
0
#define RESET_ALL_PICTURES          8
52
53
struct field_t
54
{
55
    /* picNum of tbe reference field              */
56
    WORD32 i4_pic_num;
57
58
    /*  assigned when used for long term reference */
59
    /* else MAX_REF_BUFS+1 */
60
    UWORD8 u1_long_term_frame_idx;
61
62
    /* 0 : unused for reference                   */
63
    /* 1 : used for short term reference          */
64
    /* 2 : used for long term reference           */
65
    UWORD8 u1_reference_info;
66
};
67
68
69
struct dpb_info_t
70
{
71
  struct pic_buffer_t *ps_pic_buf;       /** Pointer to picture buffer structure */
72
  WORD32 i4_frame_num;      /** frame number of picture - unique for each ref*/
73
  struct dpb_info_t *ps_prev_short;/** Link to the DPB with previous picNum */
74
  struct dpb_info_t *ps_prev_long;     /** Link to the DPB with previous long term frame*/
75
  struct field_t s_top_field;       /** Contains information of the top_field
76
                                     reference info, pic num and longt term frame idx */
77
  struct field_t s_bot_field;       /** Contains information of the bot_field
78
                                     reference info, pic num and longt term frame idx */
79
  UWORD8 u1_buf_id;     /** bufID from bufAPI */
80
  UWORD8 u1_used_as_ref;        /** whether buffer is used as ref for frame or
81
                                     complementary reference field pair */
82
  UWORD8 u1_lt_idx;     /** If buf is assigned long-term index; else MAX_REF_BUFS+1 */
83
84
};
85
86
typedef struct
87
{
88
  struct pic_buffer_t *ps_def_dpb[MAX_REF_BUFS];/** DPB in default index order */
89
  struct pic_buffer_t *ps_mod_dpb[2][2 * MAX_REF_BUFS];/** DPB in reordered index order, 0-fwd,1-bwd */
90
  struct pic_buffer_t *ps_init_dpb[2][2 * MAX_REF_BUFS];/** DPB in reordered index order, 0-fwd,1-bwd */
91
  struct dpb_info_t *ps_dpb_st_head;     /** Pointer to the most recent picNum */
92
  struct dpb_info_t *ps_dpb_ht_head;     /** Pointer to the smallest LT index */
93
  struct dpb_info_t as_dpb_info[MAX_REF_BUFS];       /** Physical storage for dpbInfo for ref bufs */
94
  UWORD8 u1_num_st_ref_bufs;        /** Number of short term ref. buffers */
95
  UWORD8 u1_num_lt_ref_bufs;        /** Number of long term ref. buffer */
96
  UWORD8 u1_max_lt_pic_idx_plus1;       /** Maximum long term pictures - 0 to max_long_term_pic_idx */
97
  UWORD8 u1_num_gaps;       /** Total number of outstanding gaps */
98
  void * pv_codec_handle;             /* For Error Handling */
99
  WORD32 i4_max_frm_num;        /** Max frame number */
100
  WORD32 ai4_gaps_start_frm_num[MAX_FRAMES];/** start frame number for a gap seqn */
101
  WORD32 ai4_gaps_end_frm_num[MAX_FRAMES];       /** start frame number for a gap seqn */
102
  WORD8  ai1_gaps_per_seq[MAX_FRAMES];      /** number of gaps with each gap seqn */
103
  WORD32 ai4_poc_buf_id_map[MAX_FRAMES][3];
104
  WORD8 i1_poc_buf_id_entries;
105
  WORD8 i1_gaps_deleted;
106
  UWORD16 u2_pic_wd;
107
  UWORD16 u2_pic_ht;
108
}dpb_manager_t;
109
110
/** Structure store the MMC Commands */
111
struct MMCParams
112
{
113
  UWORD32 u4_mmco;      /** memory managemet control operation */
114
  UWORD32 u4_diff_pic_num;      /** diff Of Pic Nums Minus1 */
115
  UWORD32 u4_lt_idx;        /** Long Term Pic Idx */
116
  UWORD32 u4_max_lt_idx_plus1;      /** MaxLongTermPicIdxPlus1 */
117
};
118
119
typedef struct
120
{
121
  UWORD8  u1_dpb_commands_read;     /** Flag to indicate that DBP commands are read */
122
  UWORD8  u1_buf_mode;      /** decoder Pic bugffering mode*/
123
  UWORD8  u1_num_of_commands;       /** Number of MMC commands */
124
  /* These variables are ised in case of IDR pictures only */
125
  UWORD8  u1_idr_pic;       /** = 1 ,IDR pic */
126
  UWORD8  u1_no_output_of_prior_pics_flag;
127
  UWORD8  u1_long_term_reference_flag;
128
  struct MMCParams  as_mmc_params[MAX_REF_BUFS];      /* < Buffer to store MMC commands */
129
  UWORD8 u1_dpb_commands_read_slc;
130
}dpb_commands_t;
131
132
void ih264d_init_ref_bufs(dpb_manager_t *ps_dpb_mgr);
133
134
WORD32 ih264d_insert_st_node(dpb_manager_t *ps_dpb_mgr,
135
                          struct pic_buffer_t *ps_pic_buf,
136
                          UWORD8 u1_buf_id,
137
                          UWORD32 u2_cur_pic_num);
138
WORD32 ih264d_update_default_index_list(dpb_manager_t *ps_dpb_mgr);
139
WORD32 ih264d_do_mmco_buffer(dpb_commands_t *ps_dpb_cmds,
140
                          dpb_manager_t *ps_dpb_mgr,
141
                          UWORD8 u1_numRef_frames_for_seq,
142
                          UWORD32 u4_cur_pic_num,
143
                          UWORD32 u2_u4_max_pic_num_minus1,
144
                          UWORD8 u1_nal_unit_type,
145
                          struct pic_buffer_t *ps_pic_buf,
146
                          UWORD8 u1_buf_id,
147
                          UWORD8 u1_fld_pic_flag,
148
                          UWORD8 u1_curr_pic_in_err);
149
void ih264d_release_pics_in_dpb(void *pv_dec,
150
                                UWORD8 u1_disp_bufs);
151
void ih264d_reset_ref_bufs(dpb_manager_t *ps_dpb_mgr);
152
WORD32 ih264d_delete_st_node_or_make_lt(dpb_manager_t *ps_dpb_mgr,
153
                                      WORD32 u4_pic_num,
154
                                      UWORD32 u4_lt_idx,
155
                                      UWORD8 u1_fld_pic_flag);
156
157
WORD32 ih264d_delete_gap_frm_mmco(dpb_manager_t *ps_dpb_mgr,
158
                                  WORD32 i4_frame_num,
159
                                  UWORD8 *pu1_del_node);
160
161
WORD32 ih264d_delete_gap_frm_sliding(dpb_manager_t *ps_dpb_mgr,
162
                                     WORD32 i4_frame_num,
163
                                     UWORD8 *pu1_del_node);
164
165
WORD32 ih264d_do_mmco_for_gaps(dpb_manager_t *ps_dpb_mgr,
166
                             UWORD8 u1_num_ref_frames);
167
168
WORD32 ih264d_insert_pic_in_display_list(dpb_manager_t *ps_dpb_mgr,
169
                                         UWORD8 u1_buf_id,
170
                                         WORD32 i4_display_poc,
171
                                         UWORD32 u4_frame_num);
172
void ih264d_delete_nonref_nondisplay_pics(dpb_manager_t *ps_dpb_mgr);
173
#endif /*  _IH264D_DPB_MANAGER_H_ */
/proc/self/cwd/external/libavc/decoder/ih264d_dpb_mgr.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
#ifdef __ANDROID__
21
#include "log/log.h"
22
#include <cutils/log.h>
23
#endif
24
#include "ih264_typedefs.h"
25
#include "ih264_macros.h"
26
#include "ih264_platform_macros.h"
27
#include "iv.h"
28
#include "ih264d_dpb_manager.h"
29
#include "ih264d_bitstrm.h"
30
#include "ih264d_parse_cavlc.h"
31
#include "ih264d_defs.h"
32
#include "ih264d_structs.h"
33
#include "ih264d_process_bslice.h"
34
#include "ih264d_debug.h"
35
#include "ih264d_tables.h"
36
#include "ih264d_error_handler.h"
37
#include "string.h"
38
#include "ih264d_defs.h"
39
#include "ih264_error.h"
40
#include "ih264_buf_mgr.h"
41
#include "assert.h"
42
43
/*!
44
 ***************************************************************************
45
 * \file ih264d_dpb_mgr.c
46
 *
47
 * \brief
48
 *    Functions for managing the decoded picture buffer
49
 *
50
 * Detailed_description
51
 *
52
 * \date
53
 *    19-12-2002
54
 *
55
 * \author  Sriram Sethuraman
56
 ***************************************************************************
57
 */
58
59
/*!
60
 **************************************************************************
61
 * \if Function name : ih264d_init_ref_bufs \endif
62
 *
63
 * \brief
64
 *    Called at the start for initialization.
65
 *
66
 * \return
67
 *    none
68
 **************************************************************************
69
 */
70
void ih264d_init_ref_bufs(dpb_manager_t *ps_dpb_mgr)
71
2
{
72
2
    UWORD32 i;
73
2
    struct dpb_info_t *ps_dpb_info = ps_dpb_mgr->as_dpb_info;
74
66
    for(i = 0; i < MAX_REF_BUFS; i++)
75
64
    {
76
64
        ps_dpb_info[i].u1_used_as_ref = UNUSED_FOR_REF;
77
64
        ps_dpb_info[i].u1_lt_idx = MAX_REF_BUFS + 1;
78
64
        ps_dpb_info[i].ps_prev_short = NULL;
79
64
        ps_dpb_info[i].ps_prev_long = NULL;
80
64
        ps_dpb_info[i].ps_pic_buf = NULL;
81
64
        ps_dpb_info[i].s_top_field.u1_reference_info = UNUSED_FOR_REF;
82
64
        ps_dpb_info[i].s_bot_field.u1_reference_info = UNUSED_FOR_REF;
83
64
        ps_dpb_info[i].s_top_field.u1_long_term_frame_idx = MAX_REF_BUFS + 1;
84
64
        ps_dpb_info[i].s_bot_field.u1_long_term_frame_idx = MAX_REF_BUFS + 1;
85
64
86
64
    }
87
2
    ps_dpb_mgr->u1_num_st_ref_bufs = ps_dpb_mgr->u1_num_lt_ref_bufs = 0;
88
2
    ps_dpb_mgr->ps_dpb_st_head = NULL;
89
2
    ps_dpb_mgr->ps_dpb_ht_head = NULL;
90
2
    ps_dpb_mgr->i1_gaps_deleted = 0;
91
2
    ps_dpb_mgr->i1_poc_buf_id_entries = 0;
92
2
93
2
    ps_dpb_mgr->u1_num_gaps = 0;
94
34
    for(i = 0; i < MAX_FRAMES; i++)
95
32
    {
96
32
        ps_dpb_mgr->ai4_gaps_start_frm_num[i] = INVALID_FRAME_NUM;
97
32
        ps_dpb_mgr->ai4_gaps_end_frm_num[i] = 0;
98
32
        ps_dpb_mgr->ai1_gaps_per_seq[i] = 0;
99
32
        ps_dpb_mgr->ai4_poc_buf_id_map[i][0] = -1;
100
32
        ps_dpb_mgr->ai4_poc_buf_id_map[i][1] = 0x7fffffff;
101
32
        ps_dpb_mgr->ai4_poc_buf_id_map[i][2] = 0;
102
32
    }
103
2
104
2
}
105
106
void ih264d_free_ref_pic_mv_bufs(void* pv_dec, UWORD8 pic_buf_id)
107
10
{
108
10
    dec_struct_t *ps_dec = (dec_struct_t *)pv_dec;
109
10
110
10
    if((pic_buf_id == ps_dec->u1_pic_buf_id) &&
111
10
                    ps_dec->ps_cur_slice->u1_field_pic_flag &&
112
10
                    (ps_dec->u1_top_bottom_decoded == 0))
113
0
    {
114
0
        return;
115
0
    }
116
10
117
10
    ih264_buf_mgr_release((buf_mgr_t *)ps_dec->pv_pic_buf_mgr,
118
10
                          pic_buf_id,
119
10
                          BUF_MGR_REF);
120
10
    ih264_buf_mgr_release((buf_mgr_t *)ps_dec->pv_mv_buf_mgr,
121
10
                          ps_dec->au1_pic_buf_id_mv_buf_id_map[pic_buf_id],
122
10
                          BUF_MGR_REF);
123
10
}
124
/*!
125
 **************************************************************************
126
 * \if Function name : ih264d_delete_lt_node \endif
127
 *
128
 * \brief
129
 *    Delete a buffer with a long term index from the LT linked list
130
 *
131
 * \return
132
 *    none
133
 **************************************************************************
134
 */
135
WORD32 ih264d_delete_lt_node(dpb_manager_t *ps_dpb_mgr,
136
                             UWORD32 u4_lt_idx,
137
                             UWORD8 u1_fld_pic_flag,
138
                             struct dpb_info_t *ps_lt_node_to_insert,
139
                             WORD32 *pi4_status)
140
0
{
141
0
    *pi4_status = 0;
142
0
    if(ps_dpb_mgr->u1_num_lt_ref_bufs > 0)
143
0
    {
144
0
        WORD32 i;
145
0
        struct dpb_info_t *ps_next_dpb;
146
0
        /* ps_unmark_node points to the node to be removed */
147
0
        /* from long term list.                            */
148
0
        struct dpb_info_t *ps_unmark_node;
149
0
        //Find the node with matching LTIndex
150
0
        ps_next_dpb = ps_dpb_mgr->ps_dpb_ht_head;
151
0
        if(ps_next_dpb->u1_lt_idx == u4_lt_idx)
152
0
        {
153
0
            ps_unmark_node = ps_next_dpb;
154
0
        }
155
0
        else
156
0
        {
157
0
            for(i = 1; i < ps_dpb_mgr->u1_num_lt_ref_bufs; i++)
158
0
            {
159
0
                if(ps_next_dpb->ps_prev_long->u1_lt_idx == u4_lt_idx)
160
0
                    break;
161
0
                ps_next_dpb = ps_next_dpb->ps_prev_long;
162
0
            }
163
0
            if(i == ps_dpb_mgr->u1_num_lt_ref_bufs)
164
0
                *pi4_status = 1;
165
0
            else
166
0
                ps_unmark_node = ps_next_dpb->ps_prev_long;
167
0
        }
168
0
169
0
        if(*pi4_status == 0)
170
0
        {
171
0
            if(u1_fld_pic_flag)
172
0
            {
173
0
                if(ps_lt_node_to_insert != ps_unmark_node)
174
0
                {
175
0
                    UWORD8 u1_deleted = 0;
176
0
                    /* for the ps_unmark_node mark the corresponding field */
177
0
                    /* field as unused for reference                       */
178
0
179
0
                    if(ps_unmark_node->s_top_field.u1_long_term_frame_idx
180
0
                                    == u4_lt_idx)
181
0
                    {
182
0
                        ps_unmark_node->s_top_field.u1_reference_info =
183
0
                                        UNUSED_FOR_REF;
184
0
                        ps_unmark_node->s_top_field.u1_long_term_frame_idx =
185
0
                        MAX_REF_BUFS + 1;
186
0
                        u1_deleted = 1;
187
0
                    }
188
0
                    if(ps_unmark_node->s_bot_field.u1_long_term_frame_idx
189
0
                                    == u4_lt_idx)
190
0
                    {
191
0
                        ps_unmark_node->s_bot_field.u1_reference_info =
192
0
                                        UNUSED_FOR_REF;
193
0
                        ps_unmark_node->s_bot_field.u1_long_term_frame_idx =
194
0
                        MAX_REF_BUFS + 1;
195
0
                        u1_deleted = 1;
196
0
                    }
197
0
198
0
                    if(!u1_deleted)
199
0
                    {
200
0
201
0
                        UWORD32 i4_error_code;
202
0
                        i4_error_code = ERROR_DBP_MANAGER_T;
203
0
204
0
                        return i4_error_code;
205
0
                    }
206
0
                }
207
0
208
0
                ps_unmark_node->u1_used_as_ref =
209
0
                                ps_unmark_node->s_top_field.u1_reference_info
210
0
                                                | ps_unmark_node->s_bot_field.u1_reference_info;
211
0
            }
212
0
            else
213
0
                ps_unmark_node->u1_used_as_ref = UNUSED_FOR_REF;
214
0
215
0
            if(UNUSED_FOR_REF == ps_unmark_node->u1_used_as_ref)
216
0
            {
217
0
                if(ps_unmark_node == ps_dpb_mgr->ps_dpb_ht_head)
218
0
                    ps_dpb_mgr->ps_dpb_ht_head = ps_next_dpb->ps_prev_long;
219
0
220
0
                ps_unmark_node->u1_lt_idx = MAX_REF_BUFS + 1;
221
0
                ps_unmark_node->s_top_field.u1_reference_info =
222
0
                UNUSED_FOR_REF;
223
0
                ps_unmark_node->s_bot_field.u1_reference_info =
224
0
                UNUSED_FOR_REF;
225
0
                // Release the physical buffer
226
0
                ih264d_free_ref_pic_mv_bufs(ps_dpb_mgr->pv_codec_handle,
227
0
                                            ps_unmark_node->u1_buf_id);
228
0
                ps_next_dpb->ps_prev_long = ps_unmark_node->ps_prev_long; //update link
229
0
                ps_unmark_node->ps_prev_long = NULL;
230
0
                ps_dpb_mgr->u1_num_lt_ref_bufs--; //decrement LT buf count
231
0
            }
232
0
        }
233
0
    }
234
0
    return OK;
235
0
}
236
237
/*!
238
 **************************************************************************
239
 * \if Function name : ih264d_insert_lt_node \endif
240
 *
241
 * \brief
242
 *    Insert a buffer into the LT linked list at a given LT index
243
 *
244
 * \return
245
 *    none
246
 **************************************************************************
247
 */
248
WORD32 ih264d_insert_lt_node(dpb_manager_t *ps_dpb_mgr,
249
                           struct dpb_info_t *ps_mov_node,
250
                           UWORD32 u4_lt_idx,
251
                           UWORD8 u1_fld_pic_flag)
252
0
{
253
0
    UWORD8 u1_mark_top_field_long_term = 0;
254
0
    UWORD8 u1_mark_bot_field_long_term = 0;
255
0
256
0
    {
257
0
        if(u1_fld_pic_flag)
258
0
        {
259
0
            /* Assign corresponding field (top or bottom) long_term_frame_idx */
260
0
261
0
            if((ps_mov_node->s_top_field.u1_reference_info == IS_LONG_TERM)
262
0
                            && (ps_mov_node->s_bot_field.u1_reference_info
263
0
                                            == IS_LONG_TERM))
264
0
            {
265
0
                if(ps_mov_node->u1_lt_idx == u4_lt_idx)
266
0
                    u1_mark_bot_field_long_term = 1;
267
0
                else
268
0
                {
269
0
270
0
                    UWORD32 i4_error_code;
271
0
                    i4_error_code = ERROR_DBP_MANAGER_T;
272
0
273
0
                    return i4_error_code;
274
0
275
0
                }
276
0
            }
277
0
            else if(ps_mov_node->s_top_field.u1_reference_info == IS_LONG_TERM)
278
0
            {
279
0
                u1_mark_top_field_long_term = 1;
280
0
            }
281
0
282
0
            if(!(u1_mark_top_field_long_term || u1_mark_bot_field_long_term))
283
0
            {
284
0
                UWORD32 i4_error_code;
285
0
                i4_error_code = ERROR_DBP_MANAGER_T;
286
0
                return i4_error_code;
287
0
            }
288
0
        }
289
0
        else
290
0
        {
291
0
            ps_mov_node->s_top_field.u1_reference_info = IS_LONG_TERM;
292
0
            ps_mov_node->s_bot_field.u1_reference_info = IS_LONG_TERM;
293
0
            ps_mov_node->s_top_field.u1_long_term_frame_idx = u4_lt_idx;
294
0
            ps_mov_node->s_bot_field.u1_long_term_frame_idx = u4_lt_idx;
295
0
            u1_mark_bot_field_long_term = 1;
296
0
            u1_mark_top_field_long_term = 1;
297
0
        }
298
0
299
0
        ps_mov_node->u1_lt_idx = u4_lt_idx; //Assign the LT index to the node
300
0
        ps_mov_node->ps_pic_buf->u1_long_term_frm_idx = u4_lt_idx;
301
0
        ps_mov_node->u1_used_as_ref = IS_LONG_TERM;
302
0
303
0
        /* Insert the new long term in the LT list with  u4_lt_idx    */
304
0
        /* in ascending order.                                         */
305
0
        if(ps_dpb_mgr->u1_num_lt_ref_bufs > 0)
306
0
        {
307
0
            struct dpb_info_t *ps_next_dpb = ps_dpb_mgr->ps_dpb_ht_head;
308
0
            if(u4_lt_idx < ps_next_dpb->u1_lt_idx)
309
0
            {
310
0
                //LTIndex to be inserted is the smallest LT index
311
0
                //Update head and point prev to the next higher index
312
0
                ps_mov_node->ps_prev_long = ps_next_dpb;
313
0
                ps_dpb_mgr->ps_dpb_ht_head = ps_mov_node;
314
0
            }
315
0
            else
316
0
            {
317
0
                WORD32 i;
318
0
                struct dpb_info_t *ps_nxtDPB = ps_next_dpb;
319
0
                ps_next_dpb = ps_next_dpb->ps_prev_long;
320
0
                for(i = 1; i < ps_dpb_mgr->u1_num_lt_ref_bufs; i++)
321
0
                {
322
0
                    if(ps_next_dpb->u1_lt_idx > u4_lt_idx)
323
0
                        break;
324
0
                    ps_nxtDPB = ps_next_dpb;
325
0
                    ps_next_dpb = ps_next_dpb->ps_prev_long;
326
0
                }
327
0
328
0
                ps_nxtDPB->ps_prev_long = ps_mov_node;
329
0
                ps_mov_node->ps_prev_long = ps_next_dpb;
330
0
            }
331
0
        }
332
0
        else
333
0
        {
334
0
            ps_dpb_mgr->ps_dpb_ht_head = ps_mov_node;
335
0
            ps_mov_node->ps_prev_long = NULL;
336
0
        }
337
0
        /* Identify the picture buffer as a long term picture buffer */
338
0
        ps_mov_node->ps_pic_buf->u1_is_short = 0;
339
0
340
0
        /* Increment LT buf count only if new LT node inserted    */
341
0
        /* If Increment during top_field is done, don't increment */
342
0
        /* for bottom field, as both them are part of same pic.   */
343
0
        if(u1_mark_bot_field_long_term)
344
0
            ps_dpb_mgr->u1_num_lt_ref_bufs++;
345
0
346
0
    }
347
0
    return OK;
348
0
}
349
350
/*!
351
 **************************************************************************
352
 * \if Function name : ih264d_insert_st_node \endif
353
 *
354
 * \brief
355
 *    Adds a short term reference picture into the ST linked list
356
 *
357
 * \return
358
 *    None
359
 *
360
 * \note
361
 *    Called only for a new coded picture with nal_ref_idc!=0
362
 **************************************************************************
363
 */
364
WORD32 ih264d_insert_st_node(dpb_manager_t *ps_dpb_mgr,
365
                          struct pic_buffer_t *ps_pic_buf,
366
                          UWORD8 u1_buf_id,
367
                          UWORD32 u4_cur_pic_num)
368
11
{
369
11
    WORD32 i;
370
11
    struct dpb_info_t *ps_dpb_info = ps_dpb_mgr->as_dpb_info;
371
11
    UWORD8 u1_picture_type = ps_pic_buf->u1_picturetype;
372
11
    /* Find an unused dpb location */
373
11
    for(i = 0; i < MAX_REF_BUFS; i++)
374
11
    {
375
11
        if((ps_dpb_info[i].ps_pic_buf == ps_pic_buf)
376
11
                        && ps_dpb_info[i].u1_used_as_ref)
377
0
        {
378
0
            /*signal an error in the case of frame pic*/
379
0
            if(ps_dpb_info[i].ps_pic_buf->u1_pic_type == FRM_PIC)
380
0
            {
381
0
                return ERROR_DBP_MANAGER_T;
382
0
            }
383
0
            else
384
0
            {
385
0
                /* Can occur only for field bottom pictures */
386
0
                ps_dpb_info[i].s_bot_field.u1_reference_info = IS_SHORT_TERM;
387
0
                return OK;
388
0
            }
389
11
        }
390
11
391
11
        if((ps_dpb_info[i].u1_used_as_ref == UNUSED_FOR_REF)
392
11
                        && (ps_dpb_info[i].s_top_field.u1_reference_info
393
11
                                        == UNUSED_FOR_REF)
394
11
                        && (ps_dpb_info[i].s_bot_field.u1_reference_info
395
11
                                        == UNUSED_FOR_REF))
396
11
            break;
397
11
    }
398
11
    if(i == MAX_REF_BUFS)
399
11
    {
400
0
        UWORD32 i4_error_code;
401
0
        i4_error_code = ERROR_DBP_MANAGER_T;
402
0
        return i4_error_code;
403
0
    }
404
11
405
11
    /* Create dpb info */
406
11
    ps_dpb_info[i].ps_pic_buf = ps_pic_buf;
407
11
    ps_dpb_info[i].ps_prev_short = ps_dpb_mgr->ps_dpb_st_head;
408
11
    ps_dpb_info[i].u1_buf_id = u1_buf_id;
409
11
    ps_dpb_info[i].u1_used_as_ref = TRUE;
410
11
    ps_dpb_info[i].u1_lt_idx = MAX_REF_BUFS + 1;
411
11
    ps_dpb_info[i].i4_frame_num = u4_cur_pic_num;
412
11
    ps_dpb_info[i].ps_pic_buf->i4_frame_num = u4_cur_pic_num;
413
11
414
11
    /* update the head node of linked list to point to the cur Pic */
415
11
    ps_dpb_mgr->ps_dpb_st_head = ps_dpb_info + i;
416
11
417
11
    // Increment Short term bufCount
418
11
    ps_dpb_mgr->u1_num_st_ref_bufs++;
419
11
    /* Identify the picture as a short term picture buffer */
420
11
    ps_pic_buf->u1_is_short = IS_SHORT_TERM;
421
11
422
11
    if((u1_picture_type & 0x03) == FRM_PIC)
423
11
    {
424
11
        ps_dpb_info[i].u1_used_as_ref = IS_SHORT_TERM;
425
11
        ps_dpb_info[i].s_top_field.u1_reference_info = IS_SHORT_TERM;
426
11
        ps_dpb_info[i].s_bot_field.u1_reference_info = IS_SHORT_TERM;
427
11
    }
428
11
429
11
    if((u1_picture_type & 0x03) == TOP_FLD)
430
11
        ps_dpb_info[i].s_top_field.u1_reference_info = IS_SHORT_TERM;
431
11
432
11
    if((u1_picture_type & 0x03) == BOT_FLD)
433
11
        ps_dpb_info[i].s_bot_field.u1_reference_info = IS_SHORT_TERM;
434
11
435
11
    return OK;
436
11
}
437
438
/*!
439
 **************************************************************************
440
 * \if Function name : ih264d_delete_st_node_or_make_lt \endif
441
 *
442
 * \brief
443
 *    Delete short term ref with a given picNum from the ST linked list or
444
 *     make it an LT node
445
 *
446
 * \return
447
 *    0 - if successful; -1 - otherwise
448
 *
449
 * \note
450
 *    Common parts to MMCO==1 and MMCO==3 have been combined here
451
 **************************************************************************
452
 */
453
WORD32 ih264d_delete_st_node_or_make_lt(dpb_manager_t *ps_dpb_mgr,
454
                                      WORD32 i4_pic_num,
455
                                      UWORD32 u4_lt_idx,
456
                                      UWORD8 u1_fld_pic_flag)
457
0
{
458
0
    WORD32 i;
459
0
    struct dpb_info_t *ps_next_dpb;
460
0
    WORD32 i4_frame_num = i4_pic_num;
461
0
    struct dpb_info_t *ps_unmark_node = NULL;
462
0
    UWORD8 u1_del_node = 0, u1_del_st = 0;
463
0
    UWORD8 u1_reference_type = UNUSED_FOR_REF;
464
0
    WORD32 ret;
465
0
466
0
    if(u1_fld_pic_flag)
467
0
    {
468
0
        i4_frame_num = i4_frame_num >> 1;
469
0
470
0
        if(u4_lt_idx == (MAX_REF_BUFS + 1))
471
0
            u1_reference_type = UNUSED_FOR_REF;
472
0
        else
473
0
            u1_reference_type = IS_LONG_TERM;
474
0
    }
475
0
476
0
    //Find the node with matching picNum
477
0
    ps_next_dpb = ps_dpb_mgr->ps_dpb_st_head;
478
0
    if((WORD32)ps_next_dpb->i4_frame_num == i4_frame_num)
479
0
    {
480
0
        ps_unmark_node = ps_next_dpb;
481
0
    }
482
0
    else
483
0
    {
484
0
        for(i = 1; i < ps_dpb_mgr->u1_num_st_ref_bufs; i++)
485
0
        {
486
0
            if((WORD32)ps_next_dpb->ps_prev_short->i4_frame_num == i4_frame_num)
487
0
                break;
488
0
            ps_next_dpb = ps_next_dpb->ps_prev_short;
489
0
        }
490
0
491
0
        if(i == ps_dpb_mgr->u1_num_st_ref_bufs)
492
0
        {
493
0
            if(ps_dpb_mgr->u1_num_gaps)
494
0
            {
495
0
                ret = ih264d_delete_gap_frm_mmco(ps_dpb_mgr, i4_frame_num, &u1_del_st);
496
0
                if(ret != OK)
497
0
                    return ret;
498
0
            }
499
0
            else
500
0
            {
501
0
                UWORD32 i4_error_code;
502
0
                i4_error_code = ERROR_DBP_MANAGER_T;
503
0
504
0
                return i4_error_code;
505
0
            }
506
0
507
0
            if(u1_del_st)
508
0
            {
509
0
                UWORD32 i4_error_code;
510
0
                i4_error_code = ERROR_DBP_MANAGER_T;
511
0
                return i4_error_code;
512
0
            }
513
0
            else
514
0
            {
515
0
                return 0;
516
0
            }
517
0
        }
518
0
        else
519
0
            ps_unmark_node = ps_next_dpb->ps_prev_short;
520
0
    }
521
0
522
0
    if(u1_fld_pic_flag)
523
0
    {
524
0
        /* Mark the corresponding field ( top or bot) as  */
525
0
        /* UNUSED_FOR_REF or IS_LONG_TERM depending on    */
526
0
        /* u1_reference_type.                             */
527
0
        if(ps_unmark_node->s_top_field.i4_pic_num == i4_pic_num)
528
0
        {
529
0
            ps_unmark_node->s_top_field.u1_reference_info = u1_reference_type;
530
0
            ps_unmark_node->s_top_field.u1_long_term_frame_idx = u4_lt_idx;
531
0
            {
532
0
                UWORD8 *pu1_src = ps_unmark_node->ps_pic_buf->pu1_col_zero_flag;
533
0
                WORD32 i4_size = ((ps_dpb_mgr->u2_pic_wd
534
0
                                * ps_dpb_mgr->u2_pic_ht) >> 5);
535
0
                /* memset the colocated zero u4_flag buffer */
536
0
                memset(pu1_src, 0, i4_size);
537
0
            }
538
0
        }
539
0
540
0
        else if(ps_unmark_node->s_bot_field.i4_pic_num == i4_pic_num)
541
0
        {
542
0
543
0
            ps_unmark_node->s_bot_field.u1_reference_info = u1_reference_type;
544
0
            ps_unmark_node->s_bot_field.u1_long_term_frame_idx = u4_lt_idx;
545
0
            {
546
0
                UWORD8 *pu1_src =
547
0
                                ps_unmark_node->ps_pic_buf->pu1_col_zero_flag
548
0
                                                + ((ps_dpb_mgr->u2_pic_wd
549
0
                                                                * ps_dpb_mgr->u2_pic_ht)
550
0
                                                                >> 5);
551
0
                WORD32 i4_size = ((ps_dpb_mgr->u2_pic_wd
552
0
                                * ps_dpb_mgr->u2_pic_ht) >> 5);
553
0
                /* memset the colocated zero u4_flag buffer */
554
0
                memset(pu1_src, 0, i4_size);
555
0
            }
556
0
        }
557
0
        ps_unmark_node->u1_used_as_ref =
558
0
                        ps_unmark_node->s_top_field.u1_reference_info
559
0
                                        | ps_unmark_node->s_bot_field.u1_reference_info;
560
0
    }
561
0
    else
562
0
    {
563
0
        ps_unmark_node->u1_used_as_ref = UNUSED_FOR_REF;
564
0
        ps_unmark_node->s_top_field.u1_reference_info = UNUSED_FOR_REF;
565
0
        ps_unmark_node->s_bot_field.u1_reference_info = UNUSED_FOR_REF;
566
0
567
0
        {
568
0
            UWORD8 *pu1_src = ps_unmark_node->ps_pic_buf->pu1_col_zero_flag;
569
0
570
0
            WORD32 i4_size = ((ps_dpb_mgr->u2_pic_wd
571
0
                            * ps_dpb_mgr->u2_pic_ht) >> 4);
572
0
            /* memset the colocated zero u4_flag buffer */
573
0
            memset(pu1_src, 0, i4_size);
574
0
        }
575
0
    }
576
0
577
0
    if(!(ps_unmark_node->u1_used_as_ref & IS_SHORT_TERM))
578
0
    {
579
0
        if(ps_unmark_node == ps_dpb_mgr->ps_dpb_st_head)
580
0
            ps_dpb_mgr->ps_dpb_st_head = ps_next_dpb->ps_prev_short;
581
0
        else
582
0
            ps_next_dpb->ps_prev_short = ps_unmark_node->ps_prev_short; //update link
583
0
        ps_dpb_mgr->u1_num_st_ref_bufs--; //decrement ST buf count
584
0
        u1_del_node = 1;
585
0
    }
586
0
587
0
    if(u4_lt_idx == MAX_REF_BUFS + 1)
588
0
    {
589
0
        if(u1_del_node)
590
0
        {
591
0
            // Release the physical buffer
592
0
            ih264d_free_ref_pic_mv_bufs(ps_dpb_mgr->pv_codec_handle,
593
0
                                        ps_unmark_node->u1_buf_id);
594
0
            ps_unmark_node->ps_prev_short = NULL;
595
0
        }
596
0
    }
597
0
    else
598
0
    {
599
0
        WORD32 i4_status;
600
0
        //If another node has the same LT index, delete that node
601
0
        ret = ih264d_delete_lt_node(ps_dpb_mgr, u4_lt_idx,
602
0
                              u1_fld_pic_flag, ps_unmark_node, &i4_status);
603
0
        if(ret != OK)
604
0
            return ret;
605
0
        // Now insert the short term node as a long term node
606
0
        ret = ih264d_insert_lt_node(ps_dpb_mgr, ps_unmark_node, u4_lt_idx,
607
0
                              u1_fld_pic_flag);
608
0
        if(ret != OK)
609
0
            return ret;
610
0
    }
611
0
    return OK;
612
0
}
613
/*!
614
 **************************************************************************
615
 * \if Function name : ih264d_reset_ref_bufs \endif
616
 *
617
 * \brief
618
 *    Called if MMCO==5/7 or on the first slice of an IDR picture
619
 *
620
 * \return
621
 *    none
622
 **************************************************************************
623
 */
624
void ih264d_reset_ref_bufs(dpb_manager_t *ps_dpb_mgr)
625
22
{
626
22
    WORD32 i;
627
22
    struct dpb_info_t *ps_dpb_info = ps_dpb_mgr->as_dpb_info;
628
22
629
726
    for(i = 0; i < MAX_REF_BUFS; i++)
630
704
    {
631
704
        if(ps_dpb_info[i].u1_used_as_ref)
632
10
        {
633
10
            ps_dpb_info[i].u1_used_as_ref = UNUSED_FOR_REF;
634
10
            ps_dpb_info[i].u1_lt_idx = MAX_REF_BUFS + 1;
635
10
            ps_dpb_info[i].ps_prev_short = NULL;
636
10
            ps_dpb_info[i].ps_prev_long = NULL;
637
10
            ps_dpb_info[i].ps_pic_buf = NULL;
638
10
            ps_dpb_info[i].s_top_field.u1_reference_info = UNUSED_FOR_REF;
639
10
            ps_dpb_info[i].s_bot_field.u1_reference_info = UNUSED_FOR_REF;
640
10
            ps_dpb_info[i].s_top_field.u1_long_term_frame_idx = MAX_REF_BUFS + 1;
641
10
            ps_dpb_info[i].s_bot_field.u1_long_term_frame_idx = MAX_REF_BUFS + 1;
642
10
643
10
            //Release physical buffer
644
10
            ih264d_free_ref_pic_mv_bufs(ps_dpb_mgr->pv_codec_handle,
645
10
                                        ps_dpb_info[i].u1_buf_id);
646
10
        }
647
704
    }
648
22
    ps_dpb_mgr->u1_num_st_ref_bufs = ps_dpb_mgr->u1_num_lt_ref_bufs = 0;
649
22
    ps_dpb_mgr->ps_dpb_st_head = NULL;
650
22
    ps_dpb_mgr->ps_dpb_ht_head = NULL;
651
22
652
22
    /* release all gaps */
653
22
    ps_dpb_mgr->u1_num_gaps = 0;
654
374
    for(i = 0; i < MAX_FRAMES; i++)
655
352
    {
656
352
        ps_dpb_mgr->ai4_gaps_start_frm_num[i] = INVALID_FRAME_NUM;
657
352
        ps_dpb_mgr->ai4_gaps_end_frm_num[i] = 0;
658
352
        ps_dpb_mgr->ai1_gaps_per_seq[i] = 0;
659
352
    }
660
22
}
661
662
/*!
663
 **************************************************************************
664
 * \if Function name : Name \endif
665
 *
666
 * \brief
667
 *     create the default index list after an MMCO
668
 *
669
 * \return
670
 *    0 - if no_error; -1 - error
671
 *
672
 **************************************************************************
673
 */
674
WORD32 ih264d_update_default_index_list(dpb_manager_t *ps_dpb_mgr)
675
11
{
676
11
    WORD32 i;
677
11
    struct dpb_info_t *ps_next_dpb = ps_dpb_mgr->ps_dpb_st_head;
678
11
679
22
    for(i = 0; i < ps_dpb_mgr->u1_num_st_ref_bufs; i++)
680
11
    {
681
11
        ps_dpb_mgr->ps_def_dpb[i] = ps_next_dpb->ps_pic_buf;
682
11
        ps_next_dpb = ps_next_dpb->ps_prev_short;
683
11
    }
684
11
685
11
    ps_next_dpb = ps_dpb_mgr->ps_dpb_ht_head;
686
11
    for(;i< ps_dpb_mgr->u1_num_st_ref_bufs + ps_dpb_mgr->u1_num_lt_ref_bufs; i++)
687
0
    {
688
0
        ps_dpb_mgr->ps_def_dpb[i] = ps_next_dpb->ps_pic_buf;
689
0
        ps_next_dpb = ps_next_dpb->ps_prev_long;
690
0
    }
691
11
    return 0;
692
11
}
693
694
/*!
695
 **************************************************************************
696
 * \if Function name : ref_idx_reordering \endif
697
 *
698
 * \brief
699
 *     Parse the bitstream and reorder indices for the current slice
700
 *
701
 * \return
702
 *    0 - if no_error; -1 - error
703
 *
704
 * \note
705
 *    Called only if ref_idx_reordering_flag_l0 is decoded as 1
706
 *    Remove error checking for unmatching picNum or LTIndex later (if not needed)
707
 * \para
708
 *    This section implements 7.3.3.1 and 8.2.6.4
709
 *    Uses the default index list as the starting point and
710
 *    remaps the picNums sent to the next higher index in the
711
 *    modified list. The unmodified ones are copied from the
712
 *    default to modified list retaining their order in the default list.
713
 *
714
 **************************************************************************
715
 */
716
WORD32 ih264d_ref_idx_reordering(dec_struct_t *ps_dec, UWORD8 uc_lx)
717
0
{
718
0
    dpb_manager_t *ps_dpb_mgr = ps_dec->ps_dpb_mgr;
719
0
    UWORD16 u4_cur_pic_num = ps_dec->ps_cur_slice->u2_frame_num;
720
0
    /*< Maximum Picture Number Minus 1 */
721
0
    UWORD16 ui_max_frame_num =
722
0
                    ps_dec->ps_cur_sps->u2_u4_max_pic_num_minus1 + 1;
723
0
724
0
    WORD32 i, count = 0;
725
0
    UWORD32 ui_remapIdc, ui_nextUev;
726
0
    WORD16 u2_pred_frame_num = u4_cur_pic_num;
727
0
    WORD32 i_temp;
728
0
    UWORD16 u2_def_mod_flag = 0; /* Flag to keep track of which indices have been remapped */
729
0
    UWORD8 modCount = 0;
730
0
    UWORD32 *pu4_bitstrm_buf = ps_dec->ps_bitstrm->pu4_buffer;
731
0
    UWORD32 *pu4_bitstrm_ofst = &ps_dec->ps_bitstrm->u4_ofst;
732
0
    dec_slice_params_t *ps_cur_slice = ps_dec->ps_cur_slice;
733
0
    UWORD8 u1_field_pic_flag = ps_cur_slice->u1_field_pic_flag;
734
0
735
0
    if(u1_field_pic_flag)
736
0
    {
737
0
        u4_cur_pic_num = u4_cur_pic_num * 2 + 1;
738
0
        ui_max_frame_num = ui_max_frame_num * 2;
739
0
    }
740
0
741
0
    u2_pred_frame_num = u4_cur_pic_num;
742
0
743
0
    ui_remapIdc = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
744
0
745
0
    while((ui_remapIdc != 3)
746
0
                    && (count < ps_cur_slice->u1_num_ref_idx_lx_active[uc_lx]))
747
0
    {
748
0
        ui_nextUev = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
749
0
        if(ui_remapIdc != 2)
750
0
        {
751
0
            ui_nextUev = ui_nextUev + 1;
752
0
            if(ui_remapIdc == 0)
753
0
            {
754
0
                // diffPicNum is -ve
755
0
                i_temp = u2_pred_frame_num - ui_nextUev;
756
0
                if(i_temp < 0)
757
0
                    i_temp += ui_max_frame_num;
758
0
            }
759
0
            else
760
0
            {
761
0
                // diffPicNum is +ve
762
0
                i_temp = u2_pred_frame_num + ui_nextUev;
763
0
                if(i_temp >= ui_max_frame_num)
764
0
                    i_temp -= ui_max_frame_num;
765
0
            }
766
0
            /* Find the dpb with the matching picNum (picNum==frameNum for framePic) */
767
0
768
0
            if(i_temp > u4_cur_pic_num)
769
0
                i_temp = i_temp - ui_max_frame_num;
770
0
771
0
            for(i = 0; i < (ps_cur_slice->u1_initial_list_size[uc_lx]); i++)
772
0
            {
773
0
                if(ps_dpb_mgr->ps_init_dpb[uc_lx][i]->i4_pic_num == i_temp)
774
0
                    break;
775
0
            }
776
0
            if(i == (ps_cur_slice->u1_initial_list_size[uc_lx]))
777
0
            {
778
0
                UWORD32 i4_error_code;
779
0
                i4_error_code = ERROR_DBP_MANAGER_T;
780
0
                return i4_error_code;
781
0
            }
782
0
783
0
            u2_def_mod_flag |= (1 << i);
784
0
            ps_dpb_mgr->ps_mod_dpb[uc_lx][modCount++] =
785
0
                            ps_dpb_mgr->ps_init_dpb[uc_lx][i];
786
0
            u2_pred_frame_num = i_temp; //update predictor to be the picNum just obtained
787
0
        }
788
0
        else //2
789
0
        {
790
0
            UWORD8 u1_lt_idx = (UWORD8)ui_nextUev;
791
0
792
0
            for(i = 0; i < (ps_cur_slice->u1_initial_list_size[uc_lx]); i++)
793
0
            {
794
0
                if(!ps_dpb_mgr->ps_init_dpb[uc_lx][i]->u1_is_short)
795
0
                {
796
0
                    if(ps_dpb_mgr->ps_init_dpb[uc_lx][i]->u1_long_term_pic_num
797
0
                                    == u1_lt_idx)
798
0
                        break;
799
0
                }
800
0
            }
801
0
            if(i == (ps_cur_slice->u1_initial_list_size[uc_lx]))
802
0
            {
803
0
                UWORD32 i4_error_code;
804
0
                i4_error_code = ERROR_DBP_MANAGER_T;
805
0
                return i4_error_code;
806
0
            }
807
0
808
0
            u2_def_mod_flag |= (1 << i);
809
0
            ps_dpb_mgr->ps_mod_dpb[uc_lx][modCount++] =
810
0
                            ps_dpb_mgr->ps_init_dpb[uc_lx][i];
811
0
        }
812
0
813
0
        ui_remapIdc = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
814
0
        /* Get the remapping_idc - 0/1/2/3 */
815
0
        count++;
816
0
    }
817
0
818
0
    //Handle the ref indices that were not remapped
819
0
    for(i = 0; i < (ps_cur_slice->u1_num_ref_idx_lx_active[uc_lx]); i++)
820
0
    {
821
0
        if(!(u2_def_mod_flag & (1 << i)))
822
0
            ps_dpb_mgr->ps_mod_dpb[uc_lx][modCount++] =
823
0
                            ps_dpb_mgr->ps_init_dpb[uc_lx][i];
824
0
    }
825
0
    return OK;
826
0
}
827
/*!
828
 **************************************************************************
829
 * \if Function name : ih264d_read_mmco_commands \endif
830
 *
831
 * \brief
832
 *    Parses MMCO commands and stores them in a structure for later use.
833
 *
834
 * \return
835
 *    0 - No error; -1 - Error
836
 *
837
 * \note
838
 *    This function stores MMCO commands in structure only for the first time.
839
 *    In case of MMCO commands being issued for same Picture Number, they are
840
 *    just parsed and not stored them in the structure.
841
 *
842
 **************************************************************************
843
 */
844
WORD32 ih264d_read_mmco_commands(struct _DecStruct * ps_dec)
845
11
{
846
11
    dec_bit_stream_t *ps_bitstrm = ps_dec->ps_bitstrm;
847
11
    dpb_commands_t *ps_dpb_cmds = &(ps_dec->s_dpb_cmds_scratch);
848
11
    dec_slice_params_t * ps_slice = ps_dec->ps_cur_slice;
849
11
    WORD32 j;
850
11
    UWORD8 u1_buf_mode;
851
11
    struct MMCParams *ps_mmc_params;
852
11
    UWORD32 *pu4_bitstrm_buf = ps_dec->ps_bitstrm->pu4_buffer;
853
11
    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
854
11
    UWORD32 u4_bit_ofst = ps_dec->ps_bitstrm->u4_ofst;
855
11
856
11
    ps_slice->u1_mmco_equalto5 = 0;
857
11
    {
858
11
        if(ps_dec->u1_nal_unit_type == IDR_SLICE_NAL)
859
11
        {
860
11
            ps_slice->u1_no_output_of_prior_pics_flag =
861
11
                            ih264d_get_bit_h264(ps_bitstrm);
862
11
            COPYTHECONTEXT("SH: no_output_of_prior_pics_flag",
863
11
                            ps_slice->u1_no_output_of_prior_pics_flag);
864
11
            ps_slice->u1_long_term_reference_flag = ih264d_get_bit_h264(
865
11
                            ps_bitstrm);
866
11
            COPYTHECONTEXT("SH: long_term_reference_flag",
867
11
                            ps_slice->u1_long_term_reference_flag);
868
11
            ps_dpb_cmds->u1_idr_pic = 1;
869
11
            ps_dpb_cmds->u1_no_output_of_prior_pics_flag =
870
11
                            ps_slice->u1_no_output_of_prior_pics_flag;
871
11
            ps_dpb_cmds->u1_long_term_reference_flag =
872
11
                            ps_slice->u1_long_term_reference_flag;
873
11
        }
874
0
        else
875
0
        {
876
0
            u1_buf_mode = ih264d_get_bit_h264(ps_bitstrm); //0 - sliding window; 1 - arbitrary
877
0
            COPYTHECONTEXT("SH: adaptive_ref_pic_buffering_flag", u1_buf_mode);
878
0
            ps_dpb_cmds->u1_buf_mode = u1_buf_mode;
879
0
            j = 0;
880
0
881
0
            if(u1_buf_mode == 1)
882
0
            {
883
0
                UWORD32 u4_mmco;
884
0
                UWORD32 u4_diff_pic_num;
885
0
                UWORD32 u4_lt_idx, u4_max_lt_idx;
886
0
887
0
                u4_mmco = ih264d_uev(pu4_bitstrm_ofst,
888
0
                                     pu4_bitstrm_buf);
889
0
                while(u4_mmco != END_OF_MMCO)
890
0
                {
891
0
                    if (j >= MAX_REF_BUFS)
892
0
                    {
893
0
#ifdef __ANDROID__
894
0
                        ALOGE("b/25818142");
895
0
                        android_errorWriteLog(0x534e4554, "25818142");
896
0
#endif
897
0
                        ps_dpb_cmds->u1_num_of_commands = 0;
898
0
                        return -1;
899
0
                    }
900
0
                    ps_mmc_params = &ps_dpb_cmds->as_mmc_params[j];
901
0
                    ps_mmc_params->u4_mmco = u4_mmco;
902
0
                    switch(u4_mmco)
903
0
                    {
904
0
                        case MARK_ST_PICNUM_AS_NONREF:
905
0
                            u4_diff_pic_num = ih264d_uev(pu4_bitstrm_ofst,
906
0
                                                         pu4_bitstrm_buf);
907
0
                            //Get absDiffPicnumMinus1
908
0
                            ps_mmc_params->u4_diff_pic_num = u4_diff_pic_num;
909
0
                            break;
910
0
911
0
                        case MARK_LT_INDEX_AS_NONREF:
912
0
                            u4_lt_idx = ih264d_uev(pu4_bitstrm_ofst,
913
0
                                                   pu4_bitstrm_buf);
914
0
                            ps_mmc_params->u4_lt_idx = u4_lt_idx;
915
0
                            break;
916
0
917
0
                        case MARK_ST_PICNUM_AS_LT_INDEX:
918
0
                            u4_diff_pic_num = ih264d_uev(pu4_bitstrm_ofst,
919
0
                                                         pu4_bitstrm_buf);
920
0
                            ps_mmc_params->u4_diff_pic_num = u4_diff_pic_num;
921
0
                            u4_lt_idx = ih264d_uev(pu4_bitstrm_ofst,
922
0
                                                   pu4_bitstrm_buf);
923
0
                            ps_mmc_params->u4_lt_idx = u4_lt_idx;
924
0
                            break;
925
0
926
0
                        case SET_MAX_LT_INDEX:
927
0
                        {
928
0
                            u4_max_lt_idx = ih264d_uev(pu4_bitstrm_ofst,
929
0
                                                       pu4_bitstrm_buf);
930
0
                            ps_mmc_params->u4_max_lt_idx_plus1 = u4_max_lt_idx;
931
0
                            break;
932
0
                        }
933
0
                        case RESET_REF_PICTURES:
934
0
                        {
935
0
                            ps_slice->u1_mmco_equalto5 = 1;
936
0
                            break;
937
0
                        }
938
0
939
0
                        case SET_LT_INDEX:
940
0
                            u4_lt_idx = ih264d_uev(pu4_bitstrm_ofst,
941
0
                                                   pu4_bitstrm_buf);
942
0
                            ps_mmc_params->u4_lt_idx = u4_lt_idx;
943
0
                            break;
944
0
945
0
                        default:
946
0
                            break;
947
0
                    }
948
0
                    u4_mmco = ih264d_uev(pu4_bitstrm_ofst,
949
0
                                         pu4_bitstrm_buf);
950
0
951
0
                    j++;
952
0
                }
953
0
                ps_dpb_cmds->u1_num_of_commands = j;
954
0
955
0
            }
956
0
        }
957
11
        ps_dpb_cmds->u1_dpb_commands_read = 1;
958
11
        ps_dpb_cmds->u1_dpb_commands_read_slc = 1;
959
11
960
11
    }
961
11
    u4_bit_ofst = ps_dec->ps_bitstrm->u4_ofst - u4_bit_ofst;
962
11
    return u4_bit_ofst;
963
11
}
964
965
/*!
966
 **************************************************************************
967
 * \if Function name : ih264d_do_mmco_buffer \endif
968
 *
969
 * \brief
970
 *    Perform decoded picture buffer memory management control operations
971
 *
972
 * \return
973
 *    0 - No error; -1 - Error
974
 *
975
 * \note
976
 *    Bitstream is also parsed here to get the MMCOs
977
 *
978
 **************************************************************************
979
 */
980
WORD32 ih264d_do_mmco_buffer(dpb_commands_t *ps_dpb_cmds,
981
                          dpb_manager_t *ps_dpb_mgr,
982
                          UWORD8 u1_numRef_frames_for_seq, /*!< num_ref_frames from active SeqParSet*/
983
                          UWORD32 u4_cur_pic_num,
984
                          UWORD32 u2_u4_max_pic_num_minus1,
985
                          UWORD8 u1_nal_unit_type,
986
                          struct pic_buffer_t *ps_pic_buf,
987
                          UWORD8 u1_buf_id,
988
                          UWORD8 u1_fld_pic_flag,
989
                          UWORD8 u1_curr_pic_in_err)
990
0
{
991
0
    WORD32 i;
992
0
    UWORD8 u1_buf_mode, u1_marked_lt;
993
0
    struct dpb_info_t *ps_next_dpb;
994
0
    UWORD8 u1_num_gaps;
995
0
    UWORD8 u1_del_node = 1;
996
0
    UWORD8 u1_insert_st_pic = 1;
997
0
    WORD32 ret;
998
0
    UNUSED(u1_nal_unit_type);
999
0
    UNUSED(u2_u4_max_pic_num_minus1);
1000
0
    u1_buf_mode = ps_dpb_cmds->u1_buf_mode; //0 - sliding window; 1 - Adaptive
1001
0
    u1_marked_lt = 0;
1002
0
    u1_num_gaps = ps_dpb_mgr->u1_num_gaps;
1003
0
1004
0
    if(!u1_buf_mode)
1005
0
    {
1006
0
        //Sliding window - implements 8.2.5.3
1007
0
        if((ps_dpb_mgr->u1_num_st_ref_bufs
1008
0
                        + ps_dpb_mgr->u1_num_lt_ref_bufs + u1_num_gaps)
1009
0
                        == u1_numRef_frames_for_seq)
1010
0
        {
1011
0
            UWORD8 u1_new_node_flag = 1;
1012
0
            if((0 == ps_dpb_mgr->u1_num_st_ref_bufs) && (0 == u1_num_gaps))
1013
0
            {
1014
0
                UWORD32 i4_error_code;
1015
0
                i4_error_code = ERROR_DBP_MANAGER_T;
1016
0
                return i4_error_code;
1017
0
            }
1018
0
1019
0
            // Chase the links to reach the last but one picNum, if available
1020
0
            ps_next_dpb = ps_dpb_mgr->ps_dpb_st_head;
1021
0
1022
0
            if(ps_dpb_mgr->u1_num_st_ref_bufs > 1)
1023
0
            {
1024
0
                if(ps_next_dpb->i4_frame_num == (WORD32)u4_cur_pic_num)
1025
0
                {
1026
0
                    /* Incase of  filed pictures top_field has been allocated   */
1027
0
                    /* picture buffer and complementary bottom field pair comes */
1028
0
                    /* then the sliding window mechanism should not allocate a  */
1029
0
                    /* new node                                                 */
1030
0
                    u1_new_node_flag = 0;
1031
0
                }
1032
0
1033
0
                for(i = 1; i < (ps_dpb_mgr->u1_num_st_ref_bufs - 1); i++)
1034
0
                {
1035
0
                    if(ps_next_dpb == NULL)
1036
0
                    {
1037
0
                        UWORD32 i4_error_code;
1038
0
                        i4_error_code = ERROR_DBP_MANAGER_T;
1039
0
                        return i4_error_code;
1040
0
                    }
1041
0
                    if(ps_next_dpb->i4_frame_num == (WORD32)u4_cur_pic_num)
1042
0
                    {
1043
0
                        /* Incase of  field pictures top_field has been allocated   */
1044
0
                        /* picture buffer and complementary bottom field pair comes */
1045
0
                        /* then the sliding window mechanism should not allocate a  */
1046
0
                        /* new node                                                 */
1047
0
                        u1_new_node_flag = 0;
1048
0
                    }
1049
0
                    ps_next_dpb = ps_next_dpb->ps_prev_short;
1050
0
                }
1051
0
1052
0
                if(ps_next_dpb->ps_prev_short->ps_prev_short != NULL)
1053
0
                {
1054
0
                    UWORD32 i4_error_code;
1055
0
                    i4_error_code = ERROR_DBP_MANAGER_T;
1056
0
                    return i4_error_code;
1057
0
                }
1058
0
1059
0
                if(u1_new_node_flag)
1060
0
                {
1061
0
                    if(u1_num_gaps)
1062
0
                    {
1063
0
                        ret = ih264d_delete_gap_frm_sliding(ps_dpb_mgr,
1064
0
                                                            ps_next_dpb->ps_prev_short->i4_frame_num,
1065
0
                                                            &u1_del_node);
1066
0
                        if(ret != OK)
1067
0
                            return ret;
1068
0
                    }
1069
0
1070
0
                    if(u1_del_node)
1071
0
                    {
1072
0
                        ps_dpb_mgr->u1_num_st_ref_bufs--;
1073
0
                        ps_next_dpb->ps_prev_short->u1_used_as_ref =
1074
0
                                        UNUSED_FOR_REF;
1075
0
                        ps_next_dpb->ps_prev_short->s_top_field.u1_reference_info =
1076
0
                                        UNUSED_FOR_REF;
1077
0
                        ps_next_dpb->ps_prev_short->s_bot_field.u1_reference_info =
1078
0
                                        UNUSED_FOR_REF;
1079
0
                        ih264d_free_ref_pic_mv_bufs(ps_dpb_mgr->pv_codec_handle,
1080
0
                                                    ps_next_dpb->ps_prev_short->u1_buf_id);
1081
0
                        ps_next_dpb->ps_prev_short->ps_pic_buf = NULL;
1082
0
                        ps_next_dpb->ps_prev_short = NULL;
1083
0
                    }
1084
0
                }
1085
0
            }
1086
0
            else
1087
0
            {
1088
0
                if(ps_dpb_mgr->u1_num_st_ref_bufs)
1089
0
                {
1090
0
                    ret = ih264d_delete_gap_frm_sliding(ps_dpb_mgr,
1091
0
                                                       ps_next_dpb->i4_frame_num,
1092
0
                                                       &u1_del_node);
1093
0
                    if(ret != OK)
1094
0
                        return ret;
1095
0
                    if((ps_next_dpb->i4_frame_num != (WORD32)u4_cur_pic_num)
1096
0
                                    && u1_del_node)
1097
0
                    {
1098
0
                        ps_dpb_mgr->u1_num_st_ref_bufs--;
1099
0
                        ps_next_dpb->u1_used_as_ref = FALSE;
1100
0
                        ps_next_dpb->s_top_field.u1_reference_info =
1101
0
                                        UNUSED_FOR_REF;
1102
0
                        ps_next_dpb->s_bot_field.u1_reference_info =
1103
0
                                        UNUSED_FOR_REF;
1104
0
                        ih264d_free_ref_pic_mv_bufs(ps_dpb_mgr->pv_codec_handle,
1105
0
                                                    ps_next_dpb->u1_buf_id);
1106
0
                        ps_next_dpb->ps_pic_buf = NULL;
1107
0
                        ps_next_dpb->ps_prev_short = NULL;
1108
0
                        ps_dpb_mgr->ps_dpb_st_head = NULL;
1109
0
                        ps_next_dpb = NULL;
1110
0
                    }
1111
0
                    else if(ps_next_dpb->i4_frame_num == (WORD32)u4_cur_pic_num)
1112
0
                    {
1113
0
                        if(u1_curr_pic_in_err)
1114
0
                        {
1115
0
                            u1_insert_st_pic = 0;
1116
0
                        }
1117
0
                        else if(ps_dpb_mgr->u1_num_st_ref_bufs > 0)
1118
0
                        {
1119
0
                            ps_dpb_mgr->u1_num_st_ref_bufs--;
1120
0
                            ps_next_dpb->u1_used_as_ref = FALSE;
1121
0
                            ps_next_dpb->s_top_field.u1_reference_info =
1122
0
                                            UNUSED_FOR_REF;
1123
0
                            ps_next_dpb->s_bot_field.u1_reference_info =
1124
0
                                            UNUSED_FOR_REF;
1125
0
                            ih264d_free_ref_pic_mv_bufs(ps_dpb_mgr->pv_codec_handle,
1126
0
                                                        ps_next_dpb->u1_buf_id);
1127
0
                            ps_next_dpb->ps_pic_buf = NULL;
1128
0
                            ps_next_dpb = NULL;
1129
0
                        }
1130
0
                    }
1131
0
                }
1132
0
                else
1133
0
                {
1134
0
                    ret = ih264d_delete_gap_frm_sliding(ps_dpb_mgr,
1135
0
                                                        INVALID_FRAME_NUM,
1136
0
                                                        &u1_del_node);
1137
0
                    if(ret != OK)
1138
0
                        return ret;
1139
0
                    if(u1_del_node)
1140
0
                    {
1141
0
                        UWORD32 i4_error_code;
1142
0
                        i4_error_code = ERROR_DBP_MANAGER_T;
1143
0
                        return i4_error_code;
1144
0
                    }
1145
0
                }
1146
0
            }
1147
0
        }
1148
0
    }
1149
0
    else
1150
0
    {
1151
0
        //Adaptive memory control - implements 8.2.5.4
1152
0
        UWORD32 u4_mmco;
1153
0
        UWORD32 u4_diff_pic_num;
1154
0
        WORD32 i4_pic_num;
1155
0
        UWORD32 u4_lt_idx;
1156
0
        WORD32 j;
1157
0
        struct MMCParams *ps_mmc_params;
1158
0
1159
0
        for(j = 0; j < ps_dpb_cmds->u1_num_of_commands; j++)
1160
0
        {
1161
0
            ps_mmc_params = &ps_dpb_cmds->as_mmc_params[j];
1162
0
            u4_mmco = ps_mmc_params->u4_mmco; //Get MMCO
1163
0
1164
0
            switch(u4_mmco)
1165
0
            {
1166
0
                case MARK_ST_PICNUM_AS_NONREF:
1167
0
                {
1168
0
1169
0
                    {
1170
0
                        UWORD32 i4_cur_pic_num = u4_cur_pic_num;
1171
0
                        u4_diff_pic_num = ps_mmc_params->u4_diff_pic_num; //Get absDiffPicnumMinus1
1172
0
                        if(u1_fld_pic_flag)
1173
0
                            i4_cur_pic_num = i4_cur_pic_num * 2 + 1;
1174
0
                        i4_pic_num = i4_cur_pic_num - (u4_diff_pic_num + 1);
1175
0
                    }
1176
0
1177
0
                    if(ps_dpb_mgr->u1_num_st_ref_bufs > 0)
1178
0
                    {
1179
0
                        ret = ih264d_delete_st_node_or_make_lt(ps_dpb_mgr,
1180
0
                                                               i4_pic_num,
1181
0
                                                               MAX_REF_BUFS + 1,
1182
0
                                                               u1_fld_pic_flag);
1183
0
                        if(ret != OK)
1184
0
                            return ret;
1185
0
                    }
1186
0
                    else
1187
0
                    {
1188
0
                        UWORD8 u1_dummy;
1189
0
                        ret = ih264d_delete_gap_frm_mmco(ps_dpb_mgr, i4_pic_num, &u1_dummy);
1190
0
                        if(ret != OK)
1191
0
                            return ret;
1192
0
                    }
1193
0
                    break;
1194
0
                }
1195
0
                case MARK_LT_INDEX_AS_NONREF:
1196
0
                {
1197
0
                    WORD32 i4_status;
1198
0
                    u4_lt_idx = ps_mmc_params->u4_lt_idx; //Get long term index
1199
0
                    ret = ih264d_delete_lt_node(ps_dpb_mgr,
1200
0
                                                u4_lt_idx,
1201
0
                                                u1_fld_pic_flag,
1202
0
                                                0, &i4_status);
1203
0
                    if(ret != OK)
1204
0
                        return ret;
1205
0
                    if(i4_status)
1206
0
                    {
1207
0
                        UWORD32 i4_error_code;
1208
0
                        i4_error_code = ERROR_DBP_MANAGER_T;
1209
0
                        return i4_error_code;
1210
0
                    }
1211
0
                    break;
1212
0
                }
1213
0
1214
0
                case MARK_ST_PICNUM_AS_LT_INDEX:
1215
0
                {
1216
0
                    {
1217
0
                        UWORD32 i4_cur_pic_num = u4_cur_pic_num;
1218
0
                        u4_diff_pic_num = ps_mmc_params->u4_diff_pic_num; //Get absDiffPicnumMinus1
1219
0
                        if(u1_fld_pic_flag)
1220
0
                            i4_cur_pic_num = i4_cur_pic_num * 2 + 1;
1221
0
1222
0
                        i4_pic_num = i4_cur_pic_num - (u4_diff_pic_num + 1);
1223
0
                    }
1224
0
1225
0
                    u4_lt_idx = ps_mmc_params->u4_lt_idx; //Get long term index
1226
0
                    if(ps_dpb_mgr->u1_num_st_ref_bufs > 0)
1227
0
                    {
1228
0
                        ret = ih264d_delete_st_node_or_make_lt(ps_dpb_mgr,
1229
0
                                                               i4_pic_num, u4_lt_idx,
1230
0
                                                               u1_fld_pic_flag);
1231
0
                        if(ret != OK)
1232
0
                            return ret;
1233
0
                    }
1234
0
                    break;
1235
0
                }
1236
0
                case SET_MAX_LT_INDEX:
1237
0
                {
1238
0
                    UWORD8 uc_numLT = ps_dpb_mgr->u1_num_lt_ref_bufs;
1239
0
                    u4_lt_idx = ps_mmc_params->u4_max_lt_idx_plus1; //Get Max_long_term_index_plus1
1240
0
                    if(u4_lt_idx < ps_dpb_mgr->u1_max_lt_pic_idx_plus1
1241
0
                                    && uc_numLT > 0)
1242
0
                    {
1243
0
                        struct dpb_info_t *ps_nxtDPB;
1244
0
                        //Set all LT buffers with index >= u4_lt_idx to nonreference
1245
0
                        ps_nxtDPB = ps_dpb_mgr->ps_dpb_ht_head;
1246
0
                        ps_next_dpb = ps_nxtDPB->ps_prev_long;
1247
0
                        if(ps_nxtDPB->u1_lt_idx >= u4_lt_idx)
1248
0
                        {
1249
0
                            i = 0;
1250
0
                            ps_dpb_mgr->ps_dpb_ht_head = NULL;
1251
0
                        }
1252
0
                        else
1253
0
                        {
1254
0
                            for(i = 1; i < uc_numLT; i++)
1255
0
                            {
1256
0
                                if(ps_next_dpb->u1_lt_idx >= u4_lt_idx)
1257
0
                                    break;
1258
0
                                ps_nxtDPB = ps_next_dpb;
1259
0
                                ps_next_dpb = ps_next_dpb->ps_prev_long;
1260
0
                            }
1261
0
                            ps_nxtDPB->ps_prev_long = NULL; //Terminate the link of the closest LTIndex that is <=Max
1262
0
                        }
1263
0
                        ps_dpb_mgr->u1_num_lt_ref_bufs = i;
1264
0
                        if(i == 0)
1265
0
                            ps_next_dpb = ps_nxtDPB;
1266
0
1267
0
                        for(; i < uc_numLT; i++)
1268
0
                        {
1269
0
                            ps_nxtDPB = ps_next_dpb;
1270
0
                            ps_nxtDPB->u1_lt_idx = MAX_REF_BUFS + 1;
1271
0
                            ps_nxtDPB->u1_used_as_ref = UNUSED_FOR_REF;
1272
0
                            ps_nxtDPB->s_top_field.u1_reference_info =
1273
0
                                            UNUSED_FOR_REF;
1274
0
                            ps_nxtDPB->s_bot_field.u1_reference_info =
1275
0
                                            UNUSED_FOR_REF;
1276
0
1277
0
                            ps_nxtDPB->ps_pic_buf = NULL;
1278
0
                            //Release buffer
1279
0
                            ih264d_free_ref_pic_mv_bufs(ps_dpb_mgr->pv_codec_handle,
1280
0
                                                        ps_nxtDPB->u1_buf_id);
1281
0
                            ps_next_dpb = ps_nxtDPB->ps_prev_long;
1282
0
                            ps_nxtDPB->ps_prev_long = NULL;
1283
0
                        }
1284
0
                    }
1285
0
                    ps_dpb_mgr->u1_max_lt_pic_idx_plus1 = u4_lt_idx;
1286
0
1287
0
                    break;
1288
0
                }
1289
0
                case SET_LT_INDEX:
1290
0
                {
1291
0
                    u4_lt_idx = ps_mmc_params->u4_lt_idx; //Get long term index
1292
0
                    ret = ih264d_insert_st_node(ps_dpb_mgr, ps_pic_buf, u1_buf_id,
1293
0
                                          u4_cur_pic_num);
1294
0
                    if(ret != OK)
1295
0
                        return ret;
1296
0
1297
0
                    if(ps_dpb_mgr->u1_num_st_ref_bufs > 0)
1298
0
1299
0
                    {
1300
0
                        ret = ih264d_delete_st_node_or_make_lt(ps_dpb_mgr,
1301
0
                                                               u4_cur_pic_num,
1302
0
                                                               u4_lt_idx,
1303
0
                                                               u1_fld_pic_flag);
1304
0
                        if(ret != OK)
1305
0
                            return ret;
1306
0
                    }
1307
0
                    else
1308
0
                    {
1309
0
                        return ERROR_DBP_MANAGER_T;
1310
0
                    }
1311
0
1312
0
                    u1_marked_lt = 1;
1313
0
                    break;
1314
0
                }
1315
0
1316
0
                default:
1317
0
                    break;
1318
0
            }
1319
0
            if(u4_mmco == RESET_REF_PICTURES || u4_mmco == RESET_ALL_PICTURES)
1320
0
            {
1321
0
                ih264d_reset_ref_bufs(ps_dpb_mgr);
1322
0
                u4_cur_pic_num = 0;
1323
0
            }
1324
0
        }
1325
0
    }
1326
0
    if(!u1_marked_lt && u1_insert_st_pic)
1327
0
    {
1328
0
        ret = ih264d_insert_st_node(ps_dpb_mgr, ps_pic_buf, u1_buf_id,
1329
0
                              u4_cur_pic_num);
1330
0
        if(ret != OK)
1331
0
            return ret;
1332
0
    }
1333
0
    return OK;
1334
0
}
1335
1336
/*****************************************************************************/
1337
/*                                                                           */
1338
/*  Function Name : ih264d_release_pics_in_dpb                                         */
1339
/*                                                                           */
1340
/*  Description   : This function deletes all pictures from DPB              */
1341
/*                                                                           */
1342
/*  Inputs        : h_pic_buf_api: pointer to picture buffer API               */
1343
/*                  u1_disp_bufs: number pictures ready for display           */
1344
/*                                                                           */
1345
/*  Globals       : None                                                     */
1346
/*  Outputs       : None                                                     */
1347
/*  Returns       : None                                                     */
1348
/*                                                                           */
1349
/*  Issues        : None                                                     */
1350
/*                                                                           */
1351
/*  Revision History:                                                        */
1352
/*                                                                           */
1353
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1354
/*         22 06 2005   NS              Draft                                */
1355
/*                                                                           */
1356
/*****************************************************************************/
1357
void ih264d_release_pics_in_dpb(void *pv_dec,
1358
                                UWORD8 u1_disp_bufs)
1359
0
{
1360
0
    WORD8 i;
1361
0
    dec_struct_t *ps_dec = (dec_struct_t *)pv_dec;
1362
0
1363
0
    for(i = 0; i < u1_disp_bufs; i++)
1364
0
    {
1365
0
        ih264_buf_mgr_release((buf_mgr_t *)ps_dec->pv_pic_buf_mgr,
1366
0
                              i,
1367
0
                              BUF_MGR_REF);
1368
0
        ih264_buf_mgr_release((buf_mgr_t *)ps_dec->pv_mv_buf_mgr,
1369
0
                              ps_dec->au1_pic_buf_id_mv_buf_id_map[i],
1370
0
                              BUF_MGR_REF);
1371
0
    }
1372
0
}
1373
1374
/*****************************************************************************/
1375
/*                                                                           */
1376
/*  Function Name : ih264d_delete_gap_frm_sliding                            */
1377
/*                                                                           */
1378
/*  Description   : This function deletes a picture from the list of gaps,   */
1379
/*                  if the frame number of gap frame is lesser than the one  */
1380
/*                  to be deleted by sliding window                          */
1381
/*  Inputs        : ps_dpb_mgr: pointer to dpb manager                       */
1382
/*                  i4_frame_num:  frame number of picture that's going to   */
1383
/*                  be deleted by sliding window                             */
1384
/*                  pu1_del_node: holds 0 if a gap is deleted else 1         */
1385
/*  Globals       : None                                                     */
1386
/*  Processing    : Function searches for frame number lesser than           */
1387
/*                  i4_frame_num in the gaps list                            */
1388
/*  Outputs       : None                                                     */
1389
/*  Returns       : None                                                     */
1390
/*                                                                           */
1391
/*  Issues        : None                                                     */
1392
/*                                                                           */
1393
/*  Revision History:                                                        */
1394
/*                                                                           */
1395
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1396
/*         22 06 2005   NS              Draft                                */
1397
/*                                                                           */
1398
/*****************************************************************************/
1399
WORD32 ih264d_delete_gap_frm_sliding(dpb_manager_t *ps_dpb_mgr,
1400
                                    WORD32 i4_frame_num,
1401
                                    UWORD8 *pu1_del_node)
1402
0
{
1403
0
    WORD8 i1_gap_idx, i, j, j_min;
1404
0
    WORD32 *pi4_gaps_start_frm_num, *pi4_gaps_end_frm_num, i4_gap_frame_num;
1405
0
    WORD32 i4_start_frm_num, i4_end_frm_num;
1406
0
    WORD32 i4_max_frm_num;
1407
0
    WORD32 i4_frm_num, i4_gap_frm_num_min;
1408
0
1409
0
    /* find the least frame num from gaps and current DPB node    */
1410
0
    /* Delete the least one                                       */
1411
0
    *pu1_del_node = 1;
1412
0
    if(0 == ps_dpb_mgr->u1_num_gaps)
1413
0
        return OK;
1414
0
    pi4_gaps_start_frm_num = ps_dpb_mgr->ai4_gaps_start_frm_num;
1415
0
    pi4_gaps_end_frm_num = ps_dpb_mgr->ai4_gaps_end_frm_num;
1416
0
    i4_gap_frame_num = INVALID_FRAME_NUM;
1417
0
    i4_max_frm_num = ps_dpb_mgr->i4_max_frm_num;
1418
0
1419
0
    i1_gap_idx = -1;
1420
0
    if(INVALID_FRAME_NUM != i4_frame_num)
1421
0
    {
1422
0
        i4_gap_frame_num = i4_frame_num;
1423
0
        for(i = 0; i < MAX_FRAMES; i++)
1424
0
        {
1425
0
            i4_start_frm_num = pi4_gaps_start_frm_num[i];
1426
0
            if(INVALID_FRAME_NUM != i4_start_frm_num)
1427
0
            {
1428
0
                i4_end_frm_num = pi4_gaps_end_frm_num[i];
1429
0
                if(i4_end_frm_num < i4_max_frm_num)
1430
0
                {
1431
0
                    if(i4_start_frm_num <= i4_gap_frame_num)
1432
0
                    {
1433
0
                        i4_gap_frame_num = i4_start_frm_num;
1434
0
                        i1_gap_idx = i;
1435
0
                    }
1436
0
                }
1437
0
                else
1438
0
                {
1439
0
                    if(((i4_start_frm_num <= i4_gap_frame_num)
1440
0
                                    && (i4_gap_frame_num <= i4_max_frm_num))
1441
0
                                    || ((i4_start_frm_num >= i4_gap_frame_num)
1442
0
                                                    && ((i4_gap_frame_num
1443
0
                                                                    + i4_max_frm_num)
1444
0
                                                                    >= i4_end_frm_num)))
1445
0
                    {
1446
0
                        i4_gap_frame_num = i4_start_frm_num;
1447
0
                        i1_gap_idx = i;
1448
0
                    }
1449
0
                }
1450
0
            }
1451
0
        }
1452
0
    }
1453
0
    else
1454
0
    {
1455
0
        /* no valid short term buffers, delete one gap from the least start */
1456
0
        /* of gap sequence                                                  */
1457
0
        i4_gap_frame_num = pi4_gaps_start_frm_num[0];
1458
0
        i1_gap_idx = 0;
1459
0
        for(i = 1; i < MAX_FRAMES; i++)
1460
0
        {
1461
0
            if(INVALID_FRAME_NUM != pi4_gaps_start_frm_num[i])
1462
0
            {
1463
0
                if(pi4_gaps_start_frm_num[i] < i4_gap_frame_num)
1464
0
                {
1465
0
                    i4_gap_frame_num = pi4_gaps_start_frm_num[i];
1466
0
                    i1_gap_idx = i;
1467
0
                }
1468
0
            }
1469
0
        }
1470
0
        if(INVALID_FRAME_NUM == i4_gap_frame_num)
1471
0
        {
1472
0
            UWORD32 i4_error_code;
1473
0
            i4_error_code = ERROR_DBP_MANAGER_T;
1474
0
            return i4_error_code;
1475
0
        }
1476
0
    }
1477
0
1478
0
    if(-1 != i1_gap_idx)
1479
0
    {
1480
0
        /* find least frame_num in the poc_map, which is in this range */
1481
0
        i4_start_frm_num = pi4_gaps_start_frm_num[i1_gap_idx];
1482
0
        if(i4_start_frm_num < 0)
1483
0
            i4_start_frm_num += i4_max_frm_num;
1484
0
        i4_end_frm_num = pi4_gaps_end_frm_num[i1_gap_idx];
1485
0
        if(i4_end_frm_num < 0)
1486
0
            i4_end_frm_num += i4_max_frm_num;
1487
0
1488
0
        i4_gap_frm_num_min = 0xfffffff;
1489
0
        j_min = MAX_FRAMES;
1490
0
        for(j = 0; j < MAX_FRAMES; j++)
1491
0
        {
1492
0
            i4_frm_num = ps_dpb_mgr->ai4_poc_buf_id_map[j][2];
1493
0
            if((i4_start_frm_num <= i4_frm_num)
1494
0
                            && (i4_end_frm_num >= i4_frm_num))
1495
0
            {
1496
0
                if(i4_frm_num < i4_gap_frm_num_min)
1497
0
                {
1498
0
                    j_min = j;
1499
0
                    i4_gap_frm_num_min = i4_frm_num;
1500
0
                }
1501
0
            }
1502
0
        }
1503
0
1504
0
        if(j_min != MAX_FRAMES)
1505
0
        {
1506
0
1507
0
            ps_dpb_mgr->ai4_poc_buf_id_map[j_min][0] = -1;
1508
0
            ps_dpb_mgr->ai4_poc_buf_id_map[j_min][1] = 0x7fffffff;
1509
0
            ps_dpb_mgr->ai4_poc_buf_id_map[j_min][2] = GAP_FRAME_NUM;
1510
0
            ps_dpb_mgr->i1_gaps_deleted++;
1511
0
1512
0
            ps_dpb_mgr->ai1_gaps_per_seq[i1_gap_idx]--;
1513
0
            ps_dpb_mgr->u1_num_gaps--;
1514
0
            *pu1_del_node = 0;
1515
0
            if(0 == ps_dpb_mgr->ai1_gaps_per_seq[i1_gap_idx])
1516
0
            {
1517
0
                ps_dpb_mgr->ai4_gaps_start_frm_num[i1_gap_idx] =
1518
0
                INVALID_FRAME_NUM;
1519
0
                ps_dpb_mgr->ai4_gaps_end_frm_num[i1_gap_idx] = 0;
1520
0
            }
1521
0
        }
1522
0
    }
1523
0
1524
0
    return OK;
1525
0
}
1526
1527
/*****************************************************************************/
1528
/*                                                                           */
1529
/*  Function Name : ih264d_delete_gap_frm_mmco                               */
1530
/*                                                                           */
1531
/*  Description   : This function deletes a picture from the list of gaps,   */
1532
/*                  if the frame number (specified by mmco commands) to be   */
1533
/*                  deleted is in the range by gap sequence.                 */
1534
/*                                                                           */
1535
/*  Inputs        : ps_dpb_mgr: pointer to dpb manager                       */
1536
/*                  i4_frame_num:  frame number of picture that's going to   */
1537
/*                  be deleted by mmco                                       */
1538
/*                  pu1_del_node: holds 0 if a gap is deleted else 1         */
1539
/*  Globals       : None                                                     */
1540
/*  Processing    : Function searches for frame number lesser in the range   */
1541
/*                  specified by gap sequence                                */
1542
/*  Outputs       : None                                                     */
1543
/*  Returns       : None                                                     */
1544
/*                                                                           */
1545
/*  Issues        : None                                                     */
1546
/*                                                                           */
1547
/*  Revision History:                                                        */
1548
/*                                                                           */
1549
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1550
/*         22 06 2005   NS              Draft                                */
1551
/*                                                                           */
1552
/*****************************************************************************/
1553
WORD32 ih264d_delete_gap_frm_mmco(dpb_manager_t *ps_dpb_mgr,
1554
                                  WORD32 i4_frame_num,
1555
                                  UWORD8 *pu1_del_node)
1556
0
{
1557
0
    WORD8 i, j;
1558
0
    WORD32 *pi4_start, *pi4_end;
1559
0
    WORD32 i4_start_frm_num, i4_end_frm_num, i4_max_frm_num;
1560
0
1561
0
    /* find the least frame num from gaps and current DPB node    */
1562
0
    /* Delete the gaps                                            */
1563
0
    *pu1_del_node = 1;
1564
0
    pi4_start = ps_dpb_mgr->ai4_gaps_start_frm_num;
1565
0
    pi4_end = ps_dpb_mgr->ai4_gaps_end_frm_num;
1566
0
    i4_max_frm_num = ps_dpb_mgr->i4_max_frm_num;
1567
0
1568
0
    if(0 == ps_dpb_mgr->u1_num_gaps)
1569
0
        return OK;
1570
0
1571
0
    if(i4_frame_num < 0)
1572
0
        i4_frame_num += i4_max_frm_num;
1573
0
    for(i = 0; i < MAX_FRAMES; i++)
1574
0
    {
1575
0
        i4_start_frm_num = pi4_start[i];
1576
0
        if(i4_start_frm_num < 0)
1577
0
            i4_start_frm_num += i4_max_frm_num;
1578
0
        if(INVALID_FRAME_NUM != i4_start_frm_num)
1579
0
        {
1580
0
            i4_end_frm_num = pi4_end[i];
1581
0
            if(i4_end_frm_num < 0)
1582
0
                i4_end_frm_num += i4_max_frm_num;
1583
0
1584
0
            if((i4_frame_num >= i4_start_frm_num)
1585
0
                            && (i4_frame_num <= i4_end_frm_num))
1586
0
            {
1587
0
                break;
1588
0
            }
1589
0
            else
1590
0
            {
1591
0
                if(((i4_frame_num + i4_max_frm_num) >= i4_start_frm_num)
1592
0
                                && ((i4_frame_num + i4_max_frm_num)
1593
0
                                                <= i4_end_frm_num))
1594
0
                {
1595
0
                    UWORD32 i4_error_code;
1596
0
                    i4_error_code = ERROR_DBP_MANAGER_T;
1597
0
                    return i4_error_code;
1598
0
                }
1599
0
            }
1600
0
        }
1601
0
    }
1602
0
1603
0
    /* find frame_num index, in the poc_map which needs to be deleted */
1604
0
    for(j = 0; j < MAX_FRAMES; j++)
1605
0
    {
1606
0
        if(i4_frame_num == ps_dpb_mgr->ai4_poc_buf_id_map[j][2])
1607
0
            break;
1608
0
    }
1609
0
1610
0
    if(MAX_FRAMES != i)
1611
0
    {
1612
0
        if(j == MAX_FRAMES)
1613
0
        {
1614
0
            UWORD32 i4_error_code;
1615
0
            i4_error_code = ERROR_DBP_MANAGER_T;
1616
0
            return i4_error_code;
1617
0
        }
1618
0
1619
0
        ps_dpb_mgr->ai4_poc_buf_id_map[j][0] = -1;
1620
0
        ps_dpb_mgr->ai4_poc_buf_id_map[j][1] = 0x7fffffff;
1621
0
        ps_dpb_mgr->ai4_poc_buf_id_map[j][2] = GAP_FRAME_NUM;
1622
0
        ps_dpb_mgr->i1_gaps_deleted++;
1623
0
1624
0
        ps_dpb_mgr->ai1_gaps_per_seq[i]--;
1625
0
        ps_dpb_mgr->u1_num_gaps--;
1626
0
        *pu1_del_node = 0;
1627
0
        if(0 == ps_dpb_mgr->ai1_gaps_per_seq[i])
1628
0
        {
1629
0
            ps_dpb_mgr->ai4_gaps_start_frm_num[i] = INVALID_FRAME_NUM;
1630
0
            ps_dpb_mgr->ai4_gaps_end_frm_num[i] = 0;
1631
0
        }
1632
0
    }
1633
0
    else
1634
0
    {
1635
0
        UWORD32 i4_error_code;
1636
0
        i4_error_code = ERROR_DBP_MANAGER_T;
1637
0
        return i4_error_code;
1638
0
    }
1639
0
1640
0
    return OK;
1641
0
}
1642
1643
/*!
1644
 **************************************************************************
1645
 * \if Function name : ih264d_do_mmco_for_gaps \endif
1646
 *
1647
 * \brief
1648
 *    Perform decoded picture buffer memory management control operations
1649
 *
1650
 * \return
1651
 *    0 - No error; -1 - Error
1652
 *
1653
 * \note
1654
 *    Bitstream is also parsed here to get the MMCOs
1655
 *
1656
 **************************************************************************
1657
 */
1658
WORD32 ih264d_do_mmco_for_gaps(dpb_manager_t *ps_dpb_mgr,
1659
                             UWORD8 u1_num_ref_frames /*!< num_ref_frames from active SeqParSet*/
1660
                             )
1661
0
{
1662
0
    struct dpb_info_t *ps_next_dpb;
1663
0
    UWORD8 u1_num_gaps;
1664
0
    UWORD8 u1_st_ref_bufs, u1_lt_ref_bufs, u1_del_node;
1665
0
    WORD8 i;
1666
0
    WORD32 i4_frame_gaps = 1;
1667
0
    WORD32 ret;
1668
0
1669
0
    //Sliding window - implements 8.2.5.3, flush out buffers
1670
0
    u1_st_ref_bufs = ps_dpb_mgr->u1_num_st_ref_bufs;
1671
0
    u1_lt_ref_bufs = ps_dpb_mgr->u1_num_lt_ref_bufs;
1672
0
1673
0
    while(1)
1674
0
    {
1675
0
        u1_num_gaps = ps_dpb_mgr->u1_num_gaps;
1676
0
        if((u1_st_ref_bufs + u1_lt_ref_bufs + u1_num_gaps + i4_frame_gaps)
1677
0
                        > u1_num_ref_frames)
1678
0
        {
1679
0
            if(0 == (u1_st_ref_bufs + u1_num_gaps))
1680
0
            {
1681
0
                i4_frame_gaps = 0;
1682
0
                ps_dpb_mgr->u1_num_gaps = (u1_num_ref_frames
1683
0
                                - u1_lt_ref_bufs);
1684
0
            }
1685
0
            else
1686
0
            {
1687
0
                u1_del_node = 1;
1688
0
                ps_next_dpb = ps_dpb_mgr->ps_dpb_st_head;
1689
0
1690
0
                if(u1_st_ref_bufs > 1)
1691
0
                {
1692
0
                    for(i = 1; i < (u1_st_ref_bufs - 1); i++)
1693
0
                    {
1694
0
                        if(ps_next_dpb == NULL)
1695
0
                        {
1696
0
                            UWORD32 i4_error_code;
1697
0
                            i4_error_code = ERROR_DBP_MANAGER_T;
1698
0
                            return i4_error_code;
1699
0
                        }
1700
0
                        ps_next_dpb = ps_next_dpb->ps_prev_short;
1701
0
                    }
1702
0
1703
0
                    if(ps_next_dpb->ps_prev_short->ps_prev_short != NULL)
1704
0
                    {
1705
0
                        return ERROR_DBP_MANAGER_T;
1706
0
                    }
1707
0
1708
0
                    if(u1_num_gaps)
1709
0
                    {
1710
0
                        ret = ih264d_delete_gap_frm_sliding(ps_dpb_mgr,
1711
0
                                                            ps_next_dpb->ps_prev_short->i4_frame_num,
1712
0
                                                            &u1_del_node);
1713
0
                        if(ret != OK)
1714
0
                            return ret;
1715
0
                    }
1716
0
1717
0
                    if(u1_del_node)
1718
0
                    {
1719
0
                        u1_st_ref_bufs--;
1720
0
                        ps_next_dpb->ps_prev_short->u1_used_as_ref =
1721
0
                                        UNUSED_FOR_REF;
1722
0
                        ps_next_dpb->ps_prev_short->s_top_field.u1_reference_info =
1723
0
                                        UNUSED_FOR_REF;
1724
0
                        ps_next_dpb->ps_prev_short->s_bot_field.u1_reference_info =
1725
0
                                        UNUSED_FOR_REF;
1726
0
                        ih264d_free_ref_pic_mv_bufs(ps_dpb_mgr->pv_codec_handle,
1727
0
                                                    ps_next_dpb->ps_prev_short->u1_buf_id);
1728
0
                        ps_next_dpb->ps_prev_short->ps_pic_buf = NULL;
1729
0
                        ps_next_dpb->ps_prev_short = NULL;
1730
0
                    }
1731
0
                }
1732
0
                else
1733
0
                {
1734
0
                    if(u1_st_ref_bufs)
1735
0
                    {
1736
0
                        if(u1_num_gaps)
1737
0
                        {
1738
0
                            ret = ih264d_delete_gap_frm_sliding(ps_dpb_mgr,
1739
0
                                                                ps_next_dpb->i4_frame_num,
1740
0
                                                                &u1_del_node);
1741
0
                            if(ret != OK)
1742
0
                                return ret;
1743
0
                        }
1744
0
1745
0
                        if(u1_del_node)
1746
0
                        {
1747
0
                            u1_st_ref_bufs--;
1748
0
                            ps_next_dpb->u1_used_as_ref = FALSE;
1749
0
                            ps_next_dpb->s_top_field.u1_reference_info =
1750
0
                                            UNUSED_FOR_REF;
1751
0
                            ps_next_dpb->s_bot_field.u1_reference_info =
1752
0
                                            UNUSED_FOR_REF;
1753
0
                            ih264d_free_ref_pic_mv_bufs(ps_dpb_mgr->pv_codec_handle,
1754
0
                                                        ps_next_dpb->u1_buf_id);
1755
0
                            ps_next_dpb->ps_pic_buf = NULL;
1756
0
                            ps_next_dpb = NULL;
1757
0
                            ps_dpb_mgr->ps_dpb_st_head = NULL;
1758
0
                            ps_dpb_mgr->u1_num_st_ref_bufs = u1_st_ref_bufs;
1759
0
                        }
1760
0
                    }
1761
0
                    else
1762
0
                    {
1763
0
                        ret = ih264d_delete_gap_frm_sliding(ps_dpb_mgr,
1764
0
                                                            INVALID_FRAME_NUM,
1765
0
                                                            &u1_del_node);
1766
0
                        if(ret != OK)
1767
0
                            return ret;
1768
0
                        if(u1_del_node)
1769
0
                        {
1770
0
                            return ERROR_DBP_MANAGER_T;
1771
0
                        }
1772
0
                    }
1773
0
                }
1774
0
            }
1775
0
        }
1776
0
        else
1777
0
        {
1778
0
            ps_dpb_mgr->u1_num_gaps += i4_frame_gaps;
1779
0
            break;
1780
0
        }
1781
0
    }
1782
0
1783
0
    ps_dpb_mgr->u1_num_st_ref_bufs = u1_st_ref_bufs;
1784
0
1785
0
    return OK;
1786
0
}
1787
/****************************************************************************/
1788
/*                                                                          */
1789
/* Function Name  : ih264d_free_node_from_dpb                                      */
1790
/*                                                                          */
1791
/* Description    :                                                         */
1792
/*                                                                          */
1793
/* Inputs         :                                                         */
1794
/*                                                                          */
1795
/* Globals        :                                                         */
1796
/*                                                                          */
1797
/* Processing     :                                                         */
1798
/*                                                                          */
1799
/* Outputs        :                                                         */
1800
/*                                                                          */
1801
/* Returns        :                                                         */
1802
/*                                                                          */
1803
/* Known Issues   :                                                         */
1804
/*                                                                          */
1805
/* Revision History                                                         */
1806
/*                                                                          */
1807
/*      DD MM YY            Author        Changes                           */
1808
/*                          Sarat                                           */
1809
/****************************************************************************/
1810
/**** Function Added for Error Resilience *****/
1811
WORD32 ih264d_free_node_from_dpb(dpb_manager_t *ps_dpb_mgr,
1812
                               UWORD32 u4_cur_pic_num,
1813
                               UWORD8 u1_numRef_frames_for_seq)
1814
0
{
1815
0
    WORD32 i;
1816
0
    UWORD8 u1_num_gaps = ps_dpb_mgr->u1_num_gaps;
1817
0
    struct dpb_info_t *ps_next_dpb;
1818
0
    UWORD8 u1_del_node = 1;
1819
0
    WORD32 ret;
1820
0
1821
0
    //Sliding window - implements 8.2.5.3
1822
0
    if((ps_dpb_mgr->u1_num_st_ref_bufs + ps_dpb_mgr->u1_num_lt_ref_bufs
1823
0
                    + u1_num_gaps) == u1_numRef_frames_for_seq)
1824
0
    {
1825
0
        UWORD8 u1_new_node_flag = 1;
1826
0
        if((0 == ps_dpb_mgr->u1_num_st_ref_bufs) && (0 == u1_num_gaps))
1827
0
        {
1828
0
            return ERROR_DBP_MANAGER_T;
1829
0
        }
1830
0
1831
0
        // Chase the links to reach the last but one picNum, if available
1832
0
        ps_next_dpb = ps_dpb_mgr->ps_dpb_st_head;
1833
0
1834
0
        if(ps_dpb_mgr->u1_num_st_ref_bufs > 1)
1835
0
        {
1836
0
            if(ps_next_dpb->i4_frame_num == (WORD32)u4_cur_pic_num)
1837
0
            {
1838
0
                /* Incase of  filed pictures top_field has been allocated   */
1839
0
                /* picture buffer and complementary bottom field pair comes */
1840
0
                /* then the sliding window mechanism should not allocate a  */
1841
0
                /* new node                                                 */
1842
0
                u1_new_node_flag = 0;
1843
0
            }
1844
0
1845
0
            for(i = 1; i < (ps_dpb_mgr->u1_num_st_ref_bufs - 1); i++)
1846
0
            {
1847
0
                if(ps_next_dpb == NULL)
1848
0
                    return ERROR_DBP_MANAGER_T;
1849
0
1850
0
                if(ps_next_dpb->i4_frame_num == (WORD32)u4_cur_pic_num)
1851
0
                {
1852
0
                    /* Incase of  field pictures top_field has been allocated   */
1853
0
                    /* picture buffer and complementary bottom field pair comes */
1854
0
                    /* then the sliding window mechanism should not allocate a  */
1855
0
                    /* new node                                                 */
1856
0
                    u1_new_node_flag = 0;
1857
0
                }
1858
0
                ps_next_dpb = ps_next_dpb->ps_prev_short;
1859
0
            }
1860
0
1861
0
            if(ps_next_dpb->ps_prev_short->ps_prev_short != NULL)
1862
0
                return ERROR_DBP_MANAGER_T;
1863
0
1864
0
            if(u1_new_node_flag)
1865
0
            {
1866
0
                if(u1_num_gaps)
1867
0
                {
1868
0
                    ret = ih264d_delete_gap_frm_sliding(ps_dpb_mgr,
1869
0
                                                        ps_next_dpb->ps_prev_short->i4_frame_num,
1870
0
                                                        &u1_del_node);
1871
0
                    if(ret != OK)
1872
0
                        return ret;
1873
0
                }
1874
0
1875
0
                if(u1_del_node)
1876
0
                {
1877
0
                    ps_dpb_mgr->u1_num_st_ref_bufs--;
1878
0
                    ps_next_dpb->ps_prev_short->u1_used_as_ref = UNUSED_FOR_REF;
1879
0
                    ps_next_dpb->ps_prev_short->s_top_field.u1_reference_info =
1880
0
                                    UNUSED_FOR_REF;
1881
0
                    ps_next_dpb->ps_prev_short->s_bot_field.u1_reference_info =
1882
0
                                    UNUSED_FOR_REF;
1883
0
                    ih264d_free_ref_pic_mv_bufs(ps_dpb_mgr->pv_codec_handle,
1884
0
                                                ps_next_dpb->ps_prev_short->u1_buf_id);
1885
0
                    ps_next_dpb->ps_prev_short->ps_pic_buf = NULL;
1886
0
                    ps_next_dpb->ps_prev_short = NULL;
1887
0
                }
1888
0
            }
1889
0
        }
1890
0
        else
1891
0
        {
1892
0
            if(ps_dpb_mgr->u1_num_st_ref_bufs)
1893
0
            {
1894
0
                ret = ih264d_delete_gap_frm_sliding(ps_dpb_mgr,
1895
0
                                                    ps_next_dpb->i4_frame_num,
1896
0
                                                    &u1_del_node);
1897
0
                if(ret != OK)
1898
0
                    return ret;
1899
0
                if((ps_next_dpb->i4_frame_num != (WORD32)u4_cur_pic_num)
1900
0
                                && u1_del_node)
1901
0
                {
1902
0
                    ps_dpb_mgr->u1_num_st_ref_bufs--;
1903
0
                    ps_next_dpb->u1_used_as_ref = FALSE;
1904
0
                    ps_next_dpb->s_top_field.u1_reference_info = UNUSED_FOR_REF;
1905
0
                    ps_next_dpb->s_bot_field.u1_reference_info = UNUSED_FOR_REF;
1906
0
                    ih264d_free_ref_pic_mv_bufs(ps_dpb_mgr->pv_codec_handle,
1907
0
                                                ps_next_dpb->u1_buf_id);
1908
0
                    ps_next_dpb->ps_pic_buf = NULL;
1909
0
                    ps_next_dpb = NULL;
1910
0
                }
1911
0
            }
1912
0
            else
1913
0
            {
1914
0
                ret = ih264d_delete_gap_frm_sliding(ps_dpb_mgr, INVALID_FRAME_NUM, &u1_del_node);
1915
0
                if(ret != OK)
1916
0
                    return ret;
1917
0
                if(u1_del_node)
1918
0
                    return ERROR_DBP_MANAGER_T;
1919
0
            }
1920
0
        }
1921
0
    }
1922
0
    return OK;
1923
0
}
1924
/*****************************************************************************/
1925
/*                                                                           */
1926
/*  Function Name : ih264d_delete_nonref_nondisplay_pics                            */
1927
/*                                                                           */
1928
/*  Description   :                                                          */
1929
/*                                                                           */
1930
/*                                                                           */
1931
/*  Inputs        :                                                          */
1932
/*  Globals       :                                                          */
1933
/*  Processing    :                                                          */
1934
/*                                                                           */
1935
/*  Outputs       :                                                          */
1936
/*  Returns       :                                                          */
1937
/*                                                                           */
1938
/*  Issues        :                                                          */
1939
/*                                                                           */
1940
/*  Revision History:                                                        */
1941
/*                                                                           */
1942
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1943
/*         05 06 2007   Varun           Draft                                */
1944
/*                                                                           */
1945
/*****************************************************************************/
1946
1947
void ih264d_delete_nonref_nondisplay_pics(dpb_manager_t *ps_dpb_mgr)
1948
22
{
1949
22
    WORD8 i;
1950
22
    WORD32 (*i4_poc_buf_id_map)[3] = ps_dpb_mgr->ai4_poc_buf_id_map;
1951
22
1952
22
    /* remove all gaps marked as unused for ref */
1953
22
    for(i = 0; (i < MAX_FRAMES) && ps_dpb_mgr->i1_gaps_deleted; i++)
1954
0
    {
1955
0
        if(GAP_FRAME_NUM == i4_poc_buf_id_map[i][2])
1956
0
        {
1957
0
            ps_dpb_mgr->i1_gaps_deleted--;
1958
0
            ps_dpb_mgr->i1_poc_buf_id_entries--;
1959
0
            i4_poc_buf_id_map[i][0] = -1;
1960
0
            i4_poc_buf_id_map[i][1] = 0x7fffffff;
1961
0
            i4_poc_buf_id_map[i][2] = 0;
1962
0
        }
1963
0
    }
1964
22
}
1965
/*****************************************************************************/
1966
/*                                                                           */
1967
/*  Function Name : ih264d_insert_pic_in_display_list                               */
1968
/*                                                                           */
1969
/*  Description   :                                                          */
1970
/*                                                                           */
1971
/*                                                                           */
1972
/*  Inputs        :                                                          */
1973
/*  Globals       :                                                          */
1974
/*  Processing    :                                                          */
1975
/*                                                                           */
1976
/*  Outputs       :                                                          */
1977
/*  Returns       :                                                          */
1978
/*                                                                           */
1979
/*  Issues        :                                                          */
1980
/*                                                                           */
1981
/*  Revision History:                                                        */
1982
/*                                                                           */
1983
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1984
/*         05 06 2007   Varun           Draft                                */
1985
/*                                                                           */
1986
/*****************************************************************************/
1987
1988
WORD32 ih264d_insert_pic_in_display_list(dpb_manager_t *ps_dpb_mgr,
1989
                                         UWORD8 u1_buf_id,
1990
                                         WORD32 i4_display_poc,
1991
                                         UWORD32 u4_frame_num)
1992
11
{
1993
11
    WORD8 i;
1994
11
    WORD32 (*i4_poc_buf_id_map)[3] = ps_dpb_mgr->ai4_poc_buf_id_map;
1995
11
1996
11
    for(i = 0; i < MAX_FRAMES; i++)
1997
11
    {
1998
11
        /* Find an empty slot */
1999
11
        if(i4_poc_buf_id_map[i][0] == -1)
2000
11
        {
2001
11
            if(GAP_FRAME_NUM == i4_poc_buf_id_map[i][2])
2002
0
                ps_dpb_mgr->i1_gaps_deleted--;
2003
11
            else
2004
11
                ps_dpb_mgr->i1_poc_buf_id_entries++;
2005
11
2006
11
            i4_poc_buf_id_map[i][0] = u1_buf_id;
2007
11
            i4_poc_buf_id_map[i][1] = i4_display_poc;
2008
11
            i4_poc_buf_id_map[i][2] = u4_frame_num;
2009
11
2010
11
            break;
2011
11
        }
2012
11
    }
2013
11
2014
11
    if(MAX_FRAMES == i)
2015
0
    {
2016
0
2017
0
        UWORD32 i4_error_code;
2018
0
        i4_error_code = ERROR_GAPS_IN_FRM_NUM;
2019
0
        return i4_error_code;
2020
0
    }
2021
11
    return OK;
2022
11
}
2023
/proc/self/cwd/external/libavc/decoder/ih264d_format_conv.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/*****************************************************************************/
21
/*                                                                           */
22
/*  File Name         : ih264d_format_conv.c                                */
23
/*                                                                           */
24
/*  Description       : Contains functions needed to convert the images in   */
25
/*                      different color spaces to yuv 422i color space       */
26
/*                                                                           */
27
/*                                                                           */
28
/*  Issues / Problems : None                                                 */
29
/*                                                                           */
30
/*  Revision History  :                                                      */
31
/*                                                                           */
32
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
33
/*         28 08 2007  Naveen Kumar T        Draft                           */
34
/*                                                                           */
35
/*****************************************************************************/
36
/*****************************************************************************/
37
/* File Includes                                                             */
38
/*****************************************************************************/
39
40
/* System include files */
41
#include <string.h>
42
/* User include files */
43
#include "ih264_typedefs.h"
44
#include "iv.h"
45
#include "ih264_macros.h"
46
#include "ih264_platform_macros.h"
47
#include "ih264d_structs.h"
48
#include "ih264d_format_conv.h"
49
#include "ih264d_defs.h"
50
51
52
53
#ifdef LOGO_EN
54
#include "ih264d_ittiam_logo.h"
55
#define INSERT_LOGO(pu1_buf_y,pu1_buf_u,pu1_buf_v, u4_stride, u4_x_pos, u4_y_pos, u4_yuv_fmt, u4_disp_wd, u4_disp_ht) \
56
                    ih264d_insert_logo(pu1_buf_y,pu1_buf_u,pu1_buf_v, u4_stride,\
57
                          u4_x_pos, u4_y_pos, u4_yuv_fmt, u4_disp_wd, u4_disp_ht)
58
#else
59
#define INSERT_LOGO(pu1_buf_y,pu1_buf_u,pu1_buf_v, u4_stride, u4_x_pos, u4_y_pos, u4_yuv_fmt, u4_disp_wd, u4_disp_ht)
60
#endif
61
62
/**
63
 *******************************************************************************
64
 *
65
 * @brief Function used from copying a 420SP buffer
66
 *
67
 * @par   Description
68
 * Function used from copying a 420SP buffer
69
 *
70
 * @param[in] pu1_y_src
71
 *   Input Y pointer
72
 *
73
 * @param[in] pu1_uv_src
74
 *   Input UV pointer (UV is interleaved either in UV or VU format)
75
 *
76
 * @param[in] pu1_y_dst
77
 *   Output Y pointer
78
 *
79
 * @param[in] pu1_uv_dst
80
 *   Output UV pointer (UV is interleaved in the same format as that of input)
81
 *
82
 * @param[in] wd
83
 *   Width
84
 *
85
 * @param[in] ht
86
 *   Height
87
 *
88
 * @param[in] src_y_strd
89
 *   Input Y Stride
90
 *
91
 * @param[in] src_uv_strd
92
 *   Input UV stride
93
 *
94
 * @param[in] dst_y_strd
95
 *   Output Y stride
96
 *
97
 * @param[in] dst_uv_strd
98
 *   Output UV stride
99
 *
100
 * @returns None
101
 *
102
 * @remarks In case there is a need to perform partial frame copy then
103
 * by passion appropriate source and destination pointers and appropriate
104
 * values for wd and ht it can be done
105
 *
106
 *******************************************************************************
107
 */
108
void ih264d_fmt_conv_420sp_to_rgb565(UWORD8 *pu1_y_src,
109
                                     UWORD8 *pu1_uv_src,
110
                                     UWORD16 *pu2_rgb_dst,
111
                                     WORD32 wd,
112
                                     WORD32 ht,
113
                                     WORD32 src_y_strd,
114
                                     WORD32 src_uv_strd,
115
                                     WORD32 dst_strd,
116
                                     WORD32 is_u_first)
117
0
{
118
0
119
0
    WORD16 i2_r, i2_g, i2_b;
120
0
    UWORD32 u4_r, u4_g, u4_b;
121
0
    WORD16 i2_i, i2_j;
122
0
    UWORD8 *pu1_y_src_nxt;
123
0
    UWORD16 *pu2_rgb_dst_next_row;
124
0
125
0
    UWORD8 *pu1_u_src, *pu1_v_src;
126
0
127
0
    if(is_u_first)
128
0
    {
129
0
        pu1_u_src = (UWORD8 *)pu1_uv_src;
130
0
        pu1_v_src = (UWORD8 *)pu1_uv_src + 1;
131
0
    }
132
0
    else
133
0
    {
134
0
        pu1_u_src = (UWORD8 *)pu1_uv_src + 1;
135
0
        pu1_v_src = (UWORD8 *)pu1_uv_src;
136
0
    }
137
0
138
0
    pu1_y_src_nxt = pu1_y_src + src_y_strd;
139
0
    pu2_rgb_dst_next_row = pu2_rgb_dst + dst_strd;
140
0
141
0
    for(i2_i = 0; i2_i < (ht >> 1); i2_i++)
142
0
    {
143
0
        for(i2_j = (wd >> 1); i2_j > 0; i2_j--)
144
0
        {
145
0
            i2_b = ((*pu1_u_src - 128) * COEFF4 >> 13);
146
0
            i2_g = ((*pu1_u_src - 128) * COEFF2 + (*pu1_v_src - 128) * COEFF3)
147
0
                            >> 13;
148
0
            i2_r = ((*pu1_v_src - 128) * COEFF1) >> 13;
149
0
150
0
            pu1_u_src += 2;
151
0
            pu1_v_src += 2;
152
0
            /* pixel 0 */
153
0
            /* B */
154
0
            u4_b = CLIP_U8(*pu1_y_src + i2_b);
155
0
            u4_b >>= 3;
156
0
            /* G */
157
0
            u4_g = CLIP_U8(*pu1_y_src + i2_g);
158
0
            u4_g >>= 2;
159
0
            /* R */
160
0
            u4_r = CLIP_U8(*pu1_y_src + i2_r);
161
0
            u4_r >>= 3;
162
0
163
0
            pu1_y_src++;
164
0
            *pu2_rgb_dst++ = ((u4_r << 11) | (u4_g << 5) | u4_b);
165
0
166
0
            /* pixel 1 */
167
0
            /* B */
168
0
            u4_b = CLIP_U8(*pu1_y_src + i2_b);
169
0
            u4_b >>= 3;
170
0
            /* G */
171
0
            u4_g = CLIP_U8(*pu1_y_src + i2_g);
172
0
            u4_g >>= 2;
173
0
            /* R */
174
0
            u4_r = CLIP_U8(*pu1_y_src + i2_r);
175
0
            u4_r >>= 3;
176
0
177
0
            pu1_y_src++;
178
0
            *pu2_rgb_dst++ = ((u4_r << 11) | (u4_g << 5) | u4_b);
179
0
180
0
            /* pixel 2 */
181
0
            /* B */
182
0
            u4_b = CLIP_U8(*pu1_y_src_nxt + i2_b);
183
0
            u4_b >>= 3;
184
0
            /* G */
185
0
            u4_g = CLIP_U8(*pu1_y_src_nxt + i2_g);
186
0
            u4_g >>= 2;
187
0
            /* R */
188
0
            u4_r = CLIP_U8(*pu1_y_src_nxt + i2_r);
189
0
            u4_r >>= 3;
190
0
191
0
            pu1_y_src_nxt++;
192
0
            *pu2_rgb_dst_next_row++ = ((u4_r << 11) | (u4_g << 5) | u4_b);
193
0
194
0
            /* pixel 3 */
195
0
            /* B */
196
0
            u4_b = CLIP_U8(*pu1_y_src_nxt + i2_b);
197
0
            u4_b >>= 3;
198
0
            /* G */
199
0
            u4_g = CLIP_U8(*pu1_y_src_nxt + i2_g);
200
0
            u4_g >>= 2;
201
0
            /* R */
202
0
            u4_r = CLIP_U8(*pu1_y_src_nxt + i2_r);
203
0
            u4_r >>= 3;
204
0
205
0
            pu1_y_src_nxt++;
206
0
            *pu2_rgb_dst_next_row++ = ((u4_r << 11) | (u4_g << 5) | u4_b);
207
0
208
0
        }
209
0
210
0
        pu1_u_src = pu1_u_src + src_uv_strd - wd;
211
0
        pu1_v_src = pu1_v_src + src_uv_strd - wd;
212
0
213
0
        pu1_y_src = pu1_y_src + (src_y_strd << 1) - wd;
214
0
        pu1_y_src_nxt = pu1_y_src_nxt + (src_y_strd << 1) - wd;
215
0
216
0
        pu2_rgb_dst = pu2_rgb_dst_next_row - wd + dst_strd;
217
0
        pu2_rgb_dst_next_row = pu2_rgb_dst_next_row + (dst_strd << 1) - wd;
218
0
    }
219
0
220
0
}
221
222
void ih264d_fmt_conv_420sp_to_rgba8888(UWORD8 *pu1_y_src,
223
                                       UWORD8 *pu1_uv_src,
224
                                       UWORD32 *pu4_rgba_dst,
225
                                       WORD32 wd,
226
                                       WORD32 ht,
227
                                       WORD32 src_y_strd,
228
                                       WORD32 src_uv_strd,
229
                                       WORD32 dst_strd,
230
                                       WORD32 is_u_first)
231
0
{
232
0
233
0
    WORD16 i2_r, i2_g, i2_b;
234
0
    UWORD32 u4_r, u4_g, u4_b;
235
0
    WORD16 i2_i, i2_j;
236
0
    UWORD8 *pu1_y_src_nxt;
237
0
    UWORD32 *pu4_rgba_dst_next_row;
238
0
239
0
    UWORD8 *pu1_u_src, *pu1_v_src;
240
0
241
0
    if(is_u_first)
242
0
    {
243
0
        pu1_u_src = (UWORD8 *)pu1_uv_src;
244
0
        pu1_v_src = (UWORD8 *)pu1_uv_src + 1;
245
0
    }
246
0
    else
247
0
    {
248
0
        pu1_u_src = (UWORD8 *)pu1_uv_src + 1;
249
0
        pu1_v_src = (UWORD8 *)pu1_uv_src;
250
0
    }
251
0
252
0
    pu1_y_src_nxt = pu1_y_src + src_y_strd;
253
0
    pu4_rgba_dst_next_row = pu4_rgba_dst + dst_strd;
254
0
255
0
    for(i2_i = 0; i2_i < (ht >> 1); i2_i++)
256
0
    {
257
0
        for(i2_j = (wd >> 1); i2_j > 0; i2_j--)
258
0
        {
259
0
            i2_b = ((*pu1_u_src - 128) * COEFF4 >> 13);
260
0
            i2_g = ((*pu1_u_src - 128) * COEFF2 + (*pu1_v_src - 128) * COEFF3)
261
0
                            >> 13;
262
0
            i2_r = ((*pu1_v_src - 128) * COEFF1) >> 13;
263
0
264
0
            pu1_u_src += 2;
265
0
            pu1_v_src += 2;
266
0
            /* pixel 0 */
267
0
            /* B */
268
0
            u4_b = CLIP_U8(*pu1_y_src + i2_b);
269
0
            /* G */
270
0
            u4_g = CLIP_U8(*pu1_y_src + i2_g);
271
0
            /* R */
272
0
            u4_r = CLIP_U8(*pu1_y_src + i2_r);
273
0
274
0
            pu1_y_src++;
275
0
            *pu4_rgba_dst++ = ((u4_r << 16) | (u4_g << 8) | (u4_b << 0));
276
0
277
0
            /* pixel 1 */
278
0
            /* B */
279
0
            u4_b = CLIP_U8(*pu1_y_src + i2_b);
280
0
            /* G */
281
0
            u4_g = CLIP_U8(*pu1_y_src + i2_g);
282
0
            /* R */
283
0
            u4_r = CLIP_U8(*pu1_y_src + i2_r);
284
0
285
0
            pu1_y_src++;
286
0
            *pu4_rgba_dst++ = ((u4_r << 16) | (u4_g << 8) | (u4_b << 0));
287
0
288
0
            /* pixel 2 */
289
0
            /* B */
290
0
            u4_b = CLIP_U8(*pu1_y_src_nxt + i2_b);
291
0
            /* G */
292
0
            u4_g = CLIP_U8(*pu1_y_src_nxt + i2_g);
293
0
            /* R */
294
0
            u4_r = CLIP_U8(*pu1_y_src_nxt + i2_r);
295
0
296
0
            pu1_y_src_nxt++;
297
0
            *pu4_rgba_dst_next_row++ =
298
0
                            ((u4_r << 16) | (u4_g << 8) | (u4_b << 0));
299
0
300
0
            /* pixel 3 */
301
0
            /* B */
302
0
            u4_b = CLIP_U8(*pu1_y_src_nxt + i2_b);
303
0
            /* G */
304
0
            u4_g = CLIP_U8(*pu1_y_src_nxt + i2_g);
305
0
            /* R */
306
0
            u4_r = CLIP_U8(*pu1_y_src_nxt + i2_r);
307
0
308
0
            pu1_y_src_nxt++;
309
0
            *pu4_rgba_dst_next_row++ =
310
0
                            ((u4_r << 16) | (u4_g << 8) | (u4_b << 0));
311
0
312
0
        }
313
0
314
0
        pu1_u_src = pu1_u_src + src_uv_strd - wd;
315
0
        pu1_v_src = pu1_v_src + src_uv_strd - wd;
316
0
317
0
        pu1_y_src = pu1_y_src + (src_y_strd << 1) - wd;
318
0
        pu1_y_src_nxt = pu1_y_src_nxt + (src_y_strd << 1) - wd;
319
0
320
0
        pu4_rgba_dst = pu4_rgba_dst_next_row - wd + dst_strd;
321
0
        pu4_rgba_dst_next_row = pu4_rgba_dst_next_row + (dst_strd << 1) - wd;
322
0
    }
323
0
324
0
}
325
326
/**
327
 *******************************************************************************
328
 *
329
 * @brief Function used from copying a 420SP buffer
330
 *
331
 * @par   Description
332
 * Function used from copying a 420SP buffer
333
 *
334
 * @param[in] pu1_y_src
335
 *   Input Y pointer
336
 *
337
 * @param[in] pu1_uv_src
338
 *   Input UV pointer (UV is interleaved either in UV or VU format)
339
 *
340
 * @param[in] pu1_y_dst
341
 *   Output Y pointer
342
 *
343
 * @param[in] pu1_uv_dst
344
 *   Output UV pointer (UV is interleaved in the same format as that of input)
345
 *
346
 * @param[in] wd
347
 *   Width
348
 *
349
 * @param[in] ht
350
 *   Height
351
 *
352
 * @param[in] src_y_strd
353
 *   Input Y Stride
354
 *
355
 * @param[in] src_uv_strd
356
 *   Input UV stride
357
 *
358
 * @param[in] dst_y_strd
359
 *   Output Y stride
360
 *
361
 * @param[in] dst_uv_strd
362
 *   Output UV stride
363
 *
364
 * @returns None
365
 *
366
 * @remarks In case there is a need to perform partial frame copy then
367
 * by passion appropriate source and destination pointers and appropriate
368
 * values for wd and ht it can be done
369
 *
370
 *******************************************************************************
371
 */
372
373
void ih264d_fmt_conv_420sp_to_420sp(UWORD8 *pu1_y_src,
374
                                    UWORD8 *pu1_uv_src,
375
                                    UWORD8 *pu1_y_dst,
376
                                    UWORD8 *pu1_uv_dst,
377
                                    WORD32 wd,
378
                                    WORD32 ht,
379
                                    WORD32 src_y_strd,
380
                                    WORD32 src_uv_strd,
381
                                    WORD32 dst_y_strd,
382
                                    WORD32 dst_uv_strd)
383
0
{
384
0
    UWORD8 *pu1_src, *pu1_dst;
385
0
    WORD32 num_rows, num_cols, src_strd, dst_strd;
386
0
    WORD32 i;
387
0
388
0
    /* copy luma */
389
0
    pu1_src = (UWORD8 *)pu1_y_src;
390
0
    pu1_dst = (UWORD8 *)pu1_y_dst;
391
0
392
0
    num_rows = ht;
393
0
    num_cols = wd;
394
0
395
0
    src_strd = src_y_strd;
396
0
    dst_strd = dst_y_strd;
397
0
398
0
    for(i = 0; i < num_rows; i++)
399
0
    {
400
0
        memcpy(pu1_dst, pu1_src, num_cols);
401
0
        pu1_dst += dst_strd;
402
0
        pu1_src += src_strd;
403
0
    }
404
0
405
0
    /* copy U and V */
406
0
    pu1_src = (UWORD8 *)pu1_uv_src;
407
0
    pu1_dst = (UWORD8 *)pu1_uv_dst;
408
0
409
0
    num_rows = ht >> 1;
410
0
    num_cols = wd;
411
0
412
0
    src_strd = src_uv_strd;
413
0
    dst_strd = dst_uv_strd;
414
0
415
0
    for(i = 0; i < num_rows; i++)
416
0
    {
417
0
        memcpy(pu1_dst, pu1_src, num_cols);
418
0
        pu1_dst += dst_strd;
419
0
        pu1_src += src_strd;
420
0
    }
421
0
    return;
422
0
}
423
424
/**
425
 *******************************************************************************
426
 *
427
 * @brief Function used from copying a 420SP buffer
428
 *
429
 * @par   Description
430
 * Function used from copying a 420SP buffer
431
 *
432
 * @param[in] pu1_y_src
433
 *   Input Y pointer
434
 *
435
 * @param[in] pu1_uv_src
436
 *   Input UV pointer (UV is interleaved either in UV or VU format)
437
 *
438
 * @param[in] pu1_y_dst
439
 *   Output Y pointer
440
 *
441
 * @param[in] pu1_uv_dst
442
 *   Output UV pointer (UV is interleaved in the same format as that of input)
443
 *
444
 * @param[in] wd
445
 *   Width
446
 *
447
 * @param[in] ht
448
 *   Height
449
 *
450
 * @param[in] src_y_strd
451
 *   Input Y Stride
452
 *
453
 * @param[in] src_uv_strd
454
 *   Input UV stride
455
 *
456
 * @param[in] dst_y_strd
457
 *   Output Y stride
458
 *
459
 * @param[in] dst_uv_strd
460
 *   Output UV stride
461
 *
462
 * @returns None
463
 *
464
 * @remarks In case there is a need to perform partial frame copy then
465
 * by passion appropriate source and destination pointers and appropriate
466
 * values for wd and ht it can be done
467
 *
468
 *******************************************************************************
469
 */
470
void ih264d_fmt_conv_420sp_to_420sp_swap_uv(UWORD8 *pu1_y_src,
471
                                            UWORD8 *pu1_uv_src,
472
                                            UWORD8 *pu1_y_dst,
473
                                            UWORD8 *pu1_uv_dst,
474
                                            WORD32 wd,
475
                                            WORD32 ht,
476
                                            WORD32 src_y_strd,
477
                                            WORD32 src_uv_strd,
478
                                            WORD32 dst_y_strd,
479
                                            WORD32 dst_uv_strd)
480
0
{
481
0
    UWORD8 *pu1_src, *pu1_dst;
482
0
    WORD32 num_rows, num_cols, src_strd, dst_strd;
483
0
    WORD32 i;
484
0
485
0
    /* copy luma */
486
0
    pu1_src = (UWORD8 *)pu1_y_src;
487
0
    pu1_dst = (UWORD8 *)pu1_y_dst;
488
0
489
0
    num_rows = ht;
490
0
    num_cols = wd;
491
0
492
0
    src_strd = src_y_strd;
493
0
    dst_strd = dst_y_strd;
494
0
495
0
    for(i = 0; i < num_rows; i++)
496
0
    {
497
0
        memcpy(pu1_dst, pu1_src, num_cols);
498
0
        pu1_dst += dst_strd;
499
0
        pu1_src += src_strd;
500
0
    }
501
0
502
0
    /* copy U and V */
503
0
    pu1_src = (UWORD8 *)pu1_uv_src;
504
0
    pu1_dst = (UWORD8 *)pu1_uv_dst;
505
0
506
0
    num_rows = ht >> 1;
507
0
    num_cols = wd;
508
0
509
0
    src_strd = src_uv_strd;
510
0
    dst_strd = dst_uv_strd;
511
0
512
0
    for(i = 0; i < num_rows; i++)
513
0
    {
514
0
        WORD32 j;
515
0
        for(j = 0; j < num_cols; j += 2)
516
0
        {
517
0
            pu1_dst[j + 0] = pu1_src[j + 1];
518
0
            pu1_dst[j + 1] = pu1_src[j + 0];
519
0
        }
520
0
        pu1_dst += dst_strd;
521
0
        pu1_src += src_strd;
522
0
    }
523
0
    return;
524
0
}
525
/**
526
 *******************************************************************************
527
 *
528
 * @brief Function used from copying a 420SP buffer
529
 *
530
 * @par   Description
531
 * Function used from copying a 420SP buffer
532
 *
533
 * @param[in] pu1_y_src
534
 *   Input Y pointer
535
 *
536
 * @param[in] pu1_uv_src
537
 *   Input UV pointer (UV is interleaved either in UV or VU format)
538
 *
539
 * @param[in] pu1_y_dst
540
 *   Output Y pointer
541
 *
542
 * @param[in] pu1_u_dst
543
 *   Output U pointer
544
 *
545
 * @param[in] pu1_v_dst
546
 *   Output V pointer
547
 *
548
 * @param[in] wd
549
 *   Width
550
 *
551
 * @param[in] ht
552
 *   Height
553
 *
554
 * @param[in] src_y_strd
555
 *   Input Y Stride
556
 *
557
 * @param[in] src_uv_strd
558
 *   Input UV stride
559
 *
560
 * @param[in] dst_y_strd
561
 *   Output Y stride
562
 *
563
 * @param[in] dst_uv_strd
564
 *   Output UV stride
565
 *
566
 * @param[in] is_u_first
567
 *   Flag to indicate if U is the first byte in input chroma part
568
 *
569
 * @returns none
570
 *
571
 * @remarks In case there is a need to perform partial frame copy then
572
 * by passion appropriate source and destination pointers and appropriate
573
 * values for wd and ht it can be done
574
 *
575
 *******************************************************************************
576
 */
577
578
void ih264d_fmt_conv_420sp_to_420p(UWORD8 *pu1_y_src,
579
                                   UWORD8 *pu1_uv_src,
580
                                   UWORD8 *pu1_y_dst,
581
                                   UWORD8 *pu1_u_dst,
582
                                   UWORD8 *pu1_v_dst,
583
                                   WORD32 wd,
584
                                   WORD32 ht,
585
                                   WORD32 src_y_strd,
586
                                   WORD32 src_uv_strd,
587
                                   WORD32 dst_y_strd,
588
                                   WORD32 dst_uv_strd,
589
                                   WORD32 is_u_first,
590
                                   WORD32 disable_luma_copy)
591
51
{
592
51
    UWORD8 *pu1_src, *pu1_dst;
593
51
    UWORD8 *pu1_u_src, *pu1_v_src;
594
51
    WORD32 num_rows, num_cols, src_strd, dst_strd;
595
51
    WORD32 i, j;
596
51
597
51
    if(0 == disable_luma_copy)
598
51
    {
599
51
        /* copy luma */
600
51
        pu1_src = (UWORD8 *)pu1_y_src;
601
51
        pu1_dst = (UWORD8 *)pu1_y_dst;
602
51
603
51
        num_rows = ht;
604
51
        num_cols = wd;
605
51
606
51
        src_strd = src_y_strd;
607
51
        dst_strd = dst_y_strd;
608
51
609
2.80k
        for(i = 0; i < num_rows; i++)
610
2.75k
        {
611
2.75k
            memcpy(pu1_dst, pu1_src, num_cols);
612
2.75k
            pu1_dst += dst_strd;
613
2.75k
            pu1_src += src_strd;
614
2.75k
        }
615
51
    }
616
51
    /* de-interleave U and V and copy to destination */
617
51
    if(is_u_first)
618
51
    {
619
51
        pu1_u_src = (UWORD8 *)pu1_uv_src;
620
51
        pu1_v_src = (UWORD8 *)pu1_uv_src + 1;
621
51
    }
622
0
    else
623
0
    {
624
0
        pu1_u_src = (UWORD8 *)pu1_uv_src + 1;
625
0
        pu1_v_src = (UWORD8 *)pu1_uv_src;
626
0
    }
627
51
628
51
    num_rows = ht >> 1;
629
51
    num_cols = wd >> 1;
630
51
631
51
    src_strd = src_uv_strd;
632
51
    dst_strd = dst_uv_strd;
633
51
634
1.42k
    for(i = 0; i < num_rows; i++)
635
1.37k
    {
636
246k
        for(j = 0; j < num_cols; j++)
637
245k
        {
638
245k
            pu1_u_dst[j] = pu1_u_src[j * 2];
639
245k
            pu1_v_dst[j] = pu1_v_src[j * 2];
640
245k
        }
641
1.37k
642
1.37k
        pu1_u_dst += dst_strd;
643
1.37k
        pu1_v_dst += dst_strd;
644
1.37k
        pu1_u_src += src_strd;
645
1.37k
        pu1_v_src += src_strd;
646
1.37k
    }
647
51
    return;
648
51
}
649
650
/*****************************************************************************/
651
/*  Function Name : ih264d_format_convert                                    */
652
/*                                                                           */
653
/*  Description   : Implements format conversion/frame copy                  */
654
/*  Inputs        : ps_dec - Decoder parameters                              */
655
/*  Globals       : None                                                     */
656
/*  Processing    : Refer bumping process in the standard                    */
657
/*  Outputs       : Assigns display sequence number.                         */
658
/*  Returns       : None                                                     */
659
/*                                                                           */
660
/*  Issues        : None                                                     */
661
/*                                                                           */
662
/*  Revision History:                                                        */
663
/*                                                                           */
664
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
665
/*         27 04 2005   NS              Draft                                */
666
/*                                                                           */
667
/*****************************************************************************/
668
void ih264d_format_convert(dec_struct_t *ps_dec,
669
                           ivd_get_display_frame_op_t *pv_disp_op,
670
                           UWORD32 u4_start_y,
671
                           UWORD32 u4_num_rows_y)
672
51
{
673
51
    UWORD32 convert_uv_only = 0;
674
51
    iv_yuv_buf_t *ps_op_frm;
675
51
    UWORD8 *pu1_y_src, *pu1_uv_src;
676
51
    UWORD32 start_uv = u4_start_y >> 1;
677
51
678
51
    if(1 == pv_disp_op->u4_error_code)
679
0
        return;
680
51
681
51
    ps_op_frm = &(ps_dec->s_disp_frame_info);
682
51
683
51
    /* Requires u4_start_y and u4_num_rows_y to be even */
684
51
    if(u4_start_y & 1)
685
0
    {
686
0
        return;
687
0
    }
688
51
689
51
    if((1 == ps_dec->u4_share_disp_buf) &&
690
51
       (pv_disp_op->e_output_format == IV_YUV_420SP_UV))
691
0
    {
692
0
        return;
693
0
    }
694
51
695
51
    pu1_y_src = (UWORD8 *)ps_op_frm->pv_y_buf;
696
51
    pu1_y_src += u4_start_y * ps_op_frm->u4_y_strd,
697
51
698
51
    pu1_uv_src = (UWORD8 *)ps_op_frm->pv_u_buf;
699
51
    pu1_uv_src += start_uv * ps_op_frm->u4_u_strd;
700
51
701
51
    if(pv_disp_op->e_output_format == IV_YUV_420P)
702
51
    {
703
51
        UWORD8 *pu1_y_dst, *pu1_u_dst, *pu1_v_dst;
704
51
        IV_COLOR_FORMAT_T e_output_format = pv_disp_op->e_output_format;
705
51
706
51
        if(0 == ps_dec->u4_share_disp_buf)
707
51
        {
708
51
            convert_uv_only = 0;
709
51
        }
710
0
        else
711
0
        {
712
0
            convert_uv_only = 1;
713
0
        }
714
51
715
51
        pu1_y_dst = (UWORD8 *)pv_disp_op->s_disp_frm_buf.pv_y_buf;
716
51
        pu1_y_dst += u4_start_y * pv_disp_op->s_disp_frm_buf.u4_y_strd;
717
51
718
51
        pu1_u_dst = (UWORD8 *)pv_disp_op->s_disp_frm_buf.pv_u_buf;
719
51
        pu1_u_dst += start_uv * pv_disp_op->s_disp_frm_buf.u4_u_strd;
720
51
721
51
        pu1_v_dst = (UWORD8 *)pv_disp_op->s_disp_frm_buf.pv_v_buf;
722
51
        pu1_v_dst += start_uv * pv_disp_op->s_disp_frm_buf.u4_v_strd;
723
51
724
51
        ih264d_fmt_conv_420sp_to_420p(pu1_y_src,
725
51
                                      pu1_uv_src,
726
51
                                      pu1_y_dst,
727
51
                                      pu1_u_dst,
728
51
                                      pu1_v_dst,
729
51
                                      ps_op_frm->u4_y_wd,
730
51
                                      u4_num_rows_y,
731
51
                                      ps_op_frm->u4_y_strd,
732
51
                                      ps_op_frm->u4_u_strd,
733
51
                                      pv_disp_op->s_disp_frm_buf.u4_y_strd,
734
51
                                      pv_disp_op->s_disp_frm_buf.u4_u_strd,
735
51
                                      1,
736
51
                                      convert_uv_only);
737
51
738
51
    }
739
0
    else if((pv_disp_op->e_output_format == IV_YUV_420SP_UV) ||
740
0
            (pv_disp_op->e_output_format == IV_YUV_420SP_VU))
741
0
    {
742
0
        UWORD8* pu1_y_dst, *pu1_uv_dst;
743
0
744
0
        pu1_y_dst = (UWORD8 *)pv_disp_op->s_disp_frm_buf.pv_y_buf;
745
0
        pu1_y_dst +=  u4_start_y * pv_disp_op->s_disp_frm_buf.u4_y_strd;
746
0
747
0
        pu1_uv_dst = (UWORD8 *)pv_disp_op->s_disp_frm_buf.pv_u_buf;
748
0
        pu1_uv_dst += start_uv * pv_disp_op->s_disp_frm_buf.u4_u_strd;
749
0
750
0
        if(pv_disp_op->e_output_format == IV_YUV_420SP_UV)
751
0
        {
752
0
            ih264d_fmt_conv_420sp_to_420sp(pu1_y_src,
753
0
                                           pu1_uv_src,
754
0
                                           pu1_y_dst,
755
0
                                           pu1_uv_dst,
756
0
                                           ps_op_frm->u4_y_wd,
757
0
                                           u4_num_rows_y,
758
0
                                           ps_op_frm->u4_y_strd,
759
0
                                           ps_op_frm->u4_u_strd,
760
0
                                           pv_disp_op->s_disp_frm_buf.u4_y_strd,
761
0
                                           pv_disp_op->s_disp_frm_buf.u4_u_strd);
762
0
        }
763
0
        else
764
0
        {
765
0
            ih264d_fmt_conv_420sp_to_420sp_swap_uv(pu1_y_src,
766
0
                                                   pu1_uv_src,
767
0
                                                   pu1_y_dst,
768
0
                                                   pu1_uv_dst,
769
0
                                                   ps_op_frm->u4_y_wd,
770
0
                                                   u4_num_rows_y,
771
0
                                                   ps_op_frm->u4_y_strd,
772
0
                                                   ps_op_frm->u4_u_strd,
773
0
                                                   pv_disp_op->s_disp_frm_buf.u4_y_strd,
774
0
                                                   pv_disp_op->s_disp_frm_buf.u4_u_strd);
775
0
        }
776
0
    }
777
0
    else if(pv_disp_op->e_output_format == IV_RGB_565)
778
0
    {
779
0
        UWORD16 *pu2_rgb_dst;
780
0
781
0
        pu2_rgb_dst = (UWORD16 *)pv_disp_op->s_disp_frm_buf.pv_y_buf;
782
0
        pu2_rgb_dst += u4_start_y * pv_disp_op->s_disp_frm_buf.u4_y_strd;
783
0
784
0
        ih264d_fmt_conv_420sp_to_rgb565(pu1_y_src,
785
0
                                        pu1_uv_src,
786
0
                                        pu2_rgb_dst,
787
0
                                        ps_op_frm->u4_y_wd,
788
0
                                        u4_num_rows_y,
789
0
                                        ps_op_frm->u4_y_strd,
790
0
                                        ps_op_frm->u4_u_strd,
791
0
                                        pv_disp_op->s_disp_frm_buf.u4_y_strd,
792
0
                                        1);
793
0
    }
794
51
795
51
    if((u4_start_y + u4_num_rows_y) >= ps_dec->s_disp_frame_info.u4_y_ht)
796
9
    {
797
9
798
9
        INSERT_LOGO(pv_disp_op->s_disp_frm_buf.pv_y_buf,
799
9
                        pv_disp_op->s_disp_frm_buf.pv_u_buf,
800
9
                        pv_disp_op->s_disp_frm_buf.pv_v_buf,
801
9
                        pv_disp_op->s_disp_frm_buf.u4_y_strd,
802
9
                        ps_dec->u2_disp_width,
803
9
                        ps_dec->u2_disp_height,
804
9
                        pv_disp_op->e_output_format,
805
9
                        ps_op_frm->u4_y_wd,
806
9
                        ps_op_frm->u4_y_ht);
807
9
    }
808
51
809
51
    return;
810
51
}
/proc/self/cwd/external/libavc/decoder/ih264d_format_conv.h
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/*****************************************************************************/
21
/*                                                                           */
22
/*  File Name         : ih264d_format_conv.h                                */
23
/*                                                                           */
24
/*  Description       : Contains coefficients and constant reqquired for     */
25
/*                      converting from rgb and gray color spaces to yuv422i */
26
/*                      color space                                          */
27
/*                                                                           */
28
/*  List of Functions : None                                                 */
29
/*                                                                           */
30
/*  Issues / Problems : None                                                 */
31
/*                                                                           */
32
/*  Revision History  :                                                      */
33
/*                                                                           */
34
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
35
/*         27 08 2007  Naveen Kumar T        Draft                           */
36
/*                                                                           */
37
/*****************************************************************************/
38
39
#ifndef _IH264D_FORMAT_CONV_H_
40
#define _IH264D_FORMAT_CONV_H_
41
42
/*****************************************************************************/
43
/* Typedefs                                                                  */
44
/*****************************************************************************/
45
46
#define COEFF_0_Y       66
47
#define COEFF_1_Y       129
48
#define COEFF_2_Y       25
49
#define COEFF_0_U       -38
50
#define COEFF_1_U       -75
51
#define COEFF_2_U       112
52
#define COEFF_0_V       112
53
#define COEFF_1_V       -94
54
#define COEFF_2_V       -18
55
#define CONST_RGB_YUV1  4096
56
#define CONST_RGB_YUV2  32768
57
#define CONST_GRAY_YUV  128
58
#define COEF_2_V2_U  0xFFEE0070
59
60
#define COF_2Y_0Y          0X00190042
61
#define COF_1U_0U          0XFFB5FFDA
62
#define COF_1V_0V          0XFFA20070
63
64
void ih264d_fmt_conv_420sp_to_420p(UWORD8 *pu1_y_src,
65
                                   UWORD8 *pu1_uv_src,
66
                                   UWORD8 *pu1_y_dst,
67
                                   UWORD8 *pu1_u_dst,
68
                                   UWORD8 *pu1_v_dst,
69
                                   WORD32 wd,
70
                                   WORD32 ht,
71
                                   WORD32 src_y_strd,
72
                                   WORD32 src_uv_strd,
73
                                   WORD32 dst_y_strd,
74
                                   WORD32 dst_uv_strd,
75
                                   WORD32 is_u_first,
76
                                   WORD32 disable_luma_copy);
77
78
void ih264d_fmt_conv_420sp_to_420sp_swap_uv(UWORD8 *pu1_y_src,
79
                                            UWORD8 *pu1_uv_src,
80
                                            UWORD8 *pu1_y_dst,
81
                                            UWORD8 *pu1_uv_dst,
82
                                            WORD32 wd,
83
                                            WORD32 ht,
84
                                            WORD32 src_y_strd,
85
                                            WORD32 src_uv_strd,
86
                                            WORD32 dst_y_strd,
87
                                            WORD32 dst_uv_strd);
88
89
void ih264d_fmt_conv_420sp_to_420sp(UWORD8 *pu1_y_src,
90
                                    UWORD8 *pu1_uv_src,
91
                                    UWORD8 *pu1_y_dst,
92
                                    UWORD8 *pu1_uv_dst,
93
                                    WORD32 wd,
94
                                    WORD32 ht,
95
                                    WORD32 src_y_strd,
96
                                    WORD32 src_uv_strd,
97
                                    WORD32 dst_y_strd,
98
                                    WORD32 dst_uv_strd);
99
100
void ih264d_fmt_conv_420sp_to_rgb565(UWORD8 *pu1_y_src,
101
                                     UWORD8 *pu1_uv_src,
102
                                     UWORD16 *pu2_rgb_dst,
103
                                     WORD32 wd,
104
                                     WORD32 ht,
105
                                     WORD32 src_y_strd,
106
                                     WORD32 src_uv_strd,
107
                                     WORD32 dst_strd,
108
                                     WORD32 is_u_first);
109
0
#define COEFF1          13073
110
0
#define COEFF2          -3207
111
0
#define COEFF3          -6664
112
0
#define COEFF4          16530
113
114
void ih264d_format_convert(dec_struct_t *ps_dec,
115
                           ivd_get_display_frame_op_t *pv_disp_op,
116
                           UWORD32 u4_start_y,
117
                           UWORD32 u4_num_rows_y);
118
119
120
#endif /* _IH264D_FORMAT_CONV_H_ */
/proc/self/cwd/external/libavc/decoder/ih264d_function_selector_generic.c
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/**
21
 *******************************************************************************
22
 * @file
23
 *  ih264e_function_selector_generic.c
24
 *
25
 * @brief
26
 *  Contains functions to initialize function pointers of codec context
27
 *
28
 * @author
29
 *  Ittiam
30
 *
31
 * @par List of Functions:
32
 *  - ih264e_init_function_ptr_generic
33
 *
34
 * @remarks
35
 *  None
36
 *
37
 *******************************************************************************
38
 */
39
40
/*****************************************************************************/
41
/* File Includes                                                             */
42
/*****************************************************************************/
43
44
/* System Include files */
45
#include <stdio.h>
46
#include <stddef.h>
47
#include <stdlib.h>
48
#include <string.h>
49
50
/* User Include files */
51
#include "ih264_typedefs.h"
52
#include "iv.h"
53
#include "ivd.h"
54
#include "ih264_defs.h"
55
#include "ih264_size_defs.h"
56
#include "ih264_error.h"
57
#include "ih264_trans_quant_itrans_iquant.h"
58
#include "ih264_inter_pred_filters.h"
59
60
#include "ih264d_structs.h"
61
#include "ih264d_function_selector.h"
62
63
/**
64
 *******************************************************************************
65
 *
66
 * @brief Initialize the intra/inter/transform/deblk function pointers of
67
 * codec context
68
 *
69
 * @par Description: the current routine initializes the function pointers of
70
 * codec context basing on the architecture in use
71
 *
72
 * @param[in] ps_codec
73
 *  Codec context pointer
74
 *
75
 * @returns  none
76
 *
77
 * @remarks none
78
 *
79
 *******************************************************************************
80
 */
81
void ih264d_init_function_ptr_generic(dec_struct_t *ps_codec)
82
2
{
83
2
84
2
    WORD32 i = 0;
85
2
86
2
    /* Init function pointers for intra pred leaf level functions luma
87
2
     * Intra 16x16 */
88
2
    ps_codec->apf_intra_pred_luma_16x16[0] =
89
2
                    ih264_intra_pred_luma_16x16_mode_vert;
90
2
    ps_codec->apf_intra_pred_luma_16x16[1] =
91
2
                    ih264_intra_pred_luma_16x16_mode_horz;
92
2
    ps_codec->apf_intra_pred_luma_16x16[2] =
93
2
                    ih264_intra_pred_luma_16x16_mode_dc;
94
2
    ps_codec->apf_intra_pred_luma_16x16[3] =
95
2
                    ih264_intra_pred_luma_16x16_mode_plane;
96
2
97
2
    /* Init function pointers for intra pred leaf level functions luma
98
2
     * Intra 4x4 */
99
2
    ps_codec->apf_intra_pred_luma_4x4[0] = ih264_intra_pred_luma_4x4_mode_vert;
100
2
    ps_codec->apf_intra_pred_luma_4x4[1] = ih264_intra_pred_luma_4x4_mode_horz;
101
2
    ps_codec->apf_intra_pred_luma_4x4[2] = ih264_intra_pred_luma_4x4_mode_dc;
102
2
    ps_codec->apf_intra_pred_luma_4x4[3] =
103
2
                    ih264_intra_pred_luma_4x4_mode_diag_dl;
104
2
    ps_codec->apf_intra_pred_luma_4x4[4] =
105
2
                    ih264_intra_pred_luma_4x4_mode_diag_dr;
106
2
    ps_codec->apf_intra_pred_luma_4x4[5] =
107
2
                    ih264_intra_pred_luma_4x4_mode_vert_r;
108
2
    ps_codec->apf_intra_pred_luma_4x4[6] =
109
2
                    ih264_intra_pred_luma_4x4_mode_horz_d;
110
2
    ps_codec->apf_intra_pred_luma_4x4[7] =
111
2
                    ih264_intra_pred_luma_4x4_mode_vert_l;
112
2
    ps_codec->apf_intra_pred_luma_4x4[8] =
113
2
                    ih264_intra_pred_luma_4x4_mode_horz_u;
114
2
115
2
    /* Init function pointers for intra pred leaf level functions luma
116
2
     * Intra 8x8 */
117
2
    ps_codec->apf_intra_pred_luma_8x8[0] = ih264_intra_pred_luma_8x8_mode_vert;
118
2
    ps_codec->apf_intra_pred_luma_8x8[1] = ih264_intra_pred_luma_8x8_mode_horz;
119
2
    ps_codec->apf_intra_pred_luma_8x8[2] = ih264_intra_pred_luma_8x8_mode_dc;
120
2
    ps_codec->apf_intra_pred_luma_8x8[3] =
121
2
                    ih264_intra_pred_luma_8x8_mode_diag_dl;
122
2
    ps_codec->apf_intra_pred_luma_8x8[4] =
123
2
                    ih264_intra_pred_luma_8x8_mode_diag_dr;
124
2
    ps_codec->apf_intra_pred_luma_8x8[5] =
125
2
                    ih264_intra_pred_luma_8x8_mode_vert_r;
126
2
    ps_codec->apf_intra_pred_luma_8x8[6] =
127
2
                    ih264_intra_pred_luma_8x8_mode_horz_d;
128
2
    ps_codec->apf_intra_pred_luma_8x8[7] =
129
2
                    ih264_intra_pred_luma_8x8_mode_vert_l;
130
2
    ps_codec->apf_intra_pred_luma_8x8[8] =
131
2
                    ih264_intra_pred_luma_8x8_mode_horz_u;
132
2
133
2
    ps_codec->pf_intra_pred_ref_filtering =
134
2
                    ih264_intra_pred_luma_8x8_mode_ref_filtering;
135
2
136
2
    /* Init function pointers for intra pred leaf level functions chroma
137
2
     * Intra 8x8 */
138
2
    ps_codec->apf_intra_pred_chroma[0] = ih264_intra_pred_chroma_8x8_mode_vert;
139
2
    ps_codec->apf_intra_pred_chroma[1] = ih264_intra_pred_chroma_8x8_mode_horz;
140
2
    ps_codec->apf_intra_pred_chroma[2] = ih264_intra_pred_chroma_8x8_mode_dc;
141
2
    ps_codec->apf_intra_pred_chroma[3] = ih264_intra_pred_chroma_8x8_mode_plane;
142
2
143
2
    ps_codec->pf_default_weighted_pred_luma = ih264_default_weighted_pred_luma;
144
2
    ps_codec->pf_default_weighted_pred_chroma =
145
2
                    ih264_default_weighted_pred_chroma;
146
2
    ps_codec->pf_weighted_pred_luma = ih264_weighted_pred_luma;
147
2
    ps_codec->pf_weighted_pred_chroma = ih264_weighted_pred_chroma;
148
2
    ps_codec->pf_weighted_bi_pred_luma = ih264_weighted_bi_pred_luma;
149
2
    ps_codec->pf_weighted_bi_pred_chroma = ih264_weighted_bi_pred_chroma;
150
2
151
2
    /* Padding Functions */
152
2
    ps_codec->pf_pad_top = ih264_pad_top;
153
2
    ps_codec->pf_pad_bottom = ih264_pad_bottom;
154
2
    ps_codec->pf_pad_left_luma = ih264_pad_left_luma;
155
2
    ps_codec->pf_pad_left_chroma = ih264_pad_left_chroma;
156
2
    ps_codec->pf_pad_right_luma = ih264_pad_right_luma;
157
2
    ps_codec->pf_pad_right_chroma = ih264_pad_right_chroma;
158
2
159
2
    ps_codec->pf_iquant_itrans_recon_luma_4x4 = ih264_iquant_itrans_recon_4x4;
160
2
    ps_codec->pf_iquant_itrans_recon_luma_4x4_dc =
161
2
                    ih264_iquant_itrans_recon_4x4_dc;
162
2
    ps_codec->pf_iquant_itrans_recon_luma_8x8 = ih264_iquant_itrans_recon_8x8;
163
2
    ps_codec->pf_iquant_itrans_recon_luma_8x8_dc =
164
2
                    ih264_iquant_itrans_recon_8x8_dc;
165
2
    ps_codec->pf_iquant_itrans_recon_chroma_4x4 =
166
2
                    ih264_iquant_itrans_recon_chroma_4x4;
167
2
    ps_codec->pf_iquant_itrans_recon_chroma_4x4_dc =
168
2
                    ih264_iquant_itrans_recon_chroma_4x4_dc;
169
2
    ps_codec->pf_ihadamard_scaling_4x4 = ih264_ihadamard_scaling_4x4;
170
2
171
2
    /* Init fn ptr luma deblocking */
172
2
    ps_codec->pf_deblk_luma_vert_bs4 = ih264_deblk_luma_vert_bs4;
173
2
    ps_codec->pf_deblk_luma_vert_bslt4 = ih264_deblk_luma_vert_bslt4;
174
2
    ps_codec->pf_deblk_luma_vert_bs4_mbaff = ih264_deblk_luma_vert_bs4_mbaff;
175
2
    ps_codec->pf_deblk_luma_vert_bslt4_mbaff =
176
2
                    ih264_deblk_luma_vert_bslt4_mbaff;
177
2
178
2
    ps_codec->pf_deblk_luma_horz_bs4 = ih264_deblk_luma_horz_bs4;
179
2
    ps_codec->pf_deblk_luma_horz_bslt4 = ih264_deblk_luma_horz_bslt4;
180
2
181
2
    /* Init fn ptr chroma deblocking */
182
2
    ps_codec->pf_deblk_chroma_vert_bs4 = ih264_deblk_chroma_vert_bs4;
183
2
    ps_codec->pf_deblk_chroma_vert_bslt4 = ih264_deblk_chroma_vert_bslt4;
184
2
    ps_codec->pf_deblk_chroma_vert_bs4_mbaff =
185
2
                    ih264_deblk_chroma_vert_bs4_mbaff;
186
2
    ps_codec->pf_deblk_chroma_vert_bslt4_mbaff =
187
2
                    ih264_deblk_chroma_vert_bslt4_mbaff;
188
2
189
2
    ps_codec->pf_deblk_chroma_horz_bs4 = ih264_deblk_chroma_horz_bs4;
190
2
    ps_codec->pf_deblk_chroma_horz_bslt4 = ih264_deblk_chroma_horz_bslt4;
191
2
192
2
    /* Inter pred leaf level functions */
193
2
    ps_codec->apf_inter_pred_luma[0] = ih264_inter_pred_luma_copy;
194
2
    ps_codec->apf_inter_pred_luma[1] = ih264_inter_pred_luma_horz_qpel;
195
2
    ps_codec->apf_inter_pred_luma[2] = ih264_inter_pred_luma_horz;
196
2
    ps_codec->apf_inter_pred_luma[3] = ih264_inter_pred_luma_horz_qpel;
197
2
    ps_codec->apf_inter_pred_luma[4] = ih264_inter_pred_luma_vert_qpel;
198
2
    ps_codec->apf_inter_pred_luma[5] =
199
2
                    ih264_inter_pred_luma_horz_qpel_vert_qpel;
200
2
    ps_codec->apf_inter_pred_luma[6] =
201
2
                    ih264_inter_pred_luma_horz_hpel_vert_qpel;
202
2
    ps_codec->apf_inter_pred_luma[7] =
203
2
                    ih264_inter_pred_luma_horz_qpel_vert_qpel;
204
2
    ps_codec->apf_inter_pred_luma[8] = ih264_inter_pred_luma_vert;
205
2
    ps_codec->apf_inter_pred_luma[9] =
206
2
                    ih264_inter_pred_luma_horz_qpel_vert_hpel;
207
2
    ps_codec->apf_inter_pred_luma[10] =
208
2
                    ih264_inter_pred_luma_horz_hpel_vert_hpel;
209
2
    ps_codec->apf_inter_pred_luma[11] =
210
2
                    ih264_inter_pred_luma_horz_qpel_vert_hpel;
211
2
    ps_codec->apf_inter_pred_luma[12] = ih264_inter_pred_luma_vert_qpel;
212
2
    ps_codec->apf_inter_pred_luma[13] =
213
2
                    ih264_inter_pred_luma_horz_qpel_vert_qpel;
214
2
    ps_codec->apf_inter_pred_luma[14] =
215
2
                    ih264_inter_pred_luma_horz_hpel_vert_qpel;
216
2
    ps_codec->apf_inter_pred_luma[15] =
217
2
                    ih264_inter_pred_luma_horz_qpel_vert_qpel;
218
2
219
2
    ps_codec->pf_inter_pred_chroma = ih264_inter_pred_chroma;
220
2
221
2
    return;
222
2
}
/proc/self/cwd/external/libavc/decoder/ih264d_inter_pred.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/*!
21
 **************************************************************************
22
 * \file ih264d_inter_pred.c
23
 *
24
 * \brief
25
 *    This file contains routines to perform MotionCompensation tasks
26
 *
27
 * Detailed_description
28
 *
29
 * \date
30
 *    20/11/2002
31
 *
32
 * \author  Arvind Raman
33
 **************************************************************************
34
 */
35
36
#include <string.h>
37
#include "ih264d_defs.h"
38
#include "ih264d_mvpred.h"
39
#include "ih264d_error_handler.h"
40
#include "ih264d_structs.h"
41
#include "ih264d_defs.h"
42
#include "ih264d_inter_pred.h"
43
#include "ih264_typedefs.h"
44
#include "ih264_macros.h"
45
#include "ih264_platform_macros.h"
46
#include "ih264d_debug.h"
47
#include "ih264d_tables.h"
48
#include "ih264d_mb_utils.h"
49
50
51
void ih264d_pad_on_demand(pred_info_t *ps_pred, UWORD8 lum_chrom_blk);
52
53
54
55
void ih264d_copy_multiplex_data(UWORD8 *puc_Source,
56
                                UWORD8 *puc_To,
57
                                UWORD32 uc_w,
58
                                UWORD32 uc_h,
59
                                UWORD32 ui16_sourceWidth,
60
                                UWORD32 ui16_toWidth)
61
0
{
62
0
    UWORD8 uc_i, uc_j;
63
0
64
0
    for(uc_i = 0; uc_i < uc_h; uc_i++)
65
0
    {
66
0
        memcpy(puc_To, puc_Source, uc_w);
67
0
        puc_To += ui16_toWidth;
68
0
        puc_Source += ui16_sourceWidth;
69
0
    }
70
0
}
71
72
73
/*!
74
 **************************************************************************
75
 * \if Function name : dma_2d1d \endif
76
 *
77
 * \brief
78
 *    2D -> 1D linear DMA into the reference buffers
79
 *
80
 * \return
81
 *    None
82
 **************************************************************************
83
 */
84
void ih264d_copy_2d1d(UWORD8 *puc_src,
85
                      UWORD8 *puc_dest,
86
                      UWORD16 ui16_srcWidth,
87
                      UWORD16 ui16_widthToFill,
88
                      UWORD16 ui16_heightToFill)
89
0
{
90
0
    UWORD32 uc_w, uc_h;
91
0
    for(uc_h = ui16_heightToFill; uc_h != 0; uc_h--)
92
0
    {
93
0
        memcpy(puc_dest, puc_src, ui16_widthToFill);
94
0
        puc_dest += ui16_widthToFill;
95
0
        puc_src += ui16_srcWidth;
96
0
    }
97
0
}
98
99
/*!
100
 **************************************************************************
101
 * \if Function name : ih264d_fill_pred_info \endif
102
 *
103
 * \brief
104
 *    Fills inter prediction related info
105
 *
106
 * \return
107
 *    None
108
 **************************************************************************
109
 */
110
void ih264d_fill_pred_info(WORD16 *pi2_mv,WORD32 part_width,WORD32 part_height, WORD32 sub_mb_num,
111
                           WORD32 pred_dir,pred_info_pkd_t *ps_pred_pkd,WORD8 i1_buf_id,
112
                           WORD8 i1_ref_idx,UWORD32 *pu4_wt_offset,UWORD8 u1_pic_type)
113
0
{
114
0
    WORD32 insert_bits;
115
0
116
0
    ps_pred_pkd->i2_mv[0] = pi2_mv[0];
117
0
    ps_pred_pkd->i2_mv[1] = pi2_mv[1];
118
0
119
0
    insert_bits = sub_mb_num & 3; /*sub mb x*/
120
0
    ps_pred_pkd->i1_size_pos_info = insert_bits;
121
0
    insert_bits = sub_mb_num >> 2;/*sub mb y*/
122
0
    ps_pred_pkd->i1_size_pos_info |= insert_bits << 2;
123
0
    insert_bits = part_width >> 1;
124
0
    ps_pred_pkd->i1_size_pos_info |= insert_bits << 4;
125
0
    insert_bits = part_height >> 1;
126
0
    ps_pred_pkd->i1_size_pos_info |= insert_bits << 6;
127
0
128
0
    ps_pred_pkd->i1_ref_idx_info = i1_ref_idx;
129
0
    ps_pred_pkd->i1_ref_idx_info |= (pred_dir << 6);
130
0
    ps_pred_pkd->i1_buf_id = i1_buf_id;
131
0
    ps_pred_pkd->pu4_wt_offst = pu4_wt_offset;
132
0
    ps_pred_pkd->u1_pic_type = u1_pic_type;
133
0
134
0
135
0
}
136
137
138
139
140
141
142
143
/*****************************************************************************/
144
/* \if Function name : formMbPartInfo \endif                                 */
145
/*                                                                           */
146
/* \brief                                                                    */
147
/*    Form the Mb partition information structure, to be used by the MC      */
148
/*    routine                                                                */
149
/*                                                                           */
150
/* \return                                                                   */
151
/*    None                                                                   */
152
/* \note                                                                     */
153
/*    c_bufx is used to select PredBuffer,                                   */
154
/*    if it's only Forward/Backward prediction always buffer used is         */
155
/*    puc_MbLumaPredBuffer[0 to X1],pu1_mb_cb_pred_buffer[0 to X1] and          */
156
/*    pu1_mb_cr_pred_buffer[0 to X1]                                            */
157
/*                                                                           */
158
/*    if it's bidirect for forward ..PredBuffer[0 to X1] buffer is used and  */
159
/*    ..PredBuffer[X2 to X3] for backward prediction. and                    */
160
/*                                                                           */
161
/*    Final predicted samples values are the average of ..PredBuffer[0 to X1]*/
162
/*    and ..PredBuffer[X2 to X3]                                             */
163
/*                                                                           */
164
/*    X1 is 255 for Luma and 63 for Chroma                                   */
165
/*    X2 is 256 for Luma and 64 for Chroma                                   */
166
/*    X3 is 511 for Luma and 127 for Chroma                                  */
167
/*                                                                           */
168
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
169
/*         11 05 2005   SWRN            Modified to handle pod               */
170
/*****************************************************************************/
171
172
WORD32 ih264d_form_mb_part_info_bp(pred_info_pkd_t *ps_pred_pkd,
173
                                 dec_struct_t * ps_dec,
174
                                 UWORD16 u2_mb_x,
175
                                 UWORD16 u2_mb_y,
176
                                 WORD32 mb_index,
177
                                 dec_mb_info_t *ps_cur_mb_info)
178
0
{
179
0
    /* The reference buffer pointer */
180
0
    WORD32 i2_frm_x, i2_frm_y;
181
0
    WORD32 i2_tmp_mv_x, i2_tmp_mv_y;
182
0
    WORD32 i2_rec_x, i2_rec_y;
183
0
184
0
    WORD32 u2_pic_ht;
185
0
    WORD32 u2_frm_wd;
186
0
    WORD32 u2_rec_wd;
187
0
    UWORD8 u1_sub_x = 0,u1_sub_y=0 ;
188
0
    UWORD8  u1_part_wd = 0,u1_part_ht = 0;
189
0
    WORD16 i2_mv_x,i2_mv_y;
190
0
191
0
    /********************************************/
192
0
    /* i1_mc_wd       width reqd for mcomp      */
193
0
    /* u1_dma_ht      height reqd for mcomp     */
194
0
    /* u1_dma_wd      width aligned to 4 bytes  */
195
0
    /* u1_dx          fractional part of width  */
196
0
    /* u1_dx          fractional part of height */
197
0
    /********************************************/
198
0
    UWORD32 i1_mc_wd;
199
0
200
0
    WORD32 u1_dma_ht;
201
0
202
0
    UWORD32 u1_dma_wd;
203
0
    UWORD32 u1_dx;
204
0
    UWORD32 u1_dy;
205
0
    pred_info_t * ps_pred = ps_dec->ps_pred + ps_dec->u4_pred_info_idx;
206
0
    dec_slice_params_t * const ps_cur_slice = ps_dec->ps_cur_slice;
207
0
    tfr_ctxt_t *ps_frame_buf;
208
0
    struct pic_buffer_t *ps_ref_frm;
209
0
    UWORD8 u1_scale_ref,u1_mbaff,u1_field;
210
0
    pic_buffer_t  **pps_ref_frame;
211
0
    WORD8 i1_size_pos_info,i1_buf_id;
212
0
213
0
    PROFILE_DISABLE_MB_PART_INFO()
214
0
215
0
     UNUSED(ps_cur_mb_info);
216
0
     i1_size_pos_info = ps_pred_pkd->i1_size_pos_info;
217
0
     GET_XPOS_PRED(u1_sub_x,i1_size_pos_info);
218
0
     GET_YPOS_PRED(u1_sub_y,i1_size_pos_info);
219
0
     GET_WIDTH_PRED(u1_part_wd,i1_size_pos_info);
220
0
     GET_HEIGHT_PRED(u1_part_ht,i1_size_pos_info);
221
0
     i2_mv_x = ps_pred_pkd->i2_mv[0];
222
0
     i2_mv_y = ps_pred_pkd->i2_mv[1];
223
0
     i1_buf_id = ps_pred_pkd->i1_buf_id;
224
0
225
0
226
0
     ps_ref_frm = ps_dec->apv_buf_id_pic_buf_map[i1_buf_id];
227
0
228
0
229
0
    {
230
0
        ps_frame_buf = &ps_dec->s_tran_addrecon;
231
0
    }
232
0
233
0
234
0
    /* Transfer Setup Y */
235
0
    {
236
0
        UWORD8 *pu1_pred, *pu1_rec;
237
0
238
0
        /* calculating rounded motion vectors and fractional components */
239
0
        i2_tmp_mv_x = i2_mv_x;
240
0
        i2_tmp_mv_y = i2_mv_y;
241
0
        u1_dx = i2_tmp_mv_x & 0x3;
242
0
        u1_dy = i2_tmp_mv_y & 0x3;
243
0
        i2_tmp_mv_x >>= 2;
244
0
        i2_tmp_mv_y >>= 2;
245
0
        i1_mc_wd = u1_part_wd << 2;
246
0
        u1_dma_ht = u1_part_ht << 2;
247
0
        if(u1_dx)
248
0
        {
249
0
            i2_tmp_mv_x -= 2;
250
0
            i1_mc_wd += 5;
251
0
        }
252
0
        if(u1_dy)
253
0
        {
254
0
            i2_tmp_mv_y -= 2;
255
0
            u1_dma_ht += 5;
256
0
        }
257
0
258
0
        /********************************************************************/
259
0
        /* Calulating the horizontal and the vertical u4_ofst from top left  */
260
0
        /* edge of the reference frame, and subsequent clipping             */
261
0
        /********************************************************************/
262
0
        u2_pic_ht = ps_dec->u2_pic_ht;
263
0
        u2_frm_wd = ps_dec->u2_frm_wd_y;
264
0
        i2_rec_x = u1_sub_x << 2;
265
0
        i2_rec_y = u1_sub_y << 2;
266
0
267
0
        i2_frm_x = (u2_mb_x << 4) + i2_rec_x + i2_tmp_mv_x;
268
0
        i2_frm_y = (u2_mb_y << 4) + i2_rec_y + i2_tmp_mv_y;
269
0
270
0
        i2_frm_x = CLIP3(MAX_OFFSET_OUTSIDE_X_FRM, (ps_dec->u2_pic_wd - 1),
271
0
                         i2_frm_x);
272
0
        i2_frm_y = CLIP3(((1 - u1_dma_ht)), (u2_pic_ht - (1)), i2_frm_y);
273
0
274
0
        pu1_pred = ps_ref_frm->pu1_buf1 + i2_frm_y * u2_frm_wd + i2_frm_x;
275
0
276
0
        u1_dma_wd = (i1_mc_wd + 3) & 0xFC;
277
0
278
0
        /********************************************************************/
279
0
        /* Calulating the horizontal and the vertical u4_ofst from top left  */
280
0
        /* edge of the recon buffer                                         */
281
0
        /********************************************************************/
282
0
        u2_rec_wd = MB_SIZE;
283
0
        {
284
0
            u2_rec_wd = ps_dec->u2_frm_wd_y;
285
0
            i2_rec_x += (mb_index << 4);
286
0
            pu1_rec = ps_frame_buf->pu1_dest_y + i2_rec_y * u2_rec_wd
287
0
                            + i2_rec_x;
288
0
        }
289
0
290
0
        /* filling the pred and dma structures for Y */
291
0
        u2_frm_wd = ps_dec->u2_frm_wd_y;
292
0
293
0
        ps_pred->u2_u1_ref_buf_wd = u1_dma_wd;
294
0
        ps_pred->i1_dma_ht = u1_dma_ht;
295
0
        ps_pred->i1_mc_wd = i1_mc_wd;
296
0
        ps_pred->u2_frm_wd = u2_frm_wd;
297
0
        ps_pred->pu1_rec_y_u = pu1_rec;
298
0
        ps_pred->u2_dst_stride = u2_rec_wd;
299
0
300
0
        ps_pred->i1_mb_partwidth = u1_part_wd << 2;
301
0
        ps_pred->i1_mb_partheight = u1_part_ht << 2;
302
0
        ps_pred->u1_dydx = (u1_dy << 2) + u1_dx;
303
0
304
0
        ps_pred->pu1_y_ref = pu1_pred;
305
0
306
0
    }
307
0
308
0
    /* Increment ps_pred index */
309
0
    ps_pred++;
310
0
311
0
    /* Transfer Setup U & V */
312
0
    {
313
0
        WORD32 i4_ref_offset, i4_rec_offset;
314
0
        UWORD8 *pu1_pred_u, *pu1_pred_v;
315
0
316
0
317
0
        /* calculating rounded motion vectors and fractional components */
318
0
        i2_tmp_mv_x = i2_mv_x;
319
0
        i2_tmp_mv_y = i2_mv_y;
320
0
321
0
        /************************************************************************/
322
0
        /* Table 8-9: Derivation of the vertical component of the chroma vector */
323
0
        /* in field coding mode                                                 */
324
0
        /************************************************************************/
325
0
326
0
        /* Eighth sample of the chroma MV */
327
0
        u1_dx = i2_tmp_mv_x & 0x7;
328
0
        u1_dy = i2_tmp_mv_y & 0x7;
329
0
330
0
        /********************************************************************/
331
0
        /* Calculating the full pel MV for chroma which is 1/2 of the Luma  */
332
0
        /* MV in full pel units                                             */
333
0
        /********************************************************************/
334
0
        i2_mv_x = i2_tmp_mv_x;
335
0
        i2_mv_y = i2_tmp_mv_y;
336
0
        i2_tmp_mv_x = SIGN_POW2_DIV(i2_tmp_mv_x, 3);
337
0
        i2_tmp_mv_y = SIGN_POW2_DIV(i2_tmp_mv_y, 3);
338
0
        i1_mc_wd = u1_part_wd << 1;
339
0
        u1_dma_ht = u1_part_ht << 1;
340
0
        if(u1_dx)
341
0
        {
342
0
            i2_tmp_mv_x -= (i2_mv_x < 0);
343
0
            i1_mc_wd++;
344
0
        }
345
0
        if(u1_dy != 0)
346
0
        {
347
0
            i2_tmp_mv_y -= (i2_mv_y < 0);
348
0
            u1_dma_ht++;
349
0
        }
350
0
351
0
        /********************************************************************/
352
0
        /* Calulating the horizontal and the vertical u4_ofst from top left  */
353
0
        /* edge of the reference frame, and subsequent clipping             */
354
0
        /********************************************************************/
355
0
        u2_pic_ht >>= 1;
356
0
        u2_frm_wd = ps_dec->u2_frm_wd_uv;
357
0
        i2_rec_x = u1_sub_x << 1;
358
0
        i2_rec_y = u1_sub_y << 1;
359
0
360
0
        i2_frm_x = (u2_mb_x << 3) + i2_rec_x + i2_tmp_mv_x;
361
0
        i2_frm_y = (u2_mb_y << 3) + i2_rec_y + i2_tmp_mv_y;
362
0
363
0
        i2_frm_x = CLIP3(MAX_OFFSET_OUTSIDE_UV_FRM,
364
0
                         ((ps_dec->u2_pic_wd >> 1) - 1), i2_frm_x);
365
0
        i2_frm_y = CLIP3(((1 - u1_dma_ht)), (u2_pic_ht - (1)), i2_frm_y);
366
0
367
0
        i4_ref_offset = i2_frm_y * u2_frm_wd + i2_frm_x * YUV420SP_FACTOR;
368
0
        u1_dma_wd = (i1_mc_wd + 3) & 0xFC;
369
0
370
0
        /********************************************************************/
371
0
        /* Calulating the horizontal and the vertical u4_ofst from top left  */
372
0
        /* edge of the recon buffer                                         */
373
0
        /********************************************************************/
374
0
        /* CHANGED CODE */
375
0
        u2_rec_wd = BLK8x8SIZE * YUV420SP_FACTOR;
376
0
        i4_rec_offset = i2_rec_y * u2_rec_wd + i2_rec_x * YUV420SP_FACTOR;
377
0
378
0
        {
379
0
            u2_rec_wd = ps_dec->u2_frm_wd_uv;
380
0
            i2_rec_x += (mb_index << 3);
381
0
            i4_rec_offset = i2_rec_y * u2_rec_wd + i2_rec_x * YUV420SP_FACTOR;
382
0
            ps_pred->pu1_rec_y_u = ps_frame_buf->pu1_dest_u + i4_rec_offset;
383
0
            ps_pred->u1_pi1_wt_ofst_rec_v = ps_frame_buf->pu1_dest_v
384
0
                            + i4_rec_offset;
385
0
        }
386
0
387
0
        /* CHANGED CODE */
388
0
389
0
        /* filling the common pred structures for U */
390
0
        u2_frm_wd = ps_dec->u2_frm_wd_uv;
391
0
392
0
        ps_pred->u2_u1_ref_buf_wd = u1_dma_wd;
393
0
        ps_pred->i1_dma_ht = u1_dma_ht;
394
0
        ps_pred->i1_mc_wd = i1_mc_wd;
395
0
396
0
        ps_pred->u2_frm_wd = u2_frm_wd;
397
0
        ps_pred->u2_dst_stride = u2_rec_wd;
398
0
399
0
        ps_pred->i1_mb_partwidth = u1_part_wd << 1;
400
0
        ps_pred->i1_mb_partheight = u1_part_ht << 1;
401
0
        ps_pred->u1_dydx = (u1_dy << 3) + u1_dx;
402
0
403
0
        pu1_pred_u = ps_ref_frm->pu1_buf2 + i4_ref_offset;
404
0
        pu1_pred_v = ps_ref_frm->pu1_buf3 + i4_ref_offset;
405
0
406
0
        /* Copy U & V partitions */
407
0
        ps_pred->pu1_u_ref = pu1_pred_u;
408
0
409
0
        /* Increment the reference buffer Index */
410
0
        ps_pred->pu1_v_ref = pu1_pred_v;
411
0
    }
412
0
413
0
    /* Increment ps_pred index */
414
0
    ps_dec->u4_pred_info_idx += 2;
415
0
416
0
    return OK;
417
0
418
0
}
419
420
421
/*****************************************************************************/
422
/* \if Function name : formMbPartInfo \endif                                 */
423
/*                                                                           */
424
/* \brief                                                                    */
425
/*    Form the Mb partition information structure, to be used by the MC      */
426
/*    routine                                                                */
427
/*                                                                           */
428
/* \return                                                                   */
429
/*    None                                                                   */
430
/* \note                                                                     */
431
/*    c_bufx is used to select PredBuffer,                                   */
432
/*    if it's only Forward/Backward prediction always buffer used is         */
433
/*    puc_MbLumaPredBuffer[0 to X1],pu1_mb_cb_pred_buffer[0 to X1] and          */
434
/*    pu1_mb_cr_pred_buffer[0 to X1]                                            */
435
/*                                                                           */
436
/*    if it's bidirect for forward ..PredBuffer[0 to X1] buffer is used and  */
437
/*    ..PredBuffer[X2 to X3] for backward prediction. and                    */
438
/*                                                                           */
439
/*    Final predicted samples values are the average of ..PredBuffer[0 to X1]*/
440
/*    and ..PredBuffer[X2 to X3]                                             */
441
/*                                                                           */
442
/*    X1 is 255 for Luma and 63 for Chroma                                   */
443
/*    X2 is 256 for Luma and 64 for Chroma                                   */
444
/*    X3 is 511 for Luma and 127 for Chroma                                  */
445
/*                                                                           */
446
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
447
/*         11 05 2005   SWRN            Modified to handle pod               */
448
/*****************************************************************************/
449
WORD32 ih264d_form_mb_part_info_mp(pred_info_pkd_t *ps_pred_pkd,
450
                                 dec_struct_t * ps_dec,
451
                                 UWORD16 u2_mb_x,
452
                                 UWORD16 u2_mb_y,
453
                                 WORD32 mb_index,
454
                                 dec_mb_info_t *ps_cur_mb_info)
455
0
{
456
0
    /* The reference buffer pointer */
457
0
    UWORD8 *pu1_ref_buf;
458
0
    WORD16 i2_frm_x, i2_frm_y, i2_tmp_mv_x, i2_tmp_mv_y, i2_pod_ht;
459
0
    WORD16 i2_rec_x, i2_rec_y;
460
0
    UWORD16 u2_pic_ht, u2_frm_wd, u2_rec_wd;
461
0
    UWORD8 u1_wght_pred_type, u1_wted_bipred_idc;
462
0
    UWORD16 u2_tot_ref_scratch_size;
463
0
    UWORD8 u1_sub_x = 0;
464
0
    UWORD8 u1_sub_y = 0;
465
0
    UWORD8 u1_is_bi_dir = 0;
466
0
467
0
    /********************************************/
468
0
    /* i1_mc_wd       width reqd for mcomp      */
469
0
    /* u1_dma_ht      height reqd for mcomp     */
470
0
    /* u1_dma_wd      width aligned to 4 bytes  */
471
0
    /* u1_dx          fractional part of width  */
472
0
    /* u1_dx          fractional part of height */
473
0
    /********************************************/
474
0
    UWORD8 i1_mc_wd, u1_dma_ht, u1_dma_wd, u1_dx, u1_dy;
475
0
    pred_info_t * ps_pred ;
476
0
    dec_slice_params_t * const ps_cur_slice = ps_dec->ps_cur_slice;
477
0
    const UWORD8 u1_slice_type = ps_dec->ps_decode_cur_slice->slice_type;
478
0
    UWORD8 u1_pod_bot, u1_pod_top;
479
0
480
0
    /* load the pictype for pod u4_flag & chroma motion vector derivation */
481
0
    UWORD8 u1_ref_pic_type ;
482
0
483
0
    /* set default value to flags specifying field nature of picture & mb */
484
0
    UWORD32 u1_mb_fld = 0, u1_mb_or_pic_fld;
485
0
    UWORD32 u1_mb_bot = 0, u1_pic_bot = 0, u1_mb_or_pic_bot;
486
0
    tfr_ctxt_t *ps_frame_buf;
487
0
    /* calculate flags specifying field nature of picture & mb */
488
0
    const UWORD32 u1_pic_fld = ps_cur_slice->u1_field_pic_flag;
489
0
    WORD8 i1_pred;
490
0
    WORD8 i1_size_pos_info,i1_buf_id,i1_ref_idx;
491
0
    UWORD8 u1_part_wd,u1_part_ht;
492
0
    WORD16 i2_mv_x,i2_mv_y;
493
0
    struct pic_buffer_t *ps_ref_frm;
494
0
    UWORD32 *pu4_wt_offset;
495
0
    UWORD8 *pu1_buf1,*pu1_buf2,*pu1_buf3;
496
0
497
0
498
0
    PROFILE_DISABLE_MB_PART_INFO()
499
0
500
0
    ps_pred = ps_dec->ps_pred + ps_dec->u4_pred_info_idx;
501
0
502
0
503
0
     i1_size_pos_info = ps_pred_pkd->i1_size_pos_info;
504
0
     GET_XPOS_PRED(u1_sub_x,i1_size_pos_info);
505
0
     GET_YPOS_PRED(u1_sub_y,i1_size_pos_info);
506
0
     GET_WIDTH_PRED(u1_part_wd,i1_size_pos_info);
507
0
     GET_HEIGHT_PRED(u1_part_ht,i1_size_pos_info);
508
0
     i2_mv_x = ps_pred_pkd->i2_mv[0];
509
0
     i2_mv_y = ps_pred_pkd->i2_mv[1];
510
0
     i1_ref_idx = ps_pred_pkd->i1_ref_idx_info & 0x3f;
511
0
     i1_buf_id = ps_pred_pkd->i1_buf_id;
512
0
     ps_ref_frm = ps_dec->apv_buf_id_pic_buf_map[i1_buf_id];
513
0
514
0
     i1_pred = (ps_pred_pkd->i1_ref_idx_info & 0xC0) >> 6;
515
0
     u1_is_bi_dir = (i1_pred == BI_PRED);
516
0
517
0
518
0
    u1_ref_pic_type = ps_pred_pkd->u1_pic_type & PIC_MASK;
519
0
520
0
    pu1_buf1  = ps_ref_frm->pu1_buf1;
521
0
    pu1_buf2  = ps_ref_frm->pu1_buf2;
522
0
    pu1_buf3  = ps_ref_frm->pu1_buf3;
523
0
524
0
    if(u1_ref_pic_type == BOT_FLD)
525
0
    {
526
0
        pu1_buf1 += ps_ref_frm->u2_frm_wd_y;
527
0
        pu1_buf2 += ps_ref_frm->u2_frm_wd_uv;
528
0
        pu1_buf3 += ps_ref_frm->u2_frm_wd_uv;
529
0
530
0
    }
531
0
532
0
533
0
534
0
    if(ps_dec->ps_cur_pps->u1_wted_pred_flag)
535
0
    {
536
0
            pu4_wt_offset = (UWORD32*)&ps_dec->pu4_wt_ofsts[2
537
0
                            * X3(i1_ref_idx)];
538
0
    }
539
0
540
0
541
0
    pu4_wt_offset = ps_pred_pkd->pu4_wt_offst;
542
0
543
0
544
0
    /* Pointer to the frame buffer */
545
0
    {
546
0
        ps_frame_buf = &ps_dec->s_tran_addrecon;
547
0
        /* CHANGED CODE */
548
0
    }
549
0
550
0
    if(!u1_pic_fld)
551
0
    {
552
0
        u1_mb_fld = ps_cur_mb_info->u1_mb_field_decodingflag;
553
0
        u1_mb_bot = 1 - ps_cur_mb_info->u1_topmb;
554
0
    }
555
0
    else
556
0
        u1_pic_bot = ps_cur_slice->u1_bottom_field_flag;
557
0
558
0
    /****************************************************************/
559
0
    /* calculating the flags the tell whether to use frame-padding  */
560
0
    /* or use software pad-on-demand                                */
561
0
    /****************************************************************/
562
0
    u1_mb_or_pic_bot = u1_mb_bot | u1_pic_bot;
563
0
    u1_mb_or_pic_fld = u1_mb_fld | u1_pic_fld;
564
0
    u1_pod_bot = u1_mb_or_pic_fld && (u1_ref_pic_type == TOP_FLD);
565
0
    u1_pod_top = u1_mb_or_pic_fld && (u1_ref_pic_type == BOT_FLD);
566
0
567
0
    /* Weighted Pred additions */
568
0
    u1_wted_bipred_idc = ps_dec->ps_cur_pps->u1_wted_bipred_idc;
569
0
570
0
    if((u1_slice_type == P_SLICE) || (u1_slice_type == SP_SLICE))
571
0
    {
572
0
        /* P Slice only */
573
0
        u1_wght_pred_type = ps_dec->ps_cur_pps->u1_wted_pred_flag;
574
0
575
0
    }
576
0
    else
577
0
    {
578
0
        /* B Slice only */
579
0
        u1_wght_pred_type = 1 + u1_is_bi_dir;
580
0
        if(u1_wted_bipred_idc == 0)
581
0
            u1_wght_pred_type = 0;
582
0
        if((u1_wted_bipred_idc == 2) && (!u1_is_bi_dir))
583
0
            u1_wght_pred_type = 0;
584
0
    }
585
0
    /* load the scratch reference buffer index */
586
0
    pu1_ref_buf = ps_dec->pu1_ref_buff + ps_dec->u4_dma_buf_idx;
587
0
    u2_tot_ref_scratch_size = 0;
588
0
589
0
590
0
    /* Transfer Setup Y */
591
0
    {
592
0
        UWORD8 *pu1_pred, *pu1_rec;
593
0
        /* calculating rounded motion vectors and fractional components */
594
0
        i2_tmp_mv_x = i2_mv_x;
595
0
        i2_tmp_mv_y = i2_mv_y;
596
0
597
0
        u1_dx = i2_tmp_mv_x & 0x3;
598
0
        u1_dy = i2_tmp_mv_y & 0x3;
599
0
        i2_tmp_mv_x >>= 2;
600
0
        i2_tmp_mv_y >>= 2;
601
0
        i1_mc_wd = u1_part_wd << 2;
602
0
        u1_dma_ht = u1_part_ht << 2;
603
0
        if(u1_dx)
604
0
        {
605
0
            i2_tmp_mv_x -= 2;
606
0
            i1_mc_wd += 5;
607
0
        }
608
0
        if(u1_dy)
609
0
        {
610
0
            i2_tmp_mv_y -= 2;
611
0
            u1_dma_ht += 5;
612
0
        }
613
0
614
0
        /********************************************************************/
615
0
        /* Calulating the horizontal and the vertical u4_ofst from top left  */
616
0
        /* edge of the reference frame, and subsequent clipping             */
617
0
        /********************************************************************/
618
0
        u2_pic_ht = ps_dec->u2_pic_ht >> u1_pic_fld;
619
0
        u2_frm_wd = ps_dec->u2_frm_wd_y << u1_pic_fld;
620
0
        i2_frm_x = (u2_mb_x << 4) + (u1_sub_x << 2) + i2_tmp_mv_x;
621
0
        i2_frm_y = ((u2_mb_y + (u1_mb_bot && !u1_mb_fld)) << 4)
622
0
                        + (((u1_sub_y << 2) + i2_tmp_mv_y) << u1_mb_fld);
623
0
624
0
        i2_frm_x = CLIP3(MAX_OFFSET_OUTSIDE_X_FRM, (ps_dec->u2_pic_wd - 1),
625
0
                         i2_frm_x);
626
0
        i2_frm_y = CLIP3(((1 - u1_dma_ht) << u1_mb_fld),
627
0
                         (u2_pic_ht - (1 << u1_mb_fld)), i2_frm_y);
628
0
629
0
        pu1_pred = pu1_buf1 + i2_frm_y * u2_frm_wd + i2_frm_x;
630
0
        u1_dma_wd = (i1_mc_wd + 3) & 0xFC;
631
0
        /********************************************************************/
632
0
        /* Calulating the horizontal and the vertical u4_ofst from top left  */
633
0
        /* edge of the recon buffer                                         */
634
0
        /********************************************************************/
635
0
        /* CHANGED CODE */
636
0
        u2_rec_wd = MB_SIZE;
637
0
        i2_rec_x = u1_sub_x << 2;
638
0
        i2_rec_y = u1_sub_y << 2;
639
0
        {
640
0
            u2_rec_wd = ps_dec->u2_frm_wd_y << u1_mb_or_pic_fld;
641
0
            i2_rec_x += (mb_index << 4);
642
0
            pu1_rec = ps_frame_buf->pu1_dest_y + i2_rec_y * u2_rec_wd
643
0
                            + i2_rec_x;
644
0
            if(u1_mb_bot)
645
0
                pu1_rec += ps_dec->u2_frm_wd_y << ((u1_mb_fld) ? 0 : 4);
646
0
        }
647
0
648
0
        /* CHANGED CODE */
649
0
650
0
        /* filling the pred and dma structures for Y */
651
0
        u2_frm_wd = ps_dec->u2_frm_wd_y << u1_mb_or_pic_fld;
652
0
653
0
        ps_pred->pu1_dma_dest_addr = pu1_ref_buf;
654
0
        ps_pred->u2_u1_ref_buf_wd = u1_dma_wd;
655
0
        ps_pred->u2_frm_wd = u2_frm_wd;
656
0
        ps_pred->i1_dma_ht = u1_dma_ht;
657
0
        ps_pred->i1_mc_wd = i1_mc_wd;
658
0
        ps_pred->pu1_rec_y_u = pu1_rec;
659
0
        ps_pred->u2_dst_stride = u2_rec_wd;
660
0
661
0
        ps_pred->i1_mb_partwidth = u1_part_wd << 2;
662
0
        ps_pred->i1_mb_partheight = u1_part_ht << 2;
663
0
        ps_pred->u1_dydx = (u1_dy << 2) + u1_dx;
664
0
        ps_pred->u1_is_bi_direct = u1_is_bi_dir;
665
0
        ps_pred->u1_pi1_wt_ofst_rec_v = (UWORD8 *)pu4_wt_offset;
666
0
        ps_pred->u1_wght_pred_type = u1_wght_pred_type;
667
0
        ps_pred->i1_pod_ht = 0;
668
0
669
0
        /* Increment the Reference buffer Indices */
670
0
        pu1_ref_buf += u1_dma_wd * u1_dma_ht;
671
0
        u2_tot_ref_scratch_size += u1_dma_wd * u1_dma_ht;
672
0
673
0
        /* unrestricted field motion comp for top region outside frame */
674
0
        i2_pod_ht = (-i2_frm_y) >> u1_mb_fld;
675
0
        if((i2_pod_ht > 0) && u1_pod_top)
676
0
        {
677
0
            ps_pred->i1_pod_ht = (WORD8)(-i2_pod_ht);
678
0
            u1_dma_ht -= i2_pod_ht;
679
0
            pu1_pred += i2_pod_ht * u2_frm_wd;
680
0
        }
681
0
        /* unrestricted field motion comp for bottom region outside frame */
682
0
        else if(u1_pod_bot)
683
0
        {
684
0
            i2_pod_ht = u1_dma_ht + ((i2_frm_y - u2_pic_ht) >> u1_mb_fld);
685
0
            if(i2_pod_ht > 0)
686
0
            {
687
0
                u1_dma_ht -= i2_pod_ht;
688
0
                ps_pred->i1_pod_ht = (WORD8)i2_pod_ht;
689
0
            }
690
0
        }
691
0
692
0
        /* Copy Y partition */
693
0
694
0
        /*
695
0
         * ps_pred->i1_pod_ht is non zero when MBAFF is present. In case of MBAFF the reference data
696
0
         * is copied in the Scrath buffer so that the padding_on_demand doesnot corrupt the frame data
697
0
         */
698
0
        if(ps_pred->i1_pod_ht)
699
0
        {
700
0
            ps_pred->pu1_pred = pu1_pred;
701
0
            ps_pred->u1_dma_ht_y = u1_dma_ht;
702
0
            ps_pred->u1_dma_wd_y = u1_dma_wd;
703
0
        }
704
0
        ps_pred->pu1_y_ref = pu1_pred;
705
0
    }
706
0
707
0
708
0
709
0
    /* Increment ps_pred index */
710
0
    ps_pred++;
711
0
712
0
    /* Transfer Setup U & V */
713
0
    {
714
0
        WORD32 i4_ref_offset, i4_rec_offset;
715
0
        UWORD8 *pu1_pred_u, *pu1_pred_v, u1_tmp_dma_ht;
716
0
        /* CHANGED CODE */
717
0
        UWORD8 u1_chroma_cbp = (UWORD8)(ps_cur_mb_info->u1_cbp >> 4);
718
0
        /* CHANGED CODE */
719
0
720
0
        /* calculating rounded motion vectors and fractional components */
721
0
        i2_tmp_mv_x = i2_mv_x;
722
0
        i2_tmp_mv_y = i2_mv_y;
723
0
724
0
        /************************************************************************/
725
0
        /* Table 8-9: Derivation of the vertical component of the chroma vector */
726
0
        /* in field coding mode                                                 */
727
0
        /************************************************************************/
728
0
        if(u1_pod_bot && u1_mb_or_pic_bot)
729
0
            i2_tmp_mv_y += 2;
730
0
        if(u1_pod_top && !u1_mb_or_pic_bot)
731
0
            i2_tmp_mv_y -= 2;
732
0
733
0
        /* Eighth sample of the chroma MV */
734
0
        u1_dx = i2_tmp_mv_x & 0x7;
735
0
        u1_dy = i2_tmp_mv_y & 0x7;
736
0
737
0
        /********************************************************************/
738
0
        /* Calculating the full pel MV for chroma which is 1/2 of the Luma  */
739
0
        /* MV in full pel units                                             */
740
0
        /********************************************************************/
741
0
        i2_mv_x = i2_tmp_mv_x;
742
0
        i2_mv_y = i2_tmp_mv_y;
743
0
        i2_tmp_mv_x = SIGN_POW2_DIV(i2_tmp_mv_x, 3);
744
0
        i2_tmp_mv_y = SIGN_POW2_DIV(i2_tmp_mv_y, 3);
745
0
        i1_mc_wd = u1_part_wd << 1;
746
0
        u1_dma_ht = u1_part_ht << 1;
747
0
        if(u1_dx)
748
0
        {
749
0
            if(i2_mv_x < 0)
750
0
                i2_tmp_mv_x -= 1;
751
0
            i1_mc_wd++;
752
0
        }
753
0
        if(u1_dy != 0)
754
0
        {
755
0
            if(i2_mv_y < 0)
756
0
                i2_tmp_mv_y -= 1;
757
0
            u1_dma_ht++;
758
0
        }
759
0
760
0
        /********************************************************************/
761
0
        /* Calulating the horizontal and the vertical u4_ofst from top left  */
762
0
        /* edge of the reference frame, and subsequent clipping             */
763
0
        /********************************************************************/
764
0
        u2_pic_ht >>= 1;
765
0
        u2_frm_wd = ps_dec->u2_frm_wd_uv << u1_pic_fld;
766
0
        i2_frm_x = (u2_mb_x << 3) + (u1_sub_x << 1) + i2_tmp_mv_x;
767
0
        i2_frm_y = ((u2_mb_y + (u1_mb_bot && !u1_mb_fld)) << 3)
768
0
                        + (((u1_sub_y << 1) + i2_tmp_mv_y) << u1_mb_fld);
769
0
770
0
        i2_frm_x = CLIP3(MAX_OFFSET_OUTSIDE_UV_FRM,
771
0
                         ((ps_dec->u2_pic_wd >> 1) - 1), i2_frm_x);
772
0
        i2_frm_y = CLIP3(((1 - u1_dma_ht) << u1_mb_fld),
773
0
                         (u2_pic_ht - (1 << u1_mb_fld)), i2_frm_y);
774
0
775
0
        i4_ref_offset = i2_frm_y * u2_frm_wd + i2_frm_x * YUV420SP_FACTOR;
776
0
        u1_dma_wd = (i1_mc_wd + 3) & 0xFC;
777
0
778
0
        /********************************************************************/
779
0
        /* Calulating the horizontal and the vertical u4_ofst from top left  */
780
0
        /* edge of the recon buffer                                         */
781
0
        /********************************************************************/
782
0
        /* CHANGED CODE */
783
0
        u2_rec_wd = BLK8x8SIZE * YUV420SP_FACTOR;
784
0
        i2_rec_x = u1_sub_x << 1;
785
0
        i2_rec_y = u1_sub_y << 1;
786
0
        i4_rec_offset = i2_rec_y * u2_rec_wd + i2_rec_x * YUV420SP_FACTOR;
787
0
        {
788
0
            u2_rec_wd = ps_dec->u2_frm_wd_uv << u1_mb_or_pic_fld;
789
0
790
0
            i2_rec_x += (mb_index << 3);
791
0
            i4_rec_offset = i2_rec_y * u2_rec_wd + i2_rec_x * YUV420SP_FACTOR;
792
0
            if(u1_mb_bot)
793
0
                i4_rec_offset += ps_dec->u2_frm_wd_uv << ((u1_mb_fld) ? 0 : 3);
794
0
            ps_pred->pu1_rec_y_u = ps_frame_buf->pu1_dest_u + i4_rec_offset;
795
0
            ps_pred->u1_pi1_wt_ofst_rec_v = ps_frame_buf->pu1_dest_v
796
0
                            + i4_rec_offset;
797
0
798
0
        }
799
0
800
0
        /* CHANGED CODE */
801
0
802
0
        /* filling the common pred structures for U */
803
0
        u2_frm_wd = ps_dec->u2_frm_wd_uv << u1_mb_or_pic_fld;
804
0
        u1_tmp_dma_ht = u1_dma_ht;
805
0
        ps_pred->u2_u1_ref_buf_wd = u1_dma_wd;
806
0
        ps_pred->u2_frm_wd = u2_frm_wd;
807
0
        ps_pred->i1_dma_ht = u1_dma_ht;
808
0
        ps_pred->i1_mc_wd = i1_mc_wd;
809
0
        ps_pred->u2_dst_stride = u2_rec_wd;
810
0
811
0
        ps_pred->i1_mb_partwidth = u1_part_wd << 1;
812
0
        ps_pred->i1_mb_partheight = u1_part_ht << 1;
813
0
        ps_pred->u1_dydx = (u1_dy << 3) + u1_dx;
814
0
        ps_pred->u1_is_bi_direct = u1_is_bi_dir;
815
0
        ps_pred->u1_wght_pred_type = u1_wght_pred_type;
816
0
        ps_pred->i1_pod_ht = 0;
817
0
818
0
        ps_pred->pu1_dma_dest_addr = pu1_ref_buf;
819
0
820
0
        /* unrestricted field motion comp for top region outside frame */
821
0
        i2_pod_ht = (-i2_frm_y) >> u1_mb_fld;
822
0
        if((i2_pod_ht > 0) && u1_pod_top)
823
0
        {
824
0
            i4_ref_offset += i2_pod_ht * u2_frm_wd;
825
0
            u1_dma_ht -= i2_pod_ht;
826
0
            ps_pred->i1_pod_ht = (WORD8)(-i2_pod_ht);
827
0
        }
828
0
        /* unrestricted field motion comp for bottom region outside frame */
829
0
        else if(u1_pod_bot)
830
0
        {
831
0
            i2_pod_ht = u1_dma_ht + ((i2_frm_y - u2_pic_ht) >> u1_mb_fld);
832
0
            if(i2_pod_ht > 0)
833
0
            {
834
0
                u1_dma_ht -= i2_pod_ht;
835
0
                ps_pred->i1_pod_ht = (WORD8)i2_pod_ht;
836
0
            }
837
0
        }
838
0
839
0
        pu1_pred_u = pu1_buf2 + i4_ref_offset;
840
0
        pu1_pred_v = pu1_buf3 + i4_ref_offset;
841
0
842
0
        /* Copy U & V partitions */
843
0
        if(ps_pred->i1_pod_ht)
844
0
        {
845
0
            ps_pred->pu1_pred_u = pu1_pred_u;
846
0
            ps_pred->u1_dma_ht_uv = u1_dma_ht;
847
0
            ps_pred->u1_dma_wd_uv = u1_dma_wd;
848
0
849
0
        }
850
0
        ps_pred->pu1_u_ref = pu1_pred_u;
851
0
852
0
        /* Increment the reference buffer Index */
853
0
        u2_tot_ref_scratch_size += (u1_dma_wd * u1_tmp_dma_ht) << 1;
854
0
855
0
        if(ps_pred->i1_pod_ht)
856
0
        {
857
0
            ps_pred->pu1_pred_v = pu1_pred_v;
858
0
            ps_pred->u1_dma_ht_uv = u1_dma_ht;
859
0
            ps_pred->u1_dma_wd_uv = u1_dma_wd;
860
0
        }
861
0
862
0
        ps_pred->pu1_v_ref = pu1_pred_v;
863
0
    }
864
0
865
0
    /* Increment ps_pred index */
866
0
    ps_dec->u4_pred_info_idx += 2;
867
0
868
0
869
0
    /* Increment the reference buffer Index */
870
0
    ps_dec->u4_dma_buf_idx += u2_tot_ref_scratch_size;
871
0
872
0
    if(ps_dec->u4_dma_buf_idx > MAX_REF_BUF_SIZE)
873
0
        return ERROR_NUM_MV;
874
0
875
0
    return OK;
876
0
877
0
878
0
879
0
}
880
881
882
/*!
883
 **************************************************************************
884
 * \if Function name : MotionCompensate \endif
885
 *
886
 * \brief
887
 *    The routine forms predictor blocks for the entire MB and stores it in
888
 *    predictor buffers.This function works only for BASELINE profile
889
 *
890
 * \param ps_dec: Pointer to the structure decStruct. This is used to get
891
 *     pointers to the current and the reference frame and to the MbParams
892
 *     structure.
893
 *
894
 * \return
895
 *    None
896
 *
897
 * \note
898
 *    The routine forms predictors for all the luma and the chroma MB
899
 *    partitions.
900
 **************************************************************************
901
 */
902
903
void ih264d_motion_compensate_bp(dec_struct_t * ps_dec, dec_mb_info_t *ps_cur_mb_info)
904
0
{
905
0
    pred_info_t *ps_pred ;
906
0
    UWORD8 *puc_ref, *pu1_dest_y;
907
0
    UWORD8 *pu1_dest_u;
908
0
    UWORD32 u2_num_pels, u2_ref_wd_y, u2_ref_wd_uv, u2_dst_wd;
909
0
910
0
    UWORD32 u4_wd_y, u4_ht_y, u4_wd_uv;
911
0
    UWORD32 u4_ht_uv;
912
0
    UWORD8 *puc_pred0 = (UWORD8 *)(ps_dec->pi2_pred1);
913
0
914
0
915
0
    PROFILE_DISABLE_INTER_PRED()
916
0
    UNUSED(ps_cur_mb_info);
917
0
    ps_pred = ps_dec->ps_pred ;
918
0
919
0
    for(u2_num_pels = 0; u2_num_pels < 256;)
920
0
    {
921
0
        UWORD32 uc_dx, uc_dy;
922
0
        /* Pointer to the destination buffer. If the CBPs of all 8x8 blocks in
923
0
         the MB partition are zero then it would be better to copy the
924
0
         predictor valus directly to the current frame buffer */
925
0
        /*
926
0
         * ps_pred->i1_pod_ht is non zero when MBAFF is present. In case of MBAFF the reference data
927
0
         * is copied in the Scrath buffer so that the padding_on_demand doesnot corrupt the frame data
928
0
         */
929
0
930
0
        u2_ref_wd_y = ps_pred->u2_frm_wd;
931
0
        puc_ref = ps_pred->pu1_y_ref;
932
0
        if(ps_pred->u1_dydx & 0x3)
933
0
            puc_ref += 2;
934
0
        if(ps_pred->u1_dydx >> 2)
935
0
            puc_ref += 2 * u2_ref_wd_y;
936
0
937
0
        u4_wd_y = ps_pred->i1_mb_partwidth;
938
0
        u4_ht_y = ps_pred->i1_mb_partheight;
939
0
        uc_dx = ps_pred->u1_dydx;
940
0
        uc_dy = uc_dx >> 2;
941
0
        uc_dx &= 0x3;
942
0
943
0
        pu1_dest_y = ps_pred->pu1_rec_y_u;
944
0
        u2_dst_wd = ps_pred->u2_dst_stride;
945
0
946
0
        ps_dec->apf_inter_pred_luma[ps_pred->u1_dydx](puc_ref, pu1_dest_y,
947
0
                                                      u2_ref_wd_y,
948
0
                                                      u2_dst_wd,
949
0
                                                      u4_ht_y,
950
0
                                                      u4_wd_y, puc_pred0,
951
0
                                                      ps_pred->u1_dydx);
952
0
953
0
        ps_pred++;
954
0
955
0
        /* Interpolate samples for the chroma components */
956
0
        {
957
0
            UWORD8 *pu1_ref_u;
958
0
959
0
            u2_ref_wd_uv = ps_pred->u2_frm_wd;
960
0
            pu1_ref_u = ps_pred->pu1_u_ref;
961
0
962
0
            u4_wd_uv = ps_pred->i1_mb_partwidth;
963
0
            u4_ht_uv = ps_pred->i1_mb_partheight;
964
0
            uc_dx = ps_pred->u1_dydx; /* 8*dy + dx */
965
0
            uc_dy = uc_dx >> 3;
966
0
            uc_dx &= 0x7;
967
0
968
0
            pu1_dest_u = ps_pred->pu1_rec_y_u;
969
0
            u2_dst_wd = ps_pred->u2_dst_stride;
970
0
971
0
            ps_pred++;
972
0
            ps_dec->pf_inter_pred_chroma(pu1_ref_u, pu1_dest_u, u2_ref_wd_uv,
973
0
                                         u2_dst_wd, uc_dx, uc_dy,
974
0
                                         u4_ht_uv, u4_wd_uv);
975
0
976
0
        }
977
0
978
0
        u2_num_pels += (UWORD8)u4_wd_y * (UWORD8)u4_ht_y;
979
0
980
0
    }
981
0
}
982
983
984
/*
985
 **************************************************************************
986
 * \if Function name : MotionCompensateB \endif
987
 *
988
 * \brief
989
 *    The routine forms predictor blocks for the entire MB and stores it in
990
 *    predictor buffers.
991
 *
992
 * \param ps_dec: Pointer to the structure decStruct. This is used to get
993
 *     pointers to the current and the reference frame and to the MbParams
994
 *     structure.
995
 *
996
 * \return
997
 *    None
998
 *
999
 * \note
1000
 *    The routine forms predictors for all the luma and the chroma MB
1001
 *    partitions.
1002
 **************************************************************************
1003
 */
1004
1005
void ih264d_motion_compensate_mp(dec_struct_t * ps_dec, dec_mb_info_t *ps_cur_mb_info)
1006
0
{
1007
0
    pred_info_t *ps_pred ;
1008
0
    pred_info_t *ps_pred_y_forw, *ps_pred_y_back, *ps_pred_cr_forw;
1009
0
    UWORD8 *puc_ref, *pu1_dest_y, *puc_pred0, *puc_pred1;
1010
0
    UWORD8 *pu1_dest_u, *pu1_dest_v;
1011
0
    WORD16 *pi16_intm;
1012
0
    UWORD32 u2_num_pels, u2_ref_wd_y, u2_ref_wd_uv, u2_dst_wd;
1013
0
    UWORD32 u2_dest_wd_y, u2_dest_wd_uv;
1014
0
    UWORD32 u2_row_buf_wd_y = 0;
1015
0
    UWORD32 u2_row_buf_wd_uv = 0;
1016
0
    UWORD32 u2_log2Y_crwd;
1017
0
    UWORD32 u4_wd_y, u4_ht_y, u1_dir, u4_wd_uv;
1018
0
    UWORD32 u4_ht_uv;
1019
0
    UWORD8 *pu1_temp_mc_buffer = ps_dec->pu1_temp_mc_buffer;
1020
0
    WORD32 i2_pod_ht;
1021
0
    UWORD32 u2_pic_ht, u2_frm_wd, u2_rec_wd;
1022
0
    UWORD32 u1_pod_bot, u1_pod_top;
1023
0
    UWORD8 *pu1_pred, *pu1_dma_dst;
1024
0
    UWORD32 u1_dma_wd, u1_dma_ht;
1025
0
1026
0
    dec_slice_params_t * const ps_cur_slice = ps_dec->ps_cur_slice;
1027
0
1028
0
    /* set default value to flags specifying field nature of picture & mb */
1029
0
    UWORD32 u1_mb_fld = 0, u1_mb_or_pic_fld;
1030
0
    UWORD32 u1_mb_or_pic_bot;
1031
0
    /* calculate flags specifying field nature of picture & mb */
1032
0
    const UWORD8 u1_pic_fld = ps_cur_slice->u1_field_pic_flag;
1033
0
1034
0
    PROFILE_DISABLE_INTER_PRED()
1035
0
    ps_pred = ps_dec->ps_pred ;
1036
0
    /* Initialize both ps_pred_y_forw, ps_pred_cr_forw and ps_pred_y_back
1037
0
     * to avoid static analysis warnings */
1038
0
    ps_pred_y_forw = ps_pred;
1039
0
    ps_pred_y_back = ps_pred;
1040
0
    ps_pred_cr_forw = ps_pred;
1041
0
1042
0
    u2_log2Y_crwd = ps_dec->ps_decode_cur_slice->u2_log2Y_crwd;
1043
0
1044
0
    if(!u1_pic_fld)
1045
0
    {
1046
0
        u1_mb_fld = ps_cur_mb_info->u1_mb_field_decodingflag;
1047
0
    }
1048
0
1049
0
    u1_mb_or_pic_fld = u1_mb_fld | u1_pic_fld;
1050
0
1051
0
    pi16_intm = ps_dec->pi2_pred1;
1052
0
    puc_pred0 = (UWORD8 *)pi16_intm;
1053
0
    puc_pred1 = puc_pred0 + PRED_BUFFER_WIDTH * PRED_BUFFER_HEIGHT * sizeof(WORD16);
1054
0
1055
0
    for(u2_num_pels = 0; u2_num_pels < 256;)
1056
0
    {
1057
0
        UWORD8 uc_dx, uc_dy;
1058
0
        const UWORD8 u1_is_bi_direct = ps_pred->u1_is_bi_direct;
1059
0
        for(u1_dir = 0; u1_dir <= u1_is_bi_direct; u1_dir++)
1060
0
        {
1061
0
            /* Pointer to the destination buffer. If the CBPs of all 8x8 blocks in
1062
0
             the MB partition are zero then it would be better to copy the
1063
0
             predictor valus directly to the current frame buffer */
1064
0
            /*
1065
0
             * ps_pred->i1_pod_ht is non zero when MBAFF is present. In case of MBAFF the reference data
1066
0
             * is copied in the Scrath buffer so that the padding_on_demand doesnot corrupt the frame data
1067
0
             */
1068
0
1069
0
            if(ps_pred->i1_pod_ht)
1070
0
            {
1071
0
                u2_ref_wd_y = ps_pred->u2_u1_ref_buf_wd;
1072
0
                puc_ref = ps_pred->pu1_dma_dest_addr;
1073
0
            }
1074
0
            else
1075
0
            {
1076
0
                u2_ref_wd_y = ps_pred->u2_frm_wd;
1077
0
                puc_ref = ps_pred->pu1_y_ref;
1078
0
1079
0
            }
1080
0
1081
0
            if(ps_pred->u1_dydx & 0x3)
1082
0
                puc_ref += 2;
1083
0
            if(ps_pred->u1_dydx >> 2)
1084
0
                puc_ref += 2 * u2_ref_wd_y;
1085
0
            u4_wd_y = ps_pred->i1_mb_partwidth;
1086
0
            u4_ht_y = ps_pred->i1_mb_partheight;
1087
0
1088
0
            uc_dx = ps_pred->u1_dydx;
1089
0
            uc_dy = uc_dx >> 2;
1090
0
            uc_dx &= 0x3;
1091
0
            if(u1_dir == 0)
1092
0
            {
1093
0
                pu1_dest_y = ps_pred->pu1_rec_y_u;
1094
0
                u2_row_buf_wd_y = ps_pred->u2_dst_stride;
1095
0
                u2_dst_wd = ps_pred->u2_dst_stride;
1096
0
                u2_dest_wd_y = u2_dst_wd;
1097
0
                ps_pred_y_forw = ps_pred;
1098
0
            }
1099
0
            else
1100
0
            {
1101
0
                pu1_dest_y = pu1_temp_mc_buffer;
1102
0
                u2_dst_wd = MB_SIZE;
1103
0
                u2_dest_wd_y = u2_dst_wd;
1104
0
                ps_pred_y_back = ps_pred;
1105
0
                ps_pred_y_back->pu1_rec_y_u = pu1_dest_y;
1106
0
            }
1107
0
1108
0
            /* padding on demand (POD) for y done here */
1109
0
1110
0
            if(ps_pred->i1_pod_ht)
1111
0
            {
1112
0
                pu1_pred = ps_pred->pu1_pred;
1113
0
                pu1_dma_dst = ps_pred->pu1_dma_dest_addr;
1114
0
                u1_dma_wd = ps_pred->u1_dma_wd_y;
1115
0
                u1_dma_ht = ps_pred->u1_dma_ht_y;
1116
0
                u2_frm_wd = ps_dec->u2_frm_wd_y << u1_mb_or_pic_fld;
1117
0
                if(ps_pred->i1_pod_ht < 0)
1118
0
                {
1119
0
                    pu1_dma_dst = pu1_dma_dst - (ps_pred->i1_pod_ht * ps_pred->u2_u1_ref_buf_wd);
1120
0
                }
1121
0
                ih264d_copy_2d1d(pu1_pred, pu1_dma_dst, u2_frm_wd, u1_dma_wd,
1122
0
                                 u1_dma_ht);
1123
0
                ih264d_pad_on_demand(ps_pred, LUM_BLK);
1124
0
            }
1125
0
            ps_dec->apf_inter_pred_luma[ps_pred->u1_dydx](puc_ref, pu1_dest_y,
1126
0
                                                          u2_ref_wd_y,
1127
0
                                                          u2_dst_wd,
1128
0
                                                          u4_ht_y,
1129
0
                                                          u4_wd_y,
1130
0
                                                          puc_pred0,
1131
0
                                                          ps_pred->u1_dydx);
1132
0
            ps_pred++;
1133
0
1134
0
            /* Interpolate samples for the chroma components */
1135
0
            {
1136
0
                UWORD8 *pu1_ref_u;
1137
0
                UWORD32 u1_dma_ht;
1138
0
1139
0
                /* padding on demand (POD) for U and V done here */
1140
0
                u1_dma_ht = ps_pred->i1_dma_ht;
1141
0
1142
0
                if(ps_pred->i1_pod_ht)
1143
0
                {
1144
0
                    pu1_pred = ps_pred->pu1_pred_u;
1145
0
                    pu1_dma_dst = ps_pred->pu1_dma_dest_addr;
1146
0
                    u1_dma_ht = ps_pred->u1_dma_ht_uv;
1147
0
                    u1_dma_wd = ps_pred->u1_dma_wd_uv * YUV420SP_FACTOR;
1148
0
                    u2_frm_wd = ps_dec->u2_frm_wd_uv << u1_mb_or_pic_fld;
1149
0
                    if(ps_pred->i1_pod_ht < 0)
1150
0
                    {
1151
0
                        /*Top POD*/
1152
0
                        pu1_dma_dst -= (ps_pred->i1_pod_ht
1153
0
                                        * ps_pred->u2_u1_ref_buf_wd
1154
0
                                        * YUV420SP_FACTOR);
1155
0
                    }
1156
0
1157
0
                    ih264d_copy_2d1d(pu1_pred, pu1_dma_dst, u2_frm_wd,
1158
0
                                     u1_dma_wd, u1_dma_ht);
1159
0
1160
0
                    pu1_dma_dst += (ps_pred->i1_dma_ht
1161
0
                                    * ps_pred->u2_u1_ref_buf_wd);
1162
0
                    pu1_pred = ps_pred->pu1_pred_v;
1163
0
1164
0
                    ih264d_pad_on_demand(ps_pred, CHROM_BLK);
1165
0
                }
1166
0
1167
0
                if(ps_pred->i1_pod_ht)
1168
0
                {
1169
0
                    pu1_ref_u = ps_pred->pu1_dma_dest_addr;
1170
0
1171
0
                    u2_ref_wd_uv = ps_pred->u2_u1_ref_buf_wd
1172
0
                                    * YUV420SP_FACTOR;
1173
0
                }
1174
0
                else
1175
0
                {
1176
0
                    u2_ref_wd_uv = ps_pred->u2_frm_wd;
1177
0
                    pu1_ref_u = ps_pred->pu1_u_ref;
1178
0
1179
0
                }
1180
0
1181
0
                u4_wd_uv = ps_pred->i1_mb_partwidth;
1182
0
                u4_ht_uv = ps_pred->i1_mb_partheight;
1183
0
                uc_dx = ps_pred->u1_dydx; /* 8*dy + dx */
1184
0
                uc_dy = uc_dx >> 3;
1185
0
                uc_dx &= 0x7;
1186
0
                if(u1_dir == 0)
1187
0
                {
1188
0
                    pu1_dest_u = ps_pred->pu1_rec_y_u;
1189
0
1190
0
                    pu1_dest_v = ps_pred->u1_pi1_wt_ofst_rec_v;
1191
0
                    u2_row_buf_wd_uv = ps_pred->u2_dst_stride;
1192
0
                    u2_dst_wd = ps_pred->u2_dst_stride;
1193
0
                    u2_dest_wd_uv = u2_dst_wd;
1194
0
                    ps_pred_cr_forw = ps_pred;
1195
0
                }
1196
0
                else
1197
0
                {
1198
0
                    pu1_dest_u = puc_pred0;
1199
0
1200
0
                    pu1_dest_v = puc_pred1;
1201
0
                    u2_dest_wd_uv = BUFFER_WIDTH;
1202
0
                    u2_dst_wd = BUFFER_WIDTH;
1203
0
                    ps_pred->pu1_rec_y_u = pu1_dest_u;
1204
0
                    ps_pred->u1_pi1_wt_ofst_rec_v = pu1_dest_v;
1205
0
                }
1206
0
1207
0
                ps_pred++;
1208
0
                ps_dec->pf_inter_pred_chroma(pu1_ref_u, pu1_dest_u,
1209
0
                                             u2_ref_wd_uv, u2_dst_wd,
1210
0
                                             uc_dx, uc_dy, u4_ht_uv,
1211
0
                                             u4_wd_uv);
1212
0
1213
0
                if(ps_cur_mb_info->u1_Mux == 1)
1214
0
                {
1215
0
                    /******************************************************************/
1216
0
                    /* padding on demand (POD) for U and V done here                  */
1217
0
                    /* ps_pred now points to the Y entry of the 0,0 component         */
1218
0
                    /* Y need not be checked for POD because Y lies within            */
1219
0
                    /* the picture((0,0) mv for Y doesnot get changed. But (0,0) for  */
1220
0
                    /* U and V can need POD beacause of cross-field mv adjustments    */
1221
0
                    /* (Table 8-9 of standard)                                        */
1222
0
                    /******************************************************************/
1223
0
                    if((ps_pred + 1)->i1_pod_ht)
1224
0
                    {
1225
0
                        pu1_pred = (ps_pred + 1)->pu1_pred_u;
1226
0
                        pu1_dma_dst = (ps_pred + 1)->pu1_dma_dest_addr;
1227
0
                        u1_dma_ht = (ps_pred + 1)->u1_dma_ht_uv;
1228
0
                        u1_dma_wd = (ps_pred + 1)->u1_dma_wd_uv
1229
0
                                        * YUV420SP_FACTOR;
1230
0
                        u2_frm_wd = ps_dec->u2_frm_wd_uv << u1_mb_or_pic_fld;
1231
0
                        if((ps_pred + 1)->i1_pod_ht < 0)
1232
0
                        {
1233
0
                            /*Top POD*/
1234
0
                            pu1_dma_dst -= ((ps_pred + 1)->i1_pod_ht
1235
0
                                            * (ps_pred + 1)->u2_u1_ref_buf_wd
1236
0
                                            * YUV420SP_FACTOR);
1237
0
                        }
1238
0
                        ih264d_copy_2d1d(pu1_pred, pu1_dma_dst, u2_frm_wd,
1239
0
                                         u1_dma_wd, u1_dma_ht);
1240
0
                        pu1_dma_dst += ((ps_pred + 1)->i1_dma_ht
1241
0
                                        * (ps_pred + 1)->u2_u1_ref_buf_wd); //(u1_dma_ht * u1_dma_wd);//
1242
0
                        pu1_pred = (ps_pred + 1)->pu1_pred_v;
1243
0
                        ih264d_pad_on_demand(ps_pred + 1, CHROM_BLK);
1244
0
1245
0
                    }
1246
0
1247
0
                    ih264d_multiplex_ref_data(ps_dec, ps_pred, pu1_dest_y,
1248
0
                                              pu1_dest_u, ps_cur_mb_info,
1249
0
                                              u2_dest_wd_y, u2_dest_wd_uv,
1250
0
                                              u1_dir);
1251
0
                    ps_pred += 2;
1252
0
                }
1253
0
            }
1254
0
        }
1255
0
        if(u1_dir != 0)
1256
0
            u2_ref_wd_y = MB_SIZE;
1257
0
1258
0
        u2_num_pels += u4_wd_y * u4_ht_y;
1259
0
        /* if BI_DIRECT, average the two pred's, and put in ..PredBuffer[0] */
1260
0
        if((u1_is_bi_direct != 0) || (ps_pred_y_forw->u1_wght_pred_type != 0))
1261
0
        {
1262
0
1263
0
            switch(ps_pred_y_forw->u1_wght_pred_type)
1264
0
            {
1265
0
                case 0:
1266
0
                    ps_dec->pf_default_weighted_pred_luma(
1267
0
                                    ps_pred_y_forw->pu1_rec_y_u, pu1_dest_y,
1268
0
                                    ps_pred_y_forw->pu1_rec_y_u,
1269
0
                                    u2_row_buf_wd_y, u2_ref_wd_y,
1270
0
                                    u2_row_buf_wd_y, u4_ht_uv * 2,
1271
0
                                    u4_wd_uv * 2);
1272
0
1273
0
                    ps_dec->pf_default_weighted_pred_chroma(
1274
0
                                    ps_pred_cr_forw->pu1_rec_y_u, pu1_dest_u,
1275
0
                                    ps_pred_cr_forw->pu1_rec_y_u,
1276
0
                                    u2_row_buf_wd_uv, u2_dst_wd,
1277
0
                                    u2_row_buf_wd_uv, u4_ht_uv,
1278
0
                                    u4_wd_uv);
1279
0
1280
0
                    break;
1281
0
                case 1:
1282
0
                {
1283
0
                    UWORD32 *pu4_weight_ofst =
1284
0
                                    (UWORD32*)ps_pred_y_forw->u1_pi1_wt_ofst_rec_v;
1285
0
                    UWORD32 u4_wt_ofst_u, u4_wt_ofst_v;
1286
0
                    UWORD32 u4_wt_ofst_y =
1287
0
                                    (UWORD32)(pu4_weight_ofst[0]);
1288
0
                    WORD32 weight = (WORD16)(u4_wt_ofst_y & 0xffff);
1289
0
                    WORD32 ofst = (WORD8)(u4_wt_ofst_y >> 16);
1290
0
1291
0
                    ps_dec->pf_weighted_pred_luma(ps_pred_y_forw->pu1_rec_y_u,
1292
0
                                                  ps_pred_y_forw->pu1_rec_y_u,
1293
0
                                                  u2_row_buf_wd_y,
1294
0
                                                  u2_row_buf_wd_y,
1295
0
                                                  (u2_log2Y_crwd & 0x0ff),
1296
0
                                                  weight, ofst, u4_ht_y,
1297
0
                                                  u4_wd_y);
1298
0
1299
0
                    u4_wt_ofst_u = (UWORD32)(pu4_weight_ofst[2]);
1300
0
                    u4_wt_ofst_v = (UWORD32)(pu4_weight_ofst[4]);
1301
0
                    weight = ((u4_wt_ofst_v & 0xffff) << 16)
1302
0
                                    | (u4_wt_ofst_u & 0xffff);
1303
0
                    ofst = ((u4_wt_ofst_v >> 16) << 8)
1304
0
                                    | ((u4_wt_ofst_u >> 16) & 0xFF);
1305
0
1306
0
                    ps_dec->pf_weighted_pred_chroma(
1307
0
                                    ps_pred_cr_forw->pu1_rec_y_u,
1308
0
                                    ps_pred_cr_forw->pu1_rec_y_u,
1309
0
                                    u2_row_buf_wd_uv, u2_row_buf_wd_uv,
1310
0
                                    (u2_log2Y_crwd >> 8), weight, ofst,
1311
0
                                    u4_ht_y >> 1, u4_wd_y >> 1);
1312
0
                }
1313
0
1314
0
                    break;
1315
0
                case 2:
1316
0
                {
1317
0
                    UWORD32 *pu4_weight_ofst =
1318
0
                                    (UWORD32*)ps_pred_y_forw->u1_pi1_wt_ofst_rec_v;
1319
0
                    UWORD32 u4_wt_ofst_u, u4_wt_ofst_v;
1320
0
                    UWORD32 u4_wt_ofst_y;
1321
0
                    WORD32 weight1, weight2;
1322
0
                    WORD32 ofst1, ofst2;
1323
0
1324
0
                    u4_wt_ofst_y = (UWORD32)(pu4_weight_ofst[0]);
1325
0
1326
0
                    weight1 = (WORD16)(u4_wt_ofst_y & 0xffff);
1327
0
                    ofst1 = (WORD8)(u4_wt_ofst_y >> 16);
1328
0
1329
0
                    u4_wt_ofst_y = (UWORD32)(pu4_weight_ofst[1]);
1330
0
                    weight2 = (WORD16)(u4_wt_ofst_y & 0xffff);
1331
0
                    ofst2 = (WORD8)(u4_wt_ofst_y >> 16);
1332
0
1333
0
                    ps_dec->pf_weighted_bi_pred_luma(ps_pred_y_forw->pu1_rec_y_u,
1334
0
                                                     ps_pred_y_back->pu1_rec_y_u,
1335
0
                                                     ps_pred_y_forw->pu1_rec_y_u,
1336
0
                                                     u2_row_buf_wd_y,
1337
0
                                                     u2_ref_wd_y,
1338
0
                                                     u2_row_buf_wd_y,
1339
0
                                                     (u2_log2Y_crwd & 0x0ff),
1340
0
                                                     weight1, weight2, ofst1,
1341
0
                                                     ofst2, u4_ht_y,
1342
0
                                                     u4_wd_y);
1343
0
1344
0
                    u4_wt_ofst_u = (UWORD32)(pu4_weight_ofst[2]);
1345
0
                    u4_wt_ofst_v = (UWORD32)(pu4_weight_ofst[4]);
1346
0
                    weight1 = ((u4_wt_ofst_v & 0xffff) << 16)
1347
0
                                    | (u4_wt_ofst_u & 0xffff);
1348
0
                    ofst1 = ((u4_wt_ofst_v >> 16) << 8)
1349
0
                                    | ((u4_wt_ofst_u >> 16) & 0xFF);
1350
0
1351
0
                    u4_wt_ofst_u = (UWORD32)(pu4_weight_ofst[3]);
1352
0
                    u4_wt_ofst_v = (UWORD32)(pu4_weight_ofst[5]);
1353
0
                    weight2 = ((u4_wt_ofst_v & 0xffff) << 16)
1354
0
                                    | (u4_wt_ofst_u & 0xffff);
1355
0
                    ofst2 = ((u4_wt_ofst_v >> 16) << 8)
1356
0
                                    | ((u4_wt_ofst_u >> 16) & 0xFF);
1357
0
1358
0
                    ps_dec->pf_weighted_bi_pred_chroma(
1359
0
                                    (ps_pred_y_forw + 1)->pu1_rec_y_u,
1360
0
                                    (ps_pred_y_back + 1)->pu1_rec_y_u,
1361
0
                                    (ps_pred_y_forw + 1)->pu1_rec_y_u,
1362
0
                                    u2_row_buf_wd_uv, u2_dst_wd,
1363
0
                                    u2_row_buf_wd_uv, (u2_log2Y_crwd >> 8),
1364
0
                                    weight1, weight2, ofst1, ofst2,
1365
0
                                    u4_ht_y >> 1, u4_wd_y >> 1);
1366
0
                }
1367
0
1368
0
                    break;
1369
0
            }
1370
0
1371
0
        }
1372
0
    }
1373
0
}
1374
1375
1376
/*!
1377
 **************************************************************************
1378
 * \if Function name : ih264d_multiplex_ref_data \endif
1379
 *
1380
 * \brief
1381
 *    Initializes forward and backward refernce lists for B slice decoding.
1382
 *
1383
 *
1384
 * \return
1385
 *    0 on Success and Error code otherwise
1386
 **************************************************************************
1387
 */
1388
1389
void ih264d_multiplex_ref_data(dec_struct_t * ps_dec,
1390
                               pred_info_t *ps_pred,
1391
                               UWORD8* pu1_dest_y,
1392
                               UWORD8* pu1_dest_u,
1393
                               dec_mb_info_t *ps_cur_mb_info,
1394
                               UWORD16 u2_dest_wd_y,
1395
                               UWORD16 u2_dest_wd_uv,
1396
                               UWORD8 u1_dir)
1397
0
{
1398
0
    UWORD16 u2_mask = ps_cur_mb_info->u2_mask[u1_dir];
1399
0
    UWORD8 *pu1_ref_y, *pu1_ref_u;
1400
0
    UWORD8 uc_cond, i, j, u1_dydx;
1401
0
    UWORD16 u2_ref_wd_y, u2_ref_wd_uv;
1402
0
1403
0
    PROFILE_DISABLE_INTER_PRED()
1404
0
1405
0
    if(ps_pred->i1_pod_ht)
1406
0
    {
1407
0
        pu1_ref_y = ps_pred->pu1_dma_dest_addr;
1408
0
1409
0
        u2_ref_wd_y = ps_pred->u2_u1_ref_buf_wd;
1410
0
    }
1411
0
    else
1412
0
    {
1413
0
        pu1_ref_y = ps_pred->pu1_y_ref;
1414
0
        u2_ref_wd_y = ps_pred->u2_frm_wd;
1415
0
    }
1416
0
1417
0
    ps_pred++;
1418
0
    if(ps_pred->i1_pod_ht)
1419
0
    {
1420
0
        pu1_ref_u = ps_pred->pu1_dma_dest_addr;
1421
0
        u2_ref_wd_uv = ps_pred->u2_u1_ref_buf_wd * YUV420SP_FACTOR;
1422
0
1423
0
    }
1424
0
    else
1425
0
    {
1426
0
        pu1_ref_u = ps_pred->pu1_u_ref;
1427
0
        u2_ref_wd_uv = ps_pred->u2_frm_wd;
1428
0
1429
0
    }
1430
0
1431
0
    u1_dydx = ps_pred->u1_dydx;
1432
0
1433
0
    {
1434
0
        UWORD8 uc_dx, uc_dy;
1435
0
        UWORD8 *pu1_scratch_u;
1436
0
1437
0
        uc_dx = u1_dydx & 0x3;
1438
0
        uc_dy = u1_dydx >> 3;
1439
0
        if(u1_dydx != 0)
1440
0
        {
1441
0
            pred_info_t * ps_prv_pred = ps_pred - 2;
1442
0
            pu1_scratch_u = ps_prv_pred->pu1_dma_dest_addr;
1443
0
            ps_dec->pf_inter_pred_chroma(pu1_ref_u, pu1_scratch_u,
1444
0
                                         u2_ref_wd_uv, 16, uc_dx, uc_dy, 8,
1445
0
                                         8);
1446
0
1447
0
            /* Modify ref pointer and refWidth to point to scratch    */
1448
0
            /* buffer to be used below in ih264d_copy_multiplex_data functions */
1449
0
            /* CHANGED CODE */
1450
0
            pu1_ref_u = pu1_scratch_u;
1451
0
            u2_ref_wd_uv = 8 * YUV420SP_FACTOR;
1452
0
        }
1453
0
    }
1454
0
    {
1455
0
        for(i = 0; i < 4; i++)
1456
0
        {
1457
0
            for(j = 0; j < 4; j++)
1458
0
            {
1459
0
                uc_cond = u2_mask & 1;
1460
0
                u2_mask >>= 1;
1461
0
                if(uc_cond)
1462
0
                {
1463
0
                    *(UWORD32 *)(pu1_dest_y + u2_dest_wd_y) =
1464
0
                                    *(UWORD32 *)(pu1_ref_y + u2_ref_wd_y);
1465
0
                    *(UWORD32 *)(pu1_dest_y + 2 * u2_dest_wd_y) =
1466
0
                                    *(UWORD32 *)(pu1_ref_y + 2 * u2_ref_wd_y);
1467
0
                    *(UWORD32 *)(pu1_dest_y + 3 * u2_dest_wd_y) =
1468
0
                                    *(UWORD32 *)(pu1_ref_y + 3 * u2_ref_wd_y);
1469
0
                    {
1470
0
                        UWORD32 *dst, *src;
1471
0
                        dst = (UWORD32 *)pu1_dest_y;
1472
0
                        src = (UWORD32 *)pu1_ref_y;
1473
0
                        *dst = *src;
1474
0
                        dst++;
1475
0
                        src++;
1476
0
                        pu1_dest_y = (UWORD8 *)dst;
1477
0
                        pu1_ref_y = (UWORD8 *)src;
1478
0
                    }
1479
0
                    *(UWORD32 *)(pu1_dest_u + u2_dest_wd_uv) =
1480
0
                                    *(UWORD32 *)(pu1_ref_u + u2_ref_wd_uv);
1481
0
                    {
1482
0
                        UWORD32 *dst, *src;
1483
0
                        dst = (UWORD32 *)pu1_dest_u;
1484
0
                        src = (UWORD32 *)pu1_ref_u;
1485
0
                        *dst = *src;
1486
0
                        dst++;
1487
0
                        src++;
1488
0
                        pu1_dest_u = (UWORD8 *)dst;
1489
0
                        pu1_ref_u = (UWORD8 *)src;
1490
0
                    }
1491
0
1492
0
                }
1493
0
                else
1494
0
                {
1495
0
                    pu1_dest_y += 4;
1496
0
                    pu1_ref_y += 4;
1497
0
                    pu1_dest_u += 2 * YUV420SP_FACTOR;
1498
0
                    pu1_ref_u += 2 * YUV420SP_FACTOR;
1499
0
                }
1500
0
            }
1501
0
            pu1_ref_y += 4 * (u2_ref_wd_y - 4);
1502
0
            pu1_ref_u += 2 * (u2_ref_wd_uv - 4 * YUV420SP_FACTOR);
1503
0
            pu1_dest_y += 4 * (u2_dest_wd_y - 4);
1504
0
            pu1_dest_u += 2 * (u2_dest_wd_uv - 4 * YUV420SP_FACTOR);
1505
0
        }
1506
0
    }
1507
0
}
1508
1509
void ih264d_pad_on_demand(pred_info_t *ps_pred, UWORD8 lum_chrom_blk)
1510
0
{
1511
0
    if(CHROM_BLK == lum_chrom_blk)
1512
0
    {
1513
0
        UWORD32 *pu4_pod_src_u, *pu4_pod_dst_u;
1514
0
        UWORD32 *pu4_pod_src_v, *pu4_pod_dst_v;
1515
0
        WORD32 j, u1_wd_stride;
1516
0
        WORD32 i, u1_dma_ht, i1_ht;
1517
0
        UWORD32 u2_dma_size;
1518
0
        u1_wd_stride = (ps_pred->u2_u1_ref_buf_wd >> 2) * YUV420SP_FACTOR;
1519
0
        u1_dma_ht = ps_pred->i1_dma_ht;
1520
0
        u2_dma_size = u1_wd_stride * u1_dma_ht;
1521
0
        pu4_pod_src_u = (UWORD32 *)ps_pred->pu1_dma_dest_addr;
1522
0
        pu4_pod_dst_u = pu4_pod_src_u;
1523
0
1524
0
        pu4_pod_src_v = pu4_pod_src_u + u2_dma_size;
1525
0
        pu4_pod_dst_v = pu4_pod_src_v;
1526
0
1527
0
        i1_ht = ps_pred->i1_pod_ht;
1528
0
        pu4_pod_src_u -= u1_wd_stride * i1_ht;
1529
0
        pu4_pod_src_v -= u1_wd_stride * i1_ht;
1530
0
        if(i1_ht < 0)
1531
0
            /* Top POD */
1532
0
            i1_ht = -i1_ht;
1533
0
        else
1534
0
        {
1535
0
            /* Bottom POD */
1536
0
            pu4_pod_src_u += (u1_dma_ht - 1) * u1_wd_stride;
1537
0
            pu4_pod_dst_u += (u1_dma_ht - i1_ht) * u1_wd_stride;
1538
0
            pu4_pod_src_v += (u1_dma_ht - 1) * u1_wd_stride;
1539
0
            pu4_pod_dst_v += (u1_dma_ht - i1_ht) * u1_wd_stride;
1540
0
        }
1541
0
1542
0
        for(i = 0; i < i1_ht; i++)
1543
0
            for(j = 0; j < u1_wd_stride; j++)
1544
0
            {
1545
0
                *pu4_pod_dst_u++ = *(pu4_pod_src_u + j);
1546
0
1547
0
            }
1548
0
    }
1549
0
    else
1550
0
    {
1551
0
        UWORD32 *pu4_pod_src, *pu4_pod_dst;
1552
0
        WORD32 j, u1_wd_stride;
1553
0
        WORD32 i, i1_ht;
1554
0
        pu4_pod_src = (UWORD32 *)ps_pred->pu1_dma_dest_addr;
1555
0
        pu4_pod_dst = pu4_pod_src;
1556
0
        u1_wd_stride = ps_pred->u2_u1_ref_buf_wd >> 2;
1557
0
        i1_ht = ps_pred->i1_pod_ht;
1558
0
        pu4_pod_src -= u1_wd_stride * i1_ht;
1559
0
        if(i1_ht < 0)
1560
0
            /* Top POD */
1561
0
            i1_ht = -i1_ht;
1562
0
        else
1563
0
        {
1564
0
            /* Bottom POD */
1565
0
            pu4_pod_src += (ps_pred->i1_dma_ht - 1) * u1_wd_stride;
1566
0
            pu4_pod_dst += (ps_pred->i1_dma_ht - i1_ht) * u1_wd_stride;
1567
0
        }
1568
0
1569
0
        for(i = 0; i < i1_ht; i++)
1570
0
            for(j = 0; j < u1_wd_stride; j++)
1571
0
                *pu4_pod_dst++ = *(pu4_pod_src + j);
1572
0
    }
1573
0
}
1574
/proc/self/cwd/external/libavc/decoder/ih264d_inter_pred.h
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
21
#ifndef _IH264D_INTER_PRED_H_
22
#define _IH264D_INTER_PRED_H_
23
24
/*!
25
 **************************************************************************
26
 * \file ih264d_inter_pred.h
27
 *
28
 * \brief
29
 *    Decalaration for routines defined in MorionCompensate.c
30
 *
31
 * Detailed_description
32
 *
33
 * \date
34
 *    creation_date
35
 *
36
 * \author  Arvind Raman
37
 **************************************************************************
38
 */
39
40
#include "ih264d_structs.h"
41
42
0
#define BUFFER_WIDTH        16
43
/*!
44
 **************************************************************************
45
 *   \brief   PRED_BUFFER_WIDTH / HEIGHT
46
 *
47
 *   Width and height of the 16 bit (also reused a 2 8 bits buffers). The
48
 *   required dimensions for these buffers are 21x21, however to align the
49
 *   start of every row to a WORD aligned boundary the width has been increased
50
 *   to 24.
51
 **************************************************************************
52
 */
53
//#define PRED_BUFFER_WIDTH   24
54
//#define PRED_BUFFER_HEIGHT  21
55
1
#define PRED_BUFFER_WIDTH   24*2
56
1
#define PRED_BUFFER_HEIGHT  24*2
57
58
void ih264d_fill_pred_info(WORD16 *pi2_mv,WORD32 part_width,WORD32 part_height, WORD32 sub_mb_num,
59
                           WORD32 pred_dir,pred_info_pkd_t *ps_pred_pkd,WORD8 i1_buf_id,
60
                           WORD8 i1_ref_idx,UWORD32 *pu4_wt_offset,UWORD8 u1_pic_type);
61
62
WORD32 ih264d_form_mb_part_info_bp(pred_info_pkd_t *ps_pred_pkd,
63
                                 dec_struct_t * ps_dec,
64
                                 UWORD16 u2_mb_x,
65
                                 UWORD16 u2_mb_y,
66
                                 WORD32 mb_index,
67
                                 dec_mb_info_t *ps_cur_mb_info);
68
69
WORD32 ih264d_form_mb_part_info_mp(pred_info_pkd_t *ps_pred_pkd,
70
                                 dec_struct_t * ps_dec,
71
                                 UWORD16 u2_mb_x,
72
                                 UWORD16 u2_mb_y,
73
                                 WORD32 mb_index,
74
                                 dec_mb_info_t *ps_cur_mb_info);
75
76
77
void ih264d_motion_compensate_bp(dec_struct_t * ps_dec, dec_mb_info_t *ps_cur_mb_info);
78
void ih264d_motion_compensate_mp(dec_struct_t * ps_dec, dec_mb_info_t *ps_cur_mb_info);
79
80
81
void TransferRefBuffs(dec_struct_t *ps_dec);
82
83
void ih264d_multiplex_ref_data(dec_struct_t * ps_dec,
84
                               pred_info_t *ps_pred,
85
                               UWORD8* pu1_dest_y,
86
                               UWORD8* pu1_dest_u,
87
                               dec_mb_info_t *ps_cur_mb_info,
88
                               UWORD16 u2_dest_wd_y,
89
                               UWORD16 u2_dest_wd_uv,
90
                               UWORD8 u1_dir);
91
#endif /* _IH264D_INTER_PRED_H_ */
92
/proc/self/cwd/external/libavc/decoder/ih264d_mb_utils.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/*!
21
 **************************************************************************
22
 * \file ih264d_mb_utils.c
23
 *
24
 * \brief
25
 *    Contains utitlity functions needed for Macroblock decoding
26
 *
27
 * \date
28
 *    18/12/2002
29
 *
30
 * \author  AI
31
 **************************************************************************
32
 */
33
#include <string.h>
34
#include <stdlib.h>
35
#include "ih264d_bitstrm.h"
36
#include "ih264d_defs.h"
37
#include "ih264d_debug.h"
38
#include "ih264d_structs.h"
39
#include "ih264d_defs.h"
40
#include "ih264d_mb_utils.h"
41
#include "ih264d_parse_slice.h"
42
#include "ih264d_error_handler.h"
43
#include "ih264d_parse_mb_header.h"
44
#include "ih264d_cabac.h"
45
#include "ih264d_defs.h"
46
#include "ih264d_tables.h"
47
48
/*****************************************************************************/
49
/*                                                                           */
50
/*  Function Name : get_mb_info_cavlc                                        */
51
/*                                                                           */
52
/*  Description   : This function sets the following information of cur MB   */
53
/*                  (a) mb_x and mb_y                                        */
54
/*                  (b) Neighbour availablity                                */
55
/*                  (c) Macroblock location in the frame buffer              */
56
/*                  (e) For mbaff predicts field/frame u4_flag for topMb        */
57
/*                      and sets the field/frame for botMb. This is          */
58
/*                      written in ps_dec->u1_cur_mb_fld_dec_flag            */
59
/*                                                                           */
60
/*  Inputs        : pointer to decstruct                                     */
61
/*                  pointer to current mb info                               */
62
/*                  currentMbaddress                                         */
63
/*                                                                           */
64
/*  Processing    : leftMb and TopMb params are used by DecMbskip and        */
65
/*                  DecCtxMbfield  modules so that these modules do not      */
66
/*                  check for neigbour availability and then find the        */
67
/*                  neigbours for context increments                         */
68
/*                                                                           */
69
/*  Returns       : OK                                                       */
70
/*                                                                           */
71
/*  Issues        : <List any issues or problems with this function>         */
72
/*                                                                           */
73
/*  Revision History:                                                        */
74
/*                                                                           */
75
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
76
/*         13 07 2002   Jay             Draft                                */
77
/*                                                                           */
78
/*****************************************************************************/
79
80
UWORD32 ih264d_get_mb_info_cavlc_nonmbaff(dec_struct_t *ps_dec,
81
                                          const UWORD16 u2_cur_mb_address,
82
                                          dec_mb_info_t * ps_cur_mb_info,
83
                                          UWORD32 u4_mbskip_run)
84
5.06k
{
85
5.06k
    WORD32 mb_x;
86
5.06k
    WORD32 mb_y;
87
5.06k
    UWORD8 u1_mb_ngbr_avail = 0;
88
5.06k
    UWORD16 u2_frm_width_in_mb = ps_dec->u2_frm_wd_in_mbs;
89
5.06k
    WORD16 i2_prev_slice_mbx = ps_dec->i2_prev_slice_mbx;
90
5.06k
    UWORD16 u2_top_right_mask = TOP_RIGHT_DEFAULT_AVAILABLE;
91
5.06k
    UWORD16 u2_top_left_mask = TOP_LEFT_DEFAULT_AVAILABLE;
92
5.06k
    UNUSED(u4_mbskip_run);
93
5.06k
    /*--------------------------------------------------------------------*/
94
5.06k
    /* Calculate values of mb_x and mb_y                                  */
95
5.06k
    /*--------------------------------------------------------------------*/
96
5.06k
    mb_x = (WORD16)ps_dec->u2_mbx;
97
5.06k
    mb_y = (WORD16)ps_dec->u2_mby;
98
5.06k
99
5.06k
    ps_dec->u2_cur_mb_addr = u2_cur_mb_address;
100
5.06k
101
5.06k
    mb_x++;
102
5.06k
103
5.06k
    if(mb_x == u2_frm_width_in_mb)
104
209
    {
105
209
        mb_x = 0;
106
209
        mb_y++;
107
209
    }
108
5.06k
    if(mb_y > ps_dec->i2_prev_slice_mby)
109
4.80k
    {
110
4.80k
        /* if not in the immemdiate row of prev slice end then top
111
4.80k
         will be available */
112
4.80k
        if(mb_y > (ps_dec->i2_prev_slice_mby + 1))
113
4.55k
            i2_prev_slice_mbx = -1;
114
4.80k
115
4.80k
        if(mb_x > i2_prev_slice_mbx)
116
4.80k
        {
117
4.80k
            u1_mb_ngbr_avail |= TOP_MB_AVAILABLE_MASK;
118
4.80k
            u2_top_right_mask |= TOP_RIGHT_TOP_AVAILABLE;
119
4.80k
            u2_top_left_mask |= TOP_LEFT_TOP_AVAILABLE;
120
4.80k
        }
121
4.80k
122
4.80k
        if((mb_x > (i2_prev_slice_mbx - 1))
123
4.80k
                        && (mb_x != (u2_frm_width_in_mb - 1)))
124
4.59k
        {
125
4.59k
            u1_mb_ngbr_avail |= TOP_RIGHT_MB_AVAILABLE_MASK;
126
4.59k
            u2_top_right_mask |= TOP_RIGHT_TOPR_AVAILABLE;
127
4.59k
        }
128
4.80k
129
4.80k
        if(mb_x > (i2_prev_slice_mbx + 1))
130
4.59k
        {
131
4.59k
            u1_mb_ngbr_avail |= TOP_LEFT_MB_AVAILABLE_MASK;
132
4.59k
            u2_top_left_mask |= TOP_LEFT_TOPL_AVAILABLE;
133
4.59k
        }
134
4.80k
135
4.80k
        /* Next row  Left will be available*/
136
4.80k
        i2_prev_slice_mbx = -1;
137
4.80k
    }
138
5.06k
139
5.06k
    /* Same row */
140
5.06k
    if(mb_x > (i2_prev_slice_mbx + 1))
141
4.84k
    {
142
4.84k
        u1_mb_ngbr_avail |= LEFT_MB_AVAILABLE_MASK;
143
4.84k
        u2_top_left_mask |= TOP_LEFT_LEFT_AVAILABLE;
144
4.84k
    }
145
5.06k
146
5.06k
    {
147
5.06k
        mb_neigbour_params_t *ps_cur_mb_row = ps_dec->ps_cur_mb_row;
148
5.06k
        mb_neigbour_params_t *ps_top_mb_row = ps_dec->ps_top_mb_row;
149
5.06k
150
5.06k
        /* copy the parameters of topleft Mb */
151
5.06k
        ps_cur_mb_info->u1_topleft_mbtype = ps_dec->u1_topleft_mbtype;
152
5.06k
        /* Neighbour pointer assignments*/
153
5.06k
        ps_cur_mb_info->ps_curmb = ps_cur_mb_row + mb_x;
154
5.06k
        ps_cur_mb_info->ps_left_mb = ps_cur_mb_row + mb_x - 1;
155
5.06k
        ps_cur_mb_info->ps_top_mb = ps_top_mb_row + mb_x;
156
5.06k
        ps_cur_mb_info->ps_top_right_mb = ps_top_mb_row + mb_x + 1;
157
5.06k
158
5.06k
        /* Update the parameters of topleftmb*/
159
5.06k
        ps_dec->u1_topleft_mbtype = ps_cur_mb_info->ps_top_mb->u1_mb_type;
160
5.06k
    }
161
5.06k
162
5.06k
    ps_dec->u2_mby = mb_y;
163
5.06k
    ps_dec->u2_mbx = mb_x;
164
5.06k
    ps_cur_mb_info->u2_mbx = mb_x;
165
5.06k
    ps_cur_mb_info->u2_mby = mb_y;
166
5.06k
    ps_cur_mb_info->u1_topmb = 1;
167
5.06k
    ps_dec->i4_submb_ofst += SUB_BLK_SIZE;
168
5.06k
    ps_dec->u1_mb_ngbr_availablity = u1_mb_ngbr_avail;
169
5.06k
    ps_cur_mb_info->u1_mb_ngbr_availablity = u1_mb_ngbr_avail;
170
5.06k
    ps_cur_mb_info->ps_curmb->u1_mb_fld = ps_dec->u1_cur_mb_fld_dec_flag;
171
5.06k
    ps_cur_mb_info->u1_mb_field_decodingflag = ps_dec->u1_cur_mb_fld_dec_flag;
172
5.06k
    ps_cur_mb_info->u2_top_left_avail_mask = u2_top_left_mask;
173
5.06k
    ps_cur_mb_info->u2_top_right_avail_mask = u2_top_right_mask;
174
5.06k
    return (OK);
175
5.06k
176
5.06k
}
177
178
/*****************************************************************************/
179
/*                                                                           */
180
/*  Function Name : get_mb_info_cavlc                                        */
181
/*                                                                           */
182
/*  Description   : This function sets the following information of cur MB   */
183
/*                  (a) mb_x and mb_y                                        */
184
/*                  (b) Neighbour availablity                                */
185
/*                  (c) Macroblock location in the frame buffer              */
186
/*                  (e) For mbaff predicts field/frame u4_flag for topMb        */
187
/*                      and sets the field/frame for botMb. This is          */
188
/*                      written in ps_dec->u1_cur_mb_fld_dec_flag            */
189
/*                                                                           */
190
/*  Inputs        : pointer to decstruct                                     */
191
/*                  pointer to current mb info                               */
192
/*                  currentMbaddress                                         */
193
/*                                                                           */
194
/*  Processing    : leftMb and TopMb params are used by DecMbskip and        */
195
/*                  DecCtxMbfield  modules so that these modules do not      */
196
/*                  check for neigbour availability and then find the        */
197
/*                  neigbours for context increments                         */
198
/*                                                                           */
199
/*  Returns       : OK                                                       */
200
/*                                                                           */
201
/*  Issues        : <List any issues or problems with this function>         */
202
/*                                                                           */
203
/*  Revision History:                                                        */
204
/*                                                                           */
205
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
206
/*         13 07 2002   Jay             Draft                                */
207
/*                                                                           */
208
/*****************************************************************************/
209
210
UWORD32 ih264d_get_mb_info_cavlc_mbaff(dec_struct_t *ps_dec,
211
                                       const UWORD16 u2_cur_mb_address,
212
                                       dec_mb_info_t * ps_cur_mb_info,
213
                                       UWORD32 u4_mbskip_run)
214
0
{
215
0
    UWORD16 u2_mb_x;
216
0
    UWORD16 u2_mb_y;
217
0
    UWORD8 u1_mb_ngbr_avail = 0;
218
0
    UWORD16 u2_frm_width_in_mb = ps_dec->u2_frm_wd_in_mbs;
219
0
220
0
    UWORD8 u1_top_mb = 1 - (u2_cur_mb_address & 0x01);
221
0
    WORD16 i2_prev_slice_mbx = ps_dec->i2_prev_slice_mbx;
222
0
    UWORD8 u1_cur_mb_field = 0;
223
0
    UWORD16 u2_top_right_mask = TOP_RIGHT_DEFAULT_AVAILABLE;
224
0
    UWORD16 u2_top_left_mask = TOP_LEFT_DEFAULT_AVAILABLE;
225
0
226
0
    /*--------------------------------------------------------------------*/
227
0
    /* Calculate values of mb_x and mb_y                                  */
228
0
    /*--------------------------------------------------------------------*/
229
0
    u2_mb_x = ps_dec->u2_mbx;
230
0
    u2_mb_y = ps_dec->u2_mby;
231
0
232
0
    ps_dec->u2_cur_mb_addr = u2_cur_mb_address;
233
0
234
0
235
0
    if(u1_top_mb)
236
0
    {
237
0
        u2_mb_x++;
238
0
        if(u2_mb_x == u2_frm_width_in_mb)
239
0
        {
240
0
            u2_mb_x = 0;
241
0
            u2_mb_y += 2;
242
0
        }
243
0
        if(u2_mb_y > ps_dec->i2_prev_slice_mby)
244
0
        {
245
0
            /* if not in the immemdiate row of prev slice end then top
246
0
             will be available */
247
0
            if(u2_mb_y > (ps_dec->i2_prev_slice_mby + 2))
248
0
                i2_prev_slice_mbx = -1;
249
0
            if(u2_mb_x > i2_prev_slice_mbx)
250
0
            {
251
0
                u1_mb_ngbr_avail |= TOP_MB_AVAILABLE_MASK;
252
0
                u1_cur_mb_field = ps_dec->ps_top_mb_row[u2_mb_x << 1].u1_mb_fld;
253
0
                u2_top_right_mask |= TOP_RIGHT_TOP_AVAILABLE;
254
0
                u2_top_left_mask |= TOP_LEFT_TOP_AVAILABLE;
255
0
            }
256
0
            if((u2_mb_x > (i2_prev_slice_mbx - 1))
257
0
                            && (u2_mb_x != (u2_frm_width_in_mb - 1)))
258
0
            {
259
0
                u1_mb_ngbr_avail |= TOP_RIGHT_MB_AVAILABLE_MASK;
260
0
                u2_top_right_mask |= TOP_RIGHT_TOPR_AVAILABLE;
261
0
            }
262
0
263
0
            if(u2_mb_x > (i2_prev_slice_mbx + 1))
264
0
            {
265
0
                u1_mb_ngbr_avail |= TOP_LEFT_MB_AVAILABLE_MASK;
266
0
                u2_top_left_mask |= TOP_LEFT_TOPL_AVAILABLE;
267
0
            }
268
0
269
0
            i2_prev_slice_mbx = -1;
270
0
        }
271
0
        /* Same row */
272
0
        if(u2_mb_x > (i2_prev_slice_mbx + 1))
273
0
        {
274
0
            u1_mb_ngbr_avail |= LEFT_MB_AVAILABLE_MASK;
275
0
            u1_cur_mb_field =
276
0
                            ps_dec->ps_cur_mb_row[(u2_mb_x << 1) - 1].u1_mb_fld;
277
0
            u2_top_left_mask |= TOP_LEFT_LEFT_AVAILABLE;
278
0
        }
279
0
        /* Read u1_cur_mb_field from the bitstream if u4_mbskip_run <= 1*/
280
0
        if(u4_mbskip_run <= 1)
281
0
            u1_cur_mb_field = (UWORD8)ih264d_get_bit_h264(ps_dec->ps_bitstrm);
282
0
283
0
        ps_dec->u1_cur_mb_fld_dec_flag = u1_cur_mb_field;
284
0
        ps_dec->u2_top_left_mask = u2_top_left_mask;
285
0
        ps_dec->u2_top_right_mask = u2_top_right_mask;
286
0
    }
287
0
    else
288
0
    {
289
0
        u1_mb_ngbr_avail = ps_dec->u1_mb_ngbr_availablity;
290
0
        u1_cur_mb_field = ps_dec->u1_cur_mb_fld_dec_flag;
291
0
        u2_top_left_mask = ps_dec->u2_top_left_mask;
292
0
        u2_top_right_mask = ps_dec->u2_top_right_mask;
293
0
294
0
        if(!u1_cur_mb_field)
295
0
        {
296
0
            /* Top is available */
297
0
            u1_mb_ngbr_avail |= TOP_MB_AVAILABLE_MASK;
298
0
            u2_top_right_mask |= TOP_RIGHT_TOP_AVAILABLE;
299
0
            u2_top_left_mask |= TOP_LEFT_TOP_AVAILABLE;
300
0
            /* Top Right not available */
301
0
            u1_mb_ngbr_avail &= TOP_RT_SUBBLOCK_MASK_MOD;
302
0
            u2_top_right_mask &= (~TOP_RIGHT_TOPR_AVAILABLE);
303
0
304
0
            if(u1_mb_ngbr_avail & LEFT_MB_AVAILABLE_MASK)
305
0
            {
306
0
                u1_mb_ngbr_avail |= TOP_LEFT_MB_AVAILABLE_MASK;
307
0
                u2_top_left_mask |= TOP_LEFT_LEFT_AVAILABLE;
308
0
                u2_top_left_mask |= TOP_LEFT_TOPL_AVAILABLE;
309
0
            }
310
0
        }
311
0
    }
312
0
313
0
    ps_dec->u2_mby = u2_mb_y;
314
0
    ps_dec->u2_mbx = u2_mb_x;
315
0
    ps_cur_mb_info->u2_mbx = u2_mb_x;
316
0
    ps_cur_mb_info->u2_mby = u2_mb_y;
317
0
    ps_cur_mb_info->u1_topmb = u1_top_mb;
318
0
    ps_dec->i4_submb_ofst += SUB_BLK_SIZE;
319
0
    ps_dec->u1_mb_ngbr_availablity = u1_mb_ngbr_avail;
320
0
    ps_cur_mb_info->u1_mb_ngbr_availablity = u1_mb_ngbr_avail;
321
0
    ps_cur_mb_info->u1_mb_field_decodingflag = u1_cur_mb_field;
322
0
    ps_cur_mb_info->u2_top_left_avail_mask = u2_top_left_mask;
323
0
    ps_cur_mb_info->u2_top_right_avail_mask = u2_top_right_mask;
324
0
    ih264d_get_mbaff_neighbours(ps_dec, ps_cur_mb_info, u1_cur_mb_field);
325
0
    return (OK);
326
0
}
327
328
/*****************************************************************************/
329
/*                                                                           */
330
/*  Function Name : get_mb_info_cabac                                        */
331
/*                                                                           */
332
/*  Description   : This function sets the following information of cur MB   */
333
/*                  (a) mb_x and mb_y                                        */
334
/*                  (b) Neighbour availablity                                */
335
/*                  (c) Macroblock location in the frame buffer              */
336
/*                  (e) leftMb parama and TopMb params of curMB              */
337
/*                  (f) For Mbaff case leftMb params and TopMb params of     */
338
/*                      bottomMb are also set if curMB is top                */
339
/*                  (g) For mbaff predicts field/frame u4_flag for topMb        */
340
/*                      and sets the field/frame for botMb. This is          */
341
/*                      written in ps_dec->u1_cur_mb_fld_dec_flag            */
342
/*                                                                           */
343
/*  Inputs        : pointer to decstruct                                     */
344
/*                  pointer to current mb info                               */
345
/*                  currentMbaddress                                         */
346
/*                                                                           */
347
/*  Processing    : leftMb and TopMb params are used by DecMbskip and        */
348
/*                  DecCtxMbfield  modules so that these modules do not      */
349
/*                  check for neigbour availability and then find the        */
350
/*                  neigbours for context increments                         */
351
/*                                                                           */
352
/*  Returns       : OK                                                       */
353
/*                                                                           */
354
/*  Issues        : <List any issues or problems with this function>         */
355
/*                                                                           */
356
/*  Revision History:                                                        */
357
/*                                                                           */
358
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
359
/*         13 07 2002   Jay             Draft                                */
360
/*                                                                           */
361
/*****************************************************************************/
362
UWORD32 ih264d_get_mb_info_cabac_nonmbaff(dec_struct_t *ps_dec,
363
                                          const UWORD16 u2_cur_mb_address,
364
                                          dec_mb_info_t * ps_cur_mb_info,
365
                                          UWORD32 u4_mbskip)
366
0
{
367
0
    WORD32 mb_x;
368
0
    WORD32 mb_y;
369
0
    UWORD32 u1_mb_ngbr_avail = 0;
370
0
    UWORD32 u2_frm_width_in_mb = ps_dec->u2_frm_wd_in_mbs;
371
0
    UWORD32 u1_top_mb = 1;
372
0
    WORD32 i2_prev_slice_mbx = ps_dec->i2_prev_slice_mbx;
373
0
    UWORD32 u2_top_right_mask = TOP_RIGHT_DEFAULT_AVAILABLE;
374
0
    UWORD32 u2_top_left_mask = TOP_LEFT_DEFAULT_AVAILABLE;
375
0
    ctxt_inc_mb_info_t * const p_ctx_inc_mb_map = ps_dec->p_ctxt_inc_mb_map;
376
0
377
0
    /*--------------------------------------------------------------------*/
378
0
    /* Calculate values of mb_x and mb_y                                  */
379
0
    /*--------------------------------------------------------------------*/
380
0
    mb_x = (WORD16)ps_dec->u2_mbx;
381
0
    mb_y = (WORD16)ps_dec->u2_mby;
382
0
383
0
    ps_dec->u2_cur_mb_addr = u2_cur_mb_address;
384
0
385
0
    mb_x++;
386
0
    if((UWORD32)mb_x == u2_frm_width_in_mb)
387
0
    {
388
0
        mb_x = 0;
389
0
        mb_y++;
390
0
    }
391
0
    /*********************************************************************/
392
0
    /* Cabac Context Initialisations                                     */
393
0
    /*********************************************************************/
394
0
    ps_dec->ps_curr_ctxt_mb_info = p_ctx_inc_mb_map + mb_x;
395
0
    ps_dec->p_left_ctxt_mb_info = p_ctx_inc_mb_map - 1;
396
0
    ps_dec->p_top_ctxt_mb_info = p_ctx_inc_mb_map - 1;
397
0
398
0
    /********************************************************************/
399
0
    /* neighbour availablility                                          */
400
0
    /********************************************************************/
401
0
    if(mb_y > ps_dec->i2_prev_slice_mby)
402
0
    {
403
0
        /* if not in the immemdiate row of prev slice end then top
404
0
         will be available */
405
0
        if(mb_y > (ps_dec->i2_prev_slice_mby + 1))
406
0
            i2_prev_slice_mbx = -1;
407
0
408
0
        if(mb_x > i2_prev_slice_mbx)
409
0
        {
410
0
            u1_mb_ngbr_avail |= TOP_MB_AVAILABLE_MASK;
411
0
            u2_top_right_mask |= TOP_RIGHT_TOP_AVAILABLE;
412
0
            u2_top_left_mask |= TOP_LEFT_TOP_AVAILABLE;
413
0
            ps_dec->p_top_ctxt_mb_info = ps_dec->ps_curr_ctxt_mb_info;
414
0
        }
415
0
        if((mb_x > (i2_prev_slice_mbx - 1))
416
0
                        && ((UWORD32)mb_x != (u2_frm_width_in_mb - 1)))
417
0
        {
418
0
            u1_mb_ngbr_avail |= TOP_RIGHT_MB_AVAILABLE_MASK;
419
0
            u2_top_right_mask |= TOP_RIGHT_TOPR_AVAILABLE;
420
0
        }
421
0
422
0
        if(mb_x > (i2_prev_slice_mbx + 1))
423
0
        {
424
0
            u1_mb_ngbr_avail |= TOP_LEFT_MB_AVAILABLE_MASK;
425
0
            u2_top_left_mask |= TOP_LEFT_TOPL_AVAILABLE;
426
0
        }
427
0
        /* Next row */
428
0
        i2_prev_slice_mbx = -1;
429
0
    }
430
0
    /* Same row */
431
0
    if(mb_x > (i2_prev_slice_mbx + 1))
432
0
    {
433
0
        u1_mb_ngbr_avail |= LEFT_MB_AVAILABLE_MASK;
434
0
        u2_top_left_mask |= TOP_LEFT_LEFT_AVAILABLE;
435
0
        ps_dec->p_left_ctxt_mb_info = ps_dec->ps_curr_ctxt_mb_info - 1;
436
0
    }
437
0
    {
438
0
        mb_neigbour_params_t *ps_cur_mb_row = ps_dec->ps_cur_mb_row;
439
0
        mb_neigbour_params_t *ps_top_mb_row = ps_dec->ps_top_mb_row;
440
0
        /* copy the parameters of topleft Mb */
441
0
        ps_cur_mb_info->u1_topleft_mbtype = ps_dec->u1_topleft_mbtype;
442
0
        /* Neighbour pointer assignments*/
443
0
        ps_cur_mb_info->ps_curmb = ps_cur_mb_row + mb_x;
444
0
        ps_cur_mb_info->ps_left_mb = ps_cur_mb_row + mb_x - 1;
445
0
        ps_cur_mb_info->ps_top_mb = ps_top_mb_row + mb_x;
446
0
        ps_cur_mb_info->ps_top_right_mb = ps_top_mb_row + mb_x + 1;
447
0
448
0
        /* Update the parameters of topleftmb*/
449
0
        ps_dec->u1_topleft_mbtype = ps_cur_mb_info->ps_top_mb->u1_mb_type;
450
0
    }
451
0
452
0
    ps_dec->u2_mby = mb_y;
453
0
    ps_dec->u2_mbx = mb_x;
454
0
    ps_cur_mb_info->u2_mbx = mb_x;
455
0
    ps_cur_mb_info->u2_mby = mb_y;
456
0
    ps_cur_mb_info->u1_topmb = u1_top_mb;
457
0
    ps_dec->i4_submb_ofst += SUB_BLK_SIZE;
458
0
    ps_dec->u1_mb_ngbr_availablity = u1_mb_ngbr_avail;
459
0
    ps_cur_mb_info->u1_mb_ngbr_availablity = u1_mb_ngbr_avail;
460
0
    ps_cur_mb_info->ps_curmb->u1_mb_fld = ps_dec->u1_cur_mb_fld_dec_flag;
461
0
    ps_cur_mb_info->u1_mb_field_decodingflag = ps_dec->u1_cur_mb_fld_dec_flag;
462
0
    ps_cur_mb_info->u2_top_left_avail_mask = u2_top_left_mask;
463
0
    ps_cur_mb_info->u2_top_right_avail_mask = u2_top_right_mask;
464
0
465
0
    /*********************************************************************/
466
0
    /*                  Assign the neigbours                             */
467
0
    /*********************************************************************/
468
0
    if(u4_mbskip)
469
0
    {
470
0
        UWORD32 u4_ctx_inc =
471
0
                        2
472
0
                                        - ((!!(ps_dec->p_top_ctxt_mb_info->u1_mb_type
473
0
                                                        & CAB_SKIP_MASK))
474
0
                                                        + (!!(ps_dec->p_left_ctxt_mb_info->u1_mb_type
475
0
                                                                        & CAB_SKIP_MASK)));
476
0
477
0
        u4_mbskip = ih264d_decode_bin(u4_ctx_inc, ps_dec->p_mb_skip_flag_t,
478
0
                                      ps_dec->ps_bitstrm, &ps_dec->s_cab_dec_env);
479
0
480
0
        if(!u4_mbskip)
481
0
        {
482
0
            if(!(u1_mb_ngbr_avail & LEFT_MB_AVAILABLE_MASK))
483
0
            {
484
0
                UWORD32 *pu4_buf;
485
0
                UWORD8 *pu1_buf;
486
0
487
0
                pu1_buf = ps_dec->pu1_left_nnz_y;
488
0
                pu4_buf = (UWORD32 *)pu1_buf;
489
0
                *pu4_buf = 0;
490
0
                pu1_buf = ps_dec->pu1_left_nnz_uv;
491
0
                pu4_buf = (UWORD32 *)pu1_buf;
492
0
                *pu4_buf = 0;
493
0
494
0
495
0
                *(ps_dec->pu1_left_yuv_dc_csbp) = 0;
496
0
                MEMSET_16BYTES(&ps_dec->pu1_left_mv_ctxt_inc[0][0], 0);
497
0
                *(UWORD32 *)ps_dec->pi1_left_ref_idx_ctxt_inc = 0;
498
0
            }
499
0
            if(!(u1_mb_ngbr_avail & TOP_MB_AVAILABLE_MASK))
500
0
            {
501
0
                MEMSET_16BYTES(ps_dec->ps_curr_ctxt_mb_info->u1_mv, 0);
502
0
                memset(ps_dec->ps_curr_ctxt_mb_info->i1_ref_idx, 0, 4);
503
0
            }
504
0
        }
505
0
    }
506
0
    return (u4_mbskip);
507
0
}
508
509
/*****************************************************************************/
510
/*                                                                           */
511
/*  Function Name : get_mb_info_cabac                                        */
512
/*                                                                           */
513
/*  Description   : This function sets the following information of cur MB   */
514
/*                  (a) mb_x and mb_y                                        */
515
/*                  (b) Neighbour availablity                                */
516
/*                  (c) Macroblock location in the frame buffer              */
517
/*                  (e) leftMb parama and TopMb params of curMB              */
518
/*                  (f) For Mbaff case leftMb params and TopMb params of     */
519
/*                      bottomMb are also set if curMB is top                */
520
/*                  (g) For mbaff predicts field/frame u4_flag for topMb        */
521
/*                      and sets the field/frame for botMb. This is          */
522
/*                      written in ps_dec->u1_cur_mb_fld_dec_flag            */
523
/*                                                                           */
524
/*  Inputs        : pointer to decstruct                                     */
525
/*                  pointer to current mb info                               */
526
/*                  currentMbaddress                                         */
527
/*                                                                           */
528
/*  Processing    : leftMb and TopMb params are used by DecMbskip and        */
529
/*                  DecCtxMbfield  modules so that these modules do not      */
530
/*                  check for neigbour availability and then find the        */
531
/*                  neigbours for context increments                         */
532
/*                                                                           */
533
/*  Returns       : OK                                                       */
534
/*                                                                           */
535
/*  Issues        : <List any issues or problems with this function>         */
536
/*                                                                           */
537
/*  Revision History:                                                        */
538
/*                                                                           */
539
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
540
/*         13 07 2002   Jay             Draft                                */
541
/*                                                                           */
542
/*****************************************************************************/
543
544
UWORD32 ih264d_get_mb_info_cabac_mbaff(dec_struct_t *ps_dec,
545
                                       const UWORD16 u2_cur_mb_address,
546
                                       dec_mb_info_t * ps_cur_mb_info,
547
                                       UWORD32 u4_mbskip)
548
0
{
549
0
    WORD32 mb_x;
550
0
    WORD32 mb_y;
551
0
    UWORD8 u1_mb_ngbr_avail = 0;
552
0
    UWORD16 u2_frm_width_in_mb = ps_dec->u2_frm_wd_in_mbs;
553
0
    ctxt_inc_mb_info_t * const p_ctx_inc_mb_map = ps_dec->p_ctxt_inc_mb_map;
554
0
    ctxt_inc_mb_info_t *ps_curr_ctxt, *ps_top_ctxt, *ps_left_ctxt;
555
0
    mb_neigbour_params_t *ps_cur_mb_row = ps_dec->ps_cur_mb_row;
556
0
    mb_neigbour_params_t *ps_top_mb_row = ps_dec->ps_top_mb_row;
557
0
    UWORD32 u4_left_mb_pair_fld = 0;
558
0
    UWORD32 u4_top_mb_pair_fld = 0;
559
0
    UWORD8 u1_cur_mb_field = 0;
560
0
    UWORD8 u1_top_mb = 1 - (u2_cur_mb_address & 0x01);
561
0
    WORD16 i2_prev_slice_mbx = ps_dec->i2_prev_slice_mbx;
562
0
    UWORD16 u2_top_right_mask = TOP_RIGHT_DEFAULT_AVAILABLE;
563
0
    UWORD16 u2_top_left_mask = TOP_LEFT_DEFAULT_AVAILABLE;
564
0
565
0
    /*--------------------------------------------------------------------*/
566
0
    /* Calculate values of mb_x and mb_y                                  */
567
0
    /*--------------------------------------------------------------------*/
568
0
    mb_x = (WORD16)ps_dec->u2_mbx;
569
0
    mb_y = (WORD16)ps_dec->u2_mby;
570
0
571
0
    ps_dec->u2_cur_mb_addr = u2_cur_mb_address;
572
0
573
0
    ps_top_ctxt = ps_left_ctxt = p_ctx_inc_mb_map - 1;
574
0
575
0
    if(u1_top_mb)
576
0
    {
577
0
        ctxt_inc_mb_info_t *ps_left_mb_of_bot = ps_left_ctxt;
578
0
        ctxt_inc_mb_info_t *ps_top_mb_of_bot = ps_top_ctxt;
579
0
580
0
        mb_x++;
581
0
582
0
        if(mb_x == u2_frm_width_in_mb)
583
0
        {
584
0
            mb_x = 0;
585
0
            mb_y += 2;
586
0
        }
587
0
588
0
        ps_curr_ctxt = p_ctx_inc_mb_map + (mb_x << 1);
589
0
        if(mb_y > ps_dec->i2_prev_slice_mby)
590
0
        {
591
0
            UWORD8 u1_cur_mb_fld_flag_known = 0;
592
0
            /* Next row */
593
0
            if(mb_x > 0)
594
0
            {
595
0
                /***********************************************************************/
596
0
                /*                    Left Mb is avialable                             */
597
0
                /***********************************************************************/
598
0
                u1_mb_ngbr_avail |= LEFT_MB_AVAILABLE_MASK;
599
0
                ps_left_ctxt = ps_curr_ctxt - 2;
600
0
                ps_left_mb_of_bot = ps_curr_ctxt - 1;
601
0
                u1_cur_mb_field = u4_left_mb_pair_fld = ps_cur_mb_row[(mb_x
602
0
                                << 1) - 1].u1_mb_fld;
603
0
                u1_cur_mb_fld_flag_known = 1;
604
0
                u2_top_left_mask |= TOP_LEFT_LEFT_AVAILABLE;
605
0
            }
606
0
            /* if not in the immemdiate row of prev slice end then top
607
0
             will be available */
608
0
            if(mb_y > (ps_dec->i2_prev_slice_mby + 2))
609
0
                i2_prev_slice_mbx = -1;
610
0
            if(mb_x > i2_prev_slice_mbx)
611
0
            {
612
0
                /*********************************************************************/
613
0
                /*                    Top Mb is avialable                            */
614
0
                /*********************************************************************/
615
0
                u1_mb_ngbr_avail |= TOP_MB_AVAILABLE_MASK;
616
0
                u2_top_right_mask |= TOP_RIGHT_TOP_AVAILABLE;
617
0
                u2_top_left_mask |= TOP_LEFT_TOP_AVAILABLE;
618
0
619
0
                /* point to MbAddrB + 1 */
620
0
                ps_top_ctxt = ps_curr_ctxt + 1;
621
0
                u4_top_mb_pair_fld = ps_top_mb_row[(mb_x << 1)].u1_mb_fld;
622
0
623
0
                u1_cur_mb_field =
624
0
                                u1_cur_mb_fld_flag_known ?
625
0
                                                u1_cur_mb_field :
626
0
                                                u4_top_mb_pair_fld;
627
0
                ps_top_mb_of_bot = u1_cur_mb_field ? ps_top_ctxt : ps_curr_ctxt;
628
0
629
0
                /* MbAddrB */
630
0
                ps_top_ctxt -= (u1_cur_mb_field && u4_top_mb_pair_fld);
631
0
            }
632
0
633
0
            if((mb_x > (i2_prev_slice_mbx - 1))
634
0
                            && (mb_x != (u2_frm_width_in_mb - 1)))
635
0
            {
636
0
                u1_mb_ngbr_avail |= TOP_RIGHT_MB_AVAILABLE_MASK;
637
0
                u2_top_right_mask |= TOP_RIGHT_TOPR_AVAILABLE;
638
0
            }
639
0
640
0
            if(mb_x > (i2_prev_slice_mbx + 1))
641
0
            {
642
0
                u1_mb_ngbr_avail |= TOP_LEFT_MB_AVAILABLE_MASK;
643
0
                u2_top_left_mask |= TOP_LEFT_TOPL_AVAILABLE;
644
0
            }
645
0
        }
646
0
        else
647
0
        {
648
0
            /* Same row */
649
0
            if(mb_x > (i2_prev_slice_mbx + 1))
650
0
            {
651
0
                /***************************************************************/
652
0
                /*                    Left Mb is avialable                     */
653
0
                /***************************************************************/
654
0
                u1_mb_ngbr_avail |= LEFT_MB_AVAILABLE_MASK;
655
0
656
0
                u1_cur_mb_field = u4_left_mb_pair_fld = ps_cur_mb_row[(mb_x
657
0
                                << 1) - 1].u1_mb_fld;
658
0
                ps_left_ctxt = ps_curr_ctxt - 2;
659
0
                ps_left_mb_of_bot = ps_curr_ctxt - 1;
660
0
                u2_top_left_mask |= TOP_LEFT_LEFT_AVAILABLE;
661
0
            }
662
0
        }
663
0
        /*********************************************************/
664
0
        /* Check whether the call is from I slice or Inter slice */
665
0
        /*********************************************************/
666
0
        if(u4_mbskip)
667
0
        {
668
0
            UWORD32 u4_ctx_inc = 2
669
0
                            - ((!!(ps_top_ctxt->u1_mb_type & CAB_SKIP_MASK))
670
0
                                            + (!!(ps_left_ctxt->u1_mb_type
671
0
                                                            & CAB_SKIP_MASK)));
672
0
            dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
673
0
            decoding_envirnoment_t *ps_cab_dec_env = &ps_dec->s_cab_dec_env;
674
0
            bin_ctxt_model_t *p_mb_skip_flag_t = ps_dec->p_mb_skip_flag_t;
675
0
676
0
            ps_dec->u4_next_mb_skip = 0;
677
0
            u4_mbskip = ih264d_decode_bin(u4_ctx_inc, p_mb_skip_flag_t,
678
0
                                          ps_bitstrm, ps_cab_dec_env);
679
0
680
0
            if(u4_mbskip)
681
0
            {
682
0
                UWORD32 u4_next_mbskip;
683
0
                ps_curr_ctxt->u1_mb_type = CAB_SKIP;
684
0
685
0
                u4_ctx_inc =
686
0
                                2
687
0
                                                - ((!!(ps_top_mb_of_bot->u1_mb_type
688
0
                                                                & CAB_SKIP_MASK))
689
0
                                                                + (!!(ps_left_mb_of_bot->u1_mb_type
690
0
                                                                                & CAB_SKIP_MASK)));
691
0
692
0
                /* Decode the skip u4_flag of bottom Mb */
693
0
                u4_next_mbskip = ih264d_decode_bin(u4_ctx_inc, p_mb_skip_flag_t,
694
0
                                                   ps_bitstrm,
695
0
                                                   ps_cab_dec_env);
696
0
697
0
                ps_dec->u4_next_mb_skip = u4_next_mbskip;
698
0
699
0
                if(!u4_next_mbskip)
700
0
                {
701
0
                    u4_ctx_inc = u4_top_mb_pair_fld + u4_left_mb_pair_fld;
702
0
703
0
                    u1_cur_mb_field = ih264d_decode_bin(
704
0
                                    u4_ctx_inc, ps_dec->p_mb_field_dec_flag_t,
705
0
                                    ps_bitstrm, ps_cab_dec_env);
706
0
                }
707
0
            }
708
0
        }
709
0
710
0
        if(!u4_mbskip)
711
0
        {
712
0
            UWORD32 u4_ctx_inc = u4_top_mb_pair_fld + u4_left_mb_pair_fld;
713
0
            u1_cur_mb_field = ih264d_decode_bin(u4_ctx_inc,
714
0
                                                ps_dec->p_mb_field_dec_flag_t,
715
0
                                                ps_dec->ps_bitstrm,
716
0
                                                &ps_dec->s_cab_dec_env);
717
0
        }
718
0
719
0
        ps_dec->u1_cur_mb_fld_dec_flag = u1_cur_mb_field;
720
0
        ps_dec->u2_top_left_mask = u2_top_left_mask;
721
0
        ps_dec->u2_top_right_mask = u2_top_right_mask;
722
0
        ps_dec->u2_mby = mb_y;
723
0
        ps_dec->u2_mbx = mb_x;
724
0
    }
725
0
    else
726
0
    {
727
0
        u1_cur_mb_field = ps_dec->u1_cur_mb_fld_dec_flag;
728
0
        u1_mb_ngbr_avail = ps_dec->u1_mb_ngbr_availablity;
729
0
        u2_top_left_mask = ps_dec->u2_top_left_mask;
730
0
        u2_top_right_mask = ps_dec->u2_top_right_mask;
731
0
        ps_curr_ctxt = p_ctx_inc_mb_map + (mb_x << 1) + 1;
732
0
733
0
        if(u1_mb_ngbr_avail & LEFT_MB_AVAILABLE_MASK)
734
0
        {
735
0
            u4_left_mb_pair_fld = ps_cur_mb_row[(mb_x << 1) - 1].u1_mb_fld;
736
0
737
0
            /* point to A if top else A+1 */
738
0
            ps_left_ctxt = ps_curr_ctxt - 2
739
0
                            - (u4_left_mb_pair_fld != u1_cur_mb_field);
740
0
        }
741
0
742
0
        if(u1_cur_mb_field)
743
0
        {
744
0
            if(u1_mb_ngbr_avail & TOP_MB_AVAILABLE_MASK)
745
0
            {
746
0
                /* point to MbAddrB + 1 */
747
0
                ps_top_ctxt = ps_curr_ctxt;
748
0
            }
749
0
        }
750
0
        else
751
0
        {
752
0
            /* Top is available */
753
0
            u1_mb_ngbr_avail |= TOP_MB_AVAILABLE_MASK;
754
0
            u2_top_right_mask |= TOP_RIGHT_TOP_AVAILABLE;
755
0
            u2_top_left_mask |= TOP_LEFT_TOP_AVAILABLE;
756
0
            /* Top Right not available */
757
0
            u1_mb_ngbr_avail &= TOP_RT_SUBBLOCK_MASK_MOD;
758
0
            u2_top_right_mask &= (~TOP_RIGHT_TOPR_AVAILABLE);
759
0
760
0
            if(u1_mb_ngbr_avail & LEFT_MB_AVAILABLE_MASK)
761
0
            {
762
0
                u1_mb_ngbr_avail |= TOP_LEFT_MB_AVAILABLE_MASK;
763
0
                u2_top_left_mask |= TOP_LEFT_LEFT_AVAILABLE;
764
0
                u2_top_left_mask |= TOP_LEFT_TOPL_AVAILABLE;
765
0
            }
766
0
767
0
            /* CurMbAddr - 1 */
768
0
            ps_top_ctxt = ps_curr_ctxt - 1;
769
0
        }
770
0
771
0
        if(u4_mbskip)
772
0
        {
773
0
            if(ps_curr_ctxt[-1].u1_mb_type & CAB_SKIP_MASK)
774
0
            {
775
0
                /* If previous mb is skipped, return value of next mb skip */
776
0
                u4_mbskip = ps_dec->u4_next_mb_skip;
777
0
778
0
            }
779
0
            else
780
0
            {
781
0
                /* If previous mb is not skipped then call DecMbSkip */
782
0
                UWORD32 u4_ctx_inc =
783
0
                                2
784
0
                                                - ((!!(ps_top_ctxt->u1_mb_type
785
0
                                                                & CAB_SKIP_MASK))
786
0
                                                                + (!!(ps_left_ctxt->u1_mb_type
787
0
                                                                                & CAB_SKIP_MASK)));
788
0
789
0
                u4_mbskip = ih264d_decode_bin(u4_ctx_inc,
790
0
                                              ps_dec->p_mb_skip_flag_t,
791
0
                                              ps_dec->ps_bitstrm,
792
0
                                              &ps_dec->s_cab_dec_env);
793
0
            }
794
0
        }
795
0
    }
796
0
797
0
    ps_cur_mb_info->u2_mbx = mb_x;
798
0
    ps_cur_mb_info->u2_mby = mb_y;
799
0
    ps_cur_mb_info->u1_topmb = u1_top_mb;
800
0
    ps_dec->i4_submb_ofst += SUB_BLK_SIZE;
801
0
    ps_dec->u1_mb_ngbr_availablity = u1_mb_ngbr_avail;
802
0
    ps_cur_mb_info->u1_mb_ngbr_availablity = u1_mb_ngbr_avail;
803
0
    ps_cur_mb_info->u1_mb_field_decodingflag = u1_cur_mb_field;
804
0
    ps_cur_mb_info->u2_top_left_avail_mask = u2_top_left_mask;
805
0
    ps_cur_mb_info->u2_top_right_avail_mask = u2_top_right_mask;
806
0
807
0
    ih264d_get_mbaff_neighbours(ps_dec, ps_cur_mb_info, u1_cur_mb_field);
808
0
    {
809
0
        ih264d_get_cabac_context_mbaff(ps_dec, ps_cur_mb_info, u4_mbskip);
810
0
    }
811
0
812
0
    {
813
0
        bin_ctxt_model_t *p_cabac_ctxt_table_t = ps_dec->p_cabac_ctxt_table_t;
814
0
815
0
        if(u1_cur_mb_field)
816
0
        {
817
0
            p_cabac_ctxt_table_t += SIGNIFICANT_COEFF_FLAG_FLD;
818
0
        }
819
0
        else
820
0
        {
821
0
            p_cabac_ctxt_table_t += SIGNIFICANT_COEFF_FLAG_FRAME;
822
0
        }
823
0
        {
824
0
            bin_ctxt_model_t * * p_significant_coeff_flag_t =
825
0
                            ps_dec->p_significant_coeff_flag_t;
826
0
            p_significant_coeff_flag_t[0] = p_cabac_ctxt_table_t
827
0
                            + SIG_COEFF_CTXT_CAT_0_OFFSET;
828
0
            p_significant_coeff_flag_t[1] = p_cabac_ctxt_table_t
829
0
                            + SIG_COEFF_CTXT_CAT_1_OFFSET;
830
0
            p_significant_coeff_flag_t[2] = p_cabac_ctxt_table_t
831
0
                            + SIG_COEFF_CTXT_CAT_2_OFFSET;
832
0
            p_significant_coeff_flag_t[3] = p_cabac_ctxt_table_t
833
0
                            + SIG_COEFF_CTXT_CAT_3_OFFSET;
834
0
            p_significant_coeff_flag_t[4] = p_cabac_ctxt_table_t
835
0
                            + SIG_COEFF_CTXT_CAT_4_OFFSET;
836
0
            p_significant_coeff_flag_t[5] = p_cabac_ctxt_table_t
837
0
                            + SIG_COEFF_CTXT_CAT_5_OFFSET;
838
0
839
0
        }
840
0
    }
841
0
    return (u4_mbskip);
842
0
}
843
844
/*****************************************************************************/
845
/*                                                                           */
846
/*  Function Name : ih264d_get_cabac_context_mbaff                                  */
847
/*                                                                           */
848
/*  Description   : Gets the current macroblock Cabac Context and sets the   */
849
/*                  top and left cabac context ptrs in CtxIncMbMap           */
850
/*                  1. For Coss field left neigbours it alters coded block   */
851
/*                     u4_flag , motion vectors, reference indices, cbp of      */
852
/*                     the left neigbours which increases the code i4_size      */
853
/*                  2. For Coss field top neigbours it alters motion         */
854
/*                     vectors reference indices of the top neigbours        */
855
/*                     which further increases the code i4_size                 */
856
/*                                                                           */
857
/*  Inputs        : 1. dec_struct_t                                             */
858
/*                  2. CurMbAddr used for Mbaff (only to see if curMB        */
859
/*                  is top or bottom)                                        */
860
/*                  3. uc_curMbFldDecFlag only for Mbaff                     */
861
/*                                                                           */
862
/*  Returns       : 0                                                        */
863
/*                                                                           */
864
/*  Issues        : code i4_size can be reduced if ui_CodedBlockFlag storage    */
865
/*                  structure in context is changed. This change however     */
866
/*                  would break the parseResidual4x4Cabac asm routine.       */
867
/*                                                                           */
868
/*  Revision History:                                                        */
869
/*                                                                           */
870
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
871
/*         18 06 2005   Jay                                                  */
872
/*                                                                           */
873
/*****************************************************************************/
874
UWORD32 ih264d_get_cabac_context_mbaff(dec_struct_t * ps_dec,
875
                                       dec_mb_info_t *ps_cur_mb_info,
876
                                       UWORD32 u4_mbskip)
877
0
{
878
0
    const UWORD8 u1_mb_ngbr_availablity = ps_dec->u1_mb_ngbr_availablity;
879
0
    ctxt_inc_mb_info_t * const p_ctx_inc_mb_map = ps_dec->p_ctxt_inc_mb_map;
880
0
881
0
    UWORD8 (*pu1_left_mv_ctxt_inc_2d)[4] = &ps_dec->pu1_left_mv_ctxt_inc[0];
882
0
    WORD8 (*pi1_left_ref_idx_ctxt_inc) = ps_dec->pi1_left_ref_idx_ctxt_inc;
883
0
    const UWORD8 u1_cur_mb_fld_flag = ps_cur_mb_info->u1_mb_field_decodingflag;
884
0
    const UWORD8 u1_topmb = ps_cur_mb_info->u1_topmb;
885
0
    const UWORD8 uc_botMb = 1 - ps_cur_mb_info->u1_topmb;
886
0
887
0
    ctxt_inc_mb_info_t * ps_leftMB;
888
0
889
0
    ps_dec->ps_curr_ctxt_mb_info = p_ctx_inc_mb_map + (ps_dec->u2_mbx << 1);
890
0
    ps_dec->p_top_ctxt_mb_info = ps_dec->ps_curr_ctxt_mb_info;
891
0
892
0
    if(u1_topmb)
893
0
    {
894
0
        pu1_left_mv_ctxt_inc_2d = ps_dec->u1_left_mv_ctxt_inc_arr[0];
895
0
        pi1_left_ref_idx_ctxt_inc = &ps_dec->i1_left_ref_idx_ctx_inc_arr[0][0];
896
0
        ps_dec->pu1_left_yuv_dc_csbp = &ps_dec->u1_yuv_dc_csbp_topmb;
897
0
    }
898
0
    else
899
0
    {
900
0
        /* uc_botMb */
901
0
        pu1_left_mv_ctxt_inc_2d = ps_dec->u1_left_mv_ctxt_inc_arr[1];
902
0
        pi1_left_ref_idx_ctxt_inc = &ps_dec->i1_left_ref_idx_ctx_inc_arr[1][0];
903
0
        ps_dec->pu1_left_yuv_dc_csbp = &ps_dec->u1_yuv_dc_csbp_bot_mb;
904
0
        ps_dec->ps_curr_ctxt_mb_info += 1;
905
0
    }
906
0
907
0
    ps_dec->pu1_left_mv_ctxt_inc = pu1_left_mv_ctxt_inc_2d;
908
0
    ps_dec->pi1_left_ref_idx_ctxt_inc = pi1_left_ref_idx_ctxt_inc;
909
0
910
0
    if(u1_mb_ngbr_availablity & LEFT_MB_AVAILABLE_MASK)
911
0
    {
912
0
        const UWORD8 u1_left_mb_fld_flag = ps_cur_mb_info->ps_left_mb->u1_mb_fld;
913
0
914
0
        ps_leftMB = ps_dec->ps_curr_ctxt_mb_info - 2;
915
0
        if(u1_left_mb_fld_flag != u1_cur_mb_fld_flag)
916
0
        {
917
0
            ctxt_inc_mb_info_t *ps_tempLeft;
918
0
            UWORD8 u1_cbp_t, u1_cbp_b;
919
0
            UWORD8 u1_cr_cpb;
920
0
921
0
            ps_leftMB -= uc_botMb;
922
0
            ps_tempLeft = ps_dec->ps_left_mb_ctxt_info;
923
0
            ps_tempLeft->u1_mb_type = ps_leftMB->u1_mb_type;
924
0
            ps_tempLeft->u1_intra_chroma_pred_mode =
925
0
                            ps_leftMB->u1_intra_chroma_pred_mode;
926
0
927
0
            ps_tempLeft->u1_transform8x8_ctxt = ps_leftMB->u1_transform8x8_ctxt;
928
0
929
0
            u1_cr_cpb = ps_leftMB->u1_cbp;
930
0
            /*****************************************************************/
931
0
            /* reform RefIdx, CBP, MV and CBF ctxInc taking care of A and A+1*/
932
0
            /*****************************************************************/
933
0
            if(u1_cur_mb_fld_flag)
934
0
            {
935
0
                /* current MB is a FLD and left a FRM */
936
0
                UWORD8 (* const pu1_left_mv_ctxt_inc_2d_arr_top)[4] =
937
0
                                ps_dec->u1_left_mv_ctxt_inc_arr[0];
938
0
                UWORD8 (* const pu1_left_mv_ctxt_inc_2d_arr_bot)[4] =
939
0
                                ps_dec->u1_left_mv_ctxt_inc_arr[1];
940
0
                WORD8 (* const i1_left_ref_idx_ctxt_inc_arr_top) =
941
0
                                &ps_dec->i1_left_ref_idx_ctx_inc_arr[0][0];
942
0
                WORD8 (* const i1_left_ref_idx_ctxt_inc_arr_bot) =
943
0
                                &ps_dec->i1_left_ref_idx_ctx_inc_arr[1][0];
944
0
945
0
                u1_cbp_t = ps_leftMB->u1_cbp;
946
0
                u1_cbp_b = (ps_leftMB + 1)->u1_cbp;
947
0
                ps_tempLeft->u1_cbp = (u1_cbp_t & 0x02)
948
0
                                | ((u1_cbp_b & 0x02) << 2);
949
0
950
0
                // set motionvectors as
951
0
                // 0T = 0T  0B = 0T
952
0
                // 1T = 2T  1B = 2T
953
0
                // 2T = 0B  2B = 0B
954
0
                // 3T = 2B  3B = 2B
955
0
                if(u1_topmb)
956
0
                {
957
0
                    /********************************************/
958
0
                    /*    Bottoms  DC CBF = Top DC CBF          */
959
0
                    /********************************************/
960
0
                    ps_dec->u1_yuv_dc_csbp_bot_mb =
961
0
                                    ps_dec->u1_yuv_dc_csbp_topmb;
962
0
963
0
                    *(UWORD32 *)pu1_left_mv_ctxt_inc_2d[3] =
964
0
                                    *(UWORD32 *)pu1_left_mv_ctxt_inc_2d_arr_bot[2];
965
0
                    *(UWORD32 *)pu1_left_mv_ctxt_inc_2d[1] =
966
0
                                    *(UWORD32 *)pu1_left_mv_ctxt_inc_2d_arr_top[2];
967
0
                    *(UWORD32 *)pu1_left_mv_ctxt_inc_2d[2] =
968
0
                                    *(UWORD32 *)pu1_left_mv_ctxt_inc_2d_arr_bot[0];
969
0
                    *(UWORD32 *)pu1_left_mv_ctxt_inc_2d[0] =
970
0
                                    *(UWORD32 *)pu1_left_mv_ctxt_inc_2d_arr_top[0];
971
0
972
0
                    i1_left_ref_idx_ctxt_inc_arr_top[1] =
973
0
                                    i1_left_ref_idx_ctxt_inc_arr_bot[0];
974
0
                    i1_left_ref_idx_ctxt_inc_arr_top[3] =
975
0
                                    i1_left_ref_idx_ctxt_inc_arr_bot[2];
976
0
977
0
                    *(UWORD32 *)(i1_left_ref_idx_ctxt_inc_arr_bot) =
978
0
                                    *(UWORD32 *)(i1_left_ref_idx_ctxt_inc_arr_top);
979
0
980
0
                    memcpy(pu1_left_mv_ctxt_inc_2d_arr_bot,
981
0
                           pu1_left_mv_ctxt_inc_2d_arr_top, 16);
982
0
                }
983
0
984
0
                {
985
0
                    UWORD8 i;
986
0
                    for(i = 0; i < 4; i++)
987
0
                    {
988
0
                        pu1_left_mv_ctxt_inc_2d[i][1] >>= 1;
989
0
                        pu1_left_mv_ctxt_inc_2d[i][3] >>= 1;
990
0
                    }
991
0
                }
992
0
            }
993
0
            else
994
0
            {
995
0
                /* current MB is a FRM and left FLD */
996
0
                if(u1_topmb)
997
0
                {
998
0
                    u1_cbp_t = ps_leftMB->u1_cbp;
999
0
                    u1_cbp_t = (u1_cbp_t & 0x02);
1000
0
                    ps_tempLeft->u1_cbp = (u1_cbp_t | (u1_cbp_t << 2));
1001
0
1002
0
                    /********************************************/
1003
0
                    /*    Bottoms  DC CBF = Top DC CBF          */
1004
0
                    /********************************************/
1005
0
                    ps_dec->u1_yuv_dc_csbp_bot_mb =
1006
0
                                    ps_dec->u1_yuv_dc_csbp_topmb;
1007
0
1008
0
                    // set motionvectors as
1009
0
                    // 3B = 2B = 3T
1010
0
                    // 1B = 0B = 2T
1011
0
                    // 3T = 2T = 1T
1012
0
                    // 1T = 0T = 0T
1013
0
1014
0
                    *(UWORD32 *)pu1_left_mv_ctxt_inc_2d[7] =
1015
0
                                    *(UWORD32 *)pu1_left_mv_ctxt_inc_2d[3];
1016
0
                    *(UWORD32 *)pu1_left_mv_ctxt_inc_2d[6] =
1017
0
                                    *(UWORD32 *)pu1_left_mv_ctxt_inc_2d[3];
1018
0
1019
0
                    *(UWORD32 *)pu1_left_mv_ctxt_inc_2d[5] =
1020
0
                                    *(UWORD32 *)pu1_left_mv_ctxt_inc_2d[2];
1021
0
                    *(UWORD32 *)pu1_left_mv_ctxt_inc_2d[4] =
1022
0
                                    *(UWORD32 *)pu1_left_mv_ctxt_inc_2d[2];
1023
0
1024
0
                    *(UWORD32 *)pu1_left_mv_ctxt_inc_2d[3] =
1025
0
                                    *(UWORD32 *)pu1_left_mv_ctxt_inc_2d[1];
1026
0
                    *(UWORD32 *)pu1_left_mv_ctxt_inc_2d[2] =
1027
0
                                    *(UWORD32 *)pu1_left_mv_ctxt_inc_2d[1];
1028
0
1029
0
                    *(UWORD32 *)pu1_left_mv_ctxt_inc_2d[1] =
1030
0
                                    *(UWORD32 *)pu1_left_mv_ctxt_inc_2d[0];
1031
0
1032
0
                    pi1_left_ref_idx_ctxt_inc[7] = (pi1_left_ref_idx_ctxt_inc[3]
1033
0
                                    - 1);
1034
0
                    pi1_left_ref_idx_ctxt_inc[6] = (pi1_left_ref_idx_ctxt_inc[3]
1035
0
                                    - 1);
1036
0
1037
0
                    pi1_left_ref_idx_ctxt_inc[5] = (pi1_left_ref_idx_ctxt_inc[1]
1038
0
                                    - 1);
1039
0
                    pi1_left_ref_idx_ctxt_inc[4] = (pi1_left_ref_idx_ctxt_inc[1]
1040
0
                                    - 1);
1041
0
1042
0
                    pi1_left_ref_idx_ctxt_inc[3] = (pi1_left_ref_idx_ctxt_inc[2]
1043
0
                                    - 1);
1044
0
                    pi1_left_ref_idx_ctxt_inc[2] = (pi1_left_ref_idx_ctxt_inc[2]
1045
0
                                    - 1);
1046
0
1047
0
                    pi1_left_ref_idx_ctxt_inc[1] = (pi1_left_ref_idx_ctxt_inc[0]
1048
0
                                    - 1);
1049
0
                    pi1_left_ref_idx_ctxt_inc[0] = (pi1_left_ref_idx_ctxt_inc[0]
1050
0
                                    - 1);
1051
0
                }
1052
0
                else
1053
0
                {
1054
0
                    u1_cbp_t = ps_leftMB->u1_cbp;
1055
0
                    u1_cbp_t = (u1_cbp_t & 0x08);
1056
0
                    ps_tempLeft->u1_cbp = (u1_cbp_t | (u1_cbp_t >> 2));
1057
0
                }
1058
0
1059
0
                {
1060
0
                    UWORD8 i;
1061
0
                    for(i = 0; i < 4; i++)
1062
0
                    {
1063
0
                        pu1_left_mv_ctxt_inc_2d[i][1] <<= 1;
1064
0
                        pu1_left_mv_ctxt_inc_2d[i][3] <<= 1;
1065
0
                    }
1066
0
                }
1067
0
1068
0
            }
1069
0
1070
0
            ps_tempLeft->u1_cbp = ps_tempLeft->u1_cbp + ((u1_cr_cpb >> 4) << 4);
1071
0
            ps_leftMB = ps_tempLeft;
1072
0
        }
1073
0
1074
0
        ps_dec->p_left_ctxt_mb_info = ps_leftMB;
1075
0
    }
1076
0
    else
1077
0
    {
1078
0
        ps_dec->p_left_ctxt_mb_info = p_ctx_inc_mb_map - 1;
1079
0
        if(!u4_mbskip)
1080
0
        {
1081
0
            *(ps_dec->pu1_left_yuv_dc_csbp) = 0;
1082
0
1083
0
            MEMSET_16BYTES(&pu1_left_mv_ctxt_inc_2d[0][0], 0);
1084
0
            *(UWORD32 *)pi1_left_ref_idx_ctxt_inc = 0;
1085
0
        }
1086
0
    }
1087
0
1088
0
    /*************************************************************************/
1089
0
    /*                Now get the top context mb info                        */
1090
0
    /*************************************************************************/
1091
0
    {
1092
0
        UWORD8 (*u1_top_mv_ctxt_inc_arr_2d)[4] =
1093
0
                        ps_dec->ps_curr_ctxt_mb_info->u1_mv;
1094
0
        WORD8 (*pi1_top_ref_idx_ctxt_inc) =
1095
0
                        ps_dec->ps_curr_ctxt_mb_info->i1_ref_idx;
1096
0
        UWORD8 uc_topMbFldDecFlag = ps_cur_mb_info->ps_top_mb->u1_mb_fld;
1097
0
1098
0
        if(u1_mb_ngbr_availablity & TOP_MB_AVAILABLE_MASK)
1099
0
        {
1100
0
            if(ps_cur_mb_info->i1_offset)
1101
0
                ps_dec->p_top_ctxt_mb_info += 1;
1102
0
1103
0
            if(!u4_mbskip)
1104
0
            {
1105
0
                memcpy(u1_top_mv_ctxt_inc_arr_2d,
1106
0
                       &ps_dec->p_top_ctxt_mb_info->u1_mv, 16);
1107
0
                memcpy(pi1_top_ref_idx_ctxt_inc,
1108
0
                       &ps_dec->p_top_ctxt_mb_info->i1_ref_idx, 4);
1109
0
                if(uc_topMbFldDecFlag ^ u1_cur_mb_fld_flag)
1110
0
                {
1111
0
                    UWORD8 i;
1112
0
                    if(u1_cur_mb_fld_flag)
1113
0
                    {
1114
0
                        for(i = 0; i < 4; i++)
1115
0
                        {
1116
0
                            u1_top_mv_ctxt_inc_arr_2d[i][1] >>= 1;
1117
0
                            u1_top_mv_ctxt_inc_arr_2d[i][3] >>= 1;
1118
0
                        }
1119
0
                    }
1120
0
                    else
1121
0
                    {
1122
0
                        for(i = 0; i < 4; i++)
1123
0
                        {
1124
0
                            u1_top_mv_ctxt_inc_arr_2d[i][1] <<= 1;
1125
0
                            u1_top_mv_ctxt_inc_arr_2d[i][3] <<= 1;
1126
0
                            pi1_top_ref_idx_ctxt_inc[i] -= 1;
1127
0
                        }
1128
0
                    }
1129
0
                }
1130
0
            }
1131
0
        }
1132
0
        else
1133
0
        {
1134
0
            ps_dec->p_top_ctxt_mb_info = p_ctx_inc_mb_map - 1;
1135
0
            if(!u4_mbskip)
1136
0
            {
1137
0
1138
0
                MEMSET_16BYTES(&u1_top_mv_ctxt_inc_arr_2d[0][0], 0);
1139
0
                memset(pi1_top_ref_idx_ctxt_inc, 0, 4);
1140
0
            }
1141
0
        }
1142
0
    }
1143
0
1144
0
    return OK;
1145
0
}
1146
1147
/*****************************************************************************/
1148
/*                                                                           */
1149
/*  Function Name : ih264d_update_mbaff_left_nnz                                    */
1150
/*                                                                           */
1151
/*  Description   : This function updates the left luma and chroma nnz for   */
1152
/*                  mbaff cases.                                             */
1153
/*                                                                           */
1154
/*  Inputs        : <What inputs does the function take?>                    */
1155
/*  Globals       : <Does it use any global variables?>                      */
1156
/*  Processing    : <Describe how the function operates - include algorithm  */
1157
/*                  description>                                             */
1158
/*  Outputs       : <What does the function produce?>                        */
1159
/*  Returns       : <What does the function return?>                         */
1160
/*                                                                           */
1161
/*  Issues        : <List any issues or problems with this function>         */
1162
/*                                                                           */
1163
/*  Revision History:                                                        */
1164
/*                                                                           */
1165
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1166
/*         13 07 2002   Ittiam          Draft                                */
1167
/*                                                                           */
1168
/*****************************************************************************/
1169
void ih264d_update_mbaff_left_nnz(dec_struct_t * ps_dec,
1170
                                  dec_mb_info_t * ps_cur_mb_info)
1171
0
{
1172
0
    UWORD32 *pu4_buf;
1173
0
    UWORD8 *pu1_buf;
1174
0
    if(ps_cur_mb_info->u1_topmb)
1175
0
    {
1176
0
        pu1_buf = ps_dec->pu1_left_nnz_y;
1177
0
        pu4_buf = (UWORD32 *)pu1_buf;
1178
0
        ps_dec->u4_n_left_temp_y = *pu4_buf;
1179
0
1180
0
        pu1_buf = ps_dec->pu1_left_nnz_uv;
1181
0
        pu4_buf = (UWORD32 *)pu1_buf;
1182
0
        ps_dec->u4_n_left_temp_uv = *pu4_buf;
1183
0
    }
1184
0
    else
1185
0
    {
1186
0
1187
0
        ps_dec->u4_n_leftY[0] = ps_dec->u4_n_left_temp_y;
1188
0
        pu1_buf = ps_dec->pu1_left_nnz_y;
1189
0
        pu4_buf = (UWORD32 *)pu1_buf;
1190
0
        ps_dec->u4_n_leftY[1] = *pu4_buf;
1191
0
        ps_dec->u4_n_left_cr[0] = ps_dec->u4_n_left_temp_uv;
1192
0
        pu1_buf = ps_dec->pu1_left_nnz_uv;
1193
0
        pu4_buf = (UWORD32 *)pu1_buf;
1194
0
        ps_dec->u4_n_left_cr[1] = *pu4_buf;
1195
0
1196
0
    }
1197
0
}
1198
1199
/*!
1200
 **************************************************************************
1201
 * \if Function name : ih264d_get_mbaff_neighbours \endif
1202
 *
1203
 * \brief
1204
 *    Gets the neighbors for the current MB if it is of type MB-AFF
1205
 *  frame.
1206
 *
1207
 * \return
1208
 *    None
1209
 *
1210
 **************************************************************************
1211
 */
1212
void ih264d_get_mbaff_neighbours(dec_struct_t * ps_dec,
1213
                                 dec_mb_info_t * ps_cur_mb_info,
1214
                                 UWORD8 uc_curMbFldDecFlag)
1215
0
{
1216
0
1217
0
    mb_neigbour_params_t *ps_left_mb;
1218
0
    mb_neigbour_params_t *ps_top_mb;
1219
0
    mb_neigbour_params_t *ps_top_right_mb = NULL;
1220
0
    mb_neigbour_params_t *ps_curmb;
1221
0
    const UWORD8 u1_topmb = ps_cur_mb_info->u1_topmb;
1222
0
    const UWORD8 uc_botMb = 1 - u1_topmb;
1223
0
    const UWORD32 u4_mb_x = ps_cur_mb_info->u2_mbx;
1224
0
1225
0
    /* Current MbParams location in top row buffer */
1226
0
    ps_curmb = ps_dec->ps_cur_mb_row + (u4_mb_x << 1) + uc_botMb;
1227
0
    ps_left_mb = ps_curmb - 2;
1228
0
    /* point to A if top else A+1 */
1229
0
    if(uc_botMb && (ps_left_mb->u1_mb_fld != uc_curMbFldDecFlag))
1230
0
    {
1231
0
        /* move from A + 1 to A */
1232
0
        ps_left_mb--;
1233
0
    }
1234
0
    ps_cur_mb_info->i1_offset = 0;
1235
0
    if((uc_curMbFldDecFlag == 0) && uc_botMb)
1236
0
    {
1237
0
        mb_neigbour_params_t *ps_topleft_mb;
1238
0
        /* CurMbAddr - 1 */
1239
0
        ps_top_mb = ps_curmb - 1;
1240
0
1241
0
        /* Mark Top right Not available */
1242
0
        /* point to A */
1243
0
        ps_topleft_mb = ps_curmb - 3;
1244
0
1245
0
        if(ps_topleft_mb->u1_mb_fld)
1246
0
        {
1247
0
            /* point to A + 1 */
1248
0
            ps_topleft_mb++;
1249
0
        }
1250
0
        ps_cur_mb_info->u1_topleft_mb_fld = ps_topleft_mb->u1_mb_fld;
1251
0
        ps_cur_mb_info->u1_topleft_mbtype = ps_topleft_mb->u1_mb_type;
1252
0
    }
1253
0
    else
1254
0
    {
1255
0
        /* Top = B + 1 */
1256
0
        ps_top_mb = ps_dec->ps_top_mb_row + (u4_mb_x << 1) + 1;
1257
0
        ps_top_right_mb = ps_top_mb + 2;
1258
0
        ps_cur_mb_info->i1_offset = 4;
1259
0
        /* TopRight =  C + 1 */
1260
0
1261
0
        /* TopLeft = D+1 */
1262
0
        ps_cur_mb_info->u1_topleft_mb_fld = ps_dec->u1_topleft_mb_fld_bot;
1263
0
        ps_cur_mb_info->u1_topleft_mbtype = ps_dec->u1_topleft_mbtype_bot;
1264
0
1265
0
        if(uc_curMbFldDecFlag && u1_topmb)
1266
0
        {
1267
0
            if(ps_top_mb->u1_mb_fld)
1268
0
            {
1269
0
                /* MbAddrB */
1270
0
                ps_top_mb--;
1271
0
                ps_cur_mb_info->i1_offset = 0;
1272
0
            }
1273
0
            /* If topright is field then point to C */
1274
0
            ps_top_right_mb -= ps_top_right_mb->u1_mb_fld ? 1 : 0;
1275
0
            if(ps_cur_mb_info->u1_topleft_mb_fld)
1276
0
            {
1277
0
                /* TopLeft = D */
1278
0
                ps_cur_mb_info->u1_topleft_mb_fld = ps_dec->u1_topleft_mb_fld;
1279
0
                ps_cur_mb_info->u1_topleft_mbtype = ps_dec->u1_topleft_mbtype;
1280
0
            }
1281
0
        }
1282
0
    }
1283
0
    if(u1_topmb)
1284
0
    {
1285
0
        /* Update the parameters of topleftmb*/
1286
0
        ps_dec->u1_topleft_mb_fld = ps_top_mb->u1_mb_fld;
1287
0
        ps_dec->u1_topleft_mbtype = ps_top_mb->u1_mb_type;
1288
0
        /* Set invscan and dequantMatrixScan*/
1289
0
        if(uc_curMbFldDecFlag)
1290
0
        {
1291
0
            ps_dec->pu1_inv_scan = (UWORD8 *)gau1_ih264d_inv_scan_fld;
1292
0
        }
1293
0
        else
1294
0
        {
1295
0
            ps_dec->pu1_inv_scan = (UWORD8 *)gau1_ih264d_inv_scan;
1296
0
        }
1297
0
        ps_dec->pu2_quant_scale_y =
1298
0
                        gau2_ih264_iquant_scale_4x4[ps_dec->u1_qp_y_rem6];
1299
0
        ps_dec->pu2_quant_scale_u =
1300
0
                        gau2_ih264_iquant_scale_4x4[ps_dec->u1_qp_u_rem6];
1301
0
        ps_dec->pu2_quant_scale_v =
1302
0
                        gau2_ih264_iquant_scale_4x4[ps_dec->u1_qp_v_rem6];
1303
0
1304
0
    }
1305
0
    else
1306
0
    {
1307
0
        /* Update the parameters of topleftmb*/
1308
0
        mb_neigbour_params_t *ps_top_mb_temp = ps_dec->ps_top_mb_row
1309
0
                        + (u4_mb_x << 1) + 1;
1310
0
        ps_dec->u1_topleft_mb_fld_bot = ps_top_mb_temp->u1_mb_fld;
1311
0
        ps_dec->u1_topleft_mbtype_bot = ps_top_mb_temp->u1_mb_type;
1312
0
    }
1313
0
1314
0
    ps_cur_mb_info->ps_left_mb = ps_left_mb;
1315
0
    ps_cur_mb_info->ps_top_mb = ps_top_mb;
1316
0
    ps_cur_mb_info->ps_top_right_mb = ps_top_right_mb;
1317
0
    ps_cur_mb_info->ps_curmb = ps_curmb;
1318
0
    ps_curmb->u1_mb_fld = uc_curMbFldDecFlag;
1319
0
1320
0
    {
1321
0
        /* Form Left NNZ */
1322
0
        UWORD8 u1_is_left_mb_fld = ps_left_mb->u1_mb_fld;
1323
0
        UWORD8 *pu1_left_mb_pair_nnz_y = (UWORD8 *)&ps_dec->u4_n_leftY[0];
1324
0
        UWORD8 *pu1_left_mb_pair_nnz_uv = (UWORD8 *)&ps_dec->u4_n_left_cr[0];
1325
0
        UWORD8 *pu1_left_nnz_y = ps_dec->pu1_left_nnz_y;
1326
0
        UWORD8 *pu1_left_nnz_uv = ps_dec->pu1_left_nnz_uv;
1327
0
1328
0
        if(uc_curMbFldDecFlag == u1_is_left_mb_fld)
1329
0
        {
1330
0
            *(UWORD32 *)pu1_left_nnz_y = *(UWORD32 *)(pu1_left_mb_pair_nnz_y
1331
0
                            + (uc_botMb << 2));
1332
0
            *(UWORD32 *)pu1_left_nnz_uv = *(UWORD32 *)(pu1_left_mb_pair_nnz_uv
1333
0
                            + (uc_botMb << 2));
1334
0
        }
1335
0
        else if((uc_curMbFldDecFlag == 0) && u1_topmb && u1_is_left_mb_fld)
1336
0
        {
1337
0
            /* 0 0 1 1 of u4_n_leftY[0], 0 0 2 2 of u4_n_left_cr[0] */
1338
0
            pu1_left_nnz_y[0] = pu1_left_nnz_y[1] = pu1_left_mb_pair_nnz_y[0];
1339
0
            pu1_left_nnz_y[2] = pu1_left_nnz_y[3] = pu1_left_mb_pair_nnz_y[1];
1340
0
            pu1_left_nnz_uv[0] = pu1_left_nnz_uv[1] =
1341
0
                            pu1_left_mb_pair_nnz_uv[0];
1342
0
            pu1_left_nnz_uv[2] = pu1_left_nnz_uv[3] =
1343
0
                            pu1_left_mb_pair_nnz_uv[2];
1344
0
        }
1345
0
        else if((uc_curMbFldDecFlag == 0) && uc_botMb && u1_is_left_mb_fld)
1346
0
        {
1347
0
            /* 2 2 3 3 of u4_n_leftY[0] , 1 1 3 3 of u4_n_left_cr[0] */
1348
0
            pu1_left_nnz_y[0] = pu1_left_nnz_y[1] = pu1_left_mb_pair_nnz_y[2];
1349
0
            pu1_left_nnz_y[2] = pu1_left_nnz_y[3] = pu1_left_mb_pair_nnz_y[3];
1350
0
            pu1_left_nnz_uv[0] = pu1_left_nnz_uv[1] =
1351
0
                            pu1_left_mb_pair_nnz_uv[1];
1352
0
            pu1_left_nnz_uv[2] = pu1_left_nnz_uv[3] =
1353
0
                            pu1_left_mb_pair_nnz_uv[3];
1354
0
        }
1355
0
        else
1356
0
        {
1357
0
            /* 0 2 0 2 of u4_n_leftY[0], u4_n_leftY[1] */
1358
0
            pu1_left_nnz_y[0] = pu1_left_mb_pair_nnz_y[0];
1359
0
            pu1_left_nnz_y[1] = pu1_left_mb_pair_nnz_y[2];
1360
0
            pu1_left_nnz_y[2] = pu1_left_mb_pair_nnz_y[4 + 0];
1361
0
            pu1_left_nnz_y[3] = pu1_left_mb_pair_nnz_y[4 + 2];
1362
0
1363
0
            /* 0 of u4_n_left_cr[0] and 0 u4_n_left_cr[1]
1364
0
             2 of u4_n_left_cr[0] and 2 u4_n_left_cr[1] */
1365
0
            pu1_left_nnz_uv[0] = pu1_left_mb_pair_nnz_uv[0];
1366
0
            pu1_left_nnz_uv[1] = pu1_left_mb_pair_nnz_uv[4 + 0];
1367
0
            pu1_left_nnz_uv[2] = pu1_left_mb_pair_nnz_uv[2];
1368
0
            pu1_left_nnz_uv[3] = pu1_left_mb_pair_nnz_uv[4 + 2];
1369
0
        }
1370
0
    }
1371
0
}
1372
1373
/*
1374
 **************************************************************************
1375
 * \if Function name : ih264d_transfer_mb_group_data \endif
1376
 *
1377
 * \brief
1378
 *     Transfer the Following things
1379
 *     N-Mb DeblkParams Data    ( To Ext DeblkParams Buffer )
1380
 *     N-Mb Recon Data          ( To Ext Frame Buffer )
1381
 *     N-Mb Intrapredline Data  ( Updated Internally)
1382
 *     N-Mb MV Data             ( To Ext MV Buffer )
1383
 *     N-Mb MVTop/TopRight Data ( To Int MV Top Scratch Buffers)
1384
 *
1385
 * \return
1386
 *    None
1387
 *
1388
 **************************************************************************
1389
 */
1390
void ih264d_transfer_mb_group_data(dec_struct_t * ps_dec,
1391
                                   const UWORD8 u1_num_mbs,
1392
                                   const UWORD8 u1_end_of_row, /* Cur n-Mb End of Row Flag */
1393
                                   const UWORD8 u1_end_of_row_next /* Next n-Mb End of Row Flag */
1394
                                   )
1395
220
{
1396
220
    dec_mb_info_t *ps_cur_mb_info = ps_dec->ps_nmb_info;
1397
220
    tfr_ctxt_t *ps_trns_addr = &ps_dec->s_tran_addrecon;
1398
220
    UWORD16 u2_mb_y;
1399
220
    UWORD32 y_offset;
1400
220
    UWORD32 u4_frame_stride;
1401
220
    mb_neigbour_params_t *ps_temp;
1402
220
    const UWORD8 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
1403
220
    UNUSED(u1_end_of_row_next);
1404
220
1405
220
    ps_trns_addr->pu1_dest_y += ps_trns_addr->u4_inc_y[u1_end_of_row];
1406
220
    ps_trns_addr->pu1_dest_u += ps_trns_addr->u4_inc_uv[u1_end_of_row];
1407
220
    ps_trns_addr->pu1_dest_v += ps_trns_addr->u4_inc_uv[u1_end_of_row];
1408
220
1409
220
    /* Swap top and current pointers */
1410
220
    if(u1_end_of_row)
1411
220
    {
1412
220
1413
220
        if(ps_dec->u1_separate_parse)
1414
220
        {
1415
220
            u2_mb_y = ps_dec->i2_dec_thread_mb_y;
1416
220
        }
1417
0
        else
1418
0
        {
1419
0
            ps_temp = ps_dec->ps_cur_mb_row;
1420
0
            ps_dec->ps_cur_mb_row = ps_dec->ps_top_mb_row;
1421
0
            ps_dec->ps_top_mb_row = ps_temp;
1422
0
1423
0
            u2_mb_y = ps_dec->u2_mby + (1 + u1_mbaff);
1424
0
        }
1425
220
1426
220
        u4_frame_stride = ps_dec->u2_frm_wd_y
1427
220
                        << ps_dec->ps_cur_slice->u1_field_pic_flag;
1428
220
        y_offset = (u2_mb_y * u4_frame_stride) << 4;
1429
220
        ps_trns_addr->pu1_dest_y = ps_dec->s_cur_pic.pu1_buf1 + y_offset;
1430
220
1431
220
        u4_frame_stride = ps_dec->u2_frm_wd_uv
1432
220
                        << ps_dec->ps_cur_slice->u1_field_pic_flag;
1433
220
        y_offset = (u2_mb_y * u4_frame_stride) << 3;
1434
220
        ps_trns_addr->pu1_dest_u = ps_dec->s_cur_pic.pu1_buf2 + y_offset;
1435
220
        ps_trns_addr->pu1_dest_v = ps_dec->s_cur_pic.pu1_buf3 + y_offset;
1436
220
1437
220
        ps_trns_addr->pu1_mb_y = ps_trns_addr->pu1_dest_y;
1438
220
        ps_trns_addr->pu1_mb_u = ps_trns_addr->pu1_dest_u;
1439
220
        ps_trns_addr->pu1_mb_v = ps_trns_addr->pu1_dest_v;
1440
220
    }
1441
220
1442
220
    /*
1443
220
     * The Slice boundary is also a valid condition to transfer. So recalculate
1444
220
     * the Left increment, in case the number of MBs is lesser than the
1445
220
     * N MB value. u1_num_mbs will be equal to N of N MB if the entire N Mb is
1446
220
     * decoded.
1447
220
     */
1448
220
    ps_dec->s_tran_addrecon.u2_mv_left_inc = ((u1_num_mbs >> u1_mbaff) - 1)
1449
220
                    << (4 + u1_mbaff);
1450
220
    ps_dec->s_tran_addrecon.u2_mv_top_left_inc = (u1_num_mbs << 2) - 1
1451
220
                    - (u1_mbaff << 2);
1452
220
1453
220
    if(ps_dec->u1_separate_parse == 0)
1454
0
    {
1455
0
        /* reassign left MV and cur MV pointers */
1456
0
        ps_dec->ps_mv_left = ps_dec->ps_mv_cur
1457
0
                        + ps_dec->s_tran_addrecon.u2_mv_left_inc;
1458
0
1459
0
        ps_dec->ps_mv_cur += (u1_num_mbs << 4);
1460
0
    }
1461
220
1462
220
    /* Increment deblock parameters pointer in external memory */
1463
220
1464
220
    if(ps_dec->u1_separate_parse == 0)
1465
0
    {
1466
0
        ps_dec->ps_deblk_mbn += u1_num_mbs;
1467
0
    }
1468
220
1469
220
}
1470
/proc/self/cwd/external/libavc/decoder/ih264d_mb_utils.h
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
#ifndef _IH264D_MB_UTILS_H_
21
#define _IH264D_MB_UTILS_H_
22
/*!
23
 **************************************************************************
24
 * \file ih264d_mb_utils.h
25
 *
26
 * \brief
27
 *    Contains declarations of the utility functions needed to decode MB
28
 *
29
 * \date
30
 *    18/12/2002
31
 *
32
 * \author  AI
33
 **************************************************************************
34
 */
35
#include "ih264_typedefs.h"
36
#include "ih264_macros.h"
37
#include "ih264_platform_macros.h"
38
#include "ih264d_structs.h"
39
40
/*--------------------------------------------------------------------*/
41
/* Macros to get raster scan position of a block[8x8] / sub block[4x4]*/
42
/*--------------------------------------------------------------------*/
43
44
#define GET_BLK_RASTER_POS_X(x)     ((x & 0x01) << 1)
45
#define GET_BLK_RASTER_POS_Y(y)     ((y >> 1)   << 1)
46
#define GET_SUB_BLK_RASTER_POS_X(x) ((x & 0x01))
47
#define GET_SUB_BLK_RASTER_POS_Y(y) ((y >> 1))
48
49
/*--------------------------------------------------------------------*/
50
/* Masks used in decoding of Macroblock                               */
51
/*--------------------------------------------------------------------*/
52
53
4.84k
#define LEFT_MB_AVAILABLE_MASK      0x01
54
4.59k
#define TOP_LEFT_MB_AVAILABLE_MASK  0x02
55
4.80k
#define TOP_MB_AVAILABLE_MASK       0x04
56
4.59k
#define TOP_RIGHT_MB_AVAILABLE_MASK 0x08
57
58
0
#define TOP_RT_SUBBLOCK_MASK_MOD               0xFFF7
59
60
5.06k
#define TOP_RIGHT_DEFAULT_AVAILABLE            0x5750
61
4.59k
#define TOP_RIGHT_TOPR_AVAILABLE               0x0008
62
4.80k
#define TOP_RIGHT_TOP_AVAILABLE                0x0007
63
64
5.06k
#define TOP_LEFT_DEFAULT_AVAILABLE            0xEEE0
65
4.59k
#define TOP_LEFT_TOPL_AVAILABLE               0x0001
66
4.80k
#define TOP_LEFT_TOP_AVAILABLE                0x000E
67
4.84k
#define TOP_LEFT_LEFT_AVAILABLE               0x1110
68
69
#define CHECK_MB_MAP(u4_mb_num, mb_map, u4_cond)                                                    \
70
{                                                                                                   \
71
        UWORD32 u4_bit_number;                                                                      \
72
        volatile UWORD8 *pu1_mb_flag;                                                                       \
73
                                                                                                    \
74
        u4_bit_number = u4_mb_num & 0x07;                                                           \
75
        pu1_mb_flag    = (UWORD8 *)mb_map + (u4_mb_num >> 3);                                                       \
76
                                                                                                    \
77
        u4_cond = CHECKBIT((*pu1_mb_flag), u4_bit_number);                                              \
78
}
79
80
34.5k
#define CHECK_MB_MAP_BYTE(u4_mb_num, mb_map, u4_cond)                                               \
81
34.5k
{                                                                                                   \
82
34.5k
        volatile UWORD8 *pu1_mb_flag;                                                               \
83
34.5k
                                                                                                    \
84
34.5k
        pu1_mb_flag    = (UWORD8 *)mb_map + (u4_mb_num );                                           \
85
34.5k
                                                                                                    \
86
34.5k
        u4_cond = (*pu1_mb_flag);                                                                   \
87
34.5k
}
88
89
#define UPDATE_MB_MAP(u2_frm_wd_in_mbs, u2_mbx, u2_mby, mb_map, mb_count)                     \
90
{                                                                                                   \
91
        UWORD32 u4_bit_number;                                                                      \
92
        UWORD32 u4_mb_number;                                                                       \
93
                                                                                                    \
94
        u4_mb_number    = u2_frm_wd_in_mbs * (u2_mby >> u1_mbaff) + u2_mbx;                   \
95
                                                                                                    \
96
        u4_bit_number = u4_mb_number & 0x07;                                                        \
97
        /*                                                                                          \
98
         * In case of MbAff, update the mb_map only if the entire MB is done. We can check that     \
99
         * by checking if Y is odd, implying that this is the second row in the MbAff MB            \
100
         */                                                                                         \
101
        SET_BIT(mb_map[u4_mb_number >> 3], u4_bit_number);                                           \
102
                                                                                                    \
103
        if (1 == u1_mbaff)                                                                          \
104
        {                                                                                           \
105
            /*                                                                                      \
106
             * If MBAFF u4_flag is set, set this MB and the MB just below this.                        \
107
             * So, add frame width to the MB number and set that bit.                               \
108
             */                                                                                     \
109
            /*                                                                                      \
110
            u4_mb_number    += u2_frm_wd_in_mbs;                                                  \
111
                                                                                                    \
112
            u4_bit_number = u4_mb_number & 0x07;                                                    \
113
                                                                                                    \
114
            SET_BIT(mb_map[u4_mb_number >> 3], u4_bit_number);                                       \
115
            */                                                                                      \
116
        }                                                                                           \
117
                                                                                                    \
118
        /*H264_DEC_DEBUG_PRINT("SETBIT: %d\n", u4_mb_number);*/                                     \
119
        mb_count++;                                                                                 \
120
}
121
122
#define UPDATE_MB_MAP_MBNUM(mb_map, u4_mb_number)                                                   \
123
{                                                                                                   \
124
        UWORD32 u4_bit_number;                                                                      \
125
        volatile UWORD8 *pu1_mb_flag;                                                                       \
126
                                                                                                    \
127
        u4_bit_number = u4_mb_number & 0x07;                                                        \
128
        pu1_mb_flag    = (UWORD8 *)mb_map + (u4_mb_number >> 3);                                                        \
129
        /*                                                                                          \
130
         * In case of MbAff, update the mb_map only if the entire MB is done. We can check that     \
131
         * by checking if Y is odd, implying that this is the second row in the MbAff MB            \
132
         */                                                                                         \
133
        SET_BIT((*pu1_mb_flag), u4_bit_number);                                                          \
134
}
135
136
10.1k
#define UPDATE_MB_MAP_MBNUM_BYTE(mb_map, u4_mb_number)                                                  \
137
10.1k
{                                                                                                   \
138
10.1k
        volatile UWORD8 *pu1_mb_flag;                                                                       \
139
10.1k
                                                                                                    \
140
10.1k
        pu1_mb_flag    = (UWORD8 *)mb_map + (u4_mb_number);                                                     \
141
10.1k
        /*                                                                                          \
142
10.1k
         * In case of MbAff, update the mb_map only if the entire MB is done. We can check that     \
143
10.1k
         * by checking if Y is odd, implying that this is the second row in the MbAff MB            \
144
10.1k
         */                                                                                         \
145
10.1k
        (*pu1_mb_flag) = 1;                                                             \
146
10.1k
}
147
148
5.06k
#define UPDATE_SLICE_NUM_MAP(slice_map, u4_mb_number,u2_slice_num)                                                  \
149
5.06k
{                                                                                                   \
150
5.06k
        volatile UWORD16 *pu2_slice_map;                                                               \
151
5.06k
                                                                                                    \
152
5.06k
        pu2_slice_map    = (UWORD16 *)slice_map + (u4_mb_number);                                         \
153
5.06k
        (*pu2_slice_map) = u2_slice_num;                                                              \
154
5.06k
}
155
156
10.1k
#define GET_SLICE_NUM_MAP(slice_map, mb_number,u2_slice_num)                                                  \
157
10.1k
{                                                                                                   \
158
10.1k
        volatile UWORD16 *pu2_slice_map;                                                               \
159
10.1k
                                                                                                    \
160
10.1k
        pu2_slice_map    = (UWORD16 *)slice_map + (mb_number);                                         \
161
10.1k
        u2_slice_num = (*pu2_slice_map) ;                                                               \
162
10.1k
}
163
164
165
0
#define GET_XPOS_PRED(u1_out,pkd_info)                        \
166
0
{                                                               \
167
0
    WORD32 bit_field;                                           \
168
0
    bit_field = pkd_info & 0x3;                                 \
169
0
    u1_out = bit_field;                                       \
170
0
}
171
172
173
0
#define GET_YPOS_PRED(u1_out,pkd_info)                        \
174
0
{                                                               \
175
0
    WORD32 bit_field;                                           \
176
0
    bit_field = pkd_info >> 2;                                  \
177
0
    u1_out = bit_field & 0x3;                                  \
178
0
}
179
180
181
182
0
#define GET_WIDTH_PRED(u1_out,pkd_info)                        \
183
0
{                                                               \
184
0
    WORD32 bit_field;                                           \
185
0
    bit_field = pkd_info >> 4;                                  \
186
0
    bit_field = (bit_field & 0x3) << 1 ;                        \
187
0
    u1_out = (bit_field == 0)?1:bit_field;                       \
188
0
    }
189
190
0
#define GET_HEIGHT_PRED(u1_out,pkd_info)                        \
191
0
{                                                               \
192
0
    WORD32 bit_field;                                           \
193
0
    bit_field = pkd_info >> 6;                                  \
194
0
    bit_field = (bit_field & 0x3) << 1 ;                        \
195
0
    u1_out = (bit_field == 0)?1:bit_field;                      \
196
0
}
197
198
/*!
199
 **************************************************************************
200
 *   \brief   Masks for elements present in the first column but not on the
201
 *   first row.
202
 **************************************************************************
203
 */
204
#define FIRST_COL_NOT_FIRST_ROW             0xFAFB
205
#define FIRST_ROW_MASK                      0xFFCC
206
/*!
207
 **************************************************************************
208
 *   \brief   Mask for elements presen in the first row but not in the
209
 *   last column.
210
 **************************************************************************
211
 */
212
#define FIRST_ROW_NOT_LAST_COL             0xFFEC
213
/*!
214
 **************************************************************************
215
 *   \brief   Mask for elements presen in the first row but not in the
216
 *   first column.
217
 **************************************************************************
218
 */
219
#define FIRST_ROW_NOT_FIRST_COL            0xFFCD
220
/*!
221
 **************************************************************************
222
 *   \brief   Masks for the top right subMB of a 4x4 block
223
 **************************************************************************
224
 */
225
#define TOP_RT_SUBBLOCK_MASK                0xFFDF
226
/*!
227
 **************************************************************************
228
 *   \brief   Masks for the top left subMB of a 4x4 block
229
 **************************************************************************
230
 */
231
#define TOP_LT_SUBBLOCK_MASK                0xFFFE
232
/*!
233
 **************************************************************************
234
 *   \brief   Indicates if a subMB has a top right subMB available
235
 **************************************************************************
236
 */
237
#define TOP_RT_SUBBLOCK_MB_MASK  0x5F4C
238
239
#define FIRST_COL_MASK           0xFAFA
240
241
/*--------------------------------------------------------------------*/
242
/* Macros to calculate the current position of a MB wrt picture       */
243
/*--------------------------------------------------------------------*/
244
#define MB_LUMA_PIC_OFFSET(mb_x,mb_y,frmWidthY)   (((mb_y)*(frmWidthY) + (mb_x))<<4)
245
#define MB_CHROMA_PIC_OFFSET(mb_x,mb_y,frmWidthUV) (((mb_y)*(frmWidthUV) + (mb_x))<<3)
246
247
/*--------------------------------------------------------------------*/
248
/* Macros to calculate the current position of a MB wrt N[ Num coeff] Array */
249
/*--------------------------------------------------------------------*/
250
#define MB_PARAM_OFFSET(mb_x,mb_y,frmWidthInMbs,u1_mbaff,u1_topmb)  \
251
        ((mb_x << u1_mbaff) + (1 - u1_topmb) + (mb_y * frmWidthInMbs))
252
253
UWORD32 ih264d_get_mb_info_cavlc_mbaff(dec_struct_t * ps_dec,
254
                                       const UWORD16 ui16_curMbAddress,
255
                                       dec_mb_info_t * ps_cur_mb_info,
256
                                       UWORD32 u4_mbskip_run);
257
UWORD32 ih264d_get_mb_info_cavlc_nonmbaff(dec_struct_t * ps_dec,
258
                                          const UWORD16 ui16_curMbAddress,
259
                                          dec_mb_info_t * ps_cur_mb_info,
260
                                          UWORD32 u4_mbskip_run);
261
262
UWORD32 ih264d_get_mb_info_cabac_mbaff(dec_struct_t * ps_dec,
263
                                       const UWORD16 ui16_curMbAddress,
264
                                       dec_mb_info_t * ps_cur_mb_info,
265
                                       UWORD32 u4_mbskip_run);
266
267
UWORD32 ih264d_get_mb_info_cabac_nonmbaff(dec_struct_t * ps_dec,
268
                                          const UWORD16 ui16_curMbAddress,
269
                                          dec_mb_info_t * ps_cur_mb_info,
270
                                          UWORD32 u4_mbskip_run);
271
272
UWORD8 get_cabac_context_non_mbaff(dec_struct_t * ps_dec, UWORD16 u2_mbskip);
273
274
UWORD32 ih264d_get_cabac_context_mbaff(dec_struct_t * ps_dec,
275
                                       dec_mb_info_t * ps_cur_mb_info,
276
                                       UWORD32 u4_mbskip);
277
278
WORD32 PutMbToFrame(dec_struct_t * ps_dec);
279
void ih264d_get_mbaff_neighbours(dec_struct_t * ps_dec,
280
                                 dec_mb_info_t * ps_cur_mb_info,
281
                                 UWORD8 uc_curMbFldDecFlag);
282
283
void ih264d_update_mbaff_left_nnz(dec_struct_t * ps_dec,
284
                                  dec_mb_info_t * ps_cur_mb_info);
285
void ih264d_transfer_mb_group_data(dec_struct_t * ps_dec,
286
                                   const UWORD8 u1_num_mbs,
287
                                   const UWORD8 u1_end_of_row, /* Cur n-Mb End of Row Flag */
288
                                   const UWORD8 u1_end_of_row_next /* Next n-Mb End of Row Flag */
289
                                   );
290
291
//void FillRandomData(UWORD8 *pu1_buf, WORD32 u4_bufSize);
292
293
#endif /* _MB_UTILS_H_ */
/proc/self/cwd/external/libavc/decoder/ih264d_mvpred.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/*!
21
 **************************************************************************
22
 * \file ih264d_mvpred.c
23
 *
24
 * \brief
25
 *    This file contains function specific to decoding Motion vector.
26
 *
27
 * Detailed_description
28
 *
29
 * \date
30
 *    10-12-2002
31
 *
32
 * \author  Arvind Raman
33
 **************************************************************************
34
 */
35
#include <string.h>
36
#include "ih264d_parse_cavlc.h"
37
#include "ih264d_error_handler.h"
38
#include "ih264d_structs.h"
39
#include "ih264d_defs.h"
40
#include "ih264_typedefs.h"
41
#include "ih264_macros.h"
42
#include "ih264_platform_macros.h"
43
#include "ih264d_mb_utils.h"
44
#include "ih264d_defs.h"
45
#include "ih264d_debug.h"
46
#include "ih264d_tables.h"
47
#include "ih264d_process_bslice.h"
48
#include "ih264d_mvpred.h"
49
#include "ih264d_inter_pred.h"
50
#include "ih264d_tables.h"
51
52
/*!
53
 **************************************************************************
54
 * \if ih264d_get_motion_vector_predictor name : Name \endif
55
 *
56
 * \brief
57
 *    The routine calculates the motion vector predictor for a given block,
58
 *    given the candidate MV predictors.
59
 *
60
 * \param ps_mv_pred: Candidate predictors for the current block
61
 * \param ps_currMv: Pointer to the left top edge of the current block in
62
 *     the MV bank
63
 *
64
 * \return
65
 *    _mvPred: The x & y components of the MV predictor.
66
 *
67
 * \note
68
 *    The code implements the logic as described in sec 8.4.1.2.1. Given
69
 *    the candidate predictors and the pointer to the top left edge of the
70
 *    block in the MV bank.
71
 *
72
 **************************************************************************
73
 */
74
75
void ih264d_get_motion_vector_predictor(mv_pred_t * ps_result,
76
                                        mv_pred_t **ps_mv_pred,
77
                                        UWORD8 u1_ref_idx,
78
                                        UWORD8 u1_B,
79
                                        const UWORD8 *pu1_mv_pred_condition)
80
0
{
81
0
    WORD8 c_temp;
82
0
    UWORD8 uc_B2 = (u1_B << 1);
83
0
84
0
    /* If only one of the candidate blocks has a reference frame equal to
85
0
     the current block then use the same block as the final predictor */
86
0
    c_temp =
87
0
                    (ps_mv_pred[LEFT]->i1_ref_frame[u1_B] == u1_ref_idx)
88
0
                                    | ((ps_mv_pred[TOP]->i1_ref_frame[u1_B]
89
0
                                                    == u1_ref_idx) << 1)
90
0
                                    | ((ps_mv_pred[TOP_R]->i1_ref_frame[u1_B]
91
0
                                                    == u1_ref_idx) << 2);
92
0
    c_temp = pu1_mv_pred_condition[c_temp];
93
0
94
0
    if(c_temp != -1)
95
0
    {
96
0
        /* Case when only when one of the cadidate block has the same
97
0
         reference frame as the current block */
98
0
        ps_result->i2_mv[uc_B2 + 0] = ps_mv_pred[c_temp]->i2_mv[uc_B2 + 0];
99
0
        ps_result->i2_mv[uc_B2 + 1] = ps_mv_pred[c_temp]->i2_mv[uc_B2 + 1];
100
0
    }
101
0
    else
102
0
    {
103
0
        WORD32 D0, D1;
104
0
        D0 = MIN(ps_mv_pred[0]->i2_mv[uc_B2 + 0],
105
0
                 ps_mv_pred[1]->i2_mv[uc_B2 + 0]);
106
0
        D1 = MAX(ps_mv_pred[0]->i2_mv[uc_B2 + 0],
107
0
                 ps_mv_pred[1]->i2_mv[uc_B2 + 0]);
108
0
        D1 = MIN(D1, ps_mv_pred[2]->i2_mv[uc_B2 + 0]);
109
0
        ps_result->i2_mv[uc_B2 + 0] = (WORD16)(MAX(D0, D1));
110
0
111
0
        D0 = MIN(ps_mv_pred[0]->i2_mv[uc_B2 + 1],
112
0
                 ps_mv_pred[1]->i2_mv[uc_B2 + 1]);
113
0
        D1 = MAX(ps_mv_pred[0]->i2_mv[uc_B2 + 1],
114
0
                 ps_mv_pred[1]->i2_mv[uc_B2 + 1]);
115
0
        D1 = MIN(D1, ps_mv_pred[2]->i2_mv[uc_B2 + 1]);
116
0
        ps_result->i2_mv[uc_B2 + 1] = (WORD16)(MAX(D0, D1));
117
0
118
0
    }
119
0
}
120
121
/*!
122
 **************************************************************************
123
 * \if ih264d_mbaff_mv_pred name : Name \endif
124
 *
125
 * \brief
126
 *    The routine calculates the motion vector predictor for a given block,
127
 *    given the candidate MV predictors.
128
 *
129
 * \param ps_mv_pred: Candidate predictors for the current block
130
 * \param ps_currMv: Pointer to the left top edge of the current block in
131
 *     the MV bank
132
 *
133
 * \return
134
 *    _mvPred: The x & y components of the MV predictor.
135
 *
136
 * \note
137
 *    The code implements the logic as described in sec 8.4.1.2.1. Given
138
 *    the candidate predictors and the pointer to the top left edge of the
139
 *    block in the MV bank.
140
 *
141
 **************************************************************************
142
 */
143
144
void ih264d_mbaff_mv_pred(mv_pred_t **ps_mv_pred,
145
                          UWORD8 u1_sub_mb_num,
146
                          mv_pred_t *ps_mv_nmb,
147
                          mv_pred_t *ps_mv_ntop,
148
                          dec_struct_t *ps_dec,
149
                          UWORD8 uc_mb_part_width,
150
                          dec_mb_info_t *ps_cur_mb_info,
151
                          UWORD8* pu0_scale)
152
0
{
153
0
    UWORD16 u2_a_in = 0, u2_b_in = 0, u2_c_in = 0, u2_d_in = 0;
154
0
    mv_pred_t *ps_mvpred_l, *ps_mvpred_tmp;
155
0
    UWORD8 u1_sub_mb_x = (u1_sub_mb_num & 3), uc_sub_mb_y = (u1_sub_mb_num >> 2);
156
0
    UWORD8 u1_is_cur_mb_fld, u1_is_left_mb_fld, u1_is_top_mb_fld;
157
0
    UWORD8 u1_is_cur_mb_top;
158
0
159
0
    u1_is_cur_mb_fld = ps_cur_mb_info->u1_mb_field_decodingflag;
160
0
    u1_is_cur_mb_top = ps_cur_mb_info->u1_topmb;
161
0
162
0
    u1_is_left_mb_fld = ps_cur_mb_info->ps_left_mb->u1_mb_fld;
163
0
    u1_is_top_mb_fld = ps_cur_mb_info->ps_top_mb->u1_mb_fld;
164
0
165
0
    /* Checking in the subMB exists, calculating their motion vectors to be
166
0
     used as predictors and the reference frames of those subMBs */
167
0
    ps_mv_pred[LEFT] = &ps_dec->s_default_mv_pred;
168
0
    ps_mv_pred[TOP] = &(ps_dec->s_default_mv_pred);
169
0
    ps_mv_pred[TOP_R] = &(ps_dec->s_default_mv_pred);
170
0
171
0
    /* Check if the left subMb is available */
172
0
    if(u1_sub_mb_x)
173
0
    {
174
0
        u2_a_in = 1;
175
0
        ps_mv_pred[LEFT] = (ps_mv_nmb - 1);
176
0
    }
177
0
    else
178
0
    {
179
0
        UWORD8 uc_temp;
180
0
        u2_a_in = (ps_cur_mb_info->u1_mb_ngbr_availablity & LEFT_MB_AVAILABLE_MASK);
181
0
        if(u2_a_in)
182
0
        {
183
0
            ps_mvpred_l = (ps_dec->u4_num_pmbair) ?
184
0
                            ps_mv_nmb :
185
0
                            (ps_dec->ps_mv_left + (uc_sub_mb_y << 2) + 48
186
0
                                            - (u1_is_cur_mb_top << 4));
187
0
            uc_temp = 29;
188
0
            if(u1_is_cur_mb_fld ^ u1_is_left_mb_fld)
189
0
            {
190
0
                if(u1_is_left_mb_fld)
191
0
                {
192
0
                    uc_temp +=
193
0
                                    (((uc_sub_mb_y & 1) << 2)
194
0
                                                    + ((uc_sub_mb_y & 2) << 1));
195
0
                    uc_temp += ((u1_is_cur_mb_top) ? 0 : 8);
196
0
                }
197
0
                else
198
0
                {
199
0
                    uc_temp = uc_temp - (uc_sub_mb_y << 2);
200
0
                    uc_temp += ((u1_is_cur_mb_top) ? 0 : 16);
201
0
                }
202
0
            }
203
0
            ps_mv_pred[LEFT] = (ps_mvpred_l - uc_temp);
204
0
            pu0_scale[LEFT] = u1_is_cur_mb_fld - u1_is_left_mb_fld;
205
0
        }
206
0
    }
207
0
208
0
    /* Check if the top subMB is available */
209
0
    if((uc_sub_mb_y > 0) || ((u1_is_cur_mb_top | u1_is_cur_mb_fld) == 0))
210
0
    {
211
0
        u2_b_in = 1;
212
0
        ps_mv_pred[TOP] = ps_mv_nmb - 4;
213
0
    }
214
0
    else
215
0
    {
216
0
        u2_b_in = (ps_cur_mb_info->u1_mb_ngbr_availablity & TOP_MB_AVAILABLE_MASK);
217
0
        if(u2_b_in)
218
0
        {
219
0
            /* CHANGED CODE */
220
0
221
0
            if(u1_is_top_mb_fld && u1_is_cur_mb_fld)
222
0
                ps_mvpred_tmp = ps_mv_ntop;
223
0
            else
224
0
            {
225
0
                ps_mvpred_tmp = ps_mv_ntop;
226
0
                if(u1_is_cur_mb_top)
227
0
                    ps_mvpred_tmp += 16;
228
0
            }
229
0
230
0
            ps_mv_pred[TOP] = ps_mvpred_tmp;
231
0
            pu0_scale[TOP] = u1_is_cur_mb_fld - u1_is_top_mb_fld;
232
0
        }
233
0
    }
234
0
235
0
    /* Check if the top right subMb is available. The top right subMb is
236
0
     defined as the top right subMb at the top right corner of the MB
237
0
     partition. The top right subMb index starting from the top left
238
0
     corner of the MB partition is given by
239
0
     TopRightSubMbIndx = TopLeftSubMbIndx + (WidthOfMbPartition - 6) / 2
240
0
     */
241
0
    u2_c_in = CHECKBIT(ps_cur_mb_info->u2_top_right_avail_mask,
242
0
                        (u1_sub_mb_num + uc_mb_part_width - 1));
243
0
    if(u2_c_in)
244
0
    {
245
0
        ps_mv_pred[TOP_R] = ps_mv_pred[TOP] + uc_mb_part_width;
246
0
        pu0_scale[TOP_R] = pu0_scale[TOP];
247
0
        if((uc_sub_mb_y == 0) && ((u1_sub_mb_x + uc_mb_part_width) > 3))
248
0
        {
249
0
            UWORD8 uc_isTopRtMbFld;
250
0
            uc_isTopRtMbFld = ps_cur_mb_info->ps_top_right_mb->u1_mb_fld;
251
0
            /* CHANGED CODE */
252
0
            ps_mvpred_tmp = ps_mv_ntop + uc_mb_part_width + 12;
253
0
            ps_mvpred_tmp += (u1_is_cur_mb_top) ? 16 : 0;
254
0
            ps_mvpred_tmp += (u1_is_cur_mb_fld && u1_is_cur_mb_top && uc_isTopRtMbFld) ?
255
0
                            0 : 16;
256
0
            ps_mv_pred[TOP_R] = ps_mvpred_tmp;
257
0
            pu0_scale[TOP_R] = u1_is_cur_mb_fld - uc_isTopRtMbFld;
258
0
        }
259
0
    }
260
0
    else
261
0
    {
262
0
        u2_d_in = CHECKBIT(ps_cur_mb_info->u2_top_left_avail_mask, u1_sub_mb_num);
263
0
264
0
        /* Check if the the top left subMB is available */
265
0
        if(u2_d_in)
266
0
        {
267
0
            UWORD8 uc_isTopLtMbFld;
268
0
269
0
            ps_mv_pred[TOP_R] = ps_mv_pred[TOP] - 1;
270
0
            pu0_scale[TOP_R] = pu0_scale[TOP];
271
0
272
0
            if(u1_sub_mb_x == 0)
273
0
            {
274
0
                if((uc_sub_mb_y > 0) || ((u1_is_cur_mb_top | u1_is_cur_mb_fld) == 0))
275
0
                {
276
0
                    uc_isTopLtMbFld = u1_is_left_mb_fld;
277
0
                    ps_mvpred_tmp = ps_mv_pred[LEFT] - 4;
278
0
279
0
                    if((u1_is_cur_mb_fld == 0) && uc_isTopLtMbFld)
280
0
                    {
281
0
                        ps_mvpred_tmp = ps_mv_pred[LEFT] + 16;
282
0
                        ps_mvpred_tmp -= (uc_sub_mb_y & 1) ? 0 : 4;
283
0
                    }
284
0
                }
285
0
                else
286
0
                {
287
0
                    UWORD32 u4_cond = ps_dec->u4_num_pmbair;
288
0
                    uc_isTopLtMbFld = ps_cur_mb_info->u1_topleft_mb_fld;
289
0
290
0
                    /* CHANGED CODE */
291
0
                    ps_mvpred_tmp = ps_mv_ntop - 29;
292
0
                    ps_mvpred_tmp += (u1_is_cur_mb_top) ? 16 : 0;
293
0
                    if(u1_is_cur_mb_fld && u1_is_cur_mb_top)
294
0
                        ps_mvpred_tmp -= (uc_isTopLtMbFld) ? 16 : 0;
295
0
                }
296
0
                ps_mv_pred[TOP_R] = ps_mvpred_tmp;
297
0
                pu0_scale[TOP_R] = u1_is_cur_mb_fld - uc_isTopLtMbFld;
298
0
            }
299
0
        }
300
0
        else if(u2_b_in == 0)
301
0
        {
302
0
            /* If all the subMBs B, C, D are all out of the frame then their MV
303
0
             and their reference picture is equal to that of A */
304
0
            ps_mv_pred[TOP] = ps_mv_pred[LEFT];
305
0
            ps_mv_pred[TOP_R] = ps_mv_pred[LEFT];
306
0
            pu0_scale[TOP] = pu0_scale[LEFT];
307
0
            pu0_scale[TOP_R] = pu0_scale[LEFT];
308
0
        }
309
0
    }
310
0
}
311
312
/*!
313
 **************************************************************************
314
 * \if ih264d_non_mbaff_mv_pred name : Name \endif
315
 *
316
 * \brief
317
 *    The routine calculates the motion vector predictor for a given block,
318
 *    given the candidate MV predictors.
319
 *
320
 * \param ps_mv_pred: Candidate predictors for the current block
321
 * \param ps_currMv: Pointer to the left top edge of the current block in
322
 *     the MV bank
323
 *
324
 * \return
325
 *    _mvPred: The x & y components of the MV predictor.
326
 *
327
 * \note
328
 *    The code implements the logic as described in sec 8.4.1.2.1. Given
329
 *    the candidate predictors and the pointer to the top left edge of the
330
 *    block in the MV bank.
331
 *
332
 **************************************************************************
333
 */
334
#if(!MVPRED_NONMBAFF)
335
void ih264d_non_mbaff_mv_pred(mv_pred_t **ps_mv_pred,
336
                              UWORD8 u1_sub_mb_num,
337
                              mv_pred_t *ps_mv_nmb,
338
                              mv_pred_t *ps_mv_ntop,
339
                              dec_struct_t *ps_dec,
340
                              UWORD8 uc_mb_part_width,
341
                              dec_mb_info_t *ps_cur_mb_info)
342
0
{
343
0
    UWORD16 u2_b_in = 0, u2_c_in = 0, u2_d_in = 0;
344
0
    UWORD8 u1_sub_mb_x = (u1_sub_mb_num & 3), uc_sub_mb_y = (u1_sub_mb_num >> 2);
345
0
346
0
    /* Checking in the subMB exists, calculating their motion vectors to be
347
0
     used as predictors and the reference frames of those subMBs */
348
0
349
0
    ps_mv_pred[LEFT] = &ps_dec->s_default_mv_pred;
350
0
    ps_mv_pred[TOP] = &(ps_dec->s_default_mv_pred);
351
0
    ps_mv_pred[TOP_R] = &(ps_dec->s_default_mv_pred);
352
0
    /* Check if the left subMb is available */
353
0
354
0
    if(u1_sub_mb_x)
355
0
    {
356
0
        ps_mv_pred[LEFT] = (ps_mv_nmb - 1);
357
0
    }
358
0
    else
359
0
    {
360
0
        if(ps_cur_mb_info->u1_mb_ngbr_availablity & LEFT_MB_AVAILABLE_MASK)
361
0
        {
362
0
            ps_mv_pred[LEFT] = (ps_mv_nmb - 13);
363
0
        }
364
0
    }
365
0
366
0
    /* Check if the top subMB is available */
367
0
    if(uc_sub_mb_y)
368
0
    {
369
0
        u2_b_in = 1;
370
0
        ps_mv_ntop = ps_mv_nmb - 4;
371
0
        ps_mv_pred[TOP] = ps_mv_ntop;
372
0
373
0
    }
374
0
    else
375
0
    {
376
0
        u2_b_in = (ps_cur_mb_info->u1_mb_ngbr_availablity & TOP_MB_AVAILABLE_MASK);
377
0
        if(u2_b_in)
378
0
        {
379
0
            ps_mv_pred[TOP] = ps_mv_ntop;
380
0
        }
381
0
    }
382
0
383
0
    /* Check if the top right subMb is available. The top right subMb is
384
0
     defined as the top right subMb at the top right corner of the MB
385
0
     partition. The top right subMb index starting from the top left
386
0
     corner of the MB partition is given by
387
0
     TopRightSubMbIndx = TopLeftSubMbIndx + (WidthOfMbPartition - 6) / 2
388
0
     */
389
0
    u2_c_in = CHECKBIT(ps_cur_mb_info->u2_top_right_avail_mask,
390
0
                        (u1_sub_mb_num + uc_mb_part_width - 1));
391
0
    if(u2_c_in)
392
0
    {
393
0
        ps_mv_pred[TOP_R] = (ps_mv_ntop + uc_mb_part_width);
394
0
395
0
        if(uc_sub_mb_y == 0)
396
0
        {
397
0
            /* CHANGED CODE */
398
0
            if((u1_sub_mb_x + uc_mb_part_width) > 3)
399
0
                ps_mv_pred[TOP_R] += 12;
400
0
        }
401
0
    }
402
0
    else
403
0
    {
404
0
        u2_d_in = CHECKBIT(ps_cur_mb_info->u2_top_left_avail_mask, u1_sub_mb_num);
405
0
        /* Check if the the top left subMB is available */
406
0
        if(u2_d_in)
407
0
        {
408
0
            /* CHANGED CODE */
409
0
            ps_mv_pred[TOP_R] = (ps_mv_ntop - 1);
410
0
            if(u1_sub_mb_x == 0)
411
0
            {
412
0
                if(uc_sub_mb_y)
413
0
                {
414
0
                    ps_mv_pred[TOP_R] = (ps_mv_nmb - 17);
415
0
                }
416
0
                else
417
0
                {
418
0
                    /* CHANGED CODE */
419
0
                    ps_mv_pred[TOP_R] -= 12;
420
0
                }
421
0
            }
422
0
        }
423
0
        else if(u2_b_in == 0)
424
0
        {
425
0
            /* If all the subMBs B, C, D are all out of the frame then their MV
426
0
             and their reference picture is equal to that of A */
427
0
            ps_mv_pred[TOP] = ps_mv_pred[LEFT];
428
0
            ps_mv_pred[TOP_R] = ps_mv_pred[LEFT];
429
0
        }
430
0
    }
431
0
}
432
#endif
433
434
/*****************************************************************************/
435
/*                                                                           */
436
/*  Function Name : ih264d_mvpred_nonmbaffB                                         */
437
/*                                                                           */
438
/*  Description   : This function calculates the motion vector predictor,    */
439
/*                  for B-Slices                                             */
440
/*  Inputs        : <What inputs does the function take?>                    */
441
/*  Globals       : None                                                     */
442
/*  Processing    : The neighbours A(Left),B(Top),C(TopRight) are calculated */
443
/*                  and based on the type of Mb the prediction is            */
444
/*                  appropriately done                                       */
445
/*  Outputs       : populates ps_mv_final_pred structure                       */
446
/*  Returns       : u1_direct_zero_pred_flag which is used only in              */
447
/*                    decodeSpatialdirect()                                  */
448
/*                                                                           */
449
/*  Issues        : <List any issues or problems with this function>         */
450
/*                                                                           */
451
/*  Revision History:                                                        */
452
/*                                                                           */
453
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
454
/*         03 05 2005   TA              First Draft                          */
455
/*                                                                           */
456
/*****************************************************************************/
457
#if(!MVPRED_NONMBAFF)
458
UWORD8 ih264d_mvpred_nonmbaffB(dec_struct_t *ps_dec,
459
                               dec_mb_info_t *ps_cur_mb_info,
460
                               mv_pred_t *ps_mv_nmb,
461
                               mv_pred_t *ps_mv_ntop,
462
                               mv_pred_t *ps_mv_final_pred,
463
                               UWORD8 u1_sub_mb_num,
464
                               UWORD8 uc_mb_part_width,
465
                               UWORD8 u1_lx_start,
466
                               UWORD8 u1_lxend,
467
                               UWORD8 u1_mb_mc_mode)
468
0
{
469
0
    UWORD8 u1_a_in, u1_b_in, uc_temp1, uc_temp2, uc_temp3;
470
0
    mv_pred_t *ps_mv_pred[3];
471
0
    UWORD8 uc_B2, uc_lx, u1_ref_idx;
472
0
    UWORD8 u1_direct_zero_pred_flag = 0;
473
0
474
0
    ih264d_non_mbaff_mv_pred(ps_mv_pred, u1_sub_mb_num, ps_mv_nmb, ps_mv_ntop,
475
0
                             ps_dec, uc_mb_part_width, ps_cur_mb_info);
476
0
477
0
    for(uc_lx = u1_lx_start; uc_lx < u1_lxend; uc_lx++)
478
0
    {
479
0
        u1_ref_idx = ps_mv_final_pred->i1_ref_frame[uc_lx];
480
0
        uc_B2 = (uc_lx << 1);
481
0
        switch(u1_mb_mc_mode)
482
0
        {
483
0
            case PRED_16x8:
484
0
                /* Directional prediction for a 16x8 MB partition */
485
0
                if(u1_sub_mb_num == 0)
486
0
                {
487
0
                    /* Calculating the MV pred for the top 16x8 block */
488
0
                    if(ps_mv_pred[TOP]->i1_ref_frame[uc_lx] == u1_ref_idx)
489
0
                    {
490
0
                        /* If the reference frame used by the top subMB is same as the
491
0
                         reference frame used by the current block then MV predictor to
492
0
                         be used for the current block is same as the MV of the top
493
0
                         subMB */
494
0
                        ps_mv_final_pred->i2_mv[uc_B2 + 0] =
495
0
                                        ps_mv_pred[TOP]->i2_mv[uc_B2 + 0];
496
0
                        ps_mv_final_pred->i2_mv[uc_B2 + 1] =
497
0
                                        ps_mv_pred[TOP]->i2_mv[uc_B2 + 1];
498
0
                    }
499
0
                    else
500
0
                    {
501
0
                        /* The MV predictor is calculated according to the process
502
0
                         defined in 8.4.1.2.1 */
503
0
                        ih264d_get_motion_vector_predictor(
504
0
                                        ps_mv_final_pred,
505
0
                                        ps_mv_pred,
506
0
                                        u1_ref_idx,
507
0
                                        uc_lx,
508
0
                                        (const UWORD8 *)gau1_ih264d_mv_pred_condition);
509
0
                    }
510
0
                }
511
0
                else
512
0
                {
513
0
                    if(ps_mv_pred[LEFT]->i1_ref_frame[uc_lx] == u1_ref_idx)
514
0
                    {
515
0
                        /* If the reference frame used by the left subMB is same as the
516
0
                         reference frame used by the current block then MV predictor to
517
0
                         be used for the current block is same as the MV of the left
518
0
                         subMB */
519
0
                        ps_mv_final_pred->i2_mv[uc_B2 + 0] =
520
0
                                        ps_mv_pred[LEFT]->i2_mv[uc_B2 + 0];
521
0
                        ps_mv_final_pred->i2_mv[uc_B2 + 1] =
522
0
                                        ps_mv_pred[LEFT]->i2_mv[uc_B2 + 1];
523
0
                    }
524
0
                    else
525
0
                    {
526
0
                        /* The MV predictor is calculated according to the process
527
0
                         defined in 8.4.1.2.1 */
528
0
                        ih264d_get_motion_vector_predictor(
529
0
                                        ps_mv_final_pred,
530
0
                                        ps_mv_pred,
531
0
                                        u1_ref_idx,
532
0
                                        uc_lx,
533
0
                                        (const UWORD8 *)gau1_ih264d_mv_pred_condition);
534
0
                    }
535
0
                }
536
0
                break;
537
0
            case PRED_8x16:
538
0
                /* Directional prediction for a 8x16 MB partition */
539
0
                if(u1_sub_mb_num == 0)
540
0
                {
541
0
                    if(ps_mv_pred[LEFT]->i1_ref_frame[uc_lx] == u1_ref_idx)
542
0
                    {
543
0
                        /* If the reference frame used by the left subMB is same as the
544
0
                         reference frame used by the current block then MV predictor to
545
0
                         be used for the current block is same as the MV of the left
546
0
                         subMB */
547
0
                        ps_mv_final_pred->i2_mv[uc_B2 + 0] =
548
0
                                        ps_mv_pred[LEFT]->i2_mv[uc_B2 + 0];
549
0
                        ps_mv_final_pred->i2_mv[uc_B2 + 1] =
550
0
                                        ps_mv_pred[LEFT]->i2_mv[uc_B2 + 1];
551
0
                    }
552
0
                    else
553
0
                    {
554
0
                        /* The MV predictor is calculated according to the process
555
0
                         defined in 8.4.1.2.1 */
556
0
                        ih264d_get_motion_vector_predictor(
557
0
                                        ps_mv_final_pred,
558
0
                                        ps_mv_pred,
559
0
                                        u1_ref_idx,
560
0
                                        uc_lx,
561
0
                                        (const UWORD8 *)gau1_ih264d_mv_pred_condition);
562
0
                    }
563
0
                }
564
0
                else
565
0
                {
566
0
                    if(ps_mv_pred[TOP_R]->i1_ref_frame[uc_lx] == u1_ref_idx)
567
0
                    {
568
0
                        /* If the reference frame used by the top right subMB is same as
569
0
                         the reference frame used by the current block then MV
570
0
                         predictor to be used for the current block is same as the MV
571
0
                         of the left subMB */
572
0
                        ps_mv_final_pred->i2_mv[uc_B2 + 0] =
573
0
                                        ps_mv_pred[TOP_R]->i2_mv[uc_B2 + 0];
574
0
                        ps_mv_final_pred->i2_mv[uc_B2 + 1] =
575
0
                                        ps_mv_pred[TOP_R]->i2_mv[uc_B2 + 1];
576
0
                    }
577
0
                    else
578
0
                    {
579
0
                        /* The MV predictor is calculated according to the process
580
0
                         defined in 8.4.1.2.1 */
581
0
                        ih264d_get_motion_vector_predictor(
582
0
                                        ps_mv_final_pred,
583
0
                                        ps_mv_pred,
584
0
                                        u1_ref_idx,
585
0
                                        uc_lx,
586
0
                                        (const UWORD8 *)gau1_ih264d_mv_pred_condition);
587
0
                    }
588
0
                }
589
0
                break;
590
0
            case B_DIRECT_SPATIAL:
591
0
                /* Case when the MB has been skipped */
592
0
                /* If either of left or the top subMB is not present
593
0
                 OR
594
0
                 If both the MV components of either the left or the top subMB are
595
0
                 zero and their reference frame pointer pointing to 0
596
0
                 then MV for the skipped MB is zero
597
0
                 else the Median of the mv_pred_t is used */
598
0
                uc_temp1 = (UWORD8)ps_mv_pred[LEFT]->i1_ref_frame[0];
599
0
                uc_temp2 = (UWORD8)ps_mv_pred[TOP]->i1_ref_frame[0];
600
0
                uc_temp3 = (UWORD8)ps_mv_pred[TOP_R]->i1_ref_frame[0];
601
0
602
0
                ps_mv_final_pred->i1_ref_frame[0] = MIN(uc_temp1,
603
0
                                                      MIN(uc_temp2, uc_temp3));
604
0
605
0
                uc_temp1 = (UWORD8)ps_mv_pred[LEFT]->i1_ref_frame[1];
606
0
                uc_temp2 = (UWORD8)ps_mv_pred[TOP]->i1_ref_frame[1];
607
0
                uc_temp3 = (UWORD8)ps_mv_pred[TOP_R]->i1_ref_frame[1];
608
0
609
0
                ps_mv_final_pred->i1_ref_frame[1] = MIN(uc_temp1,
610
0
                                                      MIN(uc_temp2, uc_temp3));
611
0
612
0
                if((ps_mv_final_pred->i1_ref_frame[0] < 0)
613
0
                                && (ps_mv_final_pred->i1_ref_frame[1] < 0))
614
0
                {
615
0
                    u1_direct_zero_pred_flag = 1;
616
0
                    ps_mv_final_pred->i1_ref_frame[0] = 0;
617
0
                    ps_mv_final_pred->i1_ref_frame[1] = 0;
618
0
                }
619
0
                ih264d_get_motion_vector_predictor(
620
0
                                ps_mv_final_pred, ps_mv_pred,
621
0
                                ps_mv_final_pred->i1_ref_frame[0], 0,
622
0
                                (const UWORD8 *)gau1_ih264d_mv_pred_condition);
623
0
624
0
                ih264d_get_motion_vector_predictor(
625
0
                                ps_mv_final_pred, ps_mv_pred,
626
0
                                ps_mv_final_pred->i1_ref_frame[1], 1,
627
0
                                (const UWORD8 *)gau1_ih264d_mv_pred_condition);
628
0
629
0
                break;
630
0
            case MB_SKIP:
631
0
                /* Case when the MB has been skipped */
632
0
                /* If either of left or the top subMB is not present
633
0
                 OR
634
0
                 If both the MV components of either the left or the top subMB are
635
0
                 zero and their reference frame pointer pointing to 0
636
0
                 then MV for the skipped MB is zero
637
0
                 else the Median of the mv_pred_t is used */
638
0
                u1_a_in = (ps_cur_mb_info->u1_mb_ngbr_availablity &
639
0
                LEFT_MB_AVAILABLE_MASK);
640
0
                u1_b_in = (ps_cur_mb_info->u1_mb_ngbr_availablity &
641
0
                TOP_MB_AVAILABLE_MASK);
642
0
                if(((u1_a_in * u1_b_in) == 0)
643
0
                                || ((ps_mv_pred[LEFT]->i2_mv[0]
644
0
                                                | ps_mv_pred[LEFT]->i2_mv[1]
645
0
                                                | ps_mv_pred[LEFT]->i1_ref_frame[0])
646
0
                                                == 0)
647
0
                                || ((ps_mv_pred[TOP]->i2_mv[0]
648
0
                                                | ps_mv_pred[TOP]->i2_mv[1]
649
0
                                                | ps_mv_pred[TOP]->i1_ref_frame[0])
650
0
                                                == 0))
651
0
                {
652
0
                    ps_mv_final_pred->i2_mv[0] = 0;
653
0
                    ps_mv_final_pred->i2_mv[1] = 0;
654
0
                    break;
655
0
                }
656
0
                /* If the condition above is not true calculate the MV predictor
657
0
                 according to the process defined in sec 8.4.1.2.1 */
658
0
            default:
659
0
                ih264d_get_motion_vector_predictor(
660
0
                                ps_mv_final_pred, ps_mv_pred, u1_ref_idx, uc_lx,
661
0
                                (const UWORD8 *)gau1_ih264d_mv_pred_condition);
662
0
                break;
663
0
        }
664
0
    }
665
0
    return (u1_direct_zero_pred_flag);
666
0
}
667
#endif
668
669
/*****************************************************************************/
670
/*                                                                           */
671
/*  Function Name : ih264d_mvpred_nonmbaff                                          */
672
/*                                                                           */
673
/*  Description   : This function calculates the motion vector predictor,    */
674
/*                  for all the slice types other than B_SLICE               */
675
/*  Inputs        : <What inputs does the function take?>                    */
676
/*  Globals       : None                                                     */
677
/*  Processing    : The neighbours A(Left),B(Top),C(TopRight) are calculated */
678
/*                  and based on the type of Mb the prediction is            */
679
/*                  appropriately done                                       */
680
/*  Outputs       : populates ps_mv_final_pred structure                       */
681
/*  Returns       : u1_direct_zero_pred_flag which is used only in              */
682
/*                    decodeSpatialdirect()                                  */
683
/*                                                                           */
684
/*  Issues        : <List any issues or problems with this function>         */
685
/*                                                                           */
686
/*  Revision History:                                                        */
687
/*                                                                           */
688
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
689
/*         03 05 2005   TA              First Draft                          */
690
/*                                                                           */
691
/*****************************************************************************/
692
#if(!MVPRED_NONMBAFF)
693
UWORD8 ih264d_mvpred_nonmbaff(dec_struct_t *ps_dec,
694
                              dec_mb_info_t *ps_cur_mb_info,
695
                              mv_pred_t *ps_mv_nmb,
696
                              mv_pred_t *ps_mv_ntop,
697
                              mv_pred_t *ps_mv_final_pred,
698
                              UWORD8 u1_sub_mb_num,
699
                              UWORD8 uc_mb_part_width,
700
                              UWORD8 u1_lx_start,
701
                              UWORD8 u1_lxend,
702
                              UWORD8 u1_mb_mc_mode)
703
0
{
704
0
    UWORD8 u1_a_in, u1_b_in, uc_temp1, uc_temp2, uc_temp3;
705
0
    mv_pred_t *ps_mv_pred[3];
706
0
    UWORD8 u1_ref_idx;
707
0
    UWORD8 u1_direct_zero_pred_flag = 0;
708
0
    UNUSED(u1_lx_start);
709
0
    UNUSED(u1_lxend);
710
0
    ih264d_non_mbaff_mv_pred(ps_mv_pred, u1_sub_mb_num, ps_mv_nmb, ps_mv_ntop,
711
0
                             ps_dec, uc_mb_part_width, ps_cur_mb_info);
712
0
713
0
    u1_ref_idx = ps_mv_final_pred->i1_ref_frame[0];
714
0
715
0
    switch(u1_mb_mc_mode)
716
0
    {
717
0
        case PRED_16x8:
718
0
            /* Directional prediction for a 16x8 MB partition */
719
0
            if(u1_sub_mb_num == 0)
720
0
            {
721
0
                /* Calculating the MV pred for the top 16x8 block */
722
0
                if(ps_mv_pred[TOP]->i1_ref_frame[0] == u1_ref_idx)
723
0
                {
724
0
                    /* If the reference frame used by the top subMB is same as the
725
0
                     reference frame used by the current block then MV predictor to
726
0
                     be used for the current block is same as the MV of the top
727
0
                     subMB */
728
0
729
0
                    ps_mv_final_pred->i2_mv[0] = ps_mv_pred[TOP]->i2_mv[0];
730
0
                    ps_mv_final_pred->i2_mv[1] = ps_mv_pred[TOP]->i2_mv[1];
731
0
                }
732
0
                else
733
0
                {
734
0
                    /* The MV predictor is calculated according to the process
735
0
                     defined in 8.4.1.2.1 */
736
0
                    ih264d_get_motion_vector_predictor(
737
0
                                    ps_mv_final_pred,
738
0
                                    ps_mv_pred,
739
0
                                    u1_ref_idx,
740
0
                                    0,
741
0
                                    (const UWORD8 *)gau1_ih264d_mv_pred_condition);
742
0
                }
743
0
            }
744
0
            else
745
0
            {
746
0
                if(ps_mv_pred[LEFT]->i1_ref_frame[0] == u1_ref_idx)
747
0
                {
748
0
                    /* If the reference frame used by the left subMB is same as the
749
0
                     reference frame used by the current block then MV predictor to
750
0
                     be used for the current block is same as the MV of the left
751
0
                     subMB */
752
0
753
0
                    ps_mv_final_pred->i2_mv[0] = ps_mv_pred[LEFT]->i2_mv[0];
754
0
                    ps_mv_final_pred->i2_mv[1] = ps_mv_pred[LEFT]->i2_mv[1];
755
0
                }
756
0
                else
757
0
                {
758
0
                    /* The MV predictor is calculated according to the process
759
0
                     defined in 8.4.1.2.1 */
760
0
                    ih264d_get_motion_vector_predictor(
761
0
                                    ps_mv_final_pred,
762
0
                                    ps_mv_pred,
763
0
                                    u1_ref_idx,
764
0
                                    0,
765
0
                                    (const UWORD8 *)gau1_ih264d_mv_pred_condition);
766
0
                }
767
0
            }
768
0
            break;
769
0
        case PRED_8x16:
770
0
            /* Directional prediction for a 8x16 MB partition */
771
0
            if(u1_sub_mb_num == 0)
772
0
            {
773
0
                if(ps_mv_pred[LEFT]->i1_ref_frame[0] == u1_ref_idx)
774
0
                {
775
0
                    /* If the reference frame used by the left subMB is same as the
776
0
                     reference frame used by the current block then MV predictor to
777
0
                     be used for the current block is same as the MV of the left
778
0
                     subMB */
779
0
780
0
                    ps_mv_final_pred->i2_mv[0] = ps_mv_pred[LEFT]->i2_mv[0];
781
0
                    ps_mv_final_pred->i2_mv[1] = ps_mv_pred[LEFT]->i2_mv[1];
782
0
                }
783
0
                else
784
0
                {
785
0
                    /* The MV predictor is calculated according to the process
786
0
                     defined in 8.4.1.2.1 */
787
0
                    ih264d_get_motion_vector_predictor(
788
0
                                    ps_mv_final_pred,
789
0
                                    ps_mv_pred,
790
0
                                    u1_ref_idx,
791
0
                                    0,
792
0
                                    (const UWORD8 *)gau1_ih264d_mv_pred_condition);
793
0
                }
794
0
            }
795
0
            else
796
0
            {
797
0
                if(ps_mv_pred[TOP_R]->i1_ref_frame[0] == u1_ref_idx)
798
0
                {
799
0
                    /* If the reference frame used by the top right subMB is same as
800
0
                     the reference frame used by the current block then MV
801
0
                     predictor to be used for the current block is same as the MV
802
0
                     of the left subMB */
803
0
804
0
                    ps_mv_final_pred->i2_mv[0] = ps_mv_pred[TOP_R]->i2_mv[0];
805
0
                    ps_mv_final_pred->i2_mv[1] = ps_mv_pred[TOP_R]->i2_mv[1];
806
0
                }
807
0
                else
808
0
                {
809
0
                    /* The MV predictor is calculated according to the process
810
0
                     defined in 8.4.1.2.1 */
811
0
                    ih264d_get_motion_vector_predictor(
812
0
                                    ps_mv_final_pred,
813
0
                                    ps_mv_pred,
814
0
                                    u1_ref_idx,
815
0
                                    0,
816
0
                                    (const UWORD8 *)gau1_ih264d_mv_pred_condition);
817
0
                }
818
0
            }
819
0
            break;
820
0
        case B_DIRECT_SPATIAL:
821
0
            /* Case when the MB has been skipped */
822
0
            /* If either of left or the top subMB is not present
823
0
             OR
824
0
             If both the MV components of either the left or the top subMB are
825
0
             zero and their reference frame pointer pointing to 0
826
0
             then MV for the skipped MB is zero
827
0
             else the Median of the mv_pred_t is used */
828
0
            uc_temp1 = (UWORD8)ps_mv_pred[LEFT]->i1_ref_frame[0];
829
0
            uc_temp2 = (UWORD8)ps_mv_pred[TOP]->i1_ref_frame[0];
830
0
            uc_temp3 = (UWORD8)ps_mv_pred[TOP_R]->i1_ref_frame[0];
831
0
832
0
            ps_mv_final_pred->i1_ref_frame[0] = MIN(uc_temp1,
833
0
                                                  MIN(uc_temp2, uc_temp3));
834
0
835
0
            uc_temp1 = (UWORD8)ps_mv_pred[LEFT]->i1_ref_frame[1];
836
0
            uc_temp2 = (UWORD8)ps_mv_pred[TOP]->i1_ref_frame[1];
837
0
            uc_temp3 = (UWORD8)ps_mv_pred[TOP_R]->i1_ref_frame[1];
838
0
839
0
            ps_mv_final_pred->i1_ref_frame[1] = MIN(uc_temp1,
840
0
                                                  MIN(uc_temp2, uc_temp3));
841
0
842
0
            if((ps_mv_final_pred->i1_ref_frame[0] < 0)
843
0
                            && (ps_mv_final_pred->i1_ref_frame[1] < 0))
844
0
            {
845
0
                u1_direct_zero_pred_flag = 1;
846
0
                ps_mv_final_pred->i1_ref_frame[0] = 0;
847
0
                ps_mv_final_pred->i1_ref_frame[1] = 0;
848
0
            }
849
0
            ih264d_get_motion_vector_predictor(
850
0
                            ps_mv_final_pred, ps_mv_pred,
851
0
                            ps_mv_final_pred->i1_ref_frame[0], 0,
852
0
                            (const UWORD8 *)gau1_ih264d_mv_pred_condition);
853
0
854
0
            ih264d_get_motion_vector_predictor(
855
0
                            ps_mv_final_pred, ps_mv_pred,
856
0
                            ps_mv_final_pred->i1_ref_frame[1], 1,
857
0
                            (const UWORD8 *)gau1_ih264d_mv_pred_condition);
858
0
859
0
            break;
860
0
        case MB_SKIP:
861
0
            /* Case when the MB has been skipped */
862
0
            /* If either of left or the top subMB is not present
863
0
             OR
864
0
             If both the MV components of either the left or the top subMB are
865
0
             zero and their reference frame pointer pointing to 0
866
0
             then MV for the skipped MB is zero
867
0
             else the Median of the mv_pred_t is used */
868
0
            u1_a_in = (ps_cur_mb_info->u1_mb_ngbr_availablity &
869
0
            LEFT_MB_AVAILABLE_MASK);
870
0
            u1_b_in = (ps_cur_mb_info->u1_mb_ngbr_availablity &
871
0
            TOP_MB_AVAILABLE_MASK);
872
0
            if(((u1_a_in * u1_b_in) == 0)
873
0
                            || ((ps_mv_pred[LEFT]->i2_mv[0]
874
0
                                            | ps_mv_pred[LEFT]->i2_mv[1]
875
0
                                            | ps_mv_pred[LEFT]->i1_ref_frame[0])
876
0
                                            == 0)
877
0
                            || ((ps_mv_pred[TOP]->i2_mv[0]
878
0
                                            | ps_mv_pred[TOP]->i2_mv[1]
879
0
                                            | ps_mv_pred[TOP]->i1_ref_frame[0])
880
0
                                            == 0))
881
0
            {
882
0
883
0
                ps_mv_final_pred->i2_mv[0] = 0;
884
0
                ps_mv_final_pred->i2_mv[1] = 0;
885
0
                break;
886
0
            }
887
0
            /* If the condition above is not true calculate the MV predictor
888
0
             according to the process defined in sec 8.4.1.2.1 */
889
0
        default:
890
0
            ih264d_get_motion_vector_predictor(
891
0
                            ps_mv_final_pred, ps_mv_pred, u1_ref_idx, 0,
892
0
                            (const UWORD8 *)gau1_ih264d_mv_pred_condition);
893
0
            break;
894
0
    }
895
0
896
0
    return (u1_direct_zero_pred_flag);
897
0
}
898
#endif
899
900
/*****************************************************************************/
901
/*                                                                           */
902
/*  Function Name : ih264d_mvpred_mbaff                                             */
903
/*                                                                           */
904
/*  Description   : This function calculates the motion vector predictor,    */
905
/*  Inputs        : <What inputs does the function take?>                    */
906
/*  Globals       : None                                                     */
907
/*  Processing    : The neighbours A(Left),B(Top),C(TopRight) are calculated */
908
/*                  and based on the type of Mb the prediction is            */
909
/*                  appropriately done                                       */
910
/*  Outputs       : populates ps_mv_final_pred structure                       */
911
/*  Returns       : u1_direct_zero_pred_flag which is used only in              */
912
/*                    decodeSpatialdirect()                                  */
913
/*                                                                           */
914
/*  Issues        : <List any issues or problems with this function>         */
915
/*                                                                           */
916
/*  Revision History:                                                        */
917
/*                                                                           */
918
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
919
/*         03 05 2005   TA              First Draft                          */
920
/*                                                                           */
921
/*****************************************************************************/
922
923
UWORD8 ih264d_mvpred_mbaff(dec_struct_t *ps_dec,
924
                           dec_mb_info_t *ps_cur_mb_info,
925
                           mv_pred_t *ps_mv_nmb,
926
                           mv_pred_t *ps_mv_ntop,
927
                           mv_pred_t *ps_mv_final_pred,
928
                           UWORD8 u1_sub_mb_num,
929
                           UWORD8 uc_mb_part_width,
930
                           UWORD8 u1_lx_start,
931
                           UWORD8 u1_lxend,
932
                           UWORD8 u1_mb_mc_mode)
933
0
{
934
0
    UWORD8 u1_a_in, u1_b_in, uc_temp1, uc_temp2, uc_temp3;
935
0
    mv_pred_t *ps_mv_pred[3], s_mvPred[3];
936
0
    UWORD8 uc_B2, pu0_scale[3], i, uc_lx, u1_ref_idx;
937
0
    UWORD8 u1_direct_zero_pred_flag = 0;
938
0
939
0
    pu0_scale[0] = pu0_scale[1] = pu0_scale[2] = 0;
940
0
    ih264d_mbaff_mv_pred(ps_mv_pred, u1_sub_mb_num, ps_mv_nmb, ps_mv_ntop, ps_dec,
941
0
                         uc_mb_part_width, ps_cur_mb_info, pu0_scale);
942
0
    for(i = 0; i < 3; i++)
943
0
    {
944
0
        if(pu0_scale[i] != 0)
945
0
        {
946
0
            memcpy(&s_mvPred[i], ps_mv_pred[i], sizeof(mv_pred_t));
947
0
            if(pu0_scale[i] == 1)
948
0
            {
949
0
                s_mvPred[i].i1_ref_frame[0] = s_mvPred[i].i1_ref_frame[0] << 1;
950
0
                s_mvPred[i].i1_ref_frame[1] = s_mvPred[i].i1_ref_frame[1] << 1;
951
0
                s_mvPred[i].i2_mv[1] = SIGN_POW2_DIV(s_mvPred[i].i2_mv[1], 1);
952
0
                s_mvPred[i].i2_mv[3] = SIGN_POW2_DIV(s_mvPred[i].i2_mv[3], 1);
953
0
            }
954
0
            else
955
0
            {
956
0
                s_mvPred[i].i1_ref_frame[0] = s_mvPred[i].i1_ref_frame[0] >> 1;
957
0
                s_mvPred[i].i1_ref_frame[1] = s_mvPred[i].i1_ref_frame[1] >> 1;
958
0
                s_mvPred[i].i2_mv[1] = s_mvPred[i].i2_mv[1] << 1;
959
0
                s_mvPred[i].i2_mv[3] = s_mvPred[i].i2_mv[3] << 1;
960
0
            }
961
0
            ps_mv_pred[i] = &s_mvPred[i];
962
0
        }
963
0
    }
964
0
965
0
    for(uc_lx = u1_lx_start; uc_lx < u1_lxend; uc_lx++)
966
0
    {
967
0
        u1_ref_idx = ps_mv_final_pred->i1_ref_frame[uc_lx];
968
0
        uc_B2 = (uc_lx << 1);
969
0
        switch(u1_mb_mc_mode)
970
0
        {
971
0
            case PRED_16x8:
972
0
                /* Directional prediction for a 16x8 MB partition */
973
0
                if(u1_sub_mb_num == 0)
974
0
                {
975
0
                    /* Calculating the MV pred for the top 16x8 block */
976
0
                    if(ps_mv_pred[TOP]->i1_ref_frame[uc_lx] == u1_ref_idx)
977
0
                    {
978
0
                        /* If the reference frame used by the top subMB is same as the
979
0
                         reference frame used by the current block then MV predictor to
980
0
                         be used for the current block is same as the MV of the top
981
0
                         subMB */
982
0
                        ps_mv_final_pred->i2_mv[uc_B2 + 0] =
983
0
                                        ps_mv_pred[TOP]->i2_mv[uc_B2 + 0];
984
0
                        ps_mv_final_pred->i2_mv[uc_B2 + 1] =
985
0
                                        ps_mv_pred[TOP]->i2_mv[uc_B2 + 1];
986
0
                    }
987
0
                    else
988
0
                    {
989
0
                        /* The MV predictor is calculated according to the process
990
0
                         defined in 8.4.1.2.1 */
991
0
                        ih264d_get_motion_vector_predictor(
992
0
                                        ps_mv_final_pred,
993
0
                                        ps_mv_pred,
994
0
                                        u1_ref_idx,
995
0
                                        uc_lx,
996
0
                                        (const UWORD8 *)gau1_ih264d_mv_pred_condition);
997
0
                    }
998
0
                }
999
0
                else
1000
0
                {
1001
0
                    if(ps_mv_pred[LEFT]->i1_ref_frame[uc_lx] == u1_ref_idx)
1002
0
                    {
1003
0
                        /* If the reference frame used by the left subMB is same as the
1004
0
                         reference frame used by the current block then MV predictor to
1005
0
                         be used for the current block is same as the MV of the left
1006
0
                         subMB */
1007
0
                        ps_mv_final_pred->i2_mv[uc_B2 + 0] =
1008
0
                                        ps_mv_pred[LEFT]->i2_mv[uc_B2 + 0];
1009
0
                        ps_mv_final_pred->i2_mv[uc_B2 + 1] =
1010
0
                                        ps_mv_pred[LEFT]->i2_mv[uc_B2 + 1];
1011
0
                    }
1012
0
                    else
1013
0
                    {
1014
0
                        /* The MV predictor is calculated according to the process
1015
0
                         defined in 8.4.1.2.1 */
1016
0
                        ih264d_get_motion_vector_predictor(
1017
0
                                        ps_mv_final_pred,
1018
0
                                        ps_mv_pred,
1019
0
                                        u1_ref_idx,
1020
0
                                        uc_lx,
1021
0
                                        (const UWORD8 *)gau1_ih264d_mv_pred_condition);
1022
0
                    }
1023
0
                }
1024
0
                break;
1025
0
            case PRED_8x16:
1026
0
                /* Directional prediction for a 8x16 MB partition */
1027
0
                if(u1_sub_mb_num == 0)
1028
0
                {
1029
0
                    if(ps_mv_pred[LEFT]->i1_ref_frame[uc_lx] == u1_ref_idx)
1030
0
                    {
1031
0
                        /* If the reference frame used by the left subMB is same as the
1032
0
                         reference frame used by the current block then MV predictor to
1033
0
                         be used for the current block is same as the MV of the left
1034
0
                         subMB */
1035
0
                        ps_mv_final_pred->i2_mv[uc_B2 + 0] =
1036
0
                                        ps_mv_pred[LEFT]->i2_mv[uc_B2 + 0];
1037
0
                        ps_mv_final_pred->i2_mv[uc_B2 + 1] =
1038
0
                                        ps_mv_pred[LEFT]->i2_mv[uc_B2 + 1];
1039
0
                    }
1040
0
                    else
1041
0
                    {
1042
0
                        /* The MV predictor is calculated according to the process
1043
0
                         defined in 8.4.1.2.1 */
1044
0
                        ih264d_get_motion_vector_predictor(
1045
0
                                        ps_mv_final_pred,
1046
0
                                        ps_mv_pred,
1047
0
                                        u1_ref_idx,
1048
0
                                        uc_lx,
1049
0
                                        (const UWORD8 *)gau1_ih264d_mv_pred_condition);
1050
0
                    }
1051
0
                }
1052
0
                else
1053
0
                {
1054
0
                    if(ps_mv_pred[TOP_R]->i1_ref_frame[uc_lx] == u1_ref_idx)
1055
0
                    {
1056
0
                        /* If the reference frame used by the top right subMB is same as
1057
0
                         the reference frame used by the current block then MV
1058
0
                         predictor to be used for the current block is same as the MV
1059
0
                         of the left subMB */
1060
0
                        ps_mv_final_pred->i2_mv[uc_B2 + 0] =
1061
0
                                        ps_mv_pred[TOP_R]->i2_mv[uc_B2 + 0];
1062
0
                        ps_mv_final_pred->i2_mv[uc_B2 + 1] =
1063
0
                                        ps_mv_pred[TOP_R]->i2_mv[uc_B2 + 1];
1064
0
                    }
1065
0
                    else
1066
0
                    {
1067
0
                        /* The MV predictor is calculated according to the process
1068
0
                         defined in 8.4.1.2.1 */
1069
0
                        ih264d_get_motion_vector_predictor(
1070
0
                                        ps_mv_final_pred,
1071
0
                                        ps_mv_pred,
1072
0
                                        u1_ref_idx,
1073
0
                                        uc_lx,
1074
0
                                        (const UWORD8 *)gau1_ih264d_mv_pred_condition);
1075
0
                    }
1076
0
                }
1077
0
                break;
1078
0
            case B_DIRECT_SPATIAL:
1079
0
                /* Case when the MB has been skipped */
1080
0
                /* If either of left or the top subMB is not present
1081
0
                 OR
1082
0
                 If both the MV components of either the left or the top subMB are
1083
0
                 zero and their reference frame pointer pointing to 0
1084
0
                 then MV for the skipped MB is zero
1085
0
                 else the Median of the mv_pred_t is used */
1086
0
                uc_temp1 = (UWORD8)ps_mv_pred[LEFT]->i1_ref_frame[0];
1087
0
                uc_temp2 = (UWORD8)ps_mv_pred[TOP]->i1_ref_frame[0];
1088
0
                uc_temp3 = (UWORD8)ps_mv_pred[TOP_R]->i1_ref_frame[0];
1089
0
1090
0
                ps_mv_final_pred->i1_ref_frame[0] = MIN(uc_temp1,
1091
0
                                                      MIN(uc_temp2, uc_temp3));
1092
0
1093
0
                uc_temp1 = (UWORD8)ps_mv_pred[LEFT]->i1_ref_frame[1];
1094
0
                uc_temp2 = (UWORD8)ps_mv_pred[TOP]->i1_ref_frame[1];
1095
0
                uc_temp3 = (UWORD8)ps_mv_pred[TOP_R]->i1_ref_frame[1];
1096
0
1097
0
                ps_mv_final_pred->i1_ref_frame[1] = MIN(uc_temp1,
1098
0
                                                      MIN(uc_temp2, uc_temp3));
1099
0
1100
0
                /* If the reference indices are negative clip the scaled reference indices to -1 */
1101
0
                /* i.e invalid reference index */
1102
0
1103
0
                /*if(ps_mv_final_pred->i1_ref_frame[0] < 0)
1104
0
                 ps_mv_final_pred->i1_ref_frame[0] = -1;
1105
0
1106
0
                 if(ps_mv_final_pred->i1_ref_frame[1] < 0)
1107
0
                 ps_mv_final_pred->i1_ref_frame[1] = -1; */
1108
0
1109
0
                if((ps_mv_final_pred->i1_ref_frame[0] < 0)
1110
0
                                && (ps_mv_final_pred->i1_ref_frame[1] < 0))
1111
0
                {
1112
0
                    u1_direct_zero_pred_flag = 1;
1113
0
                    ps_mv_final_pred->i1_ref_frame[0] = 0;
1114
0
                    ps_mv_final_pred->i1_ref_frame[1] = 0;
1115
0
                }
1116
0
                ih264d_get_motion_vector_predictor(
1117
0
                                ps_mv_final_pred, ps_mv_pred,
1118
0
                                ps_mv_final_pred->i1_ref_frame[0], 0,
1119
0
                                (const UWORD8 *)gau1_ih264d_mv_pred_condition);
1120
0
1121
0
                ih264d_get_motion_vector_predictor(
1122
0
                                ps_mv_final_pred, ps_mv_pred,
1123
0
                                ps_mv_final_pred->i1_ref_frame[1], 1,
1124
0
                                (const UWORD8 *)gau1_ih264d_mv_pred_condition);
1125
0
1126
0
                break;
1127
0
            case MB_SKIP:
1128
0
                /* Case when the MB has been skipped */
1129
0
                /* If either of left or the top subMB is not present
1130
0
                 OR
1131
0
                 If both the MV components of either the left or the top subMB are
1132
0
                 zero and their reference frame pointer pointing to 0
1133
0
                 then MV for the skipped MB is zero
1134
0
                 else the Median of the mv_pred_t is used */
1135
0
                u1_a_in = (ps_cur_mb_info->u1_mb_ngbr_availablity &
1136
0
                LEFT_MB_AVAILABLE_MASK);
1137
0
                u1_b_in = (ps_cur_mb_info->u1_mb_ngbr_availablity &
1138
0
                TOP_MB_AVAILABLE_MASK);
1139
0
                if(((u1_a_in * u1_b_in) == 0)
1140
0
                                || ((ps_mv_pred[LEFT]->i2_mv[0]
1141
0
                                                | ps_mv_pred[LEFT]->i2_mv[1]
1142
0
                                                | ps_mv_pred[LEFT]->i1_ref_frame[0])
1143
0
                                                == 0)
1144
0
                                || ((ps_mv_pred[TOP]->i2_mv[0]
1145
0
                                                | ps_mv_pred[TOP]->i2_mv[1]
1146
0
                                                | ps_mv_pred[TOP]->i1_ref_frame[0])
1147
0
                                                == 0))
1148
0
                {
1149
0
                    ps_mv_final_pred->i2_mv[0] = 0;
1150
0
                    ps_mv_final_pred->i2_mv[1] = 0;
1151
0
                    break;
1152
0
                }
1153
0
                /* If the condition above is not true calculate the MV predictor
1154
0
                 according to the process defined in sec 8.4.1.2.1 */
1155
0
            default:
1156
0
                ih264d_get_motion_vector_predictor(
1157
0
                                ps_mv_final_pred, ps_mv_pred, u1_ref_idx, uc_lx,
1158
0
                                (const UWORD8 *)gau1_ih264d_mv_pred_condition);
1159
0
                break;
1160
0
        }
1161
0
    }
1162
0
    return (u1_direct_zero_pred_flag);
1163
0
}
1164
1165
1166
1167
1168
void ih264d_rep_mv_colz(dec_struct_t *ps_dec,
1169
                        mv_pred_t *ps_mv_pred_src,
1170
                        mv_pred_t *ps_mv_pred_dst,
1171
                        UWORD8 u1_sub_mb_num,
1172
                        UWORD8 u1_colz,
1173
                        UWORD8 u1_ht,
1174
                        UWORD8 u1_wd)
1175
5.06k
{
1176
5.06k
1177
5.06k
    UWORD8 k, m;
1178
5.06k
    UWORD8 *pu1_colz = ps_dec->pu1_col_zero_flag + ps_dec->i4_submb_ofst
1179
5.06k
                    + u1_sub_mb_num;
1180
5.06k
1181
25.3k
    for(k = 0; k < u1_ht; k++)
1182
20.2k
    {
1183
101k
        for(m = 0; m < u1_wd; m++)
1184
80.9k
        {
1185
80.9k
            *(ps_mv_pred_dst + m) = *(ps_mv_pred_src);
1186
80.9k
            *(pu1_colz + m) = u1_colz;
1187
80.9k
1188
80.9k
        }
1189
20.2k
        pu1_colz += SUB_BLK_WIDTH;
1190
20.2k
        ps_mv_pred_dst += SUB_BLK_WIDTH;
1191
20.2k
    }
1192
5.06k
}
1193
/proc/self/cwd/external/libavc/decoder/ih264d_mvpred.h
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
21
#ifndef _IH264D_MVPRED_H_
22
#define _IH264D_MVPRED_H_
23
24
/**
25
**************************************************************************
26
* \file ih264d_mvpred.h
27
*
28
* \brief
29
*    This file contains declarations of functions specific to decoding
30
*    Motion vector.
31
*
32
* Detailed_description
33
*
34
* \date
35
*    10-12-2002
36
*
37
* \author  Arvind Raman
38
**************************************************************************
39
*/
40
#include "ih264d_structs.h"
41
#include "ih264d_defs.h"
42
//#include "structs.h"
43
44
/** Reference number that is not valid */
45
0
#define OUT_OF_RANGE_REF  -1
46
47
0
#define ONE_TO_ONE    0
48
0
#define FRM_TO_FLD    1
49
0
#define FLD_TO_FRM    2
50
51
/**
52
**************************************************************************
53
*   \brief   POSITION_IN_MVBANK
54
*
55
*   a: Pointer to the top left subMb of the MB in the MV bank array
56
*   b: Horiz posn in terms of subMbs
57
*   c: Vert posn in terms of subMbs
58
*   d: subMb number
59
**************************************************************************
60
*/
61
#define POSITION_IN_MVBANK(a, b, c, d) (a) + (c) * (d) + (b)
62
63
64
65
/**
66
**************************************************************************
67
*   \brief   col4x4_t
68
*
69
*   Container to return the information related to the co-located 4x4
70
*   sub-macroblock.
71
**************************************************************************
72
*/
73
typedef struct
74
{
75
  mv_pred_t *ps_mv;     /** Ptr to the Mv bank */
76
  UWORD16 u2_mb_addr_col;       /** Addr of the co-located MB */
77
  WORD16 i2_mv[2];      /** Mv of the colocated MB */
78
  WORD8 i1_ref_idx_col;     /** Ref idx of the co-located picture */
79
  UWORD8 u1_col_pic;        /** Idx of the colocated pic */
80
  UWORD8 u1_yM;     /** "y" coord of the colocated MB addr */
81
  UWORD8 u1_vert_mv_scale;      /** as defined in sec 8.4.1.2.1 */
82
} col4x4_t;
83
84
85
86
87
88
void ih264d_update_nnz_for_skipmb(dec_struct_t * ps_dec,
89
                                  dec_mb_info_t * ps_cur_mb_info,
90
                                  UWORD8 u1_entrpy);
91
92
void ih264d_get_motion_vector_predictor(mv_pred_t * ps_result,
93
                                        mv_pred_t **ps_mv_pred,
94
                                        UWORD8 u1_ref_idx,
95
                                        UWORD8 u1_B,
96
                                        const UWORD8 *pu1_mv_pred_condition);
97
void ih264d_mbaff_mv_pred(mv_pred_t **ps_mv_pred,
98
                          UWORD8 u1_sub_mb_num,
99
                          mv_pred_t *ps_mv_nmb,
100
                          mv_pred_t *ps_mv_ntop,
101
                          dec_struct_t *ps_dec,
102
                          UWORD8 uc_mb_part_width,
103
                          dec_mb_info_t *ps_cur_mb_info,
104
                          UWORD8* pu0_scale);
105
void ih264d_non_mbaff_mv_pred(mv_pred_t **ps_mv_pred,
106
                              UWORD8 u1_sub_mb_num,
107
                              mv_pred_t *ps_mv_nmb,
108
                              mv_pred_t *ps_mv_ntop,
109
                              dec_struct_t *ps_dec,
110
                              UWORD8 uc_mb_part_width,
111
                              dec_mb_info_t *ps_cur_mb_info);
112
UWORD8 ih264d_mvpred_nonmbaff(dec_struct_t *ps_dec,
113
                              dec_mb_info_t *ps_cur_mb_info,
114
                              mv_pred_t *ps_mv_nmb,
115
                              mv_pred_t *ps_mv_ntop,
116
                              mv_pred_t *ps_mv_final_pred,
117
                              UWORD8 u1_sub_mb_num,
118
                              UWORD8 uc_mb_part_width,
119
                              UWORD8 u1_lx_start,
120
                              UWORD8 u1_lxend,
121
                              UWORD8 u1_mb_mc_mode);
122
123
UWORD8 ih264d_mvpred_nonmbaffB(dec_struct_t *ps_dec,
124
                               dec_mb_info_t *ps_cur_mb_info,
125
                               mv_pred_t *ps_mv_nmb,
126
                               mv_pred_t *ps_mv_ntop,
127
                               mv_pred_t *ps_mv_final_pred,
128
                               UWORD8 u1_sub_mb_num,
129
                               UWORD8 uc_mb_part_width,
130
                               UWORD8 u1_lx_start,
131
                               UWORD8 u1_lxend,
132
                               UWORD8 u1_mb_mc_mode);
133
134
UWORD8 ih264d_mvpred_mbaff(dec_struct_t *ps_dec,
135
                           dec_mb_info_t *ps_cur_mb_info,
136
                           mv_pred_t *ps_mv_nmb,
137
                           mv_pred_t *ps_mv_ntop,
138
                           mv_pred_t *ps_mv_final_pred,
139
                           UWORD8 u1_sub_mb_num,
140
                           UWORD8 uc_mb_part_width,
141
                           UWORD8 u1_lx_start,
142
                           UWORD8 u1_lxend,
143
                           UWORD8 u1_mb_mc_mode);
144
145
void ih264d_rep_mv_colz(dec_struct_t *ps_dec,
146
                        mv_pred_t *ps_mv_pred_src,
147
                        mv_pred_t *ps_mv_pred_dst,
148
                        UWORD8 u1_sub_mb_num,
149
                        UWORD8 u1_colz,
150
                        UWORD8 u1_ht,
151
                        UWORD8 u1_wd);
152
153
#endif  /* _IH264D_MVPRED_H_ */
/proc/self/cwd/external/libavc/decoder/ih264d_nal.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/*!
21
 **************************************************************************
22
 *  \file   ih264d_nal.c
23
 *
24
 *  \brief  NAL parsing routines
25
 *
26
 *  Detailed_description
27
 *
28
 *  \author
29
 *         - AI  19 11 2002  Creation
30
 **************************************************************************
31
 */
32
#include "ih264d_bitstrm.h"
33
#include "ih264d_defs.h"
34
#include "ih264_typedefs.h"
35
#include "ih264_macros.h"
36
#include "ih264_platform_macros.h"
37
#include "ih264d_defs.h"
38
409k
#define NUM_OF_ZERO_BYTES_BEFORE_START_CODE 2
39
309
#define EMULATION_PREVENTION_BYTE           0x03
40
41
13
#define NAL_FIRST_BYTE_SIZE 1
42
43
/*!
44
 **************************************************************************
45
 * \if Function name : ih264d_find_start_code \endif
46
 *
47
 * \brief
48
 *    This function searches for the Start Code Prefix.
49
 *
50
 * \param pu1_buf : Pointer to char buffer which contains bitstream.
51
 * \param u4_cur_pos : Current position in the buffer.
52
 * \param u4_max_ofst : Number of bytes in Buffer.
53
 * \param pu4_length_of_start_code  : Poiter to length of Start Code.
54
 *
55
 * \return
56
 *    Returns 0 on success and -1 on error.
57
 *
58
 **************************************************************************
59
 */
60
#define START_CODE_NOT_FOUND    -1
61
#define END_OF_STREAM_BUFFER    -2
62
#define END_OF_STREAM           -1
63
64
void ih264d_check_if_aud(UWORD8 *pu1_buf,
65
                         UWORD32 u4_cur_pos,
66
                         UWORD32 u4_max_ofst,
67
                         UWORD32 *pu4_next_is_aud)
68
0
{
69
0
    UWORD8 u1_first_byte, u1_nal_unit_type;
70
0
    if(u4_cur_pos + 1 < u4_max_ofst)
71
0
    {
72
0
        u1_first_byte = pu1_buf[u4_cur_pos + 1];
73
0
        u1_nal_unit_type = NAL_UNIT_TYPE(u1_first_byte);
74
0
75
0
        if(u1_nal_unit_type == ACCESS_UNIT_DELIMITER_RBSP)
76
0
        {
77
0
            *pu4_next_is_aud = 1;
78
0
        }
79
0
    }
80
0
81
0
}
82
WORD32 ih264d_find_start_code(UWORD8 *pu1_buf,
83
                              UWORD32 u4_cur_pos,
84
                              UWORD32 u4_max_ofst,
85
                              UWORD32 *pu4_length_of_start_code,
86
                              UWORD32 *pu4_next_is_aud)
87
13
{
88
13
    WORD32 zero_byte_cnt = 0;
89
13
    UWORD32 ui_curPosTemp;
90
13
91
13
    *pu4_length_of_start_code = 0;
92
13
    /*Find first start code */
93
52
    while(u4_cur_pos < u4_max_ofst)
94
52
    {
95
52
        if(pu1_buf[u4_cur_pos] == 0)
96
39
            zero_byte_cnt++;
97
13
        else if(pu1_buf[u4_cur_pos]
98
13
                        == 0x01 && zero_byte_cnt >= NUM_OF_ZERO_BYTES_BEFORE_START_CODE)
99
13
        {
100
13
            /* Found the start code */
101
13
            u4_cur_pos++;
102
13
            break;
103
13
        }
104
0
        else
105
0
        {
106
0
            zero_byte_cnt = 0;
107
0
        }
108
52
        u4_cur_pos++;
109
39
    }
110
13
    /*Find Next Start Code */
111
13
    *pu4_length_of_start_code = u4_cur_pos;
112
13
    zero_byte_cnt = 0;
113
13
    ui_curPosTemp = u4_cur_pos;
114
203k
    while(u4_cur_pos < u4_max_ofst)
115
203k
    {
116
203k
117
203k
        if(pu1_buf[u4_cur_pos] == 0)
118
8.30k
            zero_byte_cnt++;
119
195k
        else if(pu1_buf[u4_cur_pos]
120
195k
                        == 0x01 && zero_byte_cnt >= NUM_OF_ZERO_BYTES_BEFORE_START_CODE)
121
195k
        {
122
0
            /* Found the start code */
123
0
            ih264d_check_if_aud(pu1_buf, u4_cur_pos, u4_max_ofst,
124
0
                                pu4_next_is_aud);
125
0
            return (u4_cur_pos - zero_byte_cnt - ui_curPosTemp);
126
0
        }
127
195k
        else
128
195k
        {
129
195k
            zero_byte_cnt = 0;
130
195k
        }
131
203k
        u4_cur_pos++;
132
203k
    }
133
13
134
13
    return (u4_cur_pos - zero_byte_cnt - ui_curPosTemp); //(START_CODE_NOT_FOUND);
135
13
}
136
137
/*!
138
 **************************************************************************
139
 * \if Function name : ih264d_get_next_nal_unit \endif
140
 *
141
 * \brief
142
 *    This function reads one NAl unit.
143
 *
144
 * \param ps_nalStream : Poiter to NalUnitStream structure.
145
 * \param ps_nalUnit : Pointer to NalUnit.
146
 *
147
 * \return
148
 *    Returns 0 on success and -1 on error.
149
 *
150
 **************************************************************************
151
 */
152
WORD32 ih264d_get_next_nal_unit(UWORD8 *pu1_buf,
153
                                UWORD32 u4_cur_pos,
154
                                UWORD32 u4_max_ofst,
155
                                UWORD32 *pu4_length_of_start_code)
156
0
{
157
0
158
0
    WORD32 i_length_of_nal_unit = 0;
159
0
    UWORD32 u4_next_is_aud;
160
0
161
0
    /* NAL Thread starts */
162
0
163
0
    ih264d_find_start_code(pu1_buf, u4_cur_pos, u4_max_ofst,
164
0
                           pu4_length_of_start_code, &u4_next_is_aud);
165
0
166
0
    return (i_length_of_nal_unit);
167
0
}
168
169
/*!
170
 **************************************************************************
171
 * \if Function name : ih264d_process_nal_unit \endif
172
 *
173
 * \brief
174
 *    This function removes emulation byte "0x03" from bitstream (EBSP to RBSP).
175
 *    It also converts bytestream format into 32 bit little-endian format.
176
 *
177
 * \param ps_bitstrm : Poiter to dec_bit_stream_t structure.
178
 * \param pu1_nal_unit  : Pointer to char buffer of NalUnit.
179
 * \param u4_numbytes_in_nal_unit : Number bytes in NalUnit buffer.
180
 *
181
 * \return
182
 *    Returns number of bytes in RBSP ps_bitstrm.
183
 *
184
 * \note
185
 *    This function is same as nal_unit() of 7.3.1. Apart from nal_unit()
186
 *    implementation it converts char buffer into 32 bit Buffer. This
187
 *    facilitates efficient access of bitstream. This has been done taking
188
 *    into account present processor architectures.
189
 *
190
 **************************************************************************
191
 */
192
WORD32 ih264d_process_nal_unit(dec_bit_stream_t *ps_bitstrm,
193
                            UWORD8 *pu1_nal_unit,
194
                            UWORD32 u4_numbytes_in_nal_unit)
195
13
{
196
13
    UWORD32 u4_num_bytes_in_rbsp;
197
13
    UWORD8 u1_cur_byte;
198
13
    WORD32 i = 0;
199
13
    WORD8 c_count;
200
13
    UWORD32 ui_word;
201
13
    UWORD32 *puc_bitstream_buffer = (UWORD32*)pu1_nal_unit;
202
13
    ps_bitstrm->pu4_buffer = puc_bitstream_buffer;
203
13
204
13
    /*--------------------------------------------------------------------*/
205
13
    /* First Byte of the NAL Unit                                         */
206
13
    /*--------------------------------------------------------------------*/
207
13
208
13
    ui_word = *pu1_nal_unit++;
209
13
210
13
    /*--------------------------------------------------------------------*/
211
13
    /* Convertion of the EBSP to RBSP                                     */
212
13
    /* ie Remove the emulation_prevention_byte [equal to 0x03]            */
213
13
    /*--------------------------------------------------------------------*/
214
13
    u4_num_bytes_in_rbsp = 0;
215
13
    c_count = 0;
216
13
217
13
//first iteration
218
13
219
13
    u1_cur_byte = *pu1_nal_unit++;
220
13
221
13
    ui_word = ((ui_word << 8) | u1_cur_byte);
222
13
223
13
    c_count++;
224
13
    if(u1_cur_byte != 0x00)
225
13
        c_count = 0;
226
13
227
13
//second iteration
228
13
229
13
    u1_cur_byte = *pu1_nal_unit++;
230
13
231
13
    ui_word = ((ui_word << 8) | u1_cur_byte);
232
13
    u4_num_bytes_in_rbsp = 2;
233
13
234
13
    c_count++;
235
13
    if(u1_cur_byte != 0x00)
236
13
        c_count = 0;
237
13
238
13
    if(u4_numbytes_in_nal_unit > 2)
239
13
    {
240
13
        i = ((u4_numbytes_in_nal_unit - 3));
241
13
    }
242
13
243
50.8k
    for(; i > 8; i -= 4)
244
50.8k
    {
245
50.8k
246
50.8k
// loop 0
247
50.8k
        u1_cur_byte = *pu1_nal_unit++;
248
50.8k
249
50.8k
        if(c_count == NUM_OF_ZERO_BYTES_BEFORE_START_CODE
250
50.8k
                        && u1_cur_byte == EMULATION_PREVENTION_BYTE)
251
50.8k
        {
252
0
            c_count = 0;
253
0
            u1_cur_byte = *pu1_nal_unit++;
254
0
            i--;
255
0
        }
256
50.8k
257
50.8k
        ui_word = ((ui_word << 8) | u1_cur_byte);
258
50.8k
        *puc_bitstream_buffer = ui_word;
259
50.8k
        puc_bitstream_buffer++;
260
50.8k
        c_count++;
261
50.8k
        if(u1_cur_byte != 0x00)
262
48.6k
            c_count = 0;
263
50.8k
264
50.8k
// loop 1
265
50.8k
        u1_cur_byte = *pu1_nal_unit++;
266
50.8k
267
50.8k
        if(c_count == NUM_OF_ZERO_BYTES_BEFORE_START_CODE
268
50.8k
                        && u1_cur_byte == EMULATION_PREVENTION_BYTE)
269
50.8k
        {
270
0
            c_count = 0;
271
0
            u1_cur_byte = *pu1_nal_unit++;
272
0
            i--;
273
0
        }
274
50.8k
        ui_word = ((ui_word << 8) | u1_cur_byte);
275
50.8k
276
50.8k
        c_count++;
277
50.8k
        if(u1_cur_byte != 0x00)
278
48.9k
            c_count = 0;
279
50.8k
280
50.8k
// loop 2
281
50.8k
        u1_cur_byte = *pu1_nal_unit++;
282
50.8k
283
50.8k
        if(c_count == NUM_OF_ZERO_BYTES_BEFORE_START_CODE
284
50.8k
                        && u1_cur_byte == EMULATION_PREVENTION_BYTE)
285
50.8k
        {
286
0
            c_count = 0;
287
0
            u1_cur_byte = *pu1_nal_unit++;
288
0
            i--;
289
0
        }
290
50.8k
291
50.8k
        ui_word = ((ui_word << 8) | u1_cur_byte);
292
50.8k
293
50.8k
        c_count++;
294
50.8k
        if(u1_cur_byte != 0x00)
295
48.7k
            c_count = 0;
296
50.8k
297
50.8k
// loop 3
298
50.8k
        u1_cur_byte = *pu1_nal_unit++;
299
50.8k
300
50.8k
        if(c_count == NUM_OF_ZERO_BYTES_BEFORE_START_CODE
301
50.8k
                        && u1_cur_byte == EMULATION_PREVENTION_BYTE)
302
50.8k
        {
303
0
            c_count = 0;
304
0
            u1_cur_byte = *pu1_nal_unit++;
305
0
            i--;
306
0
        }
307
50.8k
308
50.8k
        ui_word = ((ui_word << 8) | u1_cur_byte);
309
50.8k
310
50.8k
        c_count++;
311
50.8k
        if(u1_cur_byte != 0x00)
312
48.9k
            c_count = 0;
313
50.8k
314
50.8k
        u4_num_bytes_in_rbsp += 4;
315
50.8k
316
50.8k
    }
317
13
318
74
    for(; i > 0; i--)
319
61
    {
320
61
        u1_cur_byte = *pu1_nal_unit++;
321
61
322
61
        if(c_count == NUM_OF_ZERO_BYTES_BEFORE_START_CODE
323
61
                        && u1_cur_byte == EMULATION_PREVENTION_BYTE)
324
61
        {
325
0
            c_count = 0;
326
0
            i--;
327
0
            u1_cur_byte = *pu1_nal_unit++;
328
0
        }
329
61
330
61
        ui_word = ((ui_word << 8) | u1_cur_byte);
331
61
        u4_num_bytes_in_rbsp++;
332
61
333
61
        if((u4_num_bytes_in_rbsp & 0x03) == 0x03)
334
25
        {
335
25
            *puc_bitstream_buffer = ui_word;
336
25
            puc_bitstream_buffer++;
337
25
        }
338
61
        c_count++;
339
61
        if(u1_cur_byte != 0x00)
340
61
            c_count = 0;
341
61
342
61
    }
343
13
344
13
    *puc_bitstream_buffer = (ui_word
345
13
                    << ((3 - (((u4_num_bytes_in_rbsp << 30) >> 30))) << 3));
346
13
    ps_bitstrm->u4_ofst = 0;
347
13
    ps_bitstrm->u4_max_ofst = ((u4_num_bytes_in_rbsp + NAL_FIRST_BYTE_SIZE) << 3);
348
13
349
13
    return (u4_num_bytes_in_rbsp);
350
13
}
351
352
353
/*!
354
 **************************************************************************
355
 * \if Function name : ih264d_rbsp_to_sodb \endif
356
 *
357
 * \brief
358
 *    This function converts RBSP to SODB.
359
 *
360
 * \param ps_bitstrm : Poiter to dec_bit_stream_t structure.
361
 *
362
 * \return
363
 *    None.
364
 *
365
 **************************************************************************
366
 */
367
void ih264d_rbsp_to_sodb(dec_bit_stream_t *ps_bitstrm)
368
13
{
369
13
    UWORD32 ui_lastWord;
370
13
    UWORD32 ui_word;
371
13
    UWORD8 uc_lastByte;
372
13
    WORD8 i;
373
13
374
13
    ui_lastWord = (ps_bitstrm->u4_max_ofst >> 5);
375
13
    i = (ps_bitstrm->u4_max_ofst >> 3) & 0x03;
376
13
377
13
    if(i)
378
0
    {
379
0
        ui_word = ps_bitstrm->pu4_buffer[ui_lastWord];
380
0
        uc_lastByte = ((ui_word << ((i - 1) << 3)) >> 24);
381
0
    }
382
13
    else
383
13
    {
384
13
        ui_word = ps_bitstrm->pu4_buffer[ui_lastWord - 1];
385
13
        uc_lastByte = ((ui_word << 24) >> 24);
386
13
    }
387
13
    /*--------------------------------------------------------------------*/
388
13
    /* Find out the rbsp_stop_bit position in the last byte of rbsp       */
389
13
    /*--------------------------------------------------------------------*/
390
31
    for(i = 0; (i < 8) && !CHECKBIT(uc_lastByte, i); ++i)
391
18
        ;
392
13
    ps_bitstrm->u4_max_ofst = ps_bitstrm->u4_max_ofst - (i + 1);
393
13
}
/proc/self/cwd/external/libavc/decoder/ih264d_parse_bslice.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/*!
21
 **************************************************************************
22
 * \file ih264d_parse_bslice.c
23
 *
24
 * \brief
25
 *    Contains routines that decode a I slice type
26
 *
27
 * Detailed_description
28
 *
29
 * \date
30
 *    07/07/2003
31
 *
32
 * \author  NS
33
 **************************************************************************
34
 */
35
36
#include <string.h>
37
#include "ih264d_bitstrm.h"
38
#include "ih264d_defs.h"
39
#include "ih264d_debug.h"
40
#include "ih264d_tables.h"
41
#include "ih264d_structs.h"
42
#include "ih264d_defs.h"
43
#include "ih264d_parse_cavlc.h"
44
#include "ih264d_mb_utils.h"
45
#include "ih264d_parse_slice.h"
46
#include "ih264d_process_intra_mb.h"
47
#include "ih264d_mvpred.h"
48
#include "ih264d_parse_islice.h"
49
#include "ih264d_inter_pred.h"
50
#include "ih264d_process_pslice.h"
51
#include "ih264d_process_bslice.h"
52
#include "ih264d_deblocking.h"
53
#include "ih264d_cabac.h"
54
#include "ih264d_parse_mb_header.h"
55
#include "ih264d_error_handler.h"
56
#include "ih264d_mvpred.h"
57
#include "ih264d_cabac.h"
58
#include "ih264d_utils.h"
59
60
void ih264d_init_cabac_contexts(UWORD8 u1_slice_type, dec_struct_t * ps_dec);
61
62
/*!
63
 **************************************************************************
64
 * \if Function name : ParseMb_SubMb_PredBCav\endif
65
 *
66
 * \brief
67
 *    Implements sub_mb_pred() of 7.3.5.2. & mb_pred() of 7.3.5.1
68
 *
69
 * \return
70
 *    None.
71
 *
72
 **************************************************************************
73
 */
74
WORD32 ih264d_parse_bmb_non_direct_cavlc(dec_struct_t * ps_dec,
75
                                       dec_mb_info_t * ps_cur_mb_info,
76
                                       UWORD8 u1_mb_num,
77
                                       UWORD8 u1_num_mbsNby2)
78
0
{
79
0
    dec_bit_stream_t * ps_bitstrm = ps_dec->ps_bitstrm;
80
0
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
81
0
    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
82
0
    UWORD8 * pu1_sub_mb_pred_modes = (UWORD8 *)(gau1_ih264d_submb_pred_modes) + 4;
83
0
    const UWORD8 (*pu1_mb_pred_modes)[32] =
84
0
                    (const UWORD8 (*)[32])gau1_ih264d_mb_pred_modes;
85
0
    const UWORD8 * pu1_num_mb_part = (const UWORD8 *)gau1_ih264d_num_mb_part;
86
0
    const UWORD8 * pu1_sub_mb_mc_mode = (const UWORD8 *)(gau1_ih264d_submb_mc_mode)
87
0
                    + 4;
88
0
89
0
    parse_pmbarams_t * ps_parse_mb_data = ps_dec->ps_parse_mb_data
90
0
                    + u1_num_mbsNby2;
91
0
    UWORD8 * pu1_col_info = ps_parse_mb_data->u1_col_info;
92
0
    WORD8 (*pi1_ref_idx)[MAX_REFIDX_INFO_PER_MB] = ps_parse_mb_data->i1_ref_idx;
93
0
    UWORD8 u1_mb_type = ps_cur_mb_info->u1_mb_type;
94
0
    UWORD8 u1_mb_mc_mode, u1_num_mb_part, u1_sub_mb = !(u1_mb_type ^ B_8x8);
95
0
    UWORD32 u4_mb_mc_mode = 0, u4_mb_pred_mode = 0;
96
0
    WORD32 ret;
97
0
98
0
    if(u1_sub_mb)
99
0
    {
100
0
        UWORD8 uc_i;
101
0
        u1_mb_mc_mode = 0;
102
0
        u1_num_mb_part = 4;
103
0
        /* Reading the subMB type */
104
0
        for(uc_i = 0; uc_i < 4; uc_i++)
105
0
        {
106
0
107
0
            UWORD32 ui_sub_mb_mode;
108
0
109
0
//Inlined ih264d_uev
110
0
            UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
111
0
            UWORD32 u4_word, u4_ldz;
112
0
113
0
            /***************************************************************/
114
0
            /* Find leading zeros in next 32 bits                          */
115
0
            /***************************************************************/
116
0
            NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
117
0
            u4_ldz = CLZ(u4_word);
118
0
            /* Flush the ps_bitstrm */
119
0
            u4_bitstream_offset += (u4_ldz + 1);
120
0
            /* Read the suffix from the ps_bitstrm */
121
0
            u4_word = 0;
122
0
            if(u4_ldz)
123
0
                GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
124
0
                        u4_ldz);
125
0
            *pu4_bitstrm_ofst = u4_bitstream_offset;
126
0
            ui_sub_mb_mode = ((1 << u4_ldz) + u4_word - 1);
127
0
//Inlined ih264d_uev
128
0
129
0
            if(ui_sub_mb_mode > 12)
130
0
                return ERROR_SUB_MB_TYPE;
131
0
            else
132
0
            {
133
0
                UWORD8 u1_subMbPredMode = pu1_sub_mb_pred_modes[ui_sub_mb_mode];
134
0
                u4_mb_mc_mode = (u4_mb_mc_mode << 8)
135
0
                                | pu1_sub_mb_mc_mode[ui_sub_mb_mode];
136
0
                u4_mb_pred_mode = (u4_mb_pred_mode << 8) | u1_subMbPredMode;
137
0
                pi1_ref_idx[0][uc_i] = ((u1_subMbPredMode & PRED_L0) - 1) >> 1;
138
0
                pi1_ref_idx[1][uc_i] = ((u1_subMbPredMode & PRED_L1) - 1) >> 1;
139
0
                COPYTHECONTEXT("sub_mb_type", u1_subMbPredMode);
140
0
            }
141
0
            /* Storing collocated Mb and SubMb mode information */
142
0
            *pu1_col_info++ = ((PRED_8x8) << 6)
143
0
                            | ((pu1_sub_mb_mc_mode[ui_sub_mb_mode] << 4));
144
0
            if(ui_sub_mb_mode != B_DIRECT_8x8)
145
0
            {
146
0
                if(ui_sub_mb_mode > B_BI_8x8)
147
0
                {
148
0
                    ps_dec->s_high_profile.u1_no_submb_part_size_lt8x8_flag = 0;
149
0
                }
150
0
            }
151
0
            else if(!ps_dec->s_high_profile.u1_direct_8x8_inference_flag)
152
0
            {
153
0
                ps_dec->s_high_profile.u1_no_submb_part_size_lt8x8_flag = 0;
154
0
            }
155
0
        }
156
0
    }
157
0
    else
158
0
    {
159
0
        UWORD8 u1_mb_pred_mode_idx = 5 + u1_mb_type;
160
0
        UWORD8 u1_mb_pred_mode_part0 = pu1_mb_pred_modes[0][u1_mb_pred_mode_idx];
161
0
        UWORD8 u1_mb_pred_mode_part1 = pu1_mb_pred_modes[1][u1_mb_pred_mode_idx];
162
0
        u1_mb_mc_mode = ps_cur_mb_info->u1_mb_mc_mode;
163
0
        u1_num_mb_part = pu1_num_mb_part[u1_mb_mc_mode];
164
0
165
0
        pi1_ref_idx[0][0] = ((u1_mb_pred_mode_part0 & PRED_L0) - 1) >> 1;
166
0
        pi1_ref_idx[1][0] = ((u1_mb_pred_mode_part0 & PRED_L1) - 1) >> 1;
167
0
        pi1_ref_idx[0][1] = ((u1_mb_pred_mode_part1 & PRED_L0) - 1) >> 1;
168
0
        pi1_ref_idx[1][1] = ((u1_mb_pred_mode_part1 & PRED_L1) - 1) >> 1;
169
0
170
0
        u4_mb_pred_mode = (u1_mb_pred_mode_part0 << 8) | u1_mb_pred_mode_part1;
171
0
        u4_mb_mc_mode = u1_mb_mc_mode | (u1_mb_mc_mode << 8);
172
0
        u4_mb_mc_mode <<= 16;
173
0
        u4_mb_pred_mode <<= 16;
174
0
175
0
        /* Storing collocated Mb and SubMb mode information */
176
0
        *pu1_col_info++ = (u1_mb_mc_mode << 6);
177
0
        if(u1_mb_mc_mode)
178
0
            *pu1_col_info++ = (u1_mb_mc_mode << 6);
179
0
    }
180
0
181
0
    {
182
0
        UWORD8 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
183
0
        UWORD8 uc_field = ps_cur_mb_info->u1_mb_field_decodingflag;
184
0
        UWORD8 *pu1_num_ref_idx_lx_active =
185
0
                        ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active;
186
0
        const UWORD8 u1_mbaff_field = (u1_mbaff & uc_field);
187
0
        UWORD8 u4_num_ref_idx_lx_active;
188
0
189
0
        u4_num_ref_idx_lx_active = (pu1_num_ref_idx_lx_active[0]
190
0
                        << u1_mbaff_field) - 1;
191
0
192
0
        if(u4_num_ref_idx_lx_active)
193
0
        {
194
0
            if(1 == u4_num_ref_idx_lx_active)
195
0
                ih264d_parse_bmb_ref_index_cavlc_range1(
196
0
                                u1_num_mb_part, ps_bitstrm, pi1_ref_idx[0],
197
0
                                u4_num_ref_idx_lx_active);
198
0
            else
199
0
            {
200
0
                ret = ih264d_parse_bmb_ref_index_cavlc(u1_num_mb_part, ps_bitstrm,
201
0
                                                 pi1_ref_idx[0],
202
0
                                                 u4_num_ref_idx_lx_active);
203
0
                if(ret != OK)
204
0
                    return ret;
205
0
            }
206
0
        }
207
0
208
0
        u4_num_ref_idx_lx_active = (pu1_num_ref_idx_lx_active[1]
209
0
                        << u1_mbaff_field) - 1;
210
0
211
0
        if(u4_num_ref_idx_lx_active)
212
0
        {
213
0
            if(1 == u4_num_ref_idx_lx_active)
214
0
                ih264d_parse_bmb_ref_index_cavlc_range1(
215
0
                                u1_num_mb_part, ps_bitstrm, pi1_ref_idx[1],
216
0
                                u4_num_ref_idx_lx_active);
217
0
            else
218
0
            {
219
0
                ret = ih264d_parse_bmb_ref_index_cavlc(u1_num_mb_part, ps_bitstrm,
220
0
                                                 pi1_ref_idx[1],
221
0
                                                 u4_num_ref_idx_lx_active);
222
0
                if(ret != OK)
223
0
                    return ret;
224
0
            }
225
0
        }
226
0
    }
227
0
228
0
    /* Read MotionVectors */
229
0
    {
230
0
        const UWORD8 * pu1_top_left_sub_mb_indx;
231
0
232
0
        const UWORD8 * pu1_sub_mb_indx_mod =
233
0
                        (const UWORD8 *)(gau1_ih264d_submb_indx_mod)
234
0
                                        + (u1_sub_mb * 6);
235
0
        const UWORD8 * pu1_sub_mb_partw = (const UWORD8 *)gau1_ih264d_submb_partw;
236
0
        const UWORD8 * pu1_sub_mb_parth = (const UWORD8 *)gau1_ih264d_submb_parth;
237
0
        const UWORD8 * pu1_num_sub_mb_part =
238
0
                        (const UWORD8 *)gau1_ih264d_num_submb_part;
239
0
        const UWORD8 * pu1_mb_partw = (const UWORD8 *)gau1_ih264d_mb_partw;
240
0
        const UWORD8 * pu1_mb_parth = (const UWORD8 *)gau1_ih264d_mb_parth;
241
0
        UWORD8 u1_p_idx = 0, u1_num_submb_part, uc_lx;
242
0
        parse_part_params_t * ps_part;
243
0
        mv_pred_t *ps_mv_start = ps_dec->ps_mv_cur + (u1_mb_num << 4);
244
0
        UWORD8 u1_mb_part_wd, u1_mb_part_ht;
245
0
246
0
        /* Initialisations */
247
0
        ps_part = ps_dec->ps_part;
248
0
        /* Default Initialization for Non subMb Case Mode */
249
0
        u1_mb_part_wd = pu1_mb_partw[u1_mb_mc_mode];
250
0
        u1_mb_part_ht = pu1_mb_parth[u1_mb_mc_mode];
251
0
        u1_num_submb_part = 1;
252
0
253
0
        /* Decoding the MV for the subMB */
254
0
        for(uc_lx = 0; uc_lx < 2; uc_lx++)
255
0
        {
256
0
            UWORD8 u1_sub_mb_num = 0, u1_pred_mode, uc_i;
257
0
            UWORD32 u4_mb_mc_mode_tmp = u4_mb_mc_mode;
258
0
            UWORD32 u4_mb_pred_mode_tmp = u4_mb_pred_mode;
259
0
            UWORD16 u2_sub_mb_num = 0x028A; // for sub mb case
260
0
            UWORD8 u1_b2 = uc_lx << 1;
261
0
            u1_pred_mode = (uc_lx) ? PRED_L1 : PRED_L0;
262
0
            pu1_top_left_sub_mb_indx = pu1_sub_mb_indx_mod + (u1_mb_mc_mode << 1);
263
0
264
0
            for(uc_i = 0; uc_i < u1_num_mb_part; uc_i++)
265
0
            {
266
0
                UWORD8 u1_mb_mc_mode, uc_j;
267
0
                UWORD8 i1_pred = u4_mb_pred_mode_tmp >> 24;
268
0
                u1_mb_mc_mode = u4_mb_mc_mode_tmp >> 24;
269
0
                u4_mb_pred_mode_tmp <<= 8;
270
0
                u4_mb_mc_mode_tmp <<= 8;
271
0
                /* subMb prediction mode */
272
0
                if(u1_sub_mb)
273
0
                {
274
0
275
0
                    u1_mb_part_wd = pu1_sub_mb_partw[u1_mb_mc_mode];
276
0
                    u1_mb_part_ht = pu1_sub_mb_parth[u1_mb_mc_mode];
277
0
                    u1_sub_mb_num = u2_sub_mb_num >> 12;
278
0
                    u1_num_submb_part = pu1_num_sub_mb_part[u1_mb_mc_mode];
279
0
                    pu1_top_left_sub_mb_indx = pu1_sub_mb_indx_mod
280
0
                                    + (u1_mb_mc_mode << 1);
281
0
                    u2_sub_mb_num <<= 4;
282
0
                }
283
0
                for(uc_j = 0; uc_j < u1_num_submb_part;
284
0
                                uc_j++, pu1_top_left_sub_mb_indx++)
285
0
                {
286
0
                    mv_pred_t * ps_mv;
287
0
                    u1_sub_mb_num = u1_sub_mb_num + *pu1_top_left_sub_mb_indx;
288
0
                    ps_mv = ps_mv_start + u1_sub_mb_num;
289
0
290
0
                    /* Storing Info for partitions, writing only once */
291
0
                    if(uc_lx)
292
0
                    {
293
0
                        ps_part->u1_is_direct = (!i1_pred);
294
0
                        ps_part->u1_pred_mode = i1_pred;
295
0
                        ps_part->u1_sub_mb_num = u1_sub_mb_num;
296
0
                        ps_part->u1_partheight = u1_mb_part_ht;
297
0
                        ps_part->u1_partwidth = u1_mb_part_wd;
298
0
                        /* Increment partition Index */
299
0
                        u1_p_idx++;
300
0
                        ps_part++;
301
0
                    }
302
0
303
0
                    if(i1_pred & u1_pred_mode)
304
0
                    {
305
0
                        WORD16 i2_mvx, i2_mvy;
306
0
307
0
//inlining ih264d_sev
308
0
                        {
309
0
                            UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
310
0
                            UWORD32 u4_word, u4_ldz, u4_abs_val;
311
0
312
0
                            /***************************************************************/
313
0
                            /* Find leading zeros in next 32 bits                          */
314
0
                            /***************************************************************/
315
0
                            NEXTBITS_32(u4_word, u4_bitstream_offset,
316
0
                                        pu4_bitstrm_buf);
317
0
                            u4_ldz = CLZ(u4_word);
318
0
319
0
                            /* Flush the ps_bitstrm */
320
0
                            u4_bitstream_offset += (u4_ldz + 1);
321
0
322
0
                            /* Read the suffix from the ps_bitstrm */
323
0
                            u4_word = 0;
324
0
                            if(u4_ldz)
325
0
                                GETBITS(u4_word, u4_bitstream_offset,
326
0
                                        pu4_bitstrm_buf, u4_ldz);
327
0
328
0
                            *pu4_bitstrm_ofst = u4_bitstream_offset;
329
0
                            u4_abs_val = ((1 << u4_ldz) + u4_word) >> 1;
330
0
331
0
                            if(u4_word & 0x1)
332
0
                                i2_mvx = (-(WORD32)u4_abs_val);
333
0
                            else
334
0
                                i2_mvx = (u4_abs_val);
335
0
                        }
336
0
//inlinined ih264d_sev
337
0
338
0
//inlining ih264d_sev
339
0
                        {
340
0
                            UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
341
0
                            UWORD32 u4_word, u4_ldz, u4_abs_val;
342
0
343
0
                            /***************************************************************/
344
0
                            /* Find leading zeros in next 32 bits                          */
345
0
                            /***************************************************************/
346
0
                            NEXTBITS_32(u4_word, u4_bitstream_offset,
347
0
                                        pu4_bitstrm_buf);
348
0
                            u4_ldz = CLZ(u4_word);
349
0
350
0
                            /* Flush the ps_bitstrm */
351
0
                            u4_bitstream_offset += (u4_ldz + 1);
352
0
353
0
                            /* Read the suffix from the ps_bitstrm */
354
0
                            u4_word = 0;
355
0
                            if(u4_ldz)
356
0
                                GETBITS(u4_word, u4_bitstream_offset,
357
0
                                        pu4_bitstrm_buf, u4_ldz);
358
0
359
0
                            *pu4_bitstrm_ofst = u4_bitstream_offset;
360
0
                            u4_abs_val = ((1 << u4_ldz) + u4_word) >> 1;
361
0
362
0
                            if(u4_word & 0x1)
363
0
                                i2_mvy = (-(WORD32)u4_abs_val);
364
0
                            else
365
0
                                i2_mvy = (u4_abs_val);
366
0
                        }
367
0
//inlinined ih264d_sev
368
0
369
0
                        /* Storing Mv residuals */
370
0
                        ps_mv->i2_mv[u1_b2] = i2_mvx;
371
0
                        ps_mv->i2_mv[u1_b2 + 1] = i2_mvy;
372
0
                    }
373
0
                }
374
0
            }
375
0
        }
376
0
        /* write back to the scratch partition info */
377
0
        ps_dec->ps_part = ps_part;
378
0
        ps_parse_mb_data->u1_num_part = u1_sub_mb ? u1_p_idx : u1_num_mb_part;
379
0
380
0
    }
381
0
    return OK;
382
0
}
383
384
/*!
385
 **************************************************************************
386
 * \if Function name : ParseMb_SubMb_PredBCab\endif
387
 *
388
 * \brief
389
 *    Implements sub_mb_pred() of 7.3.5.2. & mb_pred() of 7.3.5.1
390
 *
391
 * \return
392
 *    None.
393
 *
394
 **************************************************************************
395
 */
396
397
WORD32 ih264d_parse_bmb_non_direct_cabac(dec_struct_t * ps_dec,
398
                                       dec_mb_info_t * ps_cur_mb_info,
399
                                       UWORD8 u1_mb_num,
400
                                       UWORD8 u1_num_mbsNby2)
401
0
{
402
0
    /* Loads from ps_dec */
403
0
    decoding_envirnoment_t * ps_cab_env = &ps_dec->s_cab_dec_env;
404
0
    dec_bit_stream_t * ps_bitstrm = ps_dec->ps_bitstrm;
405
0
    ctxt_inc_mb_info_t *p_curr_ctxt = ps_dec->ps_curr_ctxt_mb_info;
406
0
    parse_pmbarams_t * ps_parse_mb_data = ps_dec->ps_parse_mb_data
407
0
                    + u1_num_mbsNby2;
408
0
409
0
    /* table pointer loads */
410
0
    const UWORD8 * pu1_sub_mb_pred_modes = (UWORD8 *)(gau1_ih264d_submb_pred_modes)
411
0
                    + 4;
412
0
    const UWORD8 (*pu1_mb_pred_modes)[32] =
413
0
                    (const UWORD8 (*)[32])gau1_ih264d_mb_pred_modes;
414
0
    const UWORD8 *pu1_num_mb_part = (const UWORD8 *)gau1_ih264d_num_mb_part;
415
0
    const UWORD8 *pu1_sub_mb_mc_mode = (UWORD8 *)(gau1_ih264d_submb_mc_mode) + 4;
416
0
417
0
    const UWORD8 u1_mb_type = ps_cur_mb_info->u1_mb_type;
418
0
    UWORD8 * pu1_col_info = ps_parse_mb_data->u1_col_info;
419
0
    WORD8 *pi1_ref_idx_l0 = &ps_parse_mb_data->i1_ref_idx[0][0];
420
0
    WORD8 *pi1_ref_idx_l1 = &ps_parse_mb_data->i1_ref_idx[1][0];
421
0
    UWORD8 u1_dec_ref_l0, u1_dec_ref_l1;
422
0
423
0
    UWORD8 u1_num_mb_part, u1_mb_mc_mode, u1_sub_mb, u1_mbpred_mode = 5
424
0
                    + u1_mb_type;
425
0
    UWORD32 u4_mb_mc_mode = 0, u4_mb_pred_mode = 0;
426
0
    WORD32 ret;
427
0
428
0
    p_curr_ctxt->u1_mb_type = CAB_NON_BD16x16;
429
0
    u1_sub_mb = !(u1_mb_type ^ B_8x8);
430
0
431
0
    {
432
0
        UWORD8 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
433
0
        UWORD8 *pu1_num_ref_idx_lx_active =
434
0
                        ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active;
435
0
        UWORD8 uc_field = ps_cur_mb_info->u1_mb_field_decodingflag;
436
0
        UWORD8 u1_mbaff_field = (u1_mbaff & uc_field);
437
0
        u1_dec_ref_l0 = (pu1_num_ref_idx_lx_active[0] << u1_mbaff_field) - 1;
438
0
        u1_dec_ref_l1 = (pu1_num_ref_idx_lx_active[1] << u1_mbaff_field) - 1;
439
0
    }
440
0
441
0
    if(u1_sub_mb)
442
0
    {
443
0
        const UWORD8 u1_colz = ((PRED_8x8) << 6);
444
0
        UWORD8 uc_i;
445
0
        u1_mb_mc_mode = 0;
446
0
        u1_num_mb_part = 4;
447
0
        /* Reading the subMB type */
448
0
        for(uc_i = 0; uc_i < 4; uc_i++)
449
0
        {
450
0
            UWORD8 u1_sub_mb_mode, u1_subMbPredModes;
451
0
            u1_sub_mb_mode = ih264d_parse_submb_type_cabac(
452
0
                            1, ps_cab_env, ps_bitstrm,
453
0
                            ps_dec->p_sub_mb_type_t);
454
0
455
0
            if(u1_sub_mb_mode > 12)
456
0
                return ERROR_SUB_MB_TYPE;
457
0
458
0
            u1_subMbPredModes = pu1_sub_mb_pred_modes[u1_sub_mb_mode];
459
0
            u4_mb_mc_mode = (u4_mb_mc_mode << 8) | pu1_sub_mb_mc_mode[u1_sub_mb_mode];
460
0
            u4_mb_pred_mode = (u4_mb_pred_mode << 8) | u1_subMbPredModes;
461
0
            *pi1_ref_idx_l0++ =
462
0
                            (u1_subMbPredModes & PRED_L0) ? u1_dec_ref_l0 : -1;
463
0
            *pi1_ref_idx_l1++ =
464
0
                            (u1_subMbPredModes & PRED_L1) ? u1_dec_ref_l1 : -1;
465
0
            COPYTHECONTEXT("sub_mb_type", u1_sub_mb_mode);
466
0
            /* Storing collocated Mb and SubMb mode information */
467
0
            *pu1_col_info++ =
468
0
                            (u1_colz | (pu1_sub_mb_mc_mode[u1_sub_mb_mode] << 4));
469
0
            if(u1_sub_mb_mode != B_DIRECT_8x8)
470
0
            {
471
0
                if(u1_sub_mb_mode > B_BI_8x8)
472
0
                {
473
0
                    ps_dec->s_high_profile.u1_no_submb_part_size_lt8x8_flag = 0;
474
0
                }
475
0
            }
476
0
            else if(!ps_dec->s_high_profile.u1_direct_8x8_inference_flag)
477
0
            {
478
0
                ps_dec->s_high_profile.u1_no_submb_part_size_lt8x8_flag = 0;
479
0
            }
480
0
        }
481
0
        pi1_ref_idx_l0 -= 4;
482
0
        pi1_ref_idx_l1 -= 4;
483
0
    }
484
0
    else
485
0
    {
486
0
        UWORD8 u1_mb_pred_mode_part0 = pu1_mb_pred_modes[0][u1_mbpred_mode];
487
0
        UWORD8 u1_mb_pred_mode_part1 = pu1_mb_pred_modes[1][u1_mbpred_mode];
488
0
        u1_mb_mc_mode = ps_cur_mb_info->u1_mb_mc_mode;
489
0
        u1_num_mb_part = pu1_num_mb_part[u1_mb_mc_mode];
490
0
        /* Storing collocated Mb and SubMb mode information */
491
0
        *pu1_col_info++ = (u1_mb_mc_mode << 6);
492
0
        if(u1_mb_mc_mode)
493
0
            *pu1_col_info++ = (u1_mb_mc_mode << 6);
494
0
        u4_mb_mc_mode = u1_mb_mc_mode | (u1_mb_mc_mode << 8);
495
0
        u4_mb_mc_mode <<= 16;
496
0
        u4_mb_pred_mode = ((u1_mb_pred_mode_part0 << 8) | u1_mb_pred_mode_part1) << 16;
497
0
498
0
        *pi1_ref_idx_l0++ = (u1_mb_pred_mode_part0 & PRED_L0) ? u1_dec_ref_l0 : -1;
499
0
        *pi1_ref_idx_l0-- = (u1_mb_pred_mode_part1 & PRED_L0) ? u1_dec_ref_l0 : -1;
500
0
        *pi1_ref_idx_l1++ = (u1_mb_pred_mode_part0 & PRED_L1) ? u1_dec_ref_l1 : -1;
501
0
        *pi1_ref_idx_l1-- = (u1_mb_pred_mode_part1 & PRED_L1) ? u1_dec_ref_l1 : -1;
502
0
    }
503
0
    {
504
0
        WORD8 *pi1_lft_cxt = ps_dec->pi1_left_ref_idx_ctxt_inc;
505
0
        WORD8 *pi1_top_cxt = p_curr_ctxt->i1_ref_idx;
506
0
507
0
        ret = ih264d_parse_ref_idx_cabac(u1_num_mb_part, 0, u1_dec_ref_l0,
508
0
                                   u1_mb_mc_mode, pi1_ref_idx_l0, pi1_lft_cxt,
509
0
                                   pi1_top_cxt, ps_cab_env, ps_bitstrm,
510
0
                                   ps_dec->p_ref_idx_t);
511
0
        if(ret != OK)
512
0
            return ret;
513
0
514
0
        ret = ih264d_parse_ref_idx_cabac(u1_num_mb_part, 2, u1_dec_ref_l1,
515
0
                                   u1_mb_mc_mode, pi1_ref_idx_l1, pi1_lft_cxt,
516
0
                                   pi1_top_cxt, ps_cab_env, ps_bitstrm,
517
0
                                   ps_dec->p_ref_idx_t);
518
0
        if(ret != OK)
519
0
            return ret;
520
0
    }
521
0
    /* Read MotionVectors */
522
0
    {
523
0
        const UWORD8 *pu1_top_left_sub_mb_indx;
524
0
        UWORD8 uc_j, uc_lx;
525
0
        UWORD8 u1_mb_part_wd, u1_mb_part_ht;
526
0
527
0
        const UWORD8 *pu1_sub_mb_indx_mod =
528
0
                        (const UWORD8 *)gau1_ih264d_submb_indx_mod
529
0
                                        + (u1_sub_mb * 6);
530
0
        const UWORD8 *pu1_sub_mb_partw = (const UWORD8 *)gau1_ih264d_submb_partw;
531
0
        const UWORD8 *pu1_sub_mb_parth = (const UWORD8 *)gau1_ih264d_submb_parth;
532
0
        const UWORD8 *pu1_num_sub_mb_part =
533
0
                        (const UWORD8 *)gau1_ih264d_num_submb_part;
534
0
        const UWORD8 *pu1_mb_partw = (const UWORD8 *)gau1_ih264d_mb_partw;
535
0
        const UWORD8 *pu1_mb_parth = (const UWORD8 *)gau1_ih264d_mb_parth;
536
0
537
0
        UWORD8 u1_p_idx = 0;
538
0
        UWORD8 u1_num_submb_part;
539
0
        parse_part_params_t *ps_part;
540
0
        /* Initialisations */
541
0
        mv_pred_t *ps_mv_start = ps_dec->ps_mv_cur + (u1_mb_num << 4);
542
0
        ps_part = ps_dec->ps_part;
543
0
544
0
        /* Default initialization for non subMb case */
545
0
        u1_mb_part_wd = pu1_mb_partw[u1_mb_mc_mode];
546
0
        u1_mb_part_ht = pu1_mb_parth[u1_mb_mc_mode];
547
0
        u1_num_submb_part = 1;
548
0
549
0
        /* Decoding the MV for the subMB */
550
0
        for(uc_lx = 0; uc_lx < 2; uc_lx++)
551
0
        {
552
0
            UWORD8 u1_sub_mb_num = 0;
553
0
            UWORD32 u4_mb_pred_mode_tmp = u4_mb_pred_mode;
554
0
            UWORD32 u4_mb_mc_mode_tmp = u4_mb_mc_mode;
555
0
            UWORD8 u1_mb_mc_mode_1, u1_pred_mode, uc_i;
556
0
            UWORD16 u2_sub_mb_num = 0x028A;
557
0
            UWORD8 u1_b2 = uc_lx << 1;
558
0
            u1_pred_mode = (uc_lx) ? PRED_L1 : PRED_L0;
559
0
            /* Default for Cabac */
560
0
            pu1_top_left_sub_mb_indx = pu1_sub_mb_indx_mod + (u1_mb_mc_mode << 1);
561
0
            for(uc_i = 0; uc_i < u1_num_mb_part; uc_i++)
562
0
            {
563
0
564
0
                WORD8 i1_pred = (UWORD8)(u4_mb_pred_mode_tmp >> 24);
565
0
                u1_mb_mc_mode_1 = (UWORD8)(u4_mb_mc_mode_tmp >> 24);
566
0
                u4_mb_pred_mode_tmp <<= 8;
567
0
                u4_mb_mc_mode_tmp <<= 8;
568
0
569
0
                /* subMb prediction mode */
570
0
                if(u1_sub_mb)
571
0
                {
572
0
                    u1_mb_part_wd = pu1_sub_mb_partw[u1_mb_mc_mode_1];
573
0
                    u1_mb_part_ht = pu1_sub_mb_parth[u1_mb_mc_mode_1];
574
0
                    u1_sub_mb_num = u2_sub_mb_num >> 12;
575
0
                    pu1_top_left_sub_mb_indx = pu1_sub_mb_indx_mod + (u1_mb_mc_mode_1 << 1);
576
0
                    u1_num_submb_part = pu1_num_sub_mb_part[u1_mb_mc_mode_1];
577
0
                    u2_sub_mb_num = u2_sub_mb_num << 4;
578
0
                }
579
0
580
0
                for(uc_j = 0; uc_j < u1_num_submb_part;
581
0
                                uc_j++, pu1_top_left_sub_mb_indx++)
582
0
                {
583
0
                    mv_pred_t *ps_mv;
584
0
                    u1_sub_mb_num = u1_sub_mb_num + *pu1_top_left_sub_mb_indx;
585
0
                    ps_mv = ps_mv_start + u1_sub_mb_num;
586
0
587
0
                    /* Storing Info for partitions, writing only once */
588
0
                    if(uc_lx)
589
0
                    {
590
0
                        ps_part->u1_is_direct = (!i1_pred);
591
0
                        ps_part->u1_pred_mode = i1_pred;
592
0
                        ps_part->u1_sub_mb_num = u1_sub_mb_num;
593
0
                        ps_part->u1_partheight = u1_mb_part_ht;
594
0
                        ps_part->u1_partwidth = u1_mb_part_wd;
595
0
596
0
                        /* Increment partition Index */
597
0
                        u1_p_idx++;
598
0
                        ps_part++;
599
0
                    }
600
0
601
0
                    ih264d_get_mvd_cabac(u1_sub_mb_num, u1_b2, u1_mb_part_wd,
602
0
                                         u1_mb_part_ht,
603
0
                                         (UWORD8)(i1_pred & u1_pred_mode), ps_dec,
604
0
                                         ps_mv);
605
0
                }
606
0
            }
607
0
        }
608
0
        /* write back to the scratch partition info */
609
0
610
0
        ps_dec->ps_part = ps_part;
611
0
        ps_parse_mb_data->u1_num_part = u1_sub_mb ? u1_p_idx : u1_num_mb_part;
612
0
613
0
    }
614
0
615
0
    return OK;
616
0
}
617
618
/*!
619
 **************************************************************************
620
 * \if Function name : ih264d_parse_bmb_cabac \endif
621
 *
622
 * \brief
623
 *    This function parses CABAC syntax of a B MB.
624
 *
625
 * \return
626
 *    0 on Success and Error code otherwise
627
 **************************************************************************
628
 */
629
WORD32 ih264d_parse_bmb_cabac(dec_struct_t * ps_dec,
630
                              dec_mb_info_t * ps_cur_mb_info,
631
                              UWORD8 u1_mb_num,
632
                              UWORD8 u1_num_mbsNby2)
633
0
{
634
0
    UWORD8 u1_cbp;
635
0
    deblk_mb_t * ps_cur_deblk_mb = ps_dec->ps_deblk_mbn + u1_mb_num;
636
0
    const UWORD8 *puc_mb_mc_mode = (const UWORD8 *)gau1_ih264d_mb_mc_mode;
637
0
    UWORD8 u1_mb_type = ps_cur_mb_info->u1_mb_type;
638
0
    ctxt_inc_mb_info_t *p_curr_ctxt = ps_dec->ps_curr_ctxt_mb_info;
639
0
640
0
    WORD32 ret;
641
0
    UWORD8 u1_Bdirect_tranform_read = 1;
642
0
    ps_dec->s_high_profile.u1_no_submb_part_size_lt8x8_flag = 1;
643
0
644
0
    ps_cur_mb_info->u1_mb_mc_mode = puc_mb_mc_mode[5 + u1_mb_type];
645
0
646
0
    ps_cur_mb_info->u1_yuv_dc_block_flag = 0;
647
0
648
0
    ps_cur_deblk_mb->u1_mb_type |= D_B_SLICE;
649
0
    if(u1_mb_type != B_DIRECT)
650
0
    {
651
0
        ret = ih264d_parse_bmb_non_direct_cabac(ps_dec, ps_cur_mb_info, u1_mb_num,
652
0
                                          u1_num_mbsNby2);
653
0
        if(ret != OK)
654
0
            return ret;
655
0
    }
656
0
    else
657
0
    {
658
0
659
0
        /************ STORING PARTITION INFO ***********/
660
0
        parse_part_params_t * ps_part_info;
661
0
        ps_part_info = ps_dec->ps_part;
662
0
        ps_part_info->u1_is_direct = PART_DIRECT_16x16;
663
0
        ps_part_info->u1_sub_mb_num = 0;
664
0
        ps_dec->ps_part++;
665
0
        p_curr_ctxt->u1_mb_type = CAB_BD16x16;
666
0
667
0
        MEMSET_16BYTES(&ps_dec->pu1_left_mv_ctxt_inc[0][0], 0);
668
0
        memset(ps_dec->pi1_left_ref_idx_ctxt_inc, 0, 4);
669
0
        MEMSET_16BYTES(p_curr_ctxt->u1_mv, 0);
670
0
        memset(p_curr_ctxt->i1_ref_idx, 0, 4);
671
0
672
0
        /* check whether transform8x8 u4_flag to be read or not */
673
0
        u1_Bdirect_tranform_read =
674
0
                        ps_dec->s_high_profile.u1_direct_8x8_inference_flag;
675
0
    }
676
0
677
0
    /* Read the Coded block pattern */
678
0
    u1_cbp = (WORD8)ih264d_parse_ctx_cbp_cabac(ps_dec);
679
0
    p_curr_ctxt->u1_cbp = u1_cbp;
680
0
    ps_cur_mb_info->u1_cbp = u1_cbp;
681
0
682
0
    if(u1_cbp > 47)
683
0
        return ERROR_CBP;
684
0
685
0
    COPYTHECONTEXT("coded_block_pattern", u1_cbp);
686
0
687
0
    ps_cur_mb_info->u1_tran_form8x8 = 0;
688
0
    ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0;
689
0
690
0
    if((ps_dec->s_high_profile.u1_transform8x8_present) && (u1_cbp & (0xf))
691
0
                    && (ps_dec->s_high_profile.u1_no_submb_part_size_lt8x8_flag)
692
0
                    && (u1_Bdirect_tranform_read))
693
0
    {
694
0
        ps_cur_mb_info->u1_tran_form8x8 = ih264d_parse_transform8x8flag_cabac(
695
0
                        ps_dec, ps_cur_mb_info);
696
0
        COPYTHECONTEXT("transform_size_8x8_flag", ps_cur_mb_info->u1_tran_form8x8);
697
0
698
0
        ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = ps_cur_mb_info->u1_tran_form8x8;
699
0
        p_curr_ctxt->u1_transform8x8_ctxt = ps_cur_mb_info->u1_tran_form8x8;
700
0
    }
701
0
    else
702
0
    {
703
0
        p_curr_ctxt->u1_transform8x8_ctxt = 0;
704
0
    }
705
0
706
0
    p_curr_ctxt->u1_intra_chroma_pred_mode = 0;
707
0
    p_curr_ctxt->u1_yuv_dc_csbp &= 0xFE;
708
0
    ps_dec->pu1_left_yuv_dc_csbp[0] &= 0x6;
709
0
710
0
    /* Read mb_qp_delta */
711
0
    if(u1_cbp)
712
0
    {
713
0
        WORD8 c_temp;
714
0
        ret = ih264d_parse_mb_qp_delta_cabac(ps_dec, &c_temp);
715
0
        if(ret != OK)
716
0
            return ret;
717
0
        COPYTHECONTEXT("mb_qp_delta", c_temp);
718
0
        if(c_temp)
719
0
        {
720
0
            ret = ih264d_update_qp(ps_dec, c_temp);
721
0
            if(ret != OK)
722
0
                return ret;
723
0
        }
724
0
    }
725
0
    else
726
0
        ps_dec->i1_prev_mb_qp_delta = 0;
727
0
728
0
    ih264d_parse_residual4x4_cabac(ps_dec, ps_cur_mb_info, 0);
729
0
    if(EXCEED_OFFSET(ps_dec->ps_bitstrm))
730
0
        return ERROR_EOB_TERMINATE_T;
731
0
    return OK;
732
0
}
733
/*!
734
 **************************************************************************
735
 * \if Function name : ih264d_parse_bmb_cavlc \endif
736
 *
737
 * \brief
738
 *    This function parses CAVLC syntax of a B MB.
739
 *
740
 * \return
741
 *    0 on Success and Error code otherwise
742
 **************************************************************************
743
 */
744
WORD32 ih264d_parse_bmb_cavlc(dec_struct_t * ps_dec,
745
                              dec_mb_info_t * ps_cur_mb_info,
746
                              UWORD8 u1_mb_num,
747
                              UWORD8 u1_num_mbsNby2)
748
0
{
749
0
    UWORD32 u4_cbp;
750
0
    deblk_mb_t * ps_cur_deblk_mb = ps_dec->ps_deblk_mbn + u1_mb_num;
751
0
    dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
752
0
    UWORD32 * pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
753
0
    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
754
0
    const UWORD8 *puc_mb_mc_mode = (const UWORD8 *)gau1_ih264d_mb_mc_mode;
755
0
    UWORD8 u1_mb_type = ps_cur_mb_info->u1_mb_type;
756
0
757
0
    WORD32 ret;
758
0
    UWORD8 u1_Bdirect_tranform_read = 1;
759
0
    ps_dec->s_high_profile.u1_no_submb_part_size_lt8x8_flag = 1;
760
0
    ps_cur_mb_info->u1_tran_form8x8 = 0;
761
0
    ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0;
762
0
763
0
    ps_cur_mb_info->u1_yuv_dc_block_flag = 0;
764
0
765
0
    ps_cur_mb_info->u1_mb_mc_mode = puc_mb_mc_mode[5 + u1_mb_type];
766
0
767
0
    ps_cur_deblk_mb->u1_mb_type |= D_B_SLICE;
768
0
    if(u1_mb_type != B_DIRECT)
769
0
    {
770
0
        ret = ih264d_parse_bmb_non_direct_cavlc(ps_dec, ps_cur_mb_info, u1_mb_num,
771
0
                                          u1_num_mbsNby2);
772
0
        if(ret != OK)
773
0
            return ret;
774
0
    }
775
0
    else
776
0
    {
777
0
        /************ STORING PARTITION INFO ***********/
778
0
        parse_part_params_t * ps_part_info;
779
0
        ps_part_info = ps_dec->ps_part;
780
0
        ps_part_info->u1_is_direct = PART_DIRECT_16x16;
781
0
        ps_part_info->u1_sub_mb_num = 0;
782
0
        ps_dec->ps_part++;
783
0
        /* check whether transform8x8 u4_flag to be read or not */
784
0
        u1_Bdirect_tranform_read =
785
0
                        ps_dec->s_high_profile.u1_direct_8x8_inference_flag;
786
0
    }
787
0
788
0
    /* Read the Coded block pattern */
789
0
    {
790
0
        const UWORD8 * puc_CbpInter = gau1_ih264d_cbp_inter;
791
0
//Inlined ih264d_uev
792
0
        UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
793
0
        UWORD32 u4_word, u4_ldz;
794
0
795
0
        /***************************************************************/
796
0
        /* Find leading zeros in next 32 bits                          */
797
0
        /***************************************************************/
798
0
        NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
799
0
        u4_ldz = CLZ(u4_word);
800
0
        /* Flush the ps_bitstrm */
801
0
        u4_bitstream_offset += (u4_ldz + 1);
802
0
        /* Read the suffix from the ps_bitstrm */
803
0
        u4_word = 0;
804
0
        if(u4_ldz)
805
0
            GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf, u4_ldz);
806
0
        *pu4_bitstrm_ofst = u4_bitstream_offset;
807
0
        u4_cbp = ((1 << u4_ldz) + u4_word - 1);
808
0
//Inlined ih264d_uev
809
0
        if(u4_cbp > 47)
810
0
            return ERROR_CBP;
811
0
        u4_cbp = puc_CbpInter[u4_cbp];
812
0
813
0
        if((ps_dec->s_high_profile.u1_transform8x8_present) && (u4_cbp & (0xf))
814
0
                        && (ps_dec->s_high_profile.u1_no_submb_part_size_lt8x8_flag)
815
0
                        && (u1_Bdirect_tranform_read))
816
0
        {
817
0
            ps_cur_mb_info->u1_tran_form8x8 = ih264d_get_bit_h264(ps_bitstrm);
818
0
            COPYTHECONTEXT("transform_size_8x8_flag", ps_cur_mb_info->u1_tran_form8x8);
819
0
            ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = ps_cur_mb_info->u1_tran_form8x8;
820
0
        }
821
0
822
0
    }
823
0
824
0
    COPYTHECONTEXT("coded_block_pattern", u4_cbp);
825
0
    ps_cur_mb_info->u1_cbp = u4_cbp;
826
0
827
0
    /* Read mb_qp_delta */
828
0
    if(u4_cbp)
829
0
    {
830
0
        WORD32 i_temp;
831
0
//inlining ih264d_sev
832
0
833
0
        UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
834
0
        UWORD32 u4_word, u4_ldz, u4_abs_val;
835
0
836
0
        /***************************************************************/
837
0
        /* Find leading zeros in next 32 bits                          */
838
0
        /***************************************************************/
839
0
        NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
840
0
        u4_ldz = CLZ(u4_word);
841
0
842
0
        /* Flush the ps_bitstrm */
843
0
        u4_bitstream_offset += (u4_ldz + 1);
844
0
845
0
        /* Read the suffix from the ps_bitstrm */
846
0
        u4_word = 0;
847
0
        if(u4_ldz)
848
0
            GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf, u4_ldz);
849
0
850
0
        *pu4_bitstrm_ofst = u4_bitstream_offset;
851
0
        u4_abs_val = ((1 << u4_ldz) + u4_word) >> 1;
852
0
853
0
        if(u4_word & 0x1)
854
0
            i_temp = (-(WORD32)u4_abs_val);
855
0
        else
856
0
            i_temp = (u4_abs_val);
857
0
858
0
        if(i_temp < -26 || i_temp > 25)
859
0
            return ERROR_INV_RANGE_QP_T;
860
0
//inlinined ih264d_sev
861
0
        COPYTHECONTEXT("mb_qp_delta", i_temp);
862
0
        if(i_temp)
863
0
        {
864
0
            ret = ih264d_update_qp(ps_dec, (WORD8)i_temp);
865
0
            if(ret != OK)
866
0
                return ret;
867
0
        }
868
0
869
0
        ret = ih264d_parse_residual4x4_cavlc(ps_dec, ps_cur_mb_info, 0);
870
0
        if(ret != OK)
871
0
            return ret;
872
0
        if(EXCEED_OFFSET(ps_bitstrm))
873
0
            return ERROR_EOB_TERMINATE_T;
874
0
    }
875
0
    else
876
0
    {
877
0
        ps_dec->i1_prev_mb_qp_delta = 0;
878
0
        ih264d_update_nnz_for_skipmb(ps_dec, ps_cur_mb_info, CAVLC);
879
0
    }
880
0
881
0
    return OK;
882
0
}
883
884
WORD32 ih264d_mv_pred_ref_tfr_nby2_bmb(dec_struct_t * ps_dec,
885
                                     UWORD8 u1_mb_idx,
886
                                     UWORD8 u1_num_mbs)
887
0
{
888
0
    parse_pmbarams_t * ps_mb_part_info;
889
0
    parse_part_params_t * ps_part;
890
0
    mv_pred_t *ps_mv_nmb, *ps_mv_nmb_start, *ps_mv_ntop, *ps_mv_ntop_start;
891
0
    pic_buffer_t * ps_ref_frame;
892
0
    UWORD8 u1_direct_mode_width;
893
0
    UWORD8 i, j;
894
0
    dec_mb_info_t * ps_cur_mb_info;
895
0
    const UWORD8 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
896
0
    UWORD8 u1_field;
897
0
    WORD32 ret = 0;
898
0
899
0
    ps_dec->i4_submb_ofst -= (u1_num_mbs - u1_mb_idx) << 4;
900
0
    ps_mb_part_info = ps_dec->ps_parse_mb_data;
901
0
    ps_part = ps_dec->ps_parse_part_params;
902
0
903
0
    /* N/2 Mb MvPred and Transfer Setup Loop */
904
0
    for(i = u1_mb_idx; i < u1_num_mbs; i++, ps_mb_part_info++)
905
0
    {
906
0
        UWORD8 u1_colz = 0;
907
0
        ps_dec->i4_submb_ofst += SUB_BLK_SIZE;
908
0
        /* Restore the slice scratch MbX and MbY context */
909
0
        ps_cur_mb_info = ps_dec->ps_nmb_info + i;
910
0
911
0
912
0
        u1_field = ps_cur_mb_info->u1_mb_field_decodingflag;
913
0
914
0
        ps_mv_nmb_start = ps_dec->ps_mv_cur + (i << 4);
915
0
        ps_dec->u2_mbx = ps_cur_mb_info->u2_mbx;
916
0
        ps_dec->u2_mby = ps_cur_mb_info->u2_mby;
917
0
        ps_dec->u1_currB_type = 0;
918
0
        ps_dec->u2_mv_2mb[i & 0x1] = 0;
919
0
920
0
        /* Look for MV Prediction and Reference Transfer in Non-I Mbs */
921
0
        if(!ps_mb_part_info->u1_isI_mb)
922
0
        {
923
0
            UWORD8 u1_blk_no;
924
0
            WORD16 i1_ref_idx, i1_ref_idx1;
925
0
            UWORD8 u1_pred_mode;
926
0
            UWORD8 u1_sub_mb_x, u1_sub_mb_y, u1_sub_mb_num;
927
0
            UWORD8 u1_lx, u1_lx_start, u1_lxend, u1_tmp_lx;
928
0
            UWORD8 u1_num_part, u1_num_ref, u1_wd, u1_ht;
929
0
            UWORD32 *pu4_wt_offst;
930
0
            UWORD8 u1_scale_ref, u4_bot_mb;
931
0
            deblk_mb_t * ps_cur_deblk_mb = ps_dec->ps_deblk_mbn + i;
932
0
            WORD8 (*pi1_ref_idx)[MAX_REFIDX_INFO_PER_MB] =
933
0
                            ps_mb_part_info->i1_ref_idx;
934
0
            WORD8 *pi1_ref_idx0 = pi1_ref_idx[0],
935
0
                            *pi1_ref_idx1 = pi1_ref_idx[1];
936
0
            UWORD32 **ppu4_wt_ofst = ps_mb_part_info->pu4_wt_offst;
937
0
938
0
            /* MB Level initialisations */
939
0
            ps_dec->u4_num_pmbair = i >> u1_mbaff;
940
0
            ps_dec->u1_mb_idx_mv = i;
941
0
942
0
            /* CHANGED CODE */
943
0
            ps_mv_ntop_start = ps_mv_nmb_start
944
0
                            - (ps_dec->u2_frm_wd_in_mbs << (4 + u1_mbaff)) + 12;
945
0
946
0
            u1_num_part = ps_mb_part_info->u1_num_part;
947
0
            ps_cur_deblk_mb->u1_mb_type |= (u1_num_part > 1) << 1;
948
0
            u1_direct_mode_width = (1 == ps_mb_part_info->u1_num_part) ? 16 : 8;
949
0
950
0
951
0
            ps_cur_mb_info->u4_pred_info_pkd_idx = ps_dec->u4_pred_info_pkd_idx;
952
0
            ps_cur_mb_info->u1_num_pred_parts = 0;
953
0
954
0
            /****************************************************/
955
0
            /* weighted u4_ofst pointer calculations, this loop  */
956
0
            /* runs maximum 4 times, even in direct cases       */
957
0
            /****************************************************/
958
0
            u1_scale_ref = u1_mbaff & ps_cur_mb_info->u1_mb_field_decodingflag;
959
0
            u4_bot_mb = 1 - ps_cur_mb_info->u1_topmb;
960
0
            if(ps_dec->ps_cur_pps->u1_wted_bipred_idc)
961
0
            {
962
0
                u1_num_ref = MIN(u1_num_part, 4);
963
0
                if(PART_DIRECT_16x16 != ps_part->u1_is_direct)
964
0
                {
965
0
                    for(u1_blk_no = 0; u1_blk_no < u1_num_ref; u1_blk_no++)
966
0
                    {
967
0
                        i1_ref_idx = MAX(pi1_ref_idx0[u1_blk_no], 0);
968
0
                        if(u1_scale_ref)
969
0
                            i1_ref_idx >>= 1;
970
0
                        i1_ref_idx *=
971
0
                                        ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[1];
972
0
                        if(u1_scale_ref)
973
0
                            i1_ref_idx +=
974
0
                                            (MAX(pi1_ref_idx1[u1_blk_no], 0)
975
0
                                                            >> 1);
976
0
                        else
977
0
                            i1_ref_idx += MAX(pi1_ref_idx1[u1_blk_no], 0);
978
0
                        pu4_wt_offst = (UWORD32*)&ps_dec->pu4_wt_ofsts[2
979
0
                                        * X3(i1_ref_idx)];
980
0
981
0
                        if(pi1_ref_idx0[u1_blk_no] < 0)
982
0
                            pu4_wt_offst += 1;
983
0
984
0
                        ppu4_wt_ofst[u1_blk_no] = pu4_wt_offst;
985
0
                        if(u1_scale_ref
986
0
                                        && (ps_dec->ps_cur_pps->u1_wted_bipred_idc
987
0
                                                        == 2))
988
0
                        {
989
0
                            i1_ref_idx = MAX(pi1_ref_idx0[u1_blk_no], 0);
990
0
                            i1_ref_idx *=
991
0
                                            (ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[1]
992
0
                                                            << 1);
993
0
                            i1_ref_idx += MAX(pi1_ref_idx1[u1_blk_no], 0);
994
0
                            if(u4_bot_mb)
995
0
                            {
996
0
                                i1_ref_idx +=
997
0
                                                (ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[0]
998
0
                                                                << 1)
999
0
                                                                * (ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[1]
1000
0
                                                                                << 1);
1001
0
                            }
1002
0
                            pu4_wt_offst = (UWORD32*)&ps_dec->pu4_mbaff_wt_mat[2
1003
0
                                            * X3(i1_ref_idx)];
1004
0
                            ppu4_wt_ofst[u1_blk_no] = pu4_wt_offst;
1005
0
                        }
1006
0
                    }
1007
0
                }
1008
0
            }
1009
0
1010
0
            /**************************************************/
1011
0
            /* Loop on Partitions                             */
1012
0
            /* direct mode is reflected as a single partition */
1013
0
            /**************************************************/
1014
0
            for(j = 0; j < u1_num_part; j++, ps_part++)
1015
0
            {
1016
0
                u1_sub_mb_num = ps_part->u1_sub_mb_num;
1017
0
                ps_dec->u1_sub_mb_num = u1_sub_mb_num;
1018
0
1019
0
                if(PART_NOT_DIRECT != ps_part->u1_is_direct)
1020
0
                {
1021
0
                    /**************************************************/
1022
0
                    /* Direct Mode, Call DecodeSpatial/TemporalDirect */
1023
0
                    /* only (those will in turn call FormMbPartInfo)  */
1024
0
                    /**************************************************/
1025
0
                    ret = ps_dec->ps_cur_slice->pf_decodeDirect(ps_dec,
1026
0
                                                                u1_direct_mode_width,
1027
0
                                                                ps_cur_mb_info, i);
1028
0
                    if(ret != OK)
1029
0
                        return ret;
1030
0
                    ps_cur_deblk_mb->u1_mb_type |= (ps_dec->u1_currB_type << 1);
1031
0
1032
0
                }
1033
0
                else
1034
0
                {
1035
0
                    mv_pred_t s_mvPred;
1036
0
                    /**************************************************/
1037
0
                    /* Non Direct Mode, Call Motion Vector Predictor  */
1038
0
                    /* and FormMbpartInfo                             */
1039
0
                    /**************************************************/
1040
0
                    u1_sub_mb_x = u1_sub_mb_num & 0x03;
1041
0
                    u1_sub_mb_y = u1_sub_mb_num >> 2;
1042
0
                    u1_blk_no =
1043
0
                                    (u1_num_part < 4) ?
1044
0
                                                    j :
1045
0
                                                    (((u1_sub_mb_y >> 1) << 1)
1046
0
                                                                    + (u1_sub_mb_x
1047
0
                                                                                    >> 1));
1048
0
1049
0
                    ps_mv_ntop = ps_mv_ntop_start + u1_sub_mb_x;
1050
0
                    ps_mv_nmb = ps_mv_nmb_start + u1_sub_mb_num;
1051
0
1052
0
                    u1_pred_mode = ps_part->u1_pred_mode;
1053
0
                    u1_wd = ps_part->u1_partwidth;
1054
0
                    u1_ht = ps_part->u1_partheight;
1055
0
1056
0
                    u1_lx_start = 0;
1057
0
                    u1_lxend = 2;
1058
0
                    if( PRED_L0 == u1_pred_mode)
1059
0
                    {
1060
0
                        s_mvPred.i2_mv[2] = 0;
1061
0
                        s_mvPred.i2_mv[3] = 0;
1062
0
                        u1_lxend = 1;
1063
0
                    }
1064
0
                    if( PRED_L1 == u1_pred_mode)
1065
0
                    {
1066
0
                        s_mvPred.i2_mv[0] = 0;
1067
0
                        s_mvPred.i2_mv[1] = 0;
1068
0
                        u1_lx_start = 1;
1069
0
                    }
1070
0
1071
0
                    /* Populate the colpic info and reference frames */
1072
0
                    s_mvPred.i1_ref_frame[0] = pi1_ref_idx0[u1_blk_no];
1073
0
                    s_mvPred.i1_ref_frame[1] = pi1_ref_idx1[u1_blk_no];
1074
0
1075
0
                    ps_dec->pf_mvpred(ps_dec, ps_cur_mb_info, ps_mv_nmb, ps_mv_ntop,
1076
0
                                      &s_mvPred, u1_sub_mb_num, u1_wd,
1077
0
                                      u1_lx_start, u1_lxend,
1078
0
                                      ps_cur_mb_info->u1_mb_mc_mode);
1079
0
1080
0
                    /**********************************************************/
1081
0
                    /* Loop on number of predictors, 1 Each for Forw Backw    */
1082
0
                    /* Loop 2 times for BiDirect mode                         */
1083
0
                    /**********************************************************/
1084
0
                    for(u1_lx = u1_lx_start; u1_lx < u1_lxend; u1_lx++)
1085
0
                    {
1086
0
                        WORD16 i2_mv_x, i2_mv_y;
1087
0
1088
0
                        /********************************************************/
1089
0
                        /* Predict Mv                                           */
1090
0
                        /* Add Mv Residuals and store back                      */
1091
0
                        /********************************************************/
1092
0
                        i1_ref_idx = s_mvPred.i1_ref_frame[u1_lx];
1093
0
                        u1_tmp_lx = (u1_lx << 1);
1094
0
1095
0
                        i2_mv_x = ps_mv_nmb->i2_mv[u1_tmp_lx];
1096
0
                        i2_mv_y = ps_mv_nmb->i2_mv[u1_tmp_lx + 1];
1097
0
1098
0
                        i2_mv_x += s_mvPred.i2_mv[u1_tmp_lx];
1099
0
                        i2_mv_y += s_mvPred.i2_mv[u1_tmp_lx + 1];
1100
0
                        s_mvPred.i2_mv[u1_tmp_lx] = i2_mv_x;
1101
0
                        s_mvPred.i2_mv[u1_tmp_lx + 1] = i2_mv_y;
1102
0
1103
0
                        /********************************************************/
1104
0
                        /* Transfer setup call                                  */
1105
0
                        /* convert RefIdx if it is MbAff                        */
1106
0
                        /* Pass Weight Offset and refFrame                      */
1107
0
                        /********************************************************/
1108
0
                        i1_ref_idx1 = i1_ref_idx >> u1_scale_ref;
1109
0
                        if(u1_scale_ref && ((i1_ref_idx & 0x01) != u4_bot_mb))
1110
0
                            i1_ref_idx1 += MAX_REF_BUFS;
1111
0
                        ps_ref_frame =
1112
0
                                        ps_dec->ps_ref_pic_buf_lx[u1_lx][i1_ref_idx1];
1113
0
1114
0
                        /* Storing Colocated-Zero u4_flag */
1115
0
                        if(u1_lx == u1_lx_start)
1116
0
                        {
1117
0
                            /* Fill colocated info in MvPred structure */
1118
0
                            s_mvPred.u1_col_ref_pic_idx =
1119
0
                                            ps_ref_frame->u1_mv_buf_id;
1120
0
                            s_mvPred.u1_pic_type = ps_ref_frame->u1_pic_type;
1121
0
1122
0
                            /* Calculating colocated zero information */
1123
0
                            u1_colz =
1124
0
                                            (u1_field << 1)
1125
0
                                                            | ((i1_ref_idx == 0)
1126
0
                                                                            && (ABS(i2_mv_x)
1127
0
                                                                                            <= 1)
1128
0
                                                                            && (ABS(i2_mv_y)
1129
0
                                                                                            <= 1));
1130
0
                            u1_colz |= ps_mb_part_info->u1_col_info[u1_blk_no];
1131
0
                        }
1132
0
1133
0
                        pu4_wt_offst = ppu4_wt_ofst[u1_blk_no];
1134
0
                        {
1135
0
                            pred_info_pkd_t *ps_pred_pkd;
1136
0
                           WORD16 i2_mv[2];
1137
0
1138
0
                           i2_mv[0] = i2_mv_x;
1139
0
                           i2_mv[1] = i2_mv_y;
1140
0
1141
0
                           ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx;
1142
0
                        ih264d_fill_pred_info(i2_mv,u1_wd,u1_ht,u1_sub_mb_num,u1_pred_mode,
1143
0
                                        ps_pred_pkd,ps_ref_frame->u1_pic_buf_id,i1_ref_idx,pu4_wt_offst,
1144
0
                                        ps_ref_frame->u1_pic_type);
1145
0
                        ps_dec->u4_pred_info_pkd_idx++;
1146
0
                        ps_cur_mb_info->u1_num_pred_parts++;
1147
0
1148
0
1149
0
                        }
1150
0
1151
0
                    }
1152
0
                    ih264d_rep_mv_colz(ps_dec, &s_mvPred, ps_mv_nmb,
1153
0
                                       u1_sub_mb_num, u1_colz, u1_ht,
1154
0
                                       u1_wd);
1155
0
                }
1156
0
            }
1157
0
1158
0
        }
1159
0
        else
1160
0
        {
1161
0
            /* Set zero values in case of Intra Mbs */
1162
0
            mv_pred_t s_mvPred =
1163
0
                {
1164
0
                    { 0, 0, 0, 0 },
1165
0
                      { -1, -1 }, 0, 0};
1166
0
            /* Storing colocated zero information */
1167
0
            ih264d_rep_mv_colz(ps_dec, &s_mvPred, ps_mv_nmb_start, 0,
1168
0
                               (UWORD8)(u1_field << 1), 4, 4);
1169
0
        }
1170
0
1171
0
        /*if num _cores is set to 3 ,compute bs will be done in another thread*/
1172
0
        if(ps_dec->u4_num_cores < 3)
1173
0
        {
1174
0
            if(ps_dec->u4_app_disable_deblk_frm == 0)
1175
0
                ps_dec->pf_compute_bs(ps_dec, ps_cur_mb_info,
1176
0
                                     (UWORD16)(i >> u1_mbaff));
1177
0
        }
1178
0
    }
1179
0
    return OK;
1180
0
}
1181
/*!
1182
 **************************************************************************
1183
 * \if Function name : ih264d_get_implicit_weights \endif
1184
 *
1185
 * \brief
1186
 *    Calculates Implicit Weights.
1187
 *
1188
 * \return
1189
 *    None
1190
 *
1191
 **************************************************************************
1192
 */
1193
void ih264d_get_implicit_weights(dec_struct_t *ps_dec)
1194
0
{
1195
0
    UWORD32 *pu4_iwt_ofst;
1196
0
    UWORD8 i, j;
1197
0
    struct pic_buffer_t *ps_pic_buff0, *ps_pic_buff1;
1198
0
    WORD16 i2_dist_scale_factor;
1199
0
    WORD16 i16_tb, i16_td, i16_tx;
1200
0
    WORD32 i4_tb, i4_td;
1201
0
    WORD32 i4_poc0, i4_poc1;
1202
0
    UWORD32 ui_temp0, ui_temp1;
1203
0
    UWORD8 uc_num_ref_idx_l0_active, uc_num_ref_idx_l1_active;
1204
0
1205
0
    pu4_iwt_ofst = ps_dec->pu4_wts_ofsts_mat;
1206
0
    uc_num_ref_idx_l0_active =
1207
0
                    ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[0];
1208
0
    uc_num_ref_idx_l1_active =
1209
0
                    ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[1];
1210
0
1211
0
    for(i = 0; i < uc_num_ref_idx_l0_active; i++)
1212
0
    {
1213
0
        ps_pic_buff0 = ps_dec->ps_ref_pic_buf_lx[0][i];
1214
0
        i4_poc0 = ps_pic_buff0->i4_avg_poc;
1215
0
        for(j = 0; j < uc_num_ref_idx_l1_active; j++)
1216
0
        {
1217
0
            ps_pic_buff1 = ps_dec->ps_ref_pic_buf_lx[1][j];
1218
0
            i4_poc1 = ps_pic_buff1->i4_avg_poc;
1219
0
1220
0
            if(i4_poc1 != i4_poc0)
1221
0
            {
1222
0
                i4_tb = ps_dec->ps_cur_pic->i4_poc - i4_poc0;
1223
0
                i16_tb = CLIP3(-128, 127, i4_tb);
1224
0
                i4_td = i4_poc1 - i4_poc0;
1225
0
                i16_td = CLIP3(-128, 127, i4_td);
1226
0
                i16_tx = (16384 + ABS(SIGN_POW2_DIV(i16_td, 1))) / i16_td;
1227
0
                i2_dist_scale_factor = CLIP3(-1024, 1023,
1228
0
                                            (((i16_tb * i16_tx) + 32) >> 6));
1229
0
1230
0
                if(/*((u4_poc1 - u4_poc0) == 0) ||*/
1231
0
                (!(ps_pic_buff1->u1_is_short && ps_pic_buff0->u1_is_short))
1232
0
                                || ((i2_dist_scale_factor >> 2) < -64)
1233
0
                                || ((i2_dist_scale_factor >> 2) > 128))
1234
0
                {
1235
0
                    /* same for forward and backward, wt=32 and Offset = 0 */
1236
0
                    ui_temp0 = 0x00000020;
1237
0
                    ui_temp1 = 0x00000020;
1238
0
                }
1239
0
                else
1240
0
                {
1241
0
                    ui_temp0 = 64 - (i2_dist_scale_factor >> 2);
1242
0
                    ui_temp1 = (i2_dist_scale_factor >> 2);
1243
0
                }
1244
0
            }
1245
0
            else
1246
0
            {
1247
0
                ui_temp0 = 0x00000020;
1248
0
                ui_temp1 = 0x00000020;
1249
0
            }
1250
0
            pu4_iwt_ofst[0] = pu4_iwt_ofst[2] = pu4_iwt_ofst[4] = ui_temp0;
1251
0
            pu4_iwt_ofst[1] = pu4_iwt_ofst[3] = pu4_iwt_ofst[5] = ui_temp1;
1252
0
            pu4_iwt_ofst += 6;
1253
0
        }
1254
0
    }
1255
0
    if(ps_dec->ps_cur_slice->u1_mbaff_frame_flag)
1256
0
    {
1257
0
        UWORD8 k;
1258
0
        WORD32 i4_cur_poc = ps_dec->ps_cur_pic->i4_top_field_order_cnt;
1259
0
        UWORD32* pu4_wt_mat = ps_dec->pu4_mbaff_wt_mat;
1260
0
        /* Form the Implicit Weighted prediction matrix for field MBs also */
1261
0
        for(k = 0; k < 2; k++)
1262
0
        {
1263
0
            for(i = 0; i < (uc_num_ref_idx_l0_active << 1); i++)
1264
0
            {
1265
0
                UWORD16 u2_l0_idx;
1266
0
1267
0
                /*u2_l0_idx = (i >= uc_num_ref_idx_l0_active)
1268
0
                 ?(MAX_REF_BUFS + i - uc_num_ref_idx_l0_active) : (i) ;*/
1269
0
1270
0
                u2_l0_idx = i >> 1;
1271
0
                if((i & 0x01) != k)
1272
0
                {
1273
0
                    u2_l0_idx += MAX_REF_BUFS;
1274
0
                }
1275
0
                ps_pic_buff0 = ps_dec->ps_ref_pic_buf_lx[0][u2_l0_idx];
1276
0
                i4_poc0 = ps_pic_buff0->i4_poc;
1277
0
                for(j = 0; j < (uc_num_ref_idx_l1_active << 1); j++)
1278
0
                {
1279
0
                    UWORD16 u2_l1_idx;
1280
0
                    /*u2_l1_idx = (j >= uc_num_ref_idx_l1_active)
1281
0
                     ? (MAX_REF_BUFS + j - uc_num_ref_idx_l1_active ) : (j) ;*/
1282
0
1283
0
                    u2_l1_idx = j >> 1;
1284
0
                    if((j & 0x01) != k)
1285
0
                    {
1286
0
                        u2_l1_idx += MAX_REF_BUFS;
1287
0
                    }
1288
0
                    ps_pic_buff1 = ps_dec->ps_ref_pic_buf_lx[1][u2_l1_idx];
1289
0
                    i4_poc1 = ps_pic_buff1->i4_poc;
1290
0
                    if(i4_poc1 != i4_poc0)
1291
0
                    {
1292
0
                        i4_tb = i4_cur_poc - i4_poc0;
1293
0
                        i16_tb = CLIP3(-128, 127, i4_tb);
1294
0
                        i4_td = i4_poc1 - i4_poc0;
1295
0
                        i16_td = CLIP3(-128, 127, i4_td);
1296
0
                        i16_tx = (16384 + ABS(SIGN_POW2_DIV(i16_td, 1)))
1297
0
                                        / i16_td;
1298
0
                        i2_dist_scale_factor = CLIP3(
1299
0
                                        -1024, 1023,
1300
0
                                        (((i16_tb * i16_tx) + 32) >> 6));
1301
0
1302
0
                        if(/*((u4_poc1 - u4_poc0) == 0) ||*/
1303
0
                        (!(ps_pic_buff1->u1_is_short && ps_pic_buff0->u1_is_short))
1304
0
                                        || ((i2_dist_scale_factor >> 2) < -64)
1305
0
                                        || ((i2_dist_scale_factor >> 2) > 128))
1306
0
                        {
1307
0
                            /* same for forward and backward, wt=32 and Offset = 0 */
1308
0
                            ui_temp0 = 0x00000020;
1309
0
                            ui_temp1 = 0x00000020;
1310
0
                        }
1311
0
                        else
1312
0
                        {
1313
0
                            ui_temp0 = 64 - (i2_dist_scale_factor >> 2);
1314
0
                            ui_temp1 = (i2_dist_scale_factor >> 2);
1315
0
                        }
1316
0
                    }
1317
0
                    else
1318
0
                    {
1319
0
                        ui_temp0 = 0x00000020;
1320
0
                        ui_temp1 = 0x00000020;
1321
0
                    }
1322
0
                    /* Store in the weight matrix */
1323
0
                    *pu4_wt_mat++ = ui_temp0;
1324
0
                    *pu4_wt_mat++ = ui_temp1;
1325
0
                    *pu4_wt_mat++ = ui_temp0;
1326
0
                    *pu4_wt_mat++ = ui_temp1;
1327
0
                    *pu4_wt_mat++ = ui_temp0;
1328
0
                    *pu4_wt_mat++ = ui_temp1;
1329
0
1330
0
                }
1331
0
            }
1332
0
            i4_cur_poc = ps_dec->ps_cur_pic->i4_bottom_field_order_cnt;
1333
0
        }
1334
0
    }
1335
0
}
1336
1337
/*!
1338
 **************************************************************************
1339
 * \if Function name : ih264d_decode_bslice \endif
1340
 *
1341
 * \brief
1342
 *    Decodes a B Slice
1343
 *
1344
 *
1345
 * \return
1346
 *    0 on Success and Error code otherwise
1347
 **************************************************************************
1348
 */
1349
WORD32 ih264d_parse_bslice(dec_struct_t * ps_dec, UWORD16 u2_first_mb_in_slice)
1350
0
{
1351
0
    dec_pic_params_t * ps_pps = ps_dec->ps_cur_pps;
1352
0
    dec_slice_params_t * ps_slice = ps_dec->ps_cur_slice;
1353
0
    dec_bit_stream_t * ps_bitstrm = ps_dec->ps_bitstrm;
1354
0
    UWORD8 u1_ref_idx_re_flag_lx;
1355
0
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
1356
0
    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
1357
0
1358
0
    UWORD32 u4_temp, ui_temp1;
1359
0
    WORD32 i_temp;
1360
0
    WORD32 ret;
1361
0
1362
0
    /*--------------------------------------------------------------------*/
1363
0
    /* Read remaining contents of the slice header                        */
1364
0
    /*--------------------------------------------------------------------*/
1365
0
    {
1366
0
        WORD8 *pi1_buf;
1367
0
        WORD16 *pi2_mv = ps_dec->s_default_mv_pred.i2_mv;
1368
0
        WORD32 *pi4_mv = (WORD32*)pi2_mv;
1369
0
        WORD16 *pi16_refFrame;
1370
0
        pi1_buf = ps_dec->s_default_mv_pred.i1_ref_frame;
1371
0
        pi16_refFrame = (WORD16*)pi1_buf;
1372
0
        *pi4_mv = 0;
1373
0
        *(pi4_mv + 1) = 0;
1374
0
        *pi16_refFrame = OUT_OF_RANGE_REF;
1375
0
        ps_dec->s_default_mv_pred.u1_col_ref_pic_idx = (UWORD8)-1;
1376
0
        ps_dec->s_default_mv_pred.u1_pic_type = (UWORD8)-1;
1377
0
    }
1378
0
1379
0
    ps_slice->u1_num_ref_idx_active_override_flag = ih264d_get_bit_h264(
1380
0
                    ps_bitstrm);
1381
0
    COPYTHECONTEXT("SH: num_ref_idx_override_flag",
1382
0
                    ps_slice->u1_num_ref_idx_active_override_flag);
1383
0
1384
0
    u4_temp = ps_dec->ps_cur_pps->u1_num_ref_idx_lx_active[0];
1385
0
    ui_temp1 = ps_dec->ps_cur_pps->u1_num_ref_idx_lx_active[1];
1386
0
    if(ps_slice->u1_num_ref_idx_active_override_flag)
1387
0
    {
1388
0
        u4_temp = 1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1389
0
        COPYTHECONTEXT("SH: num_ref_idx_l0_active_minus1",
1390
0
                        u4_temp - 1);
1391
0
        ui_temp1 = 1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1392
0
        COPYTHECONTEXT("SH: num_ref_idx_l1_active_minus1",
1393
0
                        ui_temp1 - 1);
1394
0
    }
1395
0
1396
0
    {
1397
0
        UWORD8 u1_max_ref_idx = MAX_FRAMES;
1398
0
        if(ps_slice->u1_field_pic_flag)
1399
0
        {
1400
0
            u1_max_ref_idx = MAX_FRAMES << 1;
1401
0
        }
1402
0
        if((u4_temp > u1_max_ref_idx) || (ui_temp1 > u1_max_ref_idx)
1403
0
                        || (u4_temp < 1) || (ui_temp1 < 1))
1404
0
        {
1405
0
            return ERROR_NUM_REF;
1406
0
        }
1407
0
        ps_slice->u1_num_ref_idx_lx_active[0] = u4_temp;
1408
0
        ps_slice->u1_num_ref_idx_lx_active[1] = ui_temp1;
1409
0
    }
1410
0
1411
0
1412
0
    ih264d_init_ref_idx_lx_b(ps_dec);
1413
0
    /* Store the value for future slices in the same picture */
1414
0
    ps_dec->u1_num_ref_idx_lx_active_prev =
1415
0
                    ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[0];
1416
0
1417
0
    u1_ref_idx_re_flag_lx = ih264d_get_bit_h264(ps_bitstrm);
1418
0
    COPYTHECONTEXT("SH: ref_pic_list_reordering_flag_l0",u1_ref_idx_re_flag_lx);
1419
0
1420
0
    /* Modified temporarily */
1421
0
    if(u1_ref_idx_re_flag_lx)
1422
0
    {
1423
0
        WORD8 ret;
1424
0
        ps_dec->ps_ref_pic_buf_lx[0] = ps_dec->ps_dpb_mgr->ps_mod_dpb[0];
1425
0
        ret = ih264d_ref_idx_reordering(ps_dec, 0);
1426
0
        if(ret == -1)
1427
0
            return ERROR_REFIDX_ORDER_T;
1428
0
    }
1429
0
    else
1430
0
        ps_dec->ps_ref_pic_buf_lx[0] = ps_dec->ps_dpb_mgr->ps_init_dpb[0];
1431
0
1432
0
    u1_ref_idx_re_flag_lx = ih264d_get_bit_h264(ps_bitstrm);
1433
0
    COPYTHECONTEXT("SH: ref_pic_list_reordering_flag_l1",u1_ref_idx_re_flag_lx);
1434
0
1435
0
    /* Modified temporarily */
1436
0
    if(u1_ref_idx_re_flag_lx)
1437
0
    {
1438
0
        WORD8 ret;
1439
0
        ps_dec->ps_ref_pic_buf_lx[1] = ps_dec->ps_dpb_mgr->ps_mod_dpb[1];
1440
0
        ret = ih264d_ref_idx_reordering(ps_dec, 1);
1441
0
        if(ret == -1)
1442
0
            return ERROR_REFIDX_ORDER_T;
1443
0
    }
1444
0
    else
1445
0
        ps_dec->ps_ref_pic_buf_lx[1] = ps_dec->ps_dpb_mgr->ps_init_dpb[1];
1446
0
1447
0
    /* Create refIdx to POC mapping */
1448
0
    {
1449
0
        void **ppv_map_ref_idx_to_poc_lx;
1450
0
        WORD8 idx;
1451
0
        struct pic_buffer_t *ps_pic;
1452
0
1453
0
        ppv_map_ref_idx_to_poc_lx = ps_dec->ppv_map_ref_idx_to_poc + FRM_LIST_L0;
1454
0
        ppv_map_ref_idx_to_poc_lx[0] = 0;
1455
0
        ppv_map_ref_idx_to_poc_lx++;
1456
0
        for(idx = 0; idx < ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[0];
1457
0
                        idx++)
1458
0
        {
1459
0
            ps_pic = ps_dec->ps_ref_pic_buf_lx[0][idx];
1460
0
            ppv_map_ref_idx_to_poc_lx[idx] = (ps_pic->pu1_buf1);
1461
0
        }
1462
0
1463
0
        ppv_map_ref_idx_to_poc_lx = ps_dec->ppv_map_ref_idx_to_poc + FRM_LIST_L1;
1464
0
1465
0
        ppv_map_ref_idx_to_poc_lx[0] = 0;
1466
0
        ppv_map_ref_idx_to_poc_lx++;
1467
0
        for(idx = 0; idx < ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[1];
1468
0
                        idx++)
1469
0
        {
1470
0
            ps_pic = ps_dec->ps_ref_pic_buf_lx[1][idx];
1471
0
            ppv_map_ref_idx_to_poc_lx[idx] = (ps_pic->pu1_buf1);
1472
0
        }
1473
0
1474
0
        if(ps_dec->ps_cur_slice->u1_mbaff_frame_flag)
1475
0
        {
1476
0
            void **ppv_map_ref_idx_to_poc_lx_t, **ppv_map_ref_idx_to_poc_lx_b;
1477
0
1478
0
            ppv_map_ref_idx_to_poc_lx_t = ps_dec->ppv_map_ref_idx_to_poc
1479
0
                            + TOP_LIST_FLD_L0;
1480
0
            ppv_map_ref_idx_to_poc_lx_b = ps_dec->ppv_map_ref_idx_to_poc
1481
0
                            + BOT_LIST_FLD_L0;
1482
0
1483
0
            ppv_map_ref_idx_to_poc_lx_t[0] = 0;
1484
0
            ppv_map_ref_idx_to_poc_lx_t++;
1485
0
            ppv_map_ref_idx_to_poc_lx_b[0] = 0;
1486
0
            ppv_map_ref_idx_to_poc_lx_b++;
1487
0
            for(idx = 0; idx < ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[0];
1488
0
                            idx++)
1489
0
            {
1490
0
                ps_pic = ps_dec->ps_ref_pic_buf_lx[0][idx];
1491
0
                ppv_map_ref_idx_to_poc_lx_t[0] = (ps_pic->pu1_buf1);
1492
0
                ppv_map_ref_idx_to_poc_lx_b[1] = (ps_pic->pu1_buf1);
1493
0
1494
0
                ppv_map_ref_idx_to_poc_lx_b[0] = (ps_pic->pu1_buf1) + 1;
1495
0
                ppv_map_ref_idx_to_poc_lx_t[1] = (ps_pic->pu1_buf1) + 1;
1496
0
1497
0
                ppv_map_ref_idx_to_poc_lx_t += 2;
1498
0
                ppv_map_ref_idx_to_poc_lx_b += 2;
1499
0
            }
1500
0
1501
0
            ppv_map_ref_idx_to_poc_lx_t = ps_dec->ppv_map_ref_idx_to_poc
1502
0
                            + TOP_LIST_FLD_L1;
1503
0
            ppv_map_ref_idx_to_poc_lx_b = ps_dec->ppv_map_ref_idx_to_poc
1504
0
                            + BOT_LIST_FLD_L1;
1505
0
1506
0
            ppv_map_ref_idx_to_poc_lx_t[0] = 0;
1507
0
            ppv_map_ref_idx_to_poc_lx_t++;
1508
0
            ppv_map_ref_idx_to_poc_lx_b[0] = 0;
1509
0
            ppv_map_ref_idx_to_poc_lx_b++;
1510
0
            for(idx = 0; idx < ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[1];
1511
0
                            idx++)
1512
0
            {
1513
0
                UWORD8 u1_tmp_idx = idx << 1;
1514
0
                ps_pic = ps_dec->ps_ref_pic_buf_lx[1][idx];
1515
0
                ppv_map_ref_idx_to_poc_lx_t[u1_tmp_idx] = (ps_pic->pu1_buf1);
1516
0
                ppv_map_ref_idx_to_poc_lx_b[u1_tmp_idx + 1] = (ps_pic->pu1_buf1);
1517
0
1518
0
                ppv_map_ref_idx_to_poc_lx_b[u1_tmp_idx] = (ps_pic->pu1_buf1) + 1;
1519
0
                ppv_map_ref_idx_to_poc_lx_t[u1_tmp_idx + 1] = (ps_pic->pu1_buf1) + 1;
1520
0
1521
0
            }
1522
0
        }
1523
0
1524
0
        if(ps_dec->u4_num_cores >= 3)
1525
0
        {
1526
0
            WORD32 num_entries;
1527
0
            WORD32 size;
1528
0
            num_entries = MAX_FRAMES;
1529
0
            if((1 >= ps_dec->ps_cur_sps->u1_num_ref_frames) &&
1530
0
                (0 == ps_dec->i4_display_delay))
1531
0
            {
1532
0
                num_entries = 1;
1533
0
            }
1534
0
1535
0
            num_entries = ((2 * num_entries) + 1);
1536
0
            num_entries *= 2;
1537
0
1538
0
            size = num_entries * sizeof(void *);
1539
0
            size += PAD_MAP_IDX_POC * sizeof(void *);
1540
0
1541
0
            memcpy((void *)ps_dec->ps_parse_cur_slice->ppv_map_ref_idx_to_poc,
1542
0
               ps_dec->ppv_map_ref_idx_to_poc,
1543
0
               size);
1544
0
        }
1545
0
1546
0
    }
1547
0
1548
0
    if(ps_dec->ps_cur_slice->u1_mbaff_frame_flag
1549
0
                    && (ps_dec->ps_cur_slice->u1_field_pic_flag == 0))
1550
0
    {
1551
0
        ih264d_convert_frm_mbaff_list(ps_dec);
1552
0
    }
1553
0
1554
0
    if(ps_pps->u1_wted_bipred_idc == 1)
1555
0
    {
1556
0
        ret = ih264d_parse_pred_weight_table(ps_slice, ps_bitstrm);
1557
0
        if(ret != OK)
1558
0
            return ret;
1559
0
        ih264d_form_pred_weight_matrix(ps_dec);
1560
0
        ps_dec->pu4_wt_ofsts = ps_dec->pu4_wts_ofsts_mat;
1561
0
    }
1562
0
    else if(ps_pps->u1_wted_bipred_idc == 2)
1563
0
    {
1564
0
        /* Implicit Weighted prediction */
1565
0
        ps_slice->u2_log2Y_crwd = 0x0505;
1566
0
        ps_dec->pu4_wt_ofsts = ps_dec->pu4_wts_ofsts_mat;
1567
0
        ih264d_get_implicit_weights(ps_dec);
1568
0
    }
1569
0
    else
1570
0
        ps_dec->ps_cur_slice->u2_log2Y_crwd = 0;
1571
0
1572
0
    ps_dec->ps_parse_cur_slice->u2_log2Y_crwd =
1573
0
                    ps_dec->ps_cur_slice->u2_log2Y_crwd;
1574
0
1575
0
    /* G050 */
1576
0
    if(ps_slice->u1_nal_ref_idc != 0)
1577
0
    {
1578
0
        if(!ps_dec->ps_dpb_cmds->u1_dpb_commands_read)
1579
0
        {
1580
0
            i_temp = ih264d_read_mmco_commands(ps_dec);
1581
0
            if (i_temp < 0)
1582
0
            {
1583
0
                return ERROR_DBP_MANAGER_T;
1584
0
            }
1585
0
            ps_dec->u4_bitoffset = i_temp;
1586
0
        }
1587
0
        else
1588
0
            ps_bitstrm->u4_ofst += ps_dec->u4_bitoffset;
1589
0
    }
1590
0
    /* G050 */
1591
0
1592
0
    if(ps_pps->u1_entropy_coding_mode == CABAC)
1593
0
    {
1594
0
        u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1595
0
        if(u4_temp > MAX_CABAC_INIT_IDC)
1596
0
        {
1597
0
            return ERROR_INV_SLICE_HDR_T;
1598
0
        }
1599
0
        ps_slice->u1_cabac_init_idc = u4_temp;
1600
0
        COPYTHECONTEXT("SH: cabac_init_idc",ps_slice->u1_cabac_init_idc);
1601
0
    }
1602
0
1603
0
    /* Read slice_qp_delta */
1604
0
    i_temp = ps_pps->u1_pic_init_qp
1605
0
                    + ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1606
0
    if((i_temp < 0) || (i_temp > 51))
1607
0
    {
1608
0
        return ERROR_INV_RANGE_QP_T;
1609
0
    }
1610
0
    ps_slice->u1_slice_qp = i_temp;
1611
0
    COPYTHECONTEXT("SH: slice_qp_delta",
1612
0
                    (WORD8)(ps_slice->u1_slice_qp - ps_pps->u1_pic_init_qp));
1613
0
1614
0
    if(ps_pps->u1_deblocking_filter_parameters_present_flag == 1)
1615
0
    {
1616
0
        u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1617
0
        if(u4_temp > SLICE_BOUNDARY_DBLK_DISABLED)
1618
0
        {
1619
0
            return ERROR_INV_SLICE_HDR_T;
1620
0
        } COPYTHECONTEXT("SH: disable_deblocking_filter_idc", u4_temp);
1621
0
        ps_slice->u1_disable_dblk_filter_idc = u4_temp;
1622
0
        if(u4_temp != 1)
1623
0
        {
1624
0
            i_temp = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf)
1625
0
                            << 1;
1626
0
            if((MIN_DBLK_FIL_OFF > i_temp) || (i_temp > MAX_DBLK_FIL_OFF))
1627
0
            {
1628
0
                return ERROR_INV_SLICE_HDR_T;
1629
0
            }
1630
0
            ps_slice->i1_slice_alpha_c0_offset = i_temp;
1631
0
            COPYTHECONTEXT("SH: slice_alpha_c0_offset_div2",
1632
0
                            ps_slice->i1_slice_alpha_c0_offset >> 1);
1633
0
1634
0
            i_temp = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf)
1635
0
                            << 1;
1636
0
            if((MIN_DBLK_FIL_OFF > i_temp) || (i_temp > MAX_DBLK_FIL_OFF))
1637
0
            {
1638
0
                return ERROR_INV_SLICE_HDR_T;
1639
0
            }
1640
0
            ps_slice->i1_slice_beta_offset = i_temp;
1641
0
            COPYTHECONTEXT("SH: slice_beta_offset_div2",
1642
0
                            ps_slice->i1_slice_beta_offset >> 1);
1643
0
1644
0
        }
1645
0
        else
1646
0
        {
1647
0
            ps_slice->i1_slice_alpha_c0_offset = 0;
1648
0
            ps_slice->i1_slice_beta_offset = 0;
1649
0
        }
1650
0
    }
1651
0
    else
1652
0
    {
1653
0
        ps_slice->u1_disable_dblk_filter_idc = 0;
1654
0
        ps_slice->i1_slice_alpha_c0_offset = 0;
1655
0
        ps_slice->i1_slice_beta_offset = 0;
1656
0
    }
1657
0
1658
0
    ps_dec->u1_slice_header_done = 2;
1659
0
1660
0
    if(ps_pps->u1_entropy_coding_mode)
1661
0
    {
1662
0
        SWITCHOFFTRACE; SWITCHONTRACECABAC;
1663
0
        ps_dec->pf_parse_inter_slice = ih264d_parse_inter_slice_data_cabac;
1664
0
        ps_dec->pf_parse_inter_mb = ih264d_parse_bmb_cabac;
1665
0
        ih264d_init_cabac_contexts(B_SLICE, ps_dec);
1666
0
1667
0
        if(ps_dec->ps_cur_slice->u1_mbaff_frame_flag)
1668
0
            ps_dec->pf_get_mb_info = ih264d_get_mb_info_cabac_mbaff;
1669
0
        else
1670
0
            ps_dec->pf_get_mb_info = ih264d_get_mb_info_cabac_nonmbaff;
1671
0
    }
1672
0
    else
1673
0
    {
1674
0
        SWITCHONTRACE; SWITCHOFFTRACECABAC;
1675
0
        ps_dec->pf_parse_inter_slice = ih264d_parse_inter_slice_data_cavlc;
1676
0
        ps_dec->pf_parse_inter_mb = ih264d_parse_bmb_cavlc;
1677
0
        if(ps_dec->ps_cur_slice->u1_mbaff_frame_flag)
1678
0
            ps_dec->pf_get_mb_info = ih264d_get_mb_info_cavlc_mbaff;
1679
0
        else
1680
0
            ps_dec->pf_get_mb_info = ih264d_get_mb_info_cavlc_nonmbaff;
1681
0
    }
1682
0
1683
0
    ret = ih264d_cal_col_pic(ps_dec);
1684
0
    if(ret != OK)
1685
0
        return ret;
1686
0
    ps_dec->u1_B = 1;
1687
0
    ps_dec->pf_mvpred_ref_tfr_nby2mb = ih264d_mv_pred_ref_tfr_nby2_bmb;
1688
0
    ret = ps_dec->pf_parse_inter_slice(ps_dec, ps_slice, u2_first_mb_in_slice);
1689
0
    if(ret != OK)
1690
0
        return ret;
1691
0
    return OK;
1692
0
}
1693
/proc/self/cwd/external/libavc/decoder/ih264d_parse_cabac.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/*!
21
 ***************************************************************************
22
 * \file ih264d_parse_cabac.c
23
 *
24
 * \brief
25
 *    This file contains cabac Residual decoding routines.
26
 *
27
 * \date
28
 *    20/03/2003
29
 *
30
 * \author  NS
31
 ***************************************************************************
32
 */
33
34
#include "ih264_typedefs.h"
35
#include "ih264_macros.h"
36
#include "ih264_platform_macros.h"
37
#include "ih264d_defs.h"
38
#include "ih264d_structs.h"
39
40
#include "ih264d_cabac.h"
41
#include "ih264d_bitstrm.h"
42
#include "ih264d_parse_mb_header.h"
43
#include "ih264d_debug.h"
44
#include "ih264d_tables.h"
45
#include "ih264d_error_handler.h"
46
#include "ih264d_parse_cabac.h"
47
#include "ih264d_parse_slice.h"
48
#include "ih264d_tables.h"
49
#include "ih264d_mb_utils.h"
50
#include "ih264d_utils.h"
51
52
/*!
53
 ********************************************************************************
54
 *   \if Function name : ih264d_read_coeff4x4_cabac \endif
55
 *
56
 *   \brief  This function encodes residual_block_cabac as defined in 7.3.5.3.2.
57
 *
58
 *   \return
59
 *       Returns the index of last significant coeff.
60
 *
61
 ********************************************************************************
62
 */
63
64
UWORD8 ih264d_read_coeff4x4_cabac(dec_bit_stream_t *ps_bitstrm,
65
                                  UWORD32 u4_ctxcat,
66
                                  bin_ctxt_model_t *ps_ctxt_sig_coeff,
67
                                  dec_struct_t *ps_dec, /*!< pointer to access global variables*/
68
                                  bin_ctxt_model_t *ps_ctxt_coded)
69
0
{
70
0
71
0
    decoding_envirnoment_t *ps_cab_env = &ps_dec->s_cab_dec_env;
72
0
    UWORD32 u4_coded_flag;
73
0
    UWORD32 u4_offset, *pu4_buffer;
74
0
    UWORD32 u4_code_int_range, u4_code_int_val_ofst;
75
0
    tu_sblk4x4_coeff_data_t *ps_tu_4x4;
76
0
    WORD16 *pi2_coeff_data;
77
0
    WORD32 num_sig_coeffs = 0;
78
0
79
0
    /*loading from strcuctures*/
80
0
81
0
    ps_tu_4x4 = (tu_sblk4x4_coeff_data_t *)ps_dec->pv_parse_tu_coeff_data;
82
0
    ps_tu_4x4->u2_sig_coeff_map = 0;
83
0
    pi2_coeff_data = &ps_tu_4x4->ai2_level[0];
84
0
85
0
    u4_offset = ps_bitstrm->u4_ofst;
86
0
    pu4_buffer = ps_bitstrm->pu4_buffer;
87
0
88
0
    u4_code_int_range = ps_cab_env->u4_code_int_range;
89
0
    u4_code_int_val_ofst = ps_cab_env->u4_code_int_val_ofst;
90
0
91
0
    {
92
0
93
0
        /*inilined DecodeDecision_onebin begins*/
94
0
95
0
        {
96
0
97
0
            UWORD32 u4_qnt_int_range, u4_int_range_lps;
98
0
            UWORD32 u4_symbol, u1_mps_state;
99
0
100
0
            UWORD32 table_lookup;
101
0
            const UWORD32 *pu4_table = (const UWORD32 *)ps_cab_env->cabac_table;
102
0
            UWORD32 u4_clz;
103
0
104
0
            u1_mps_state = (ps_ctxt_coded->u1_mps_state);
105
0
            u4_clz = CLZ(u4_code_int_range);
106
0
            u4_qnt_int_range = u4_code_int_range << u4_clz;
107
0
            u4_qnt_int_range = (u4_qnt_int_range >> 29) & 0x3;
108
0
            table_lookup =
109
0
                            pu4_table[(u1_mps_state << 2) + u4_qnt_int_range];
110
0
            u4_int_range_lps = table_lookup & 0xff;
111
0
            u4_int_range_lps = u4_int_range_lps << (23 - u4_clz);
112
0
            u4_code_int_range = u4_code_int_range - u4_int_range_lps;
113
0
            u4_symbol = ((u1_mps_state >> 6) & 0x1);
114
0
            u1_mps_state = (table_lookup >> 8) & 0x7F;
115
0
116
0
            CHECK_IF_LPS(u4_code_int_range, u4_code_int_val_ofst, u4_symbol,
117
0
                         u4_int_range_lps, u1_mps_state, table_lookup)
118
0
119
0
            if(u4_code_int_range < ONE_RIGHT_SHIFTED_BY_8)
120
0
            {
121
0
122
0
                RENORM_RANGE_OFFSET(u4_code_int_range, u4_code_int_val_ofst,
123
0
                                    u4_offset, pu4_buffer)
124
0
            }
125
0
126
0
            ps_ctxt_coded->u1_mps_state = u1_mps_state;
127
0
            u4_coded_flag = u4_symbol;
128
0
129
0
            /*inilined DecodeDecision_onebin ends*/
130
0
131
0
        }
132
0
133
0
    }
134
0
135
0
    if(u4_coded_flag)
136
0
    {
137
0
138
0
        {
139
0
            bin_ctxt_model_t *p_binCtxt_last, *p_binCtxt_last_org;
140
0
            UWORD32 uc_last_coeff_idx;
141
0
            UWORD32 uc_bin;
142
0
            UWORD32 i;
143
0
            WORD32 first_coeff_offset = 0;
144
0
145
0
            if((u4_ctxcat == CHROMA_AC_CTXCAT) || (u4_ctxcat == LUMA_AC_CTXCAT))
146
0
            {
147
0
                first_coeff_offset = 1;
148
0
            }
149
0
150
0
            i = 0;
151
0
            if(u4_ctxcat == CHROMA_DC_CTXCAT)
152
0
            {
153
0
                uc_last_coeff_idx = 3;
154
0
            }
155
0
            else
156
0
            {
157
0
                UWORD32 u4_start;
158
0
                u4_start = (u4_ctxcat & 1) + (u4_ctxcat >> 2);
159
0
                uc_last_coeff_idx = 15 - u4_start;
160
0
            }
161
0
            p_binCtxt_last_org = ps_ctxt_sig_coeff
162
0
                            + LAST_COEFF_CTXT_MINUS_SIG_COEFF_CTXT;
163
0
164
0
            do
165
0
            {
166
0
167
0
                /*inilined DecodeDecision_onebin begins*/
168
0
                {
169
0
170
0
                    UWORD32 u4_qnt_int_range, u4_int_range_lps;
171
0
                    UWORD32 u4_symbol, u1_mps_state;
172
0
                    UWORD32 table_lookup;
173
0
                    const UWORD32 *pu4_table =
174
0
                                    (const UWORD32 *)ps_cab_env->cabac_table;
175
0
                    UWORD32 u4_clz;
176
0
177
0
                    u1_mps_state = (ps_ctxt_sig_coeff->u1_mps_state);
178
0
179
0
                    u4_clz = CLZ(u4_code_int_range);
180
0
181
0
                    u4_qnt_int_range = u4_code_int_range << u4_clz;
182
0
                    u4_qnt_int_range = (u4_qnt_int_range >> 29) & 0x3;
183
0
184
0
                    table_lookup = pu4_table[(u1_mps_state << 2)
185
0
                                    + u4_qnt_int_range];
186
0
187
0
                    u4_int_range_lps = table_lookup & 0xff;
188
0
189
0
                    u4_int_range_lps = u4_int_range_lps << (23 - u4_clz);
190
0
                    u4_code_int_range = u4_code_int_range - u4_int_range_lps;
191
0
                    u4_symbol = ((u1_mps_state >> 6) & 0x1);
192
0
                    u1_mps_state = (table_lookup >> 8) & 0x7F;
193
0
194
0
                    CHECK_IF_LPS(u4_code_int_range, u4_code_int_val_ofst,
195
0
                                 u4_symbol, u4_int_range_lps, u1_mps_state,
196
0
                                 table_lookup)
197
0
198
0
                    if(u4_code_int_range < ONE_RIGHT_SHIFTED_BY_14)
199
0
                    {
200
0
201
0
                        UWORD32 read_bits, u4_clz;
202
0
                        u4_clz = CLZ(u4_code_int_range);
203
0
                        NEXTBITS(read_bits, (u4_offset + 23), pu4_buffer,
204
0
                                 u4_clz)
205
0
                        FLUSHBITS(u4_offset, (u4_clz))
206
0
                        u4_code_int_range = u4_code_int_range << u4_clz;
207
0
                        u4_code_int_val_ofst = (u4_code_int_val_ofst << u4_clz)
208
0
                                        | read_bits;
209
0
                    }
210
0
211
0
                    INC_BIN_COUNT(
212
0
                                    ps_cab_env)
213
0
214
0
                    ps_ctxt_sig_coeff->u1_mps_state = u1_mps_state;
215
0
                    uc_bin = u4_symbol;
216
0
217
0
                }
218
0
                /*incrementing pointer to point to the context of the next bin*/
219
0
                ps_ctxt_sig_coeff++;
220
0
221
0
                /*inilined DecodeDecision_onebin ends*/
222
0
223
0
                if(uc_bin)
224
0
                {
225
0
                    num_sig_coeffs++;
226
0
                    SET_BIT(ps_tu_4x4->u2_sig_coeff_map, (i + first_coeff_offset));
227
0
228
0
                    p_binCtxt_last = p_binCtxt_last_org + i;
229
0
230
0
                    /*inilined DecodeDecision_onebin begins*/
231
0
232
0
                    {
233
0
234
0
                        UWORD32 u4_qnt_int_range, u4_int_range_lps;
235
0
                        UWORD32 u4_symbol, u1_mps_state;
236
0
                        UWORD32 table_lookup;
237
0
                        const UWORD32 *pu4_table =
238
0
                                        (const UWORD32 *)ps_cab_env->cabac_table;
239
0
                        UWORD32 u4_clz;
240
0
241
0
                        u1_mps_state = (p_binCtxt_last->u1_mps_state);
242
0
243
0
                        u4_clz = CLZ(u4_code_int_range);
244
0
                        u4_qnt_int_range = u4_code_int_range << u4_clz;
245
0
                        u4_qnt_int_range = (u4_qnt_int_range >> 29)
246
0
                                        & 0x3;
247
0
248
0
                        table_lookup = pu4_table[(u1_mps_state << 2)
249
0
                                        + u4_qnt_int_range];
250
0
                        u4_int_range_lps = table_lookup & 0xff;
251
0
252
0
                        u4_int_range_lps = u4_int_range_lps
253
0
                                        << (23 - u4_clz);
254
0
255
0
                        u4_code_int_range = u4_code_int_range
256
0
                                        - u4_int_range_lps;
257
0
                        u4_symbol = ((u1_mps_state >> 6) & 0x1);
258
0
                        u1_mps_state = (table_lookup >> 8) & 0x7F;
259
0
260
0
                        CHECK_IF_LPS(u4_code_int_range, u4_code_int_val_ofst,
261
0
                                     u4_symbol, u4_int_range_lps,
262
0
                                     u1_mps_state, table_lookup)
263
0
264
0
                        INC_BIN_COUNT(ps_cab_env)
265
0
266
0
                        p_binCtxt_last->u1_mps_state = u1_mps_state;
267
0
                        uc_bin = u4_symbol;
268
0
269
0
                    }
270
0
271
0
                    /*inilined DecodeDecision_onebin ends*/
272
0
                    if(uc_bin == 1)
273
0
                        goto label_read_levels;
274
0
275
0
                }
276
0
277
0
                i = i + 1;
278
0
279
0
            }
280
0
            while(i < uc_last_coeff_idx);
281
0
282
0
            num_sig_coeffs++;
283
0
            SET_BIT(ps_tu_4x4->u2_sig_coeff_map, (i + first_coeff_offset));
284
0
285
0
            label_read_levels: ;
286
0
287
0
        }
288
0
289
0
        /// VALUE of No of Coeff in BLOCK = i + 1 for second case else i;
290
0
291
0
        /* Decode coeff_abs_level_minus1 and coeff_sign_flag */
292
0
        {
293
0
294
0
            WORD32 i2_abs_lvl;
295
0
            UWORD32 u1_abs_level_equal1 = 1, u1_abs_level_gt1 = 0;
296
0
297
0
            UWORD32 u4_ctx_inc;
298
0
            UWORD32 ui_prefix;
299
0
        bin_ctxt_model_t *p_ctxt_abs_level;
300
0
301
0
302
0
        p_ctxt_abs_level = ps_dec->p_coeff_abs_level_minus1_t[u4_ctxcat];
303
0
        u4_ctx_inc = ((0x51));
304
0
305
0
        /*****************************************************/
306
0
        /* Main Loop runs for no. of Significant coefficient */
307
0
        /*****************************************************/
308
0
309
0
310
0
        do
311
0
            {
312
0
313
0
                {
314
0
                    INC_SYM_COUNT(&(ps_dec.s_cab_dec_env));
315
0
316
0
                    /*****************************************************/
317
0
                    /* inilining a modified ih264d_decode_bins_unary     */
318
0
                    /*****************************************************/
319
0
320
0
                    {
321
0
                        UWORD32 u4_value;
322
0
                        UWORD32 u4_symbol;
323
0
                        bin_ctxt_model_t *ps_bin_ctxt;
324
0
                        UWORD32 u4_ctx_Inc;
325
0
326
0
                        u4_value = 0;
327
0
328
0
                        u4_ctx_Inc = u4_ctx_inc & 0xf;
329
0
                        ps_bin_ctxt = p_ctxt_abs_level + u4_ctx_Inc;
330
0
331
0
                        do
332
0
                        {
333
0
334
0
                            {
335
0
336
0
                                UWORD32 u4_qnt_int_range,
337
0
                                                u4_int_range_lps;
338
0
                                UWORD32 u1_mps_state;
339
0
                                UWORD32 table_lookup;
340
0
                                const UWORD32 *pu4_table =
341
0
                                                (const UWORD32 *)ps_cab_env->cabac_table;
342
0
                                UWORD32 u4_clz;
343
0
344
0
                                u1_mps_state = (ps_bin_ctxt->u1_mps_state);
345
0
                                u4_clz = CLZ(u4_code_int_range);
346
0
                                u4_qnt_int_range = u4_code_int_range
347
0
                                                << u4_clz;
348
0
                                u4_qnt_int_range = (u4_qnt_int_range
349
0
                                                >> 29) & 0x3;
350
0
                                table_lookup = pu4_table[(u1_mps_state << 2)
351
0
                                                + u4_qnt_int_range];
352
0
                                u4_int_range_lps = table_lookup & 0xff;
353
0
354
0
                                u4_int_range_lps = u4_int_range_lps
355
0
                                                << (23 - u4_clz);
356
0
                                u4_code_int_range = u4_code_int_range
357
0
                                                - u4_int_range_lps;
358
0
                                u4_symbol = ((u1_mps_state >> 6) & 0x1);
359
0
                                u1_mps_state = (table_lookup >> 8) & 0x7F;
360
0
361
0
                                CHECK_IF_LPS(u4_code_int_range,
362
0
                                             u4_code_int_val_ofst, u4_symbol,
363
0
                                             u4_int_range_lps, u1_mps_state,
364
0
                                             table_lookup)
365
0
366
0
                                if(u4_code_int_range < ONE_RIGHT_SHIFTED_BY_9)
367
0
                                {
368
0
369
0
                                    RENORM_RANGE_OFFSET(u4_code_int_range,
370
0
                                                        u4_code_int_val_ofst,
371
0
                                                        u4_offset, pu4_buffer)
372
0
                                }
373
0
374
0
                                INC_BIN_COUNT(ps_cab_env);
375
0
376
0
                                ps_bin_ctxt->u1_mps_state = u1_mps_state;
377
0
                            }
378
0
379
0
                            INC_BIN_COUNT(ps_cab_env);INC_DECISION_BINS(ps_cab_env);
380
0
381
0
                            u4_value++;
382
0
                            ps_bin_ctxt = p_ctxt_abs_level + (u4_ctx_inc >> 4);
383
0
384
0
                        }
385
0
                        while(u4_symbol && (u4_value < UCOFF_LEVEL));
386
0
387
0
                        ui_prefix = u4_value - 1 + u4_symbol;
388
0
389
0
                    }
390
0
391
0
                    if(ui_prefix == UCOFF_LEVEL)
392
0
                    {
393
0
                        UWORD32 ui16_sufS = 0;
394
0
                        UWORD32 u1_max_bins;
395
0
                        UWORD32 u4_value;
396
0
397
0
                        i2_abs_lvl = UCOFF_LEVEL;
398
0
                        /*inlining ih264d_decode_bypass_bins_unary begins*/
399
0
400
0
                        {
401
0
                            UWORD32 uc_bin;
402
0
                            UWORD32 bits_to_flush;
403
0
                            UWORD32 max_bits = 32;
404
0
405
0
                            bits_to_flush = 0;
406
0
                            /*renormalize to ensure there 23 bits more in the u4_code_int_val_ofst*/
407
0
                            {
408
0
                                UWORD32 u4_clz, read_bits;
409
0
410
0
                                u4_clz = CLZ(u4_code_int_range);
411
0
                                FLUSHBITS(u4_offset, u4_clz)
412
0
                                NEXTBITS(read_bits, u4_offset, pu4_buffer, 23)
413
0
                                u4_code_int_range = u4_code_int_range << u4_clz;
414
0
                                u4_code_int_val_ofst = (u4_code_int_val_ofst
415
0
                                                << u4_clz) | read_bits;
416
0
417
0
                            }
418
0
419
0
                            do
420
0
                            {
421
0
                                bits_to_flush++;
422
0
423
0
                                u4_code_int_range = u4_code_int_range >> 1;
424
0
425
0
                                if(u4_code_int_val_ofst >= u4_code_int_range)
426
0
                                {
427
0
                                    /* S=1 */
428
0
                                    uc_bin = 1;
429
0
                                    u4_code_int_val_ofst -= u4_code_int_range;
430
0
                                }
431
0
                                else
432
0
                                {
433
0
                                    /* S=0 */
434
0
                                    uc_bin = 0;
435
0
                                }
436
0
437
0
                                INC_BIN_COUNT(
438
0
                                                ps_cab_env);INC_BYPASS_BINS(ps_cab_env);
439
0
440
0
                            }
441
0
                            while(uc_bin && (bits_to_flush < max_bits));
442
0
443
0
                            u4_value = (bits_to_flush - 1);
444
0
445
0
                        }
446
0
                        /*inlining ih264d_decode_bypass_bins_unary ends*/
447
0
448
0
                        ui16_sufS = (1 << u4_value);
449
0
                        u1_max_bins = u4_value;
450
0
451
0
                        if(u4_value > 0)
452
0
                        {
453
0
454
0
                            /*inline bypassbins_flc begins*/
455
0
456
0
                            if(u4_value > 10)
457
0
                            {
458
0
                                UWORD32 u4_clz, read_bits;
459
0
460
0
                                u4_clz = CLZ(u4_code_int_range);
461
0
                                FLUSHBITS(u4_offset, u4_clz)
462
0
                                NEXTBITS(read_bits, u4_offset, pu4_buffer, 23)
463
0
                                u4_code_int_range = u4_code_int_range << u4_clz;
464
0
                                u4_code_int_val_ofst = (u4_code_int_val_ofst
465
0
                                                << u4_clz) | read_bits;
466
0
                            }
467
0
468
0
                            {
469
0
                                UWORD32 ui_bins;
470
0
                                UWORD32 uc_bin;
471
0
                                UWORD32 bits_to_flush;
472
0
473
0
                                ui_bins = 0;
474
0
                                bits_to_flush = 0;
475
0
476
0
                                do
477
0
                                {
478
0
                                    bits_to_flush++;
479
0
480
0
                                    u4_code_int_range = u4_code_int_range >> 1;
481
0
482
0
                                    if(u4_code_int_val_ofst
483
0
                                                    >= u4_code_int_range)
484
0
                                    {
485
0
                                        /* S=1 */
486
0
                                        uc_bin = 1;
487
0
                                        u4_code_int_val_ofst -=
488
0
                                                        u4_code_int_range;
489
0
                                    }
490
0
                                    else
491
0
                                    {
492
0
                                        /* S=0 */
493
0
                                        uc_bin = 0;
494
0
                                    }
495
0
496
0
                                    INC_BIN_COUNT(
497
0
                                                    ps_cab_env);INC_BYPASS_BINS(ps_cab_env);
498
0
499
0
                                    ui_bins = ((ui_bins << 1) | uc_bin);
500
0
501
0
                                }
502
0
                                while(bits_to_flush < u1_max_bins);
503
0
504
0
                                u4_value = ui_bins;
505
0
                            }
506
0
507
0
                            /*inline bypassbins_flc ends*/
508
0
509
0
                        }
510
0
511
0
                        //Value of K
512
0
                        ui16_sufS += u4_value;
513
0
                        i2_abs_lvl += ui16_sufS;
514
0
515
0
                    }
516
0
                    else
517
0
                        i2_abs_lvl = 1 + ui_prefix;
518
0
519
0
                    if(i2_abs_lvl > 1)
520
0
                    {
521
0
                        u1_abs_level_gt1++;
522
0
                    }
523
0
                    if(!u1_abs_level_gt1)
524
0
                    {
525
0
                        u1_abs_level_equal1++;
526
0
                        u4_ctx_inc = (5 << 4) + MIN(u1_abs_level_equal1, 4);
527
0
                    }
528
0
                    else
529
0
                        u4_ctx_inc = (5 + MIN(u1_abs_level_gt1, 4)) << 4;
530
0
531
0
                    /*u4_ctx_inc = g_table_temp[u1_abs_level_gt1][u1_abs_level_equal1];*/
532
0
533
0
                    /* encode coeff_sign_flag[i] */
534
0
535
0
                    {
536
0
                        u4_code_int_range = u4_code_int_range >> 1;
537
0
538
0
                        if(u4_code_int_val_ofst >= (u4_code_int_range))
539
0
                        {
540
0
                            /* S=1 */
541
0
                            u4_code_int_val_ofst -= u4_code_int_range;
542
0
                            i2_abs_lvl = (-i2_abs_lvl);
543
0
                        }
544
0
545
0
                    }
546
0
                    num_sig_coeffs--;
547
0
                    *pi2_coeff_data++ = i2_abs_lvl;
548
0
                }
549
0
            }
550
0
            while(num_sig_coeffs > 0);
551
0
        }
552
0
    }
553
0
554
0
    if(u4_coded_flag)
555
0
    {
556
0
        WORD32 offset;
557
0
        offset = (UWORD8 *)pi2_coeff_data - (UWORD8 *)ps_tu_4x4;
558
0
        offset = ALIGN4(offset);
559
0
        ps_dec->pv_parse_tu_coeff_data = (void *)((UWORD8 *)ps_dec->pv_parse_tu_coeff_data + offset);
560
0
    }
561
0
562
0
563
0
    /*updating structures*/
564
0
    ps_cab_env->u4_code_int_val_ofst = u4_code_int_val_ofst;
565
0
    ps_cab_env->u4_code_int_range = u4_code_int_range;
566
0
    ps_bitstrm->u4_ofst = u4_offset;
567
0
    return (u4_coded_flag);
568
0
}
569
/*!
570
 ********************************************************************************
571
 *   \if Function name : ih264d_read_coeff8x8_cabac \endif
572
 *
573
 *   \brief  This function encodes residual_block_cabac as defined in 7.3.5.3.2.
574
 when transform_8x8_flag  = 1
575
 *
576
 *   \return
577
 *       Returns the index of last significant coeff.
578
 *
579
 ********************************************************************************
580
 */
581
582
void ih264d_read_coeff8x8_cabac(dec_bit_stream_t *ps_bitstrm,
583
                                dec_struct_t *ps_dec, /*!< pointer to access global variables*/
584
                                dec_mb_info_t *ps_cur_mb_info)
585
0
{
586
0
    decoding_envirnoment_t *ps_cab_env = &ps_dec->s_cab_dec_env;
587
0
    UWORD32 u4_offset, *pu4_buffer;
588
0
    UWORD32 u4_code_int_range, u4_code_int_val_ofst;
589
0
590
0
    /* High profile related declarations */
591
0
    UWORD8 u1_field_coding_flag = ps_cur_mb_info->ps_curmb->u1_mb_fld;
592
0
    const UWORD8 *pu1_lastcoeff_context_inc =
593
0
                    (UWORD8 *)gau1_ih264d_lastcoeff_context_inc;
594
0
    const UWORD8 *pu1_sigcoeff_context_inc;
595
0
    bin_ctxt_model_t *ps_ctxt_sig_coeff;
596
0
    WORD32 num_sig_coeffs = 0;
597
0
    tu_blk8x8_coeff_data_t *ps_tu_8x8;
598
0
    WORD16 *pi2_coeff_data;
599
0
600
0
    /*loading from strcuctures*/
601
0
602
0
    ps_tu_8x8 = (tu_blk8x8_coeff_data_t *)ps_dec->pv_parse_tu_coeff_data;
603
0
    ps_tu_8x8->au4_sig_coeff_map[0] = 0;
604
0
    ps_tu_8x8->au4_sig_coeff_map[1] = 0;
605
0
    pi2_coeff_data = &ps_tu_8x8->ai2_level[0];
606
0
607
0
608
0
    if(!u1_field_coding_flag)
609
0
    {
610
0
        pu1_sigcoeff_context_inc =
611
0
                        (UWORD8 *)gau1_ih264d_sigcoeff_context_inc_frame;
612
0
613
0
        /*******************************************************************/
614
0
        /* last coefficient context is derived from significant coeff u4_flag */
615
0
        /* only significant coefficient matrix need to be initialized      */
616
0
        /*******************************************************************/
617
0
        ps_ctxt_sig_coeff = ps_dec->s_high_profile.ps_sigcoeff_8x8_frame;
618
0
    }
619
0
    else
620
0
    {
621
0
        pu1_sigcoeff_context_inc =
622
0
                        (UWORD8 *)gau1_ih264d_sigcoeff_context_inc_field;
623
0
624
0
        /*******************************************************************/
625
0
        /* last coefficient context is derived from significant coeff u4_flag */
626
0
        /* only significant coefficient matrix need to be initialized      */
627
0
        /*******************************************************************/
628
0
        ps_ctxt_sig_coeff = ps_dec->s_high_profile.ps_sigcoeff_8x8_field;
629
0
    }
630
0
631
0
    /*loading from strcuctures*/
632
0
633
0
    u4_offset = ps_bitstrm->u4_ofst;
634
0
    pu4_buffer = ps_bitstrm->pu4_buffer;
635
0
636
0
    u4_code_int_range = ps_cab_env->u4_code_int_range;
637
0
    u4_code_int_val_ofst = ps_cab_env->u4_code_int_val_ofst;
638
0
639
0
    {
640
0
        {
641
0
            bin_ctxt_model_t *p_binCtxt_last, *p_binCtxt_last_org,
642
0
                            *p_ctxt_sig_coeff_org;
643
0
            UWORD32 uc_last_coeff_idx;
644
0
            UWORD32 uc_bin;
645
0
            UWORD32 i;
646
0
647
0
            i = 0;
648
0
649
0
            uc_last_coeff_idx = 63;
650
0
651
0
            p_binCtxt_last_org = ps_ctxt_sig_coeff
652
0
                            + LAST_COEFF_CTXT_MINUS_SIG_COEFF_CTXT_8X8;
653
0
654
0
            p_ctxt_sig_coeff_org = ps_ctxt_sig_coeff;
655
0
656
0
            do
657
0
            {
658
0
                /*inilined DecodeDecision_onebin begins*/
659
0
                {
660
0
                    UWORD32 u4_qnt_int_range, u4_int_range_lps;
661
0
                    UWORD32 u4_symbol, u1_mps_state;
662
0
                    UWORD32 table_lookup;
663
0
                    const UWORD32 *pu4_table =
664
0
                                    (const UWORD32 *)ps_cab_env->cabac_table;
665
0
                    UWORD32 u4_clz;
666
0
667
0
                    u1_mps_state = (ps_ctxt_sig_coeff->u1_mps_state);
668
0
669
0
                    u4_clz = CLZ(u4_code_int_range);
670
0
671
0
                    u4_qnt_int_range = u4_code_int_range << u4_clz;
672
0
                    u4_qnt_int_range = (u4_qnt_int_range >> 29) & 0x3;
673
0
674
0
                    table_lookup = pu4_table[(u1_mps_state << 2)
675
0
                                    + u4_qnt_int_range];
676
0
677
0
                    u4_int_range_lps = table_lookup & 0xff;
678
0
679
0
                    u4_int_range_lps = u4_int_range_lps << (23 - u4_clz);
680
0
                    u4_code_int_range = u4_code_int_range - u4_int_range_lps;
681
0
                    u4_symbol = ((u1_mps_state >> 6) & 0x1);
682
0
                    u1_mps_state = (table_lookup >> 8) & 0x7F;
683
0
684
0
                    CHECK_IF_LPS(u4_code_int_range, u4_code_int_val_ofst,
685
0
                                 u4_symbol, u4_int_range_lps, u1_mps_state,
686
0
                                 table_lookup)
687
0
688
0
                    if(u4_code_int_range < ONE_RIGHT_SHIFTED_BY_14)
689
0
                    {
690
0
                        UWORD32 read_bits, u4_clz;
691
0
                        u4_clz = CLZ(u4_code_int_range);
692
0
                        NEXTBITS(read_bits, (u4_offset + 23), pu4_buffer,
693
0
                                 u4_clz)
694
0
                        FLUSHBITS(u4_offset, (u4_clz))
695
0
                        u4_code_int_range = u4_code_int_range << u4_clz;
696
0
                        u4_code_int_val_ofst = (u4_code_int_val_ofst << u4_clz)
697
0
                                        | read_bits;
698
0
                    }
699
0
700
0
                    ps_ctxt_sig_coeff->u1_mps_state = u1_mps_state;
701
0
                    uc_bin = u4_symbol;
702
0
                }
703
0
                /*incrementing pointer to point to the context of the next bin*/
704
0
                ps_ctxt_sig_coeff = p_ctxt_sig_coeff_org
705
0
                                + pu1_sigcoeff_context_inc[i + 1];
706
0
707
0
                /*inilined DecodeDecision_onebin ends*/
708
0
                if(uc_bin)
709
0
                {
710
0
                    num_sig_coeffs++;
711
0
                    SET_BIT(ps_tu_8x8->au4_sig_coeff_map[i>31], (i > 31 ? i - 32:i));
712
0
713
0
                    p_binCtxt_last = p_binCtxt_last_org
714
0
                                    + pu1_lastcoeff_context_inc[i];
715
0
716
0
                    /*inilined DecodeDecision_onebin begins*/
717
0
718
0
                    {
719
0
                        UWORD32 u4_qnt_int_range, u4_int_range_lps;
720
0
                        UWORD32 u4_symbol, u1_mps_state;
721
0
                        UWORD32 table_lookup;
722
0
                        const UWORD32 *pu4_table =
723
0
                                        (const UWORD32 *)ps_cab_env->cabac_table;
724
0
                        UWORD32 u4_clz;
725
0
726
0
                        u1_mps_state = (p_binCtxt_last->u1_mps_state);
727
0
728
0
                        u4_clz = CLZ(u4_code_int_range);
729
0
                        u4_qnt_int_range = u4_code_int_range << u4_clz;
730
0
                        u4_qnt_int_range = (u4_qnt_int_range >> 29)
731
0
                                        & 0x3;
732
0
733
0
                        table_lookup = pu4_table[(u1_mps_state << 2)
734
0
                                        + u4_qnt_int_range];
735
0
                        u4_int_range_lps = table_lookup & 0xff;
736
0
737
0
                        u4_int_range_lps = u4_int_range_lps
738
0
                                        << (23 - u4_clz);
739
0
740
0
                        u4_code_int_range = u4_code_int_range
741
0
                                        - u4_int_range_lps;
742
0
                        u4_symbol = ((u1_mps_state >> 6) & 0x1);
743
0
                        u1_mps_state = (table_lookup >> 8) & 0x7F;
744
0
745
0
                        CHECK_IF_LPS(u4_code_int_range, u4_code_int_val_ofst,
746
0
                                     u4_symbol, u4_int_range_lps,
747
0
                                     u1_mps_state, table_lookup)
748
0
749
0
                        p_binCtxt_last->u1_mps_state = u1_mps_state;
750
0
                        uc_bin = u4_symbol;
751
0
                    }
752
0
753
0
                    /*inilined DecodeDecision_onebin ends*/
754
0
                    if(uc_bin == 1)
755
0
                        goto label_read_levels;
756
0
757
0
                }
758
0
759
0
                i = i + 1;
760
0
761
0
            }
762
0
            while(i < uc_last_coeff_idx);
763
0
764
0
            num_sig_coeffs++;
765
0
            SET_BIT(ps_tu_8x8->au4_sig_coeff_map[i>31], (i > 31 ? i - 32:i));
766
0
767
0
            label_read_levels: ;
768
0
        }
769
0
770
0
        /// VALUE of No of Coeff in BLOCK = i + 1 for second case else i;
771
0
772
0
        /* Decode coeff_abs_level_minus1 and coeff_sign_flag */
773
0
        {
774
0
            WORD32 i2_abs_lvl;
775
0
            UWORD32 u1_abs_level_equal1 = 1, u1_abs_level_gt1 = 0;
776
0
777
0
            UWORD32 u4_ctx_inc;
778
0
            UWORD32 ui_prefix;
779
0
            bin_ctxt_model_t *p_ctxt_abs_level;
780
0
781
0
            p_ctxt_abs_level =
782
0
                            ps_dec->p_coeff_abs_level_minus1_t[LUMA_8X8_CTXCAT];
783
0
            u4_ctx_inc = ((0x51));
784
0
785
0
            /*****************************************************/
786
0
            /* Main Loop runs for no. of Significant coefficient */
787
0
            /*****************************************************/
788
0
            do
789
0
            {
790
0
                {
791
0
792
0
                    /*****************************************************/
793
0
                    /* inilining a modified ih264d_decode_bins_unary     */
794
0
                    /*****************************************************/
795
0
796
0
                    {
797
0
                        UWORD32 u4_value;
798
0
                        UWORD32 u4_symbol;
799
0
                        bin_ctxt_model_t *ps_bin_ctxt;
800
0
                        UWORD32 u4_ctx_Inc;
801
0
                        u4_value = 0;
802
0
803
0
                        u4_ctx_Inc = u4_ctx_inc & 0xf;
804
0
                        ps_bin_ctxt = p_ctxt_abs_level + u4_ctx_Inc;
805
0
806
0
                        do
807
0
                        {
808
0
                            {
809
0
                                UWORD32 u4_qnt_int_range,
810
0
                                                u4_int_range_lps;
811
0
                                UWORD32 u1_mps_state;
812
0
                                UWORD32 table_lookup;
813
0
                                const UWORD32 *pu4_table =
814
0
                                                (const UWORD32 *)ps_cab_env->cabac_table;
815
0
                                UWORD32 u4_clz;
816
0
817
0
                                u1_mps_state = (ps_bin_ctxt->u1_mps_state);
818
0
                                u4_clz = CLZ(u4_code_int_range);
819
0
                                u4_qnt_int_range = u4_code_int_range
820
0
                                                << u4_clz;
821
0
                                u4_qnt_int_range = (u4_qnt_int_range
822
0
                                                >> 29) & 0x3;
823
0
                                table_lookup = pu4_table[(u1_mps_state << 2)
824
0
                                                + u4_qnt_int_range];
825
0
                                u4_int_range_lps = table_lookup & 0xff;
826
0
827
0
                                u4_int_range_lps = u4_int_range_lps
828
0
                                                << (23 - u4_clz);
829
0
                                u4_code_int_range = u4_code_int_range
830
0
                                                - u4_int_range_lps;
831
0
                                u4_symbol = ((u1_mps_state >> 6) & 0x1);
832
0
                                u1_mps_state = (table_lookup >> 8) & 0x7F;
833
0
834
0
                                CHECK_IF_LPS(u4_code_int_range,
835
0
                                             u4_code_int_val_ofst, u4_symbol,
836
0
                                             u4_int_range_lps, u1_mps_state,
837
0
                                             table_lookup)
838
0
839
0
                                if(u4_code_int_range < ONE_RIGHT_SHIFTED_BY_9)
840
0
                                {
841
0
842
0
                                    RENORM_RANGE_OFFSET(u4_code_int_range,
843
0
                                                        u4_code_int_val_ofst,
844
0
                                                        u4_offset, pu4_buffer)
845
0
                                }
846
0
847
0
                                ps_bin_ctxt->u1_mps_state = u1_mps_state;
848
0
                            }
849
0
850
0
                            u4_value++;
851
0
                            ps_bin_ctxt = p_ctxt_abs_level + (u4_ctx_inc >> 4);
852
0
853
0
                        }
854
0
                        while(u4_symbol && (u4_value < UCOFF_LEVEL));
855
0
856
0
                        ui_prefix = u4_value - 1 + u4_symbol;
857
0
                    }
858
0
859
0
                    if(ui_prefix == UCOFF_LEVEL)
860
0
                    {
861
0
                        UWORD32 ui16_sufS = 0;
862
0
                        UWORD32 u1_max_bins;
863
0
                        UWORD32 u4_value;
864
0
865
0
                        i2_abs_lvl = UCOFF_LEVEL;
866
0
                        /*inlining ih264d_decode_bypass_bins_unary begins*/
867
0
868
0
                        {
869
0
                            UWORD32 uc_bin;
870
0
                            UWORD32 bits_to_flush;
871
0
                            UWORD32 max_bits = 32;
872
0
873
0
                            bits_to_flush = 0;
874
0
                            /*renormalize to ensure there 23 bits more in the u4_code_int_val_ofst*/
875
0
                            {
876
0
                                UWORD32 u4_clz, read_bits;
877
0
878
0
                                u4_clz = CLZ(u4_code_int_range);
879
0
                                FLUSHBITS(u4_offset, u4_clz)
880
0
                                NEXTBITS(read_bits, u4_offset, pu4_buffer, 23)
881
0
                                u4_code_int_range = u4_code_int_range << u4_clz;
882
0
                                u4_code_int_val_ofst = (u4_code_int_val_ofst
883
0
                                                << u4_clz) | read_bits;
884
0
                            }
885
0
886
0
                            do
887
0
                            {
888
0
                                bits_to_flush++;
889
0
890
0
                                u4_code_int_range = u4_code_int_range >> 1;
891
0
892
0
                                if(u4_code_int_val_ofst >= u4_code_int_range)
893
0
                                {
894
0
                                    /* S=1 */
895
0
                                    uc_bin = 1;
896
0
                                    u4_code_int_val_ofst -= u4_code_int_range;
897
0
                                }
898
0
                                else
899
0
                                {
900
0
                                    /* S=0 */
901
0
                                    uc_bin = 0;
902
0
                                }
903
0
904
0
                            }
905
0
                            while(uc_bin && (bits_to_flush < max_bits));
906
0
907
0
                            u4_value = (bits_to_flush - 1);
908
0
                        }
909
0
                        /*inlining ih264d_decode_bypass_bins_unary ends*/
910
0
911
0
                        ui16_sufS = (1 << u4_value);
912
0
                        u1_max_bins = u4_value;
913
0
914
0
                        if(u4_value > 0)
915
0
                        {
916
0
                            /*inline bypassbins_flc begins*/
917
0
918
0
                            if(u4_value > 10)
919
0
                            {
920
0
                                UWORD32 u4_clz, read_bits;
921
0
922
0
                                u4_clz = CLZ(u4_code_int_range);
923
0
                                FLUSHBITS(u4_offset, u4_clz)
924
0
                                NEXTBITS(read_bits, u4_offset, pu4_buffer, 23)
925
0
                                u4_code_int_range = u4_code_int_range << u4_clz;
926
0
                                u4_code_int_val_ofst = (u4_code_int_val_ofst
927
0
                                                << u4_clz) | read_bits;
928
0
                            }
929
0
930
0
                            {
931
0
                                UWORD32 ui_bins;
932
0
                                UWORD32 uc_bin;
933
0
                                UWORD32 bits_to_flush;
934
0
935
0
                                ui_bins = 0;
936
0
                                bits_to_flush = 0;
937
0
938
0
                                do
939
0
                                {
940
0
                                    bits_to_flush++;
941
0
942
0
                                    u4_code_int_range = u4_code_int_range >> 1;
943
0
944
0
                                    if(u4_code_int_val_ofst
945
0
                                                    >= u4_code_int_range)
946
0
                                    {
947
0
                                        /* S=1 */
948
0
                                        uc_bin = 1;
949
0
                                        u4_code_int_val_ofst -=
950
0
                                                        u4_code_int_range;
951
0
                                    }
952
0
                                    else
953
0
                                    {
954
0
                                        /* S=0 */
955
0
                                        uc_bin = 0;
956
0
                                    }
957
0
958
0
                                    ui_bins = ((ui_bins << 1) | uc_bin);
959
0
960
0
                                }
961
0
                                while(bits_to_flush < u1_max_bins);
962
0
963
0
                                u4_value = ui_bins;
964
0
                            }
965
0
                            /*inline bypassbins_flc ends*/
966
0
                        }
967
0
968
0
                        //Value of K
969
0
                        ui16_sufS += u4_value;
970
0
                        i2_abs_lvl += ui16_sufS;
971
0
                    }
972
0
                    else
973
0
                    {
974
0
                        i2_abs_lvl = 1 + ui_prefix;
975
0
                    }
976
0
977
0
                    if(i2_abs_lvl > 1)
978
0
                    {
979
0
                        u1_abs_level_gt1++;
980
0
                    }
981
0
                    if(!u1_abs_level_gt1)
982
0
                    {
983
0
                        u1_abs_level_equal1++;
984
0
                        u4_ctx_inc = (5 << 4) + MIN(u1_abs_level_equal1, 4);
985
0
                    }
986
0
                    else
987
0
                    {
988
0
                        u4_ctx_inc = (5 + MIN(u1_abs_level_gt1, 4)) << 4;
989
0
                    }
990
0
991
0
                    /*u4_ctx_inc = g_table_temp[u1_abs_level_gt1][u1_abs_level_equal1];*/
992
0
993
0
                    /* encode coeff_sign_flag[i] */
994
0
995
0
                    {
996
0
                        u4_code_int_range = u4_code_int_range >> 1;
997
0
998
0
                        if(u4_code_int_val_ofst >= (u4_code_int_range))
999
0
                        {
1000
0
                            /* S=1 */
1001
0
                            u4_code_int_val_ofst -= u4_code_int_range;
1002
0
                            i2_abs_lvl = (-i2_abs_lvl);
1003
0
                        }
1004
0
                    }
1005
0
1006
0
                    *pi2_coeff_data++ = i2_abs_lvl;
1007
0
                    num_sig_coeffs--;
1008
0
                }
1009
0
            }
1010
0
            while(num_sig_coeffs > 0);
1011
0
        }
1012
0
    }
1013
0
1014
0
    {
1015
0
        WORD32 offset;
1016
0
        offset = (UWORD8 *)pi2_coeff_data - (UWORD8 *)ps_tu_8x8;
1017
0
        offset = ALIGN4(offset);
1018
0
        ps_dec->pv_parse_tu_coeff_data = (void *)((UWORD8 *)ps_dec->pv_parse_tu_coeff_data + offset);
1019
0
    }
1020
0
1021
0
    /*updating structures*/
1022
0
    ps_cab_env->u4_code_int_val_ofst = u4_code_int_val_ofst;
1023
0
    ps_cab_env->u4_code_int_range = u4_code_int_range;
1024
0
    ps_bitstrm->u4_ofst = u4_offset;
1025
0
}
1026
1027
/*****************************************************************************/
1028
/*                                                                           */
1029
/*  Function Name : ih264d_cabac_parse_8x8block                                     */
1030
/*                                                                           */
1031
/*  Description   : This function does the residual parsing of 4 subblocks   */
1032
/*                  in a 8x8 block.                                          */
1033
/*                                                                           */
1034
/*  Inputs        : pi2_coeff_block : pointer to residual block where        */
1035
/*                  decoded and inverse scan coefficients are updated        */
1036
/*                                                                           */
1037
/*                  u4_sub_block_strd : indicates the number of sublocks    */
1038
/*                  in a row. It is 4 for luma and 2 for chroma.             */
1039
/*                                                                           */
1040
/*                  u4_ctx_cat : inidicates context category for residual    */
1041
/*                  decoding.                                                */
1042
/*                                                                           */
1043
/*                  ps_dec : pointer to Decstruct (decoder context)          */
1044
/*                                                                           */
1045
/*                  pu1_top_nnz : top nnz pointer                            */
1046
/*                                                                           */
1047
/*                  pu1_left_nnz : left nnz pointer                          */
1048
/*                                                                           */
1049
/*  Globals       : No                                                       */
1050
/*  Processing    : Parsing for four subblocks in unrolled, top and left nnz */
1051
/*                  are updated on the fly. csbp is set in accordance to     */
1052
/*                  decoded numcoeff for the subblock index in raster order  */
1053
/*                                                                           */
1054
/*  Outputs       : The updated residue buffer, nnzs and csbp current block  */
1055
/*                                                                           */
1056
/*  Returns       : Returns the coded sub block pattern csbp for the block   */
1057
/*                                                                           */
1058
/*  Issues        : <List any issues or problems with this function>         */
1059
/*                                                                           */
1060
/*  Revision History:                                                        */
1061
/*                                                                           */
1062
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1063
/*         09 10 2008   Jay          Draft                                   */
1064
/*                                                                           */
1065
/*****************************************************************************/
1066
UWORD32 ih264d_cabac_parse_8x8block(WORD16 *pi2_coeff_block,
1067
                                    UWORD32 u4_sub_block_strd,
1068
                                    UWORD32 u4_ctx_cat,
1069
                                    dec_struct_t * ps_dec,
1070
                                    UWORD8 *pu1_top_nnz,
1071
                                    UWORD8 *pu1_left_nnz)
1072
0
{
1073
0
    UWORD32 u4_ctxinc, u4_subblock_coded;
1074
0
    UWORD32 u4_top0, u4_top1;
1075
0
    UWORD32 u4_csbp = 0;
1076
0
    UWORD32 u4_idx = 0;
1077
0
    dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
1078
0
    bin_ctxt_model_t * const ps_cbf = ps_dec->p_cbf_t[u4_ctx_cat];
1079
0
    bin_ctxt_model_t *ps_src_bin_ctxt;
1080
0
    bin_ctxt_model_t * const ps_sig_coeff_flag =
1081
0
                    ps_dec->p_significant_coeff_flag_t[u4_ctx_cat];
1082
0
1083
0
    UWORD8 *pu1_inv_scan = ps_dec->pu1_inv_scan;
1084
0
1085
0
    /*------------------------------------------------------*/
1086
0
    /* Residual 4x4 decoding: SubBlock 0                    */
1087
0
    /*------------------------------------------------------*/
1088
0
    u4_ctxinc = ((!!pu1_top_nnz[0]) << 1) + (!!pu1_left_nnz[0]);
1089
0
1090
0
    ps_src_bin_ctxt = ps_cbf + u4_ctxinc;
1091
0
1092
0
    u4_top0 = ih264d_read_coeff4x4_cabac( ps_bitstrm,
1093
0
                                         u4_ctx_cat, ps_sig_coeff_flag, ps_dec,
1094
0
                                         ps_src_bin_ctxt);
1095
0
1096
0
    INSERT_BIT(u4_csbp, u4_idx, u4_top0);
1097
0
1098
0
    /*------------------------------------------------------*/
1099
0
    /* Residual 4x4 decoding: SubBlock 1                    */
1100
0
    /*------------------------------------------------------*/
1101
0
    u4_idx++;
1102
0
    pi2_coeff_block += NUM_COEFFS_IN_4x4BLK;
1103
0
    u4_ctxinc = ((!!pu1_top_nnz[1]) << 1) + u4_top0;
1104
0
1105
0
    ps_src_bin_ctxt = ps_cbf + u4_ctxinc;
1106
0
1107
0
    u4_top1 = ih264d_read_coeff4x4_cabac(ps_bitstrm,
1108
0
                                         u4_ctx_cat, ps_sig_coeff_flag, ps_dec,
1109
0
                                         ps_src_bin_ctxt);
1110
0
1111
0
    INSERT_BIT(u4_csbp, u4_idx, u4_top1);
1112
0
    pu1_left_nnz[0] = u4_top1;
1113
0
1114
0
    /*------------------------------------------------------*/
1115
0
    /* Residual 4x4 decoding: SubBlock 2                    */
1116
0
    /*------------------------------------------------------*/
1117
0
    u4_idx += (u4_sub_block_strd - 1);
1118
0
    pi2_coeff_block += ((u4_sub_block_strd - 1) * NUM_COEFFS_IN_4x4BLK);
1119
0
    u4_ctxinc = (u4_top0 << 1) + (!!pu1_left_nnz[1]);
1120
0
1121
0
    ps_src_bin_ctxt = ps_cbf + u4_ctxinc;
1122
0
1123
0
    u4_subblock_coded = ih264d_read_coeff4x4_cabac(ps_bitstrm, u4_ctx_cat,
1124
0
                                                   ps_sig_coeff_flag, ps_dec,
1125
0
                                                   ps_src_bin_ctxt);
1126
0
1127
0
    INSERT_BIT(u4_csbp, u4_idx, u4_subblock_coded);
1128
0
    pu1_top_nnz[0] = u4_subblock_coded;
1129
0
1130
0
    /*------------------------------------------------------*/
1131
0
    /* Residual 4x4 decoding: SubBlock 3                    */
1132
0
    /*------------------------------------------------------*/
1133
0
    u4_idx++;
1134
0
    pi2_coeff_block += NUM_COEFFS_IN_4x4BLK;
1135
0
    u4_ctxinc = (u4_top1 << 1) + u4_subblock_coded;
1136
0
1137
0
    ps_src_bin_ctxt = ps_cbf + u4_ctxinc;
1138
0
1139
0
    u4_subblock_coded = ih264d_read_coeff4x4_cabac(ps_bitstrm, u4_ctx_cat,
1140
0
                                                   ps_sig_coeff_flag, ps_dec,
1141
0
                                                   ps_src_bin_ctxt);
1142
0
1143
0
    INSERT_BIT(u4_csbp, u4_idx, u4_subblock_coded);
1144
0
    pu1_top_nnz[1] = pu1_left_nnz[1] = u4_subblock_coded;
1145
0
1146
0
    return (u4_csbp);
1147
0
}
1148
1149
/*!
1150
 **************************************************************************
1151
 * \if Function name : ih264d_parse_residual4x4_cabac \endif
1152
 *
1153
 * \brief
1154
 *    This function parses CABAC syntax of a Luma and Chroma AC Residuals.
1155
 *
1156
 * \return
1157
 *    0 on Success and Error code otherwise
1158
 **************************************************************************
1159
 */
1160
1161
WORD32 ih264d_parse_residual4x4_cabac(dec_struct_t * ps_dec,
1162
                                      dec_mb_info_t *ps_cur_mb_info,
1163
                                      UWORD8 u1_offset)
1164
0
{
1165
0
    UWORD8 u1_cbp = ps_cur_mb_info->u1_cbp;
1166
0
    UWORD16 ui16_csbp = 0;
1167
0
    WORD16 *pi2_residual_buf;
1168
0
    UWORD8 uc_ctx_cat;
1169
0
    UWORD8 *pu1_top_nnz = ps_cur_mb_info->ps_curmb->pu1_nnz_y;
1170
0
    UWORD8 *pu1_left_nnz = ps_dec->pu1_left_nnz_y;
1171
0
    UWORD8 *pu1_top_nnz_uv = ps_cur_mb_info->ps_curmb->pu1_nnz_uv;
1172
0
    ctxt_inc_mb_info_t *p_curr_ctxt = ps_dec->ps_curr_ctxt_mb_info;
1173
0
    ctxt_inc_mb_info_t *ps_top_ctxt = ps_dec->p_top_ctxt_mb_info;
1174
0
    dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
1175
0
    UWORD32 u4_nbr_avail = ps_dec->u1_mb_ngbr_availablity;
1176
0
    WORD16 *pi2_coeff_block = NULL;
1177
0
    bin_ctxt_model_t *ps_src_bin_ctxt;
1178
0
1179
0
    UWORD8 u1_top_dc_csbp = (ps_top_ctxt->u1_yuv_dc_csbp) >> 1;
1180
0
    UWORD8 u1_left_dc_csbp = (ps_dec->pu1_left_yuv_dc_csbp[0]) >> 1;
1181
0
1182
0
1183
0
    if(!(u4_nbr_avail & TOP_MB_AVAILABLE_MASK))
1184
0
    {
1185
0
        if(p_curr_ctxt->u1_mb_type & CAB_INTRA_MASK)
1186
0
        {
1187
0
            *(UWORD32 *)pu1_top_nnz = 0;
1188
0
            u1_top_dc_csbp = 0;
1189
0
            *(UWORD32 *)pu1_top_nnz_uv = 0;
1190
0
        }
1191
0
        else
1192
0
        {
1193
0
            *(UWORD32 *)pu1_top_nnz = 0x01010101;
1194
0
            u1_top_dc_csbp = 0x3;
1195
0
            *(UWORD32 *)pu1_top_nnz_uv = 0x01010101;
1196
0
        }
1197
0
    }
1198
0
    else
1199
0
    {
1200
0
        UWORD32 *pu4_buf;
1201
0
        UWORD8 *pu1_buf;
1202
0
        pu1_buf = ps_cur_mb_info->ps_top_mb->pu1_nnz_y;
1203
0
        pu4_buf = (UWORD32 *)pu1_buf;
1204
0
        *(UWORD32 *)(pu1_top_nnz) = *pu4_buf;
1205
0
1206
0
        pu1_buf = ps_cur_mb_info->ps_top_mb->pu1_nnz_uv;
1207
0
        pu4_buf = (UWORD32 *)pu1_buf;
1208
0
        *(UWORD32 *)(pu1_top_nnz_uv) = *pu4_buf;
1209
0
1210
0
    }
1211
0
1212
0
    if(!(u4_nbr_avail & LEFT_MB_AVAILABLE_MASK))
1213
0
    {
1214
0
        if(p_curr_ctxt->u1_mb_type & CAB_INTRA_MASK)
1215
0
        {
1216
0
            UWORD32 *pu4_buf;
1217
0
            UWORD8 *pu1_buf;
1218
0
            *(UWORD32 *)pu1_left_nnz = 0;
1219
0
            u1_left_dc_csbp = 0;
1220
0
            pu1_buf = ps_dec->pu1_left_nnz_uv;
1221
0
            pu4_buf = (UWORD32 *)pu1_buf;
1222
0
            *pu4_buf = 0;
1223
0
        }
1224
0
        else
1225
0
        {
1226
0
            UWORD32 *pu4_buf;
1227
0
            UWORD8 *pu1_buf;
1228
0
            *(UWORD32 *)pu1_left_nnz = 0x01010101;
1229
0
            u1_left_dc_csbp = 0x3;
1230
0
            pu1_buf = ps_dec->pu1_left_nnz_uv;
1231
0
            pu4_buf = (UWORD32 *)pu1_buf;
1232
0
            *pu4_buf = 0x01010101;
1233
0
        }
1234
0
    }
1235
0
1236
0
    uc_ctx_cat = u1_offset ? LUMA_AC_CTXCAT : LUMA_4X4_CTXCAT;
1237
0
1238
0
    ps_cur_mb_info->u1_qp_div6 = ps_dec->u1_qp_y_div6;
1239
0
    ps_cur_mb_info->u1_qpc_div6 = ps_dec->u1_qp_u_div6;
1240
0
    ps_cur_mb_info->u1_qp_rem6 = ps_dec->u1_qp_y_rem6;
1241
0
    ps_cur_mb_info->u1_qpc_rem6 = ps_dec->u1_qp_u_rem6;
1242
0
    // CHECK_THIS
1243
0
    ps_cur_mb_info->u1_qpcr_div6 = ps_dec->u1_qp_v_div6;
1244
0
    ps_cur_mb_info->u1_qpcr_rem6 = ps_dec->u1_qp_v_rem6;
1245
0
1246
0
    if(u1_cbp & 0x0f)
1247
0
    {
1248
0
        if(ps_cur_mb_info->u1_tran_form8x8 == 0)
1249
0
        {
1250
0
            /*******************************************************************/
1251
0
            /* Block 0 residual decoding, check cbp and proceed (subblock = 0) */
1252
0
            /*******************************************************************/
1253
0
            if(!(u1_cbp & 0x1))
1254
0
            {
1255
0
                *(UWORD16 *)(pu1_top_nnz) = 0;
1256
0
                *(UWORD16 *)(pu1_left_nnz) = 0;
1257
0
            }
1258
0
            else
1259
0
            {
1260
0
                ui16_csbp = ih264d_cabac_parse_8x8block(pi2_coeff_block, 4,
1261
0
                                                        uc_ctx_cat, ps_dec,
1262
0
                                                        pu1_top_nnz,
1263
0
                                                        pu1_left_nnz);
1264
0
            }
1265
0
1266
0
            /*******************************************************************/
1267
0
            /* Block 1 residual decoding, check cbp and proceed (subblock = 2) */
1268
0
            /*******************************************************************/
1269
0
            pi2_coeff_block += (2 * NUM_COEFFS_IN_4x4BLK);
1270
0
            if(!(u1_cbp & 0x2))
1271
0
            {
1272
0
                *(UWORD16 *)(pu1_top_nnz + 2) = 0;
1273
0
                *(UWORD16 *)(pu1_left_nnz) = 0;
1274
0
            }
1275
0
            else
1276
0
            {
1277
0
                UWORD32 u4_temp = ih264d_cabac_parse_8x8block(pi2_coeff_block,
1278
0
                                                              4, uc_ctx_cat,
1279
0
                                                              ps_dec,
1280
0
                                                              (pu1_top_nnz + 2),
1281
0
                                                              pu1_left_nnz);
1282
0
                ui16_csbp |= (u4_temp << 2);
1283
0
            }
1284
0
1285
0
            /*******************************************************************/
1286
0
            /* Block 2 residual decoding, check cbp and proceed (subblock = 8) */
1287
0
            /*******************************************************************/
1288
0
            pi2_coeff_block += (6 * NUM_COEFFS_IN_4x4BLK);
1289
0
            if(!(u1_cbp & 0x4))
1290
0
            {
1291
0
                *(UWORD16 *)(pu1_top_nnz) = 0;
1292
0
                *(UWORD16 *)(pu1_left_nnz + 2) = 0;
1293
0
            }
1294
0
            else
1295
0
            {
1296
0
                UWORD32 u4_temp = ih264d_cabac_parse_8x8block(
1297
0
                                pi2_coeff_block, 4, uc_ctx_cat, ps_dec,
1298
0
                                pu1_top_nnz, (pu1_left_nnz + 2));
1299
0
                ui16_csbp |= (u4_temp << 8);
1300
0
            }
1301
0
1302
0
            /*******************************************************************/
1303
0
            /* Block 3 residual decoding, check cbp and proceed (subblock = 10)*/
1304
0
            /*******************************************************************/
1305
0
            pi2_coeff_block += (2 * NUM_COEFFS_IN_4x4BLK);
1306
0
            if(!(u1_cbp & 0x8))
1307
0
            {
1308
0
                *(UWORD16 *)(pu1_top_nnz + 2) = 0;
1309
0
                *(UWORD16 *)(pu1_left_nnz + 2) = 0;
1310
0
            }
1311
0
            else
1312
0
            {
1313
0
                UWORD32 u4_temp = ih264d_cabac_parse_8x8block(
1314
0
                                pi2_coeff_block, 4, uc_ctx_cat, ps_dec,
1315
0
                                (pu1_top_nnz + 2), (pu1_left_nnz + 2));
1316
0
                ui16_csbp |= (u4_temp << 10);
1317
0
            }
1318
0
1319
0
        }
1320
0
        else
1321
0
        {
1322
0
            ui16_csbp = 0;
1323
0
1324
0
            /*******************************************************************/
1325
0
            /* Block 0 residual decoding, check cbp and proceed (subblock = 0) */
1326
0
            /*******************************************************************/
1327
0
            if(!(u1_cbp & 0x1))
1328
0
            {
1329
0
                *(UWORD16 *)(pu1_top_nnz) = 0;
1330
0
                *(UWORD16 *)(pu1_left_nnz) = 0;
1331
0
            }
1332
0
            else
1333
0
            {
1334
0
1335
0
                dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
1336
0
1337
0
                ih264d_read_coeff8x8_cabac( ps_bitstrm,
1338
0
                                           ps_dec, ps_cur_mb_info);
1339
0
1340
0
                pu1_left_nnz[0] = 1;
1341
0
                pu1_left_nnz[1] = 1;
1342
0
1343
0
                pu1_top_nnz[0] = 1;
1344
0
                pu1_top_nnz[1] = 1;
1345
0
1346
0
                /* added to be used by BS computation module */
1347
0
                ui16_csbp |= 0x0033;
1348
0
            }
1349
0
1350
0
            /*******************************************************************/
1351
0
            /* Block 1 residual decoding, check cbp and proceed (subblock = 2) */
1352
0
            /*******************************************************************/
1353
0
            pi2_coeff_block += 64;
1354
0
1355
0
            if(!(u1_cbp & 0x2))
1356
0
            {
1357
0
                *(UWORD16 *)(pu1_top_nnz + 2) = 0;
1358
0
                *(UWORD16 *)(pu1_left_nnz) = 0;
1359
0
            }
1360
0
            else
1361
0
            {
1362
0
1363
0
1364
0
                dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
1365
0
1366
0
                ih264d_read_coeff8x8_cabac(ps_bitstrm,
1367
0
                                           ps_dec, ps_cur_mb_info);
1368
0
1369
0
                pu1_left_nnz[0] = 1;
1370
0
                pu1_left_nnz[1] = 1;
1371
0
1372
0
                pu1_top_nnz[2] = 1;
1373
0
                pu1_top_nnz[3] = 1;
1374
0
1375
0
                /* added to be used by BS computation module */
1376
0
                ui16_csbp |= 0x00CC;
1377
0
1378
0
            }
1379
0
1380
0
            /*******************************************************************/
1381
0
            /* Block 2 residual decoding, check cbp and proceed (subblock = 8) */
1382
0
            /*******************************************************************/
1383
0
            pi2_coeff_block += 64;
1384
0
            if(!(u1_cbp & 0x4))
1385
0
            {
1386
0
                *(UWORD16 *)(pu1_top_nnz) = 0;
1387
0
                *(UWORD16 *)(pu1_left_nnz + 2) = 0;
1388
0
            }
1389
0
            else
1390
0
            {
1391
0
1392
0
                dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
1393
0
1394
0
                ih264d_read_coeff8x8_cabac(ps_bitstrm,
1395
0
                                           ps_dec, ps_cur_mb_info);
1396
0
1397
0
                pu1_left_nnz[2] = 1;
1398
0
                pu1_left_nnz[3] = 1;
1399
0
1400
0
                pu1_top_nnz[0] = 1;
1401
0
                pu1_top_nnz[1] = 1;
1402
0
1403
0
                /* added to be used by BS computation module */
1404
0
                ui16_csbp |= 0x3300;
1405
0
            }
1406
0
1407
0
            /*******************************************************************/
1408
0
            /* Block 3 residual decoding, check cbp and proceed (subblock = 10)*/
1409
0
            /*******************************************************************/
1410
0
            pi2_coeff_block += 64;
1411
0
1412
0
            if(!(u1_cbp & 0x8))
1413
0
            {
1414
0
                *(UWORD16 *)(pu1_top_nnz + 2) = 0;
1415
0
                *(UWORD16 *)(pu1_left_nnz + 2) = 0;
1416
0
            }
1417
0
            else
1418
0
            {
1419
0
1420
0
                dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
1421
0
1422
0
                ih264d_read_coeff8x8_cabac(ps_bitstrm,
1423
0
                                           ps_dec, ps_cur_mb_info);
1424
0
1425
0
                pu1_left_nnz[2] = 1;
1426
0
                pu1_left_nnz[3] = 1;
1427
0
1428
0
                pu1_top_nnz[2] = 1;
1429
0
                pu1_top_nnz[3] = 1;
1430
0
1431
0
                /* added to be used by BS computation module */
1432
0
                ui16_csbp |= 0xCC00;
1433
0
            }
1434
0
        }
1435
0
    }
1436
0
    else
1437
0
    {
1438
0
        *(UWORD32 *)(pu1_top_nnz) = 0;
1439
0
        *(UWORD32 *)(pu1_left_nnz) = 0;
1440
0
    }
1441
0
    /*--------------------------------------------------------------------*/
1442
0
    /* Store the last row of N values to top row                          */
1443
0
    /*--------------------------------------------------------------------*/
1444
0
    ps_cur_mb_info->u2_luma_csbp = ui16_csbp;
1445
0
    ps_cur_mb_info->ps_curmb->u2_luma_csbp = ui16_csbp;
1446
0
    {
1447
0
        WORD8 i;
1448
0
        UWORD16 u2_chroma_csbp = 0;
1449
0
        ps_cur_mb_info->u2_chroma_csbp = 0;
1450
0
1451
0
        u1_cbp >>= 4;
1452
0
        pu1_top_nnz = pu1_top_nnz_uv;
1453
0
        pu1_left_nnz = ps_dec->pu1_left_nnz_uv;
1454
0
        /*--------------------------------------------------------------------*/
1455
0
        /* if Chroma Component not present OR no ac values present            */
1456
0
        /* Set the values of N to zero                                        */
1457
0
        /*--------------------------------------------------------------------*/
1458
0
        if(u1_cbp == CBPC_ALLZERO)
1459
0
        {
1460
0
            ps_dec->pu1_left_yuv_dc_csbp[0] &= 0x1;
1461
0
            *(UWORD32 *)(pu1_top_nnz) = 0;
1462
0
            *(UWORD32 *)(pu1_left_nnz) = 0;
1463
0
            p_curr_ctxt->u1_yuv_dc_csbp &= 0x1;
1464
0
            return (0);
1465
0
        }
1466
0
1467
0
        /*--------------------------------------------------------------------*/
1468
0
        /* Decode Chroma DC values                                            */
1469
0
        /*--------------------------------------------------------------------*/
1470
0
        for(i = 0; i < 2; i++)
1471
0
        {
1472
0
            UWORD8 uc_a = 1, uc_b = 1;
1473
0
            UWORD32 u4_ctx_inc;
1474
0
            UWORD8 uc_codedBlockFlag;
1475
0
            UWORD8 pu1_inv_scan[4] =
1476
0
                { 0, 1, 2, 3 };
1477
0
            WORD32 u4_scale;
1478
0
            WORD32 i4_mb_inter_inc;
1479
0
            tu_sblk4x4_coeff_data_t *ps_tu_4x4 =
1480
0
                            (tu_sblk4x4_coeff_data_t *)ps_dec->pv_parse_tu_coeff_data;
1481
0
            WORD16 *pi2_coeff_data =
1482
0
                            (WORD16 *)ps_dec->pv_parse_tu_coeff_data;
1483
0
            WORD16 ai2_dc_coef[4];
1484
0
1485
0
            INC_SYM_COUNT(&(ps_dec->s_cab_dec_env));
1486
0
            u4_scale = (i) ?
1487
0
                            (ps_dec->pu2_quant_scale_v[0]
1488
0
                                            << ps_dec->u1_qp_v_div6) :
1489
0
                            (ps_dec->pu2_quant_scale_u[0]
1490
0
                                            << ps_dec->u1_qp_u_div6);
1491
0
1492
0
            /*--------------------------------------------------------------------*/
1493
0
            /* Decode Bitstream to get the DC coeff                               */
1494
0
            /*--------------------------------------------------------------------*/
1495
0
            uc_a = (u1_left_dc_csbp >> i) & 0x01;
1496
0
            uc_b = (u1_top_dc_csbp >> i) & 0x01;
1497
0
            u4_ctx_inc = (uc_a + (uc_b << 1));
1498
0
1499
0
            ps_src_bin_ctxt = (ps_dec->p_cbf_t[CHROMA_DC_CTXCAT]) + u4_ctx_inc;
1500
0
1501
0
            uc_codedBlockFlag =
1502
0
                            ih264d_read_coeff4x4_cabac(ps_bitstrm,
1503
0
                                            CHROMA_DC_CTXCAT,
1504
0
                                            ps_dec->p_significant_coeff_flag_t[CHROMA_DC_CTXCAT],
1505
0
                                            ps_dec, ps_src_bin_ctxt);
1506
0
1507
0
            i4_mb_inter_inc = (!((ps_cur_mb_info->ps_curmb->u1_mb_type == I_4x4_MB)
1508
0
                            || (ps_cur_mb_info->ps_curmb->u1_mb_type == I_16x16_MB)))
1509
0
                            * 3;
1510
0
1511
0
            if(ps_dec->s_high_profile.u1_scaling_present)
1512
0
            {
1513
0
                u4_scale *=
1514
0
                                ps_dec->s_high_profile.i2_scalinglist4x4[i4_mb_inter_inc
1515
0
                                                + 1 + i][0];
1516
0
1517
0
            }
1518
0
            else
1519
0
            {
1520
0
                u4_scale <<= 4;
1521
0
            }
1522
0
1523
0
            if(uc_codedBlockFlag)
1524
0
            {
1525
0
                WORD32 i_z0, i_z1, i_z2, i_z3;
1526
0
                WORD32 *pi4_scale;
1527
0
1528
0
                SET_BIT(u1_top_dc_csbp, i);
1529
0
                SET_BIT(u1_left_dc_csbp, i);
1530
0
1531
0
                ai2_dc_coef[0] = 0;
1532
0
                ai2_dc_coef[1] = 0;
1533
0
                ai2_dc_coef[2] = 0;
1534
0
                ai2_dc_coef[3] = 0;
1535
0
1536
0
                ih264d_unpack_coeff4x4_dc_4x4blk(ps_tu_4x4,
1537
0
                                                 ai2_dc_coef,
1538
0
                                                 pu1_inv_scan);
1539
0
                i_z0 = (ai2_dc_coef[0] + ai2_dc_coef[2]);
1540
0
                i_z1 = (ai2_dc_coef[0] - ai2_dc_coef[2]);
1541
0
                i_z2 = (ai2_dc_coef[1] - ai2_dc_coef[3]);
1542
0
                i_z3 = (ai2_dc_coef[1] + ai2_dc_coef[3]);
1543
0
1544
0
                /*-----------------------------------------------------------*/
1545
0
                /* Scaling and storing the values back                       */
1546
0
                /*-----------------------------------------------------------*/
1547
0
                *pi2_coeff_data++ = ((i_z0 + i_z3) * u4_scale) >> 5;
1548
0
                *pi2_coeff_data++ = ((i_z0 - i_z3) * u4_scale) >> 5;
1549
0
                *pi2_coeff_data++ = ((i_z1 + i_z2) * u4_scale) >> 5;
1550
0
                *pi2_coeff_data++ = ((i_z1 - i_z2) * u4_scale) >> 5;
1551
0
1552
0
                ps_dec->pv_parse_tu_coeff_data = (void *)pi2_coeff_data;
1553
0
1554
0
                SET_BIT(ps_cur_mb_info->u1_yuv_dc_block_flag,(i+1));
1555
0
            }
1556
0
            else
1557
0
            {
1558
0
                CLEARBIT(u1_top_dc_csbp, i);
1559
0
                CLEARBIT(u1_left_dc_csbp, i);
1560
0
            }
1561
0
        }
1562
0
1563
0
        /*********************************************************************/
1564
0
        /*                   Update the DC csbp                              */
1565
0
        /*********************************************************************/
1566
0
        ps_dec->pu1_left_yuv_dc_csbp[0] &= 0x1;
1567
0
        p_curr_ctxt->u1_yuv_dc_csbp &= 0x1;
1568
0
        ps_dec->pu1_left_yuv_dc_csbp[0] |= (u1_left_dc_csbp << 1);
1569
0
        p_curr_ctxt->u1_yuv_dc_csbp |= (u1_top_dc_csbp << 1);
1570
0
        if(u1_cbp == CBPC_ACZERO)
1571
0
        {
1572
0
            *(UWORD32 *)(pu1_top_nnz) = 0;
1573
0
            *(UWORD32 *)(pu1_left_nnz) = 0;
1574
0
            return (0);
1575
0
        }
1576
0
        /*--------------------------------------------------------------------*/
1577
0
        /* Decode Chroma AC values                                            */
1578
0
        /*--------------------------------------------------------------------*/
1579
0
        {
1580
0
            UWORD32 u4_temp;
1581
0
            /*****************************************************************/
1582
0
            /* U Block  residual decoding, check cbp and proceed (subblock=0)*/
1583
0
            /*****************************************************************/
1584
0
            u2_chroma_csbp = ih264d_cabac_parse_8x8block(pi2_coeff_block, 2,
1585
0
            CHROMA_AC_CTXCAT,
1586
0
                                                         ps_dec, pu1_top_nnz,
1587
0
                                                         pu1_left_nnz);
1588
0
1589
0
            pi2_coeff_block += MB_CHROM_SIZE;
1590
0
            /*****************************************************************/
1591
0
            /* V Block  residual decoding, check cbp and proceed (subblock=1)*/
1592
0
            /*****************************************************************/
1593
0
            u4_temp = ih264d_cabac_parse_8x8block(pi2_coeff_block, 2,
1594
0
            CHROMA_AC_CTXCAT,
1595
0
                                                  ps_dec, (pu1_top_nnz + 2),
1596
0
                                                  (pu1_left_nnz + 2));
1597
0
            u2_chroma_csbp |= (u4_temp << 4);
1598
0
        }
1599
0
        /*********************************************************************/
1600
0
        /*                   Update the AC csbp                              */
1601
0
        /*********************************************************************/
1602
0
        ps_cur_mb_info->u2_chroma_csbp = u2_chroma_csbp;
1603
0
    }
1604
0
1605
0
    return (0);
1606
0
}
1607
/proc/self/cwd/external/libavc/decoder/ih264d_parse_cabac.h
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
21
/*!
22
 ***************************************************************************
23
 * \file ih264d_parse_cabac.h
24
 *
25
 * \brief
26
 *    This file contains cabac Residual decoding routines.
27
 *
28
 * \date
29
 *    20/03/2003
30
 *
31
 * \author  NS
32
 ***************************************************************************
33
 */
34
#ifndef _IH264D_PARSE_CABAC_H_
35
#define _IH264D_PARSE_CABAC_H_
36
37
#include "ih264_typedefs.h"
38
#include "ih264_macros.h"
39
#include "ih264_platform_macros.h"
40
41
0
#define UCOFF_LEVEL  14
42
43
44
UWORD8 ih264d_read_coeff4x4_cabac(dec_bit_stream_t *ps_bitstrm,
45
                                  UWORD32 u4_ctxcat,
46
                                  bin_ctxt_model_t *ps_ctxt_sig_coeff,
47
                                  dec_struct_t *ps_dec,
48
                                  bin_ctxt_model_t *ps_ctxt_coded);
49
50
void ih264d_read_coeff8x8_cabac(dec_bit_stream_t *ps_bitstrm,
51
                                dec_struct_t *ps_dec,
52
                                dec_mb_info_t *ps_cur_mb_info);
53
54
UWORD32 cabac_parse_8x8block_transform8x8_set(WORD16 *pi2_coeff_block,
55
                                              dec_struct_t * ps_dec,
56
                                              UWORD8 *pu1_top_nnz,
57
                                              UWORD8 *pu1_left_nnz,
58
                                              dec_mb_info_t *ps_cur_mb_info);
59
60
#endif  /* _IH264D_PARSE_CABAC_H_ */
/proc/self/cwd/external/libavc/decoder/ih264d_parse_cavlc.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/*!
21
 ***************************************************************************
22
 * \file ih264d_parse_cavlc.c
23
 *
24
 * \brief
25
 *    This file contains UVLC related functions.
26
 *
27
 * \date
28
 *    20/11/2002
29
 *
30
 * \author  NS
31
 ***************************************************************************
32
 */
33
34
#include <string.h>
35
#include <stdio.h>
36
37
#include "ih264d_bitstrm.h"
38
#include "ih264d_parse_cavlc.h"
39
#include "ih264d_error_handler.h"
40
#include "ih264d_defs.h"
41
#include "ih264d_debug.h"
42
#include "ih264d_cabac.h"
43
#include "ih264d_structs.h"
44
#include "ih264d_tables.h"
45
#include "ih264d_tables.h"
46
#include "ih264d_mb_utils.h"
47
48
void ih264d_unpack_coeff4x4_dc_4x4blk(tu_sblk4x4_coeff_data_t *ps_tu_4x4,
49
                                      WORD16 *pi2_out_coeff_data,
50
                                      UWORD8 *pu1_inv_scan);
51
52
/*****************************************************************************/
53
/*                                                                           */
54
/*  Function Name : ih264d_uev                                                  */
55
/*                                                                           */
56
/*  Description   : Reads the unsigned Exp Golomb codec syntax from the      */
57
/*                  ps_bitstrm as specified in section 9.1 of H264 standard      */
58
/*                  It also increases bitstream u4_ofst by the number of bits */
59
/*                  parsed for UEV decode operation                          */
60
/*                                                                           */
61
/*  Inputs        : bitstream base pointer and bitsream u4_ofst in bits       */
62
/*  Globals       : None                                                     */
63
/*  Processing    :                                                          */
64
/*  Outputs       : UEV decoded syntax element and incremented ps_bitstrm u4_ofst */
65
/*  Returns       : UEV decoded syntax element                               */
66
/*                                                                           */
67
/*  Issues        : Does not check if ps_bitstrm u4_ofst exceeds max ps_bitstrm i4_size  */
68
/*                  for performamce. Caller might have to do error resilence */
69
/*                  check for bitstream overflow                             */
70
/*                                                                           */
71
/*  Revision History:                                                        */
72
/*                                                                           */
73
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
74
/*         19 09 2008   Jay          Draft                                   */
75
/*                                                                           */
76
/*****************************************************************************/
77
UWORD32 ih264d_uev(UWORD32 *pu4_bitstrm_ofst, UWORD32 *pu4_bitstrm_buf)
78
80
{
79
80
    UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
80
80
    UWORD32 u4_word, u4_ldz;
81
80
82
80
    /***************************************************************/
83
80
    /* Find leading zeros in next 32 bits                          */
84
80
    /***************************************************************/
85
80
    NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
86
80
    u4_ldz = CLZ(u4_word);
87
80
    /* Flush the ps_bitstrm */
88
80
    u4_bitstream_offset += (u4_ldz + 1);
89
80
    /* Read the suffix from the ps_bitstrm */
90
80
    u4_word = 0;
91
80
    if(u4_ldz)
92
80
        GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf, u4_ldz);
93
80
    *pu4_bitstrm_ofst = u4_bitstream_offset;
94
80
    return ((1 << u4_ldz) + u4_word - 1);
95
80
}
96
97
/*****************************************************************************/
98
/*                                                                           */
99
/*  Function Name : ih264d_sev                                                  */
100
/*                                                                           */
101
/*  Description   : Reads the signed Exp Golomb codec syntax from the ps_bitstrm */
102
/*                  as specified in section 9.1 of H264 standard.            */
103
/*                  It also increases bitstream u4_ofst by the number of bits */
104
/*                  parsed for SEV decode operation                          */
105
/*                                                                           */
106
/*  Inputs        : bitstream base pointer and bitsream u4_ofst in bits       */
107
/*  Globals       : None                                                     */
108
/*  Processing    :                                                          */
109
/*  Outputs       : SEV decoded syntax element and incremented ps_bitstrm u4_ofst */
110
/*  Returns       : SEV decoded syntax element                               */
111
/*                                                                           */
112
/*  Issues        : Does not check if ps_bitstrm u4_ofst exceeds max ps_bitstrm i4_size  */
113
/*                  for performamce. Caller might have to do error resilence */
114
/*                  check for bitstream overflow                             */
115
/*                                                                           */
116
/*  Revision History:                                                        */
117
/*                                                                           */
118
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
119
/*         19 09 2008   Jay          Draft                                   */
120
/*                                                                           */
121
/*****************************************************************************/
122
WORD32 ih264d_sev(UWORD32 *pu4_bitstrm_ofst, UWORD32 *pu4_bitstrm_buf)
123
36
{
124
36
    UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
125
36
    UWORD32 u4_word, u4_ldz, u4_abs_val;
126
36
127
36
    /***************************************************************/
128
36
    /* Find leading zeros in next 32 bits                          */
129
36
    /***************************************************************/
130
36
    NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
131
36
    u4_ldz = CLZ(u4_word);
132
36
133
36
    /* Flush the ps_bitstrm */
134
36
    u4_bitstream_offset += (u4_ldz + 1);
135
36
136
36
    /* Read the suffix from the ps_bitstrm */
137
36
    u4_word = 0;
138
36
    if(u4_ldz)
139
36
        GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf, u4_ldz);
140
36
141
36
    *pu4_bitstrm_ofst = u4_bitstream_offset;
142
36
    u4_abs_val = ((1 << u4_ldz) + u4_word) >> 1;
143
36
144
36
    if(u4_word & 0x1)
145
33
        return (-(WORD32)u4_abs_val);
146
3
    else
147
3
        return (u4_abs_val);
148
36
}
149
150
/*****************************************************************************/
151
/*                                                                           */
152
/*  Function Name : get_tev_range_1                                          */
153
/*                                                                           */
154
/*  Description   : Reads the TEV Exp Golomb codec syntax from the ps_bitstrm    */
155
/*                  as specified in section 9.1 of H264 standard. This will  */
156
/*                  called only when the input range is 1 for TEV decode.    */
157
/*                  If range is more than 1, then UEV decode is done         */
158
/*                                                                           */
159
/*  Inputs        : bitstream base pointer and bitsream u4_ofst in bits       */
160
/*  Globals       : None                                                     */
161
/*  Processing    :                                                          */
162
/*  Outputs       : TEV decoded syntax element and incremented ps_bitstrm u4_ofst */
163
/*  Returns       : TEV decoded syntax element                               */
164
/*                                                                           */
165
/*  Issues        : Does not check if ps_bitstrm u4_ofst exceeds max ps_bitstrm i4_size  */
166
/*                  for performamce. Caller might have to do error resilence */
167
/*                  check for bitstream overflow                             */
168
/*                                                                           */
169
/*  Revision History:                                                        */
170
/*                                                                           */
171
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
172
/*         19 09 2008   Jay          Draft                                   */
173
/*                                                                           */
174
/*****************************************************************************/
175
UWORD32 ih264d_tev_range1(UWORD32 *pu4_bitstrm_ofst, UWORD32 *pu4_bitstrm_buf)
176
0
{
177
0
    UWORD32 u4_code;
178
0
    GETBIT(u4_code, *pu4_bitstrm_ofst, pu4_bitstrm_buf);
179
0
    return (!u4_code);
180
0
}
181
182
/*!
183
 **************************************************************************
184
 * \if Function name : ih264d_uvlc \endif
185
 *
186
 * \brief
187
 *
188
 *    Reads the unsigned/signed/truncated integer Exp-Golomb-coded syntax element
189
 *    with the left bit first. The parsing process for this descriptor is specified
190
 *    in subclause 9.1.
191
 *
192
 * \param ps_bitstrm       : Pointer to Bitstream Structure .
193
 * \param u4_range           : Range value in case of Truncated Exp-Golomb-code
194
 * \param pi_bitstrm_ofst : Pointer to the local copy of Bitstream u4_ofst
195
 * \param u1_flag            : Flag indicating the case of UEV,SEV or TEV
196
 * \param u4_bitstrm_ofst : Local copy of Bitstream u4_ofst
197
 * \param pu4_bitstrm_buf : Pointer to the Bitstream buffer
198
 *
199
 * \return
200
 *    Returns Code Value.
201
 *
202
 **************************************************************************
203
 */
204
205
WORD32 ih264d_uvlc(dec_bit_stream_t *ps_bitstrm,
206
                   UWORD32 u4_range,
207
                   UWORD32 *pi_bitstrm_ofst,
208
                   UWORD8 u1_flag,
209
                   UWORD32 u4_bitstrm_ofst,
210
                   UWORD32 *pu4_bitstrm_buf)
211
0
{
212
0
    UWORD32 word, word2, cur_bit, cur_word, code_val, code_num, clz;
213
0
214
0
    SWITCHOFFTRACE;
215
0
    cur_bit = u4_bitstrm_ofst & 0x1F;
216
0
    cur_word = u4_bitstrm_ofst >> 5;
217
0
    word = pu4_bitstrm_buf[cur_word];
218
0
    word2 = pu4_bitstrm_buf[cur_word + 1];
219
0
220
0
    if(cur_bit != 0)
221
0
    {
222
0
        word <<= cur_bit;
223
0
        word2 >>= (32 - cur_bit);
224
0
        word |= word2;
225
0
    }
226
0
227
0
    if(u1_flag == TEV && u4_range == 1)
228
0
    {
229
0
        word >>= 31;
230
0
        word = 1 - word;
231
0
        (*pi_bitstrm_ofst)++;
232
0
        ps_bitstrm->u4_ofst = *pi_bitstrm_ofst;
233
0
        return (WORD32)word;
234
0
    }
235
0
236
0
    //finding clz
237
0
    {
238
0
        UWORD32 ui32_code, ui32_mask;
239
0
240
0
        ui32_code = word;
241
0
        ui32_mask = 0x80000000;
242
0
        clz = 0;
243
0
244
0
        /* DSP implements this with LMBD instruction */
245
0
        /* so there we don't need to break the loop */
246
0
        while(!(ui32_code & ui32_mask))
247
0
        {
248
0
            clz++;
249
0
            ui32_mask >>= 1;
250
0
            if(0 == ui32_mask)
251
0
                break;
252
0
        }
253
0
    }
254
0
255
0
    if(clz == 0)
256
0
    {
257
0
        *pi_bitstrm_ofst = *pi_bitstrm_ofst + (2 * clz) + 1;
258
0
        ps_bitstrm->u4_ofst = *pi_bitstrm_ofst;
259
0
        return 0;
260
0
    }
261
0
262
0
    word <<= (clz + 1);
263
0
    word >>= (32 - clz);
264
0
    code_num = (1 << clz) + word - 1;
265
0
    *pi_bitstrm_ofst = *pi_bitstrm_ofst + (2 * clz) + 1;
266
0
    ps_bitstrm->u4_ofst = *pi_bitstrm_ofst;
267
0
268
0
    if(u1_flag == TEV || u1_flag == UEV)
269
0
        return (WORD32)code_num;
270
0
271
0
    code_val = (code_num + 1) >> 1;
272
0
    if(!(code_num & 0x01))
273
0
        return -((WORD32)code_val);
274
0
    return (WORD32)code_val;
275
0
276
0
}
277
278
/*****************************************************************************/
279
/*                                                                           */
280
/*  Function Name : ih264d_cavlc_4x4res_block_totalcoeff_1                          */
281
/*                                                                           */
282
/*  Description   : This function does cavlc decoding of 4x4 block residual  */
283
/*                  coefficient when total coeff is equal to 1. The parsing  */
284
/*                  is done as defined in section 9.2.2 and 9.2.3 of the     */
285
/*                  H264 standard.                                           */
286
/*                                                                           */
287
/*  Inputs        : <What inputs does the function take?>                    */
288
/*  Globals       : <Does it use any global variables?>                      */
289
/*  Processing    : <Describe how the function operates - include algorithm  */
290
/*                  description>                                             */
291
/*  Outputs       : <What does the function produce?>                        */
292
/*  Returns       : <What does the function return?>                         */
293
/*                                                                           */
294
/*  Issues        : <List any issues or problems with this function>         */
295
/*                                                                           */
296
/*  Revision History:                                                        */
297
/*                                                                           */
298
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
299
/*         25 09 2008   Jay          Draft                                   */
300
/*                                                                           */
301
/*****************************************************************************/
302
WORD32 ih264d_cavlc_4x4res_block_totalcoeff_1(UWORD32 u4_isdc,
303
                                           UWORD32 u4_total_coeff_trail_one,
304
                                           dec_bit_stream_t *ps_bitstrm)
305
1.11k
{
306
1.11k
307
1.11k
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
308
1.11k
    UWORD32 u4_bitstream_offset = ps_bitstrm->u4_ofst;
309
1.11k
    UWORD32 u4_trailing_ones = u4_total_coeff_trail_one & 0xFFFF;
310
1.11k
    WORD32 i2_level;
311
1.11k
    UWORD32 u4_tot_zero, u4_ldz, u4_scan_pos;
312
1.11k
313
1.11k
    tu_sblk4x4_coeff_data_t *ps_tu_4x4;
314
1.11k
    WORD16 *pi2_coeff_data;
315
1.11k
    dec_struct_t *ps_dec = (dec_struct_t *)ps_bitstrm->pv_codec_handle;
316
1.11k
317
1.11k
    ps_tu_4x4 = (tu_sblk4x4_coeff_data_t *)ps_dec->pv_parse_tu_coeff_data;
318
1.11k
    ps_tu_4x4->u2_sig_coeff_map = 0;
319
1.11k
    pi2_coeff_data = &ps_tu_4x4->ai2_level[0];
320
1.11k
321
1.11k
322
1.11k
    if(u4_trailing_ones)
323
814
    {
324
814
        UWORD32 u4_sign;
325
814
        /****************************************************************/
326
814
        /* Decode Trailing One as in section 9.2.2                      */
327
814
        /****************************************************************/
328
814
        GETBIT(u4_sign, u4_bitstream_offset, pu4_bitstrm_buf);
329
814
        i2_level = u4_sign ? -1 : 1;
330
814
    }
331
297
    else
332
297
    {
333
297
        /****************************************************************/
334
297
        /* Decoding Level based on prefix and suffix  as in 9.2.2       */
335
297
        /****************************************************************/
336
297
        UWORD32 u4_lev_suffix, u4_lev_suffix_size;
337
297
        WORD32 u2_lev_code, u2_abs_value;
338
297
        UWORD32 u4_lev_prefix;
339
297
        /***************************************************************/
340
297
        /* Find leading zeros in next 32 bits                          */
341
297
        /***************************************************************/
342
297
        FIND_ONE_IN_STREAM_32(u4_lev_prefix, u4_bitstream_offset,
343
297
                              pu4_bitstrm_buf);
344
297
        u2_lev_code = (2 + MIN(u4_lev_prefix, 15));
345
297
346
297
        if(14 == u4_lev_prefix)
347
0
            u4_lev_suffix_size = 4;
348
297
        else if(15 <= u4_lev_prefix)
349
11
        {
350
11
            u2_lev_code += 15;
351
11
            u4_lev_suffix_size = u4_lev_prefix - 3;
352
11
        }
353
286
        else
354
286
            u4_lev_suffix_size = 0;
355
297
356
297
        //HP_LEVEL_PREFIX
357
297
        if(16 <= u4_lev_prefix)
358
0
        {
359
0
            u2_lev_code += ((1 << (u4_lev_prefix - 3)) - 4096);
360
0
        }
361
297
        if(u4_lev_suffix_size)
362
11
        {
363
11
            GETBITS(u4_lev_suffix, u4_bitstream_offset, pu4_bitstrm_buf,
364
11
                    u4_lev_suffix_size);
365
11
            u2_lev_code += u4_lev_suffix;
366
11
        }
367
297
368
297
        u2_abs_value = (u2_lev_code + 2) >> 1;
369
297
        /*********************************************************/
370
297
        /* If Level code is odd, level is negative else positive */
371
297
        /*********************************************************/
372
297
        i2_level = (u2_lev_code & 1) ? -u2_abs_value : u2_abs_value;
373
297
374
297
    }
375
1.11k
376
1.11k
    /****************************************************************/
377
1.11k
    /* Decoding total zeros as in section 9.2.3, table 9.7          */
378
1.11k
    /****************************************************************/
379
1.11k
    FIND_ONE_IN_STREAM_LEN(u4_ldz, u4_bitstream_offset, pu4_bitstrm_buf, 8);
380
1.11k
381
1.11k
    if(u4_ldz)
382
638
    {
383
638
        GETBIT(u4_tot_zero, u4_bitstream_offset, pu4_bitstrm_buf);
384
638
        u4_tot_zero = (u4_ldz << 1) - u4_tot_zero;
385
638
    }
386
473
    else
387
473
        u4_tot_zero = 0;
388
1.11k
389
1.11k
    /***********************************************************************/
390
1.11k
    /* Inverse scan and store  residual coeff. Update the bitstream u4_ofst */
391
1.11k
    /***********************************************************************/
392
1.11k
    u4_scan_pos = u4_tot_zero + u4_isdc;
393
1.11k
    if(u4_scan_pos > 15)
394
0
        return -1;
395
1.11k
396
1.11k
    SET_BIT(ps_tu_4x4->u2_sig_coeff_map, u4_scan_pos);
397
1.11k
    *pi2_coeff_data++ = i2_level;
398
1.11k
399
1.11k
400
1.11k
    {
401
1.11k
        WORD32 offset;
402
1.11k
        offset = (UWORD8 *)pi2_coeff_data - (UWORD8 *)ps_tu_4x4;
403
1.11k
        offset = ALIGN4(offset);
404
1.11k
        ps_dec->pv_parse_tu_coeff_data = (void *)((UWORD8 *)ps_dec->pv_parse_tu_coeff_data + offset);
405
1.11k
    }
406
1.11k
407
1.11k
    ps_bitstrm->u4_ofst = u4_bitstream_offset;
408
1.11k
    return 0;
409
1.11k
}
410
411
/*****************************************************************************/
412
/*                                                                           */
413
/*  Function Name : ih264d_cavlc_4x4res_block_totalcoeff_2to10                      */
414
/*                                                                           */
415
/*  Description   : This function does cavlc decoding of 4x4 block residual  */
416
/*                  coefficient when total coeffs are between two and ten    */
417
/*                  inclusive. Parsing is done as defined in section 9.2.2   */
418
/*                  and 9.2.3 the H264 standard.                             */
419
/*                                                                           */
420
/*  Inputs        : <What inputs does the function take?>                    */
421
/*  Globals       : <Does it use any global variables?>                      */
422
/*  Processing    : <Describe how the function operates - include algorithm  */
423
/*                  description>                                             */
424
/*  Outputs       : <What does the function produce?>                        */
425
/*  Returns       : <What does the function return?>                         */
426
/*                                                                           */
427
/*  Issues        : <List any issues or problems with this function>         */
428
/*                                                                           */
429
/*  Revision History:                                                        */
430
/*                                                                           */
431
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
432
/*         25 09 2008   Jay          Draft                                   */
433
/*                                                                           */
434
/*****************************************************************************/
435
436
WORD32 ih264d_cavlc_4x4res_block_totalcoeff_2to10(UWORD32 u4_isdc,
437
                                               UWORD32 u4_total_coeff_trail_one, /*!<TotalCoefficients<<16+trailingones*/
438
                                               dec_bit_stream_t *ps_bitstrm)
439
12.3k
{
440
12.3k
    UWORD32 u4_total_zeroes;
441
12.3k
    WORD32 i;
442
12.3k
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
443
12.3k
    UWORD32 u4_bitstream_offset = ps_bitstrm->u4_ofst;
444
12.3k
    UWORD32 u4_trailing_ones = u4_total_coeff_trail_one & 0xFFFF;
445
12.3k
    UWORD32 u4_total_coeff = u4_total_coeff_trail_one >> 16;
446
12.3k
    // To avoid error check at 4x4 level, allocating for 3 extra levels(16+3)
447
12.3k
    // since u4_trailing_ones can at the max be 3. This will be required when
448
12.3k
    // u4_total_coeff is less than u4_trailing_ones
449
12.3k
    WORD16 ai2_level_arr[19];
450
12.3k
    WORD16 *i2_level_arr = &ai2_level_arr[3];
451
12.3k
452
12.3k
    tu_sblk4x4_coeff_data_t *ps_tu_4x4;
453
12.3k
    WORD16 *pi2_coeff_data;
454
12.3k
    dec_struct_t *ps_dec = (dec_struct_t *)ps_bitstrm->pv_codec_handle;
455
12.3k
456
12.3k
    ps_tu_4x4 = (tu_sblk4x4_coeff_data_t *)ps_dec->pv_parse_tu_coeff_data;
457
12.3k
    ps_tu_4x4->u2_sig_coeff_map = 0;
458
12.3k
    pi2_coeff_data = &ps_tu_4x4->ai2_level[0];
459
12.3k
460
12.3k
    i = u4_total_coeff - 1;
461
12.3k
462
12.3k
    if(u4_trailing_ones)
463
11.0k
    {
464
11.0k
        /*********************************************************************/
465
11.0k
        /* Decode Trailing Ones                                              */
466
11.0k
        /* read the sign of T1's and put them in level array                 */
467
11.0k
        /*********************************************************************/
468
11.0k
        UWORD32 u4_signs, u4_cnt = u4_trailing_ones;
469
11.0k
        WORD16 (*ppi2_trlone_lkup)[3] =
470
11.0k
                        (WORD16 (*)[3])gai2_ih264d_trailing_one_level;
471
11.0k
        WORD16 *pi2_trlone_lkup;
472
11.0k
473
11.0k
        GETBITS(u4_signs, u4_bitstream_offset, pu4_bitstrm_buf, u4_cnt);
474
11.0k
475
11.0k
        pi2_trlone_lkup = ppi2_trlone_lkup[(1 << u4_cnt) - 2 + u4_signs];
476
11.0k
477
36.7k
        while(u4_cnt--)
478
25.6k
            i2_level_arr[i--] = *pi2_trlone_lkup++;
479
11.0k
    }
480
12.3k
481
12.3k
    /****************************************************************/
482
12.3k
    /* Decoding Levels Begins                                       */
483
12.3k
    /****************************************************************/
484
12.3k
    if(i >= 0)
485
8.63k
    {
486
8.63k
        /****************************************************************/
487
8.63k
        /* First level is decoded outside the loop as it has lot of     */
488
8.63k
        /* special cases.                                               */
489
8.63k
        /****************************************************************/
490
8.63k
        UWORD32 u4_lev_suffix, u4_suffix_len, u4_lev_suffix_size;
491
8.63k
        WORD32 u2_lev_code, u2_abs_value;
492
8.63k
        UWORD32 u4_lev_prefix;
493
8.63k
494
8.63k
        /***************************************************************/
495
8.63k
        /* u4_suffix_len = 0,  Find leading zeros in next 32 bits      */
496
8.63k
        /***************************************************************/
497
8.63k
        FIND_ONE_IN_STREAM_32(u4_lev_prefix, u4_bitstream_offset,
498
8.63k
                              pu4_bitstrm_buf);
499
8.63k
500
8.63k
        /*********************************************************/
501
8.63k
        /* Special decoding case when trailing ones are 3        */
502
8.63k
        /*********************************************************/
503
8.63k
        u2_lev_code = MIN(15, u4_lev_prefix);
504
8.63k
505
8.63k
        u2_lev_code += (3 == u4_trailing_ones) ? 0 : 2;
506
8.63k
507
8.63k
        if(14 == u4_lev_prefix)
508
55
            u4_lev_suffix_size = 4;
509
8.58k
        else if(15 <= u4_lev_prefix)
510
88
        {
511
88
            u2_lev_code += 15;
512
88
            u4_lev_suffix_size = u4_lev_prefix - 3;
513
88
        }
514
8.49k
        else
515
8.49k
            u4_lev_suffix_size = 0;
516
8.63k
517
8.63k
        //HP_LEVEL_PREFIX
518
8.63k
        if(16 <= u4_lev_prefix)
519
0
        {
520
0
            u2_lev_code += ((1 << (u4_lev_prefix - 3)) - 4096);
521
0
        }
522
8.63k
        if(u4_lev_suffix_size)
523
143
        {
524
143
            GETBITS(u4_lev_suffix, u4_bitstream_offset, pu4_bitstrm_buf,
525
143
                    u4_lev_suffix_size);
526
143
            u2_lev_code += u4_lev_suffix;
527
143
        }
528
8.63k
529
8.63k
        u2_abs_value = (u2_lev_code + 2) >> 1;
530
8.63k
        /*********************************************************/
531
8.63k
        /* If Level code is odd, level is negative else positive */
532
8.63k
        /*********************************************************/
533
8.63k
        i2_level_arr[i--] = (u2_lev_code & 1) ? -u2_abs_value : u2_abs_value;
534
8.63k
535
8.63k
        u4_suffix_len = (u2_abs_value > 3) ? 2 : 1;
536
8.63k
537
8.63k
        /*********************************************************/
538
8.63k
        /* Now loop over the remaining levels                    */
539
8.63k
        /*********************************************************/
540
28.0k
        while(i >= 0)
541
19.4k
        {
542
19.4k
543
19.4k
            /***************************************************************/
544
19.4k
            /* Find leading zeros in next 32 bits                          */
545
19.4k
            /***************************************************************/
546
19.4k
            FIND_ONE_IN_STREAM_32(u4_lev_prefix, u4_bitstream_offset,
547
19.4k
                                  pu4_bitstrm_buf);
548
19.4k
549
19.4k
            u4_lev_suffix_size =
550
19.4k
                            (15 <= u4_lev_prefix) ?
551
19.2k
                                            (u4_lev_prefix - 3) : u4_suffix_len;
552
19.4k
553
19.4k
            /*********************************************************/
554
19.4k
            /* Compute level code using prefix and suffix            */
555
19.4k
            /*********************************************************/
556
19.4k
            GETBITS(u4_lev_suffix, u4_bitstream_offset, pu4_bitstrm_buf,
557
19.4k
                    u4_lev_suffix_size);
558
19.4k
            u2_lev_code = (MIN(15,u4_lev_prefix) << u4_suffix_len)
559
19.4k
                            + u4_lev_suffix;
560
19.4k
561
19.4k
            //HP_LEVEL_PREFIX
562
19.4k
            if(16 <= u4_lev_prefix)
563
0
            {
564
0
                u2_lev_code += ((1 << (u4_lev_prefix - 3)) - 4096);
565
0
            }
566
19.4k
            u2_abs_value = (u2_lev_code + 2) >> 1;
567
19.4k
568
19.4k
            /*********************************************************/
569
19.4k
            /* If Level code is odd, level is negative else positive */
570
19.4k
            /*********************************************************/
571
19.4k
            i2_level_arr[i--] =
572
19.4k
                            (u2_lev_code & 1) ? -u2_abs_value : u2_abs_value;
573
19.4k
574
19.4k
            /*********************************************************/
575
19.4k
            /* Increment suffix length if required                   */
576
19.4k
            /*********************************************************/
577
19.4k
            u4_suffix_len +=
578
19.4k
                            (u4_suffix_len < 6) ?
579
19.4k
                                            (u2_abs_value
580
19.4k
                                                            > (3
581
19.4k
                                                                            << (u4_suffix_len
582
19.4k
                                                                                            - 1))) :
583
19.4k
                                            0;
584
19.4k
        }
585
8.63k
586
8.63k
        /****************************************************************/
587
8.63k
        /* Decoding Levels Ends                                         */
588
8.63k
        /****************************************************************/
589
8.63k
    }
590
12.3k
591
12.3k
    /****************************************************************/
592
12.3k
    /* Decoding total zeros as in section 9.2.3, table 9.7          */
593
12.3k
    /****************************************************************/
594
12.3k
    {
595
12.3k
        UWORD32 u4_index;
596
12.3k
        const UWORD8 (*ppu1_total_zero_lkup)[64] =
597
12.3k
                        (const UWORD8 (*)[64])gau1_ih264d_table_total_zero_2to10;
598
12.3k
599
12.3k
        NEXTBITS(u4_index, u4_bitstream_offset, pu4_bitstrm_buf, 6);
600
12.3k
        u4_total_zeroes = ppu1_total_zero_lkup[u4_total_coeff - 2][u4_index];
601
12.3k
602
12.3k
        FLUSHBITS(u4_bitstream_offset, (u4_total_zeroes >> 4));
603
12.3k
        u4_total_zeroes &= 0xf;
604
12.3k
    }
605
12.3k
606
12.3k
    /**************************************************************/
607
12.3k
    /* Decode the runs and form the coefficient buffer            */
608
12.3k
    /**************************************************************/
609
12.3k
    {
610
12.3k
        const UWORD8 *pu1_table_runbefore;
611
12.3k
        UWORD32 u4_run;
612
12.3k
        WORD32 k;
613
12.3k
        UWORD32 u4_scan_pos = u4_total_coeff + u4_total_zeroes - 1 + u4_isdc;
614
12.3k
        WORD32 u4_zeroes_left = u4_total_zeroes;
615
12.3k
        k = u4_total_coeff - 1;
616
12.3k
617
12.3k
        /**************************************************************/
618
12.3k
        /* Decoding Runs Begin for zeros left > 6                     */
619
12.3k
        /**************************************************************/
620
14.7k
        while((u4_zeroes_left > 6) && k)
621
2.42k
        {
622
2.42k
            UWORD32 u4_code;
623
2.42k
624
2.42k
            NEXTBITS(u4_code, u4_bitstream_offset, pu4_bitstrm_buf, 3);
625
2.42k
626
2.42k
            if(u4_code != 0)
627
2.05k
            {
628
2.05k
                FLUSHBITS(u4_bitstream_offset, 3);
629
2.05k
                u4_run = (7 - u4_code);
630
2.05k
            }
631
363
            else
632
363
            {
633
363
634
363
                FIND_ONE_IN_STREAM_LEN(u4_code, u4_bitstream_offset,
635
363
                                       pu4_bitstrm_buf, 11);
636
363
                u4_run = (4 + u4_code);
637
363
            }
638
2.42k
639
2.42k
            SET_BIT(ps_tu_4x4->u2_sig_coeff_map, u4_scan_pos);
640
2.42k
            *pi2_coeff_data++ = i2_level_arr[k--];
641
2.42k
            u4_zeroes_left -= u4_run;
642
2.42k
            u4_scan_pos -= (u4_run + 1);
643
2.42k
        }
644
12.3k
645
12.3k
        /**************************************************************/
646
12.3k
        /* Decoding Runs for 0 < zeros left <=6                       */
647
12.3k
        /**************************************************************/
648
12.3k
        pu1_table_runbefore = (UWORD8 *)gau1_ih264d_table_run_before;
649
40.3k
        while((u4_zeroes_left > 0) && k)
650
27.9k
        {
651
27.9k
            UWORD32 u4_code;
652
27.9k
            NEXTBITS(u4_code, u4_bitstream_offset, pu4_bitstrm_buf, 3);
653
27.9k
654
27.9k
            u4_code = pu1_table_runbefore[u4_code + (u4_zeroes_left << 3)];
655
27.9k
            u4_run = u4_code >> 2;
656
27.9k
657
27.9k
            FLUSHBITS(u4_bitstream_offset, (u4_code & 0x03));
658
27.9k
659
27.9k
            SET_BIT(ps_tu_4x4->u2_sig_coeff_map, u4_scan_pos);
660
27.9k
            *pi2_coeff_data++ = i2_level_arr[k--];
661
27.9k
            u4_zeroes_left -= u4_run;
662
27.9k
            u4_scan_pos -= (u4_run + 1);
663
27.9k
        }
664
12.3k
        /**************************************************************/
665
12.3k
        /* Decoding Runs End                                          */
666
12.3k
        /**************************************************************/
667
12.3k
668
12.3k
        /**************************************************************/
669
12.3k
        /* Copy the remaining coefficients                            */
670
12.3k
        /**************************************************************/
671
12.3k
        if(u4_zeroes_left < 0)
672
0
            return -1;
673
35.8k
        while(k >= 0)
674
23.4k
        {
675
23.4k
676
23.4k
            SET_BIT(ps_tu_4x4->u2_sig_coeff_map, u4_scan_pos);
677
23.4k
            *pi2_coeff_data++ = i2_level_arr[k--];
678
23.4k
            u4_scan_pos--;
679
23.4k
        }
680
12.3k
    }
681
12.3k
682
12.3k
    {
683
12.3k
        WORD32 offset;
684
12.3k
        offset = (UWORD8 *)pi2_coeff_data - (UWORD8 *)ps_tu_4x4;
685
12.3k
        offset = ALIGN4(offset);
686
12.3k
        ps_dec->pv_parse_tu_coeff_data = (void *)((UWORD8 *)ps_dec->pv_parse_tu_coeff_data + offset);
687
12.3k
    }
688
12.3k
689
12.3k
    ps_bitstrm->u4_ofst = u4_bitstream_offset;
690
12.3k
    return 0;
691
12.3k
}
692
693
/*****************************************************************************/
694
/*                                                                           */
695
/*  Function Name : ih264d_cavlc_4x4res_block_totalcoeff_11to16                     */
696
/*                                                                           */
697
/*  Description   : This function does cavlc decoding of 4x4 block residual  */
698
/*                  coefficient when total coeffs are greater than ten.      */
699
/*                  Parsing is done as defined in section 9.2.2 and 9.2.3 of */
700
/*                  the H264 standard.                                       */
701
/*                                                                           */
702
/*  Inputs        : <What inputs does the function take?>                    */
703
/*  Globals       : <Does it use any global variables?>                      */
704
/*  Processing    : <Describe how the function operates - include algorithm  */
705
/*                  description>                                             */
706
/*  Outputs       : <What does the function produce?>                        */
707
/*  Returns       : <What does the function return?>                         */
708
/*                                                                           */
709
/*  Issues        : <List any issues or problems with this function>         */
710
/*                                                                           */
711
/*  Revision History:                                                        */
712
/*                                                                           */
713
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
714
/*         25 09 2008   Jay          Draft                                   */
715
/*                                                                           */
716
/*****************************************************************************/
717
718
WORD32 ih264d_cavlc_4x4res_block_totalcoeff_11to16(UWORD32 u4_isdc,
719
                                                UWORD32 u4_total_coeff_trail_one, /*!<TotalCoefficients<<16+trailingones*/
720
                                                dec_bit_stream_t *ps_bitstrm )
721
10.5k
{
722
10.5k
    UWORD32 u4_total_zeroes;
723
10.5k
    WORD32 i;
724
10.5k
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
725
10.5k
    UWORD32 u4_bitstream_offset = ps_bitstrm->u4_ofst;
726
10.5k
    UWORD32 u4_trailing_ones = u4_total_coeff_trail_one & 0xFFFF;
727
10.5k
    UWORD32 u4_total_coeff = u4_total_coeff_trail_one >> 16;
728
10.5k
    // To avoid error check at 4x4 level, allocating for 3 extra levels(16+3)
729
10.5k
    // since u4_trailing_ones can at the max be 3. This will be required when
730
10.5k
    // u4_total_coeff is less than u4_trailing_ones
731
10.5k
    WORD16 ai2_level_arr[19];//
732
10.5k
    WORD16 *i2_level_arr = &ai2_level_arr[3];
733
10.5k
734
10.5k
    tu_sblk4x4_coeff_data_t *ps_tu_4x4;
735
10.5k
    WORD16 *pi2_coeff_data;
736
10.5k
    dec_struct_t *ps_dec = (dec_struct_t *)ps_bitstrm->pv_codec_handle;
737
10.5k
738
10.5k
    ps_tu_4x4 = (tu_sblk4x4_coeff_data_t *)ps_dec->pv_parse_tu_coeff_data;
739
10.5k
    ps_tu_4x4->u2_sig_coeff_map = 0;
740
10.5k
    pi2_coeff_data = &ps_tu_4x4->ai2_level[0];
741
10.5k
742
10.5k
    i = u4_total_coeff - 1;
743
10.5k
    if(u4_trailing_ones)
744
3.10k
    {
745
3.10k
        /*********************************************************************/
746
3.10k
        /* Decode Trailing Ones                                              */
747
3.10k
        /* read the sign of T1's and put them in level array                 */
748
3.10k
        /*********************************************************************/
749
3.10k
        UWORD32 u4_signs, u4_cnt = u4_trailing_ones;
750
3.10k
        WORD16 (*ppi2_trlone_lkup)[3] =
751
3.10k
                        (WORD16 (*)[3])gai2_ih264d_trailing_one_level;
752
3.10k
        WORD16 *pi2_trlone_lkup;
753
3.10k
754
3.10k
        GETBITS(u4_signs, u4_bitstream_offset, pu4_bitstrm_buf, u4_cnt);
755
3.10k
756
3.10k
        pi2_trlone_lkup = ppi2_trlone_lkup[(1 << u4_cnt) - 2 + u4_signs];
757
3.10k
758
8.19k
        while(u4_cnt--)
759
5.09k
            i2_level_arr[i--] = *pi2_trlone_lkup++;
760
3.10k
    }
761
10.5k
762
10.5k
    /****************************************************************/
763
10.5k
    /* Decoding Levels Begins                                       */
764
10.5k
    /****************************************************************/
765
10.5k
    if(i >= 0)
766
10.5k
    {
767
10.5k
        /****************************************************************/
768
10.5k
        /* First level is decoded outside the loop as it has lot of     */
769
10.5k
        /* special cases.                                               */
770
10.5k
        /****************************************************************/
771
10.5k
        UWORD32 u4_lev_suffix, u4_suffix_len, u4_lev_suffix_size;
772
10.5k
        UWORD16 u2_lev_code, u2_abs_value;
773
10.5k
        UWORD32 u4_lev_prefix;
774
10.5k
775
10.5k
        if(u4_trailing_ones < 3)
776
9.79k
        {
777
9.79k
            /*********************************************************/
778
9.79k
            /* u4_suffix_len = 1                                     */
779
9.79k
            /*********************************************************/
780
9.79k
            /***************************************************************/
781
9.79k
            /* Find leading zeros in next 32 bits                          */
782
9.79k
            /***************************************************************/
783
9.79k
            FIND_ONE_IN_STREAM_32(u4_lev_prefix, u4_bitstream_offset,
784
9.79k
                                  pu4_bitstrm_buf);
785
9.79k
786
9.79k
            u4_lev_suffix_size =
787
9.79k
                            (15 <= u4_lev_prefix) ? (u4_lev_prefix - 3) : 1;
788
9.79k
789
9.79k
            GETBITS(u4_lev_suffix, u4_bitstream_offset, pu4_bitstrm_buf,
790
9.79k
                    u4_lev_suffix_size);
791
9.79k
            u2_lev_code = 2 + (MIN(u4_lev_prefix,15) << 1) + u4_lev_suffix;
792
9.79k
793
9.79k
            //HP_LEVEL_PREFIX
794
9.79k
            if(16 <= u4_lev_prefix)
795
0
            {
796
0
                u2_lev_code += ((1 << (u4_lev_prefix - 3)) - 4096);
797
0
            }
798
9.79k
        }
799
748
        else
800
748
        {
801
748
            /*********************************************************/
802
748
            /*u4_suffix_len = 0                                      */
803
748
            /*********************************************************/
804
748
            /***************************************************************/
805
748
            /* Find leading zeros in next 32 bits                          */
806
748
            /***************************************************************/
807
748
            FIND_ONE_IN_STREAM_32(u4_lev_prefix, u4_bitstream_offset,
808
748
                                  pu4_bitstrm_buf);
809
748
810
748
            /*********************************************************/
811
748
            /* Special decoding case when trailing ones are 3        */
812
748
            /*********************************************************/
813
748
            u2_lev_code = MIN(15, u4_lev_prefix);
814
748
815
748
            u2_lev_code += (3 == u4_trailing_ones) ? 0 : (2);
816
748
817
748
            if(14 == u4_lev_prefix)
818
22
                u4_lev_suffix_size = 4;
819
726
            else if(15 <= u4_lev_prefix)
820
0
            {
821
0
                u2_lev_code += 15;
822
0
                u4_lev_suffix_size = (u4_lev_prefix - 3);
823
0
            }
824
726
            else
825
726
                u4_lev_suffix_size = 0;
826
748
827
748
            //HP_LEVEL_PREFIX
828
748
            if(16 <= u4_lev_prefix)
829
0
            {
830
0
                u2_lev_code += ((1 << (u4_lev_prefix - 3)) - 4096);
831
0
            }
832
748
            if(u4_lev_suffix_size)
833
22
            {
834
22
                GETBITS(u4_lev_suffix, u4_bitstream_offset, pu4_bitstrm_buf,
835
22
                        u4_lev_suffix_size);
836
22
                u2_lev_code += u4_lev_suffix;
837
22
            }
838
748
        }
839
10.5k
840
10.5k
        u2_abs_value = (u2_lev_code + 2) >> 1;
841
10.5k
        /*********************************************************/
842
10.5k
        /* If Level code is odd, level is negative else positive */
843
10.5k
        /*********************************************************/
844
10.5k
        i2_level_arr[i--] = (u2_lev_code & 1) ? -u2_abs_value : u2_abs_value;
845
10.5k
846
10.5k
        u4_suffix_len = (u2_abs_value > 3) ? 2 : 1;
847
10.5k
848
10.5k
        /*********************************************************/
849
10.5k
        /* Now loop over the remaining levels                    */
850
10.5k
        /*********************************************************/
851
152k
        while(i >= 0)
852
141k
        {
853
141k
854
141k
            /***************************************************************/
855
141k
            /* Find leading zeros in next 32 bits                          */
856
141k
            /***************************************************************/
857
141k
            FIND_ONE_IN_STREAM_32(u4_lev_prefix, u4_bitstream_offset,
858
141k
                                  pu4_bitstrm_buf);
859
141k
860
141k
            u4_lev_suffix_size =
861
141k
                            (15 <= u4_lev_prefix) ?
862
140k
                                            (u4_lev_prefix - 3) : u4_suffix_len;
863
141k
864
141k
            /*********************************************************/
865
141k
            /* Compute level code using prefix and suffix            */
866
141k
            /*********************************************************/
867
141k
            GETBITS(u4_lev_suffix, u4_bitstream_offset, pu4_bitstrm_buf,
868
141k
                    u4_lev_suffix_size);
869
141k
            u2_lev_code = (MIN(15,u4_lev_prefix) << u4_suffix_len)
870
141k
                            + u4_lev_suffix;
871
141k
872
141k
            //HP_LEVEL_PREFIX
873
141k
            if(16 <= u4_lev_prefix)
874
0
            {
875
0
                u2_lev_code += ((1 << (u4_lev_prefix - 3)) - 4096);
876
0
            }
877
141k
            u2_abs_value = (u2_lev_code + 2) >> 1;
878
141k
879
141k
            /*********************************************************/
880
141k
            /* If Level code is odd, level is negative else positive */
881
141k
            /*********************************************************/
882
141k
            i2_level_arr[i--] =
883
141k
                            (u2_lev_code & 1) ? -u2_abs_value : u2_abs_value;
884
141k
885
141k
            /*********************************************************/
886
141k
            /* Increment suffix length if required                   */
887
141k
            /*********************************************************/
888
141k
            u4_suffix_len +=
889
141k
                            (u4_suffix_len < 6) ?
890
126k
                                            (u2_abs_value
891
126k
                                                            > (3
892
126k
                                                                            << (u4_suffix_len
893
126k
                                                                                            - 1))) :
894
141k
                                            0;
895
141k
        }
896
10.5k
897
10.5k
        /****************************************************************/
898
10.5k
        /* Decoding Levels Ends                                         */
899
10.5k
        /****************************************************************/
900
10.5k
    }
901
10.5k
902
10.5k
    if(u4_total_coeff < (16 - u4_isdc))
903
5.20k
    {
904
5.20k
        UWORD32 u4_index;
905
5.20k
        const UWORD8 (*ppu1_total_zero_lkup)[16] =
906
5.20k
                        (const UWORD8 (*)[16])gau1_ih264d_table_total_zero_11to15;
907
5.20k
908
5.20k
        NEXTBITS(u4_index, u4_bitstream_offset, pu4_bitstrm_buf, 4);
909
5.20k
        u4_total_zeroes = ppu1_total_zero_lkup[u4_total_coeff - 11][u4_index];
910
5.20k
911
5.20k
        FLUSHBITS(u4_bitstream_offset, (u4_total_zeroes >> 4));
912
5.20k
        u4_total_zeroes &= 0xf;
913
5.20k
    }
914
5.33k
    else
915
5.33k
        u4_total_zeroes = 0;
916
10.5k
917
10.5k
    /**************************************************************/
918
10.5k
    /* Decode the runs and form the coefficient buffer            */
919
10.5k
    /**************************************************************/
920
10.5k
    {
921
10.5k
        const UWORD8 *pu1_table_runbefore;
922
10.5k
        UWORD32 u4_run;
923
10.5k
        WORD32 k;
924
10.5k
        UWORD32 u4_scan_pos = u4_total_coeff + u4_total_zeroes - 1 + u4_isdc;
925
10.5k
        WORD32 u4_zeroes_left = u4_total_zeroes;
926
10.5k
        k = u4_total_coeff - 1;
927
10.5k
928
10.5k
        /**************************************************************/
929
10.5k
        /* Decoding Runs for 0 < zeros left <=6                       */
930
10.5k
        /**************************************************************/
931
10.5k
        pu1_table_runbefore = (UWORD8 *)gau1_ih264d_table_run_before;
932
39.8k
        while((u4_zeroes_left > 0) && k)
933
29.3k
        {
934
29.3k
            UWORD32 u4_code;
935
29.3k
            NEXTBITS(u4_code, u4_bitstream_offset, pu4_bitstrm_buf, 3);
936
29.3k
937
29.3k
            u4_code = pu1_table_runbefore[u4_code + (u4_zeroes_left << 3)];
938
29.3k
            u4_run = u4_code >> 2;
939
29.3k
940
29.3k
            FLUSHBITS(u4_bitstream_offset, (u4_code & 0x03));
941
29.3k
            SET_BIT(ps_tu_4x4->u2_sig_coeff_map, u4_scan_pos);
942
29.3k
            *pi2_coeff_data++ = i2_level_arr[k--];
943
29.3k
            u4_zeroes_left -= u4_run;
944
29.3k
            u4_scan_pos -= (u4_run + 1);
945
29.3k
        }
946
10.5k
        /**************************************************************/
947
10.5k
        /* Decoding Runs End                                          */
948
10.5k
        /**************************************************************/
949
10.5k
950
10.5k
        /**************************************************************/
951
10.5k
        /* Copy the remaining coefficients                            */
952
10.5k
        /**************************************************************/
953
10.5k
        if(u4_zeroes_left < 0)
954
0
            return -1;
955
138k
        while(k >= 0)
956
127k
        {
957
127k
            SET_BIT(ps_tu_4x4->u2_sig_coeff_map, u4_scan_pos);
958
127k
            *pi2_coeff_data++ = i2_level_arr[k--];
959
127k
            u4_scan_pos--;
960
127k
        }
961
10.5k
    }
962
10.5k
963
10.5k
    {
964
10.5k
        WORD32 offset;
965
10.5k
        offset = (UWORD8 *)pi2_coeff_data - (UWORD8 *)ps_tu_4x4;
966
10.5k
        offset = ALIGN4(offset);
967
10.5k
        ps_dec->pv_parse_tu_coeff_data = (void *)((UWORD8 *)ps_dec->pv_parse_tu_coeff_data + offset);
968
10.5k
    }
969
10.5k
970
10.5k
    ps_bitstrm->u4_ofst = u4_bitstream_offset;
971
10.5k
    return 0;
972
10.5k
}
973
974
/*****************************************************************************/
975
/*                                                                           */
976
/*  Function Name : ih264d_rest_of_residual_cav_chroma_dc_block              */
977
/*                                                                           */
978
/*  Description   : This function does the Cavlc parsing of the bitstream    */
979
/*                  for chroma dc coefficients                               */
980
/*  Inputs        : <What inputs does the function take?>                    */
981
/*  Globals       : <Does it use any global variables?>                      */
982
/*  Processing    : <Describe how the function operates - include algorithm  */
983
/*                  description>                                             */
984
/*  Outputs       : <What does the function produce?>                        */
985
/*  Returns       : <What does the function return?>                         */
986
/*                                                                           */
987
/*  Issues        : <List any issues or problems with this function>         */
988
/*                                                                           */
989
/*  Revision History:                                                        */
990
/*                                                                           */
991
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
992
/*         15 09 2008   Jay          Draft                                   */
993
/*                                                                           */
994
/*****************************************************************************/
995
void ih264d_rest_of_residual_cav_chroma_dc_block(UWORD32 u4_total_coeff_trail_one,
996
                                                 dec_bit_stream_t *ps_bitstrm)
997
3.31k
{
998
3.31k
    UWORD32 u4_total_zeroes;
999
3.31k
    WORD16 i;
1000
3.31k
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
1001
3.31k
    UWORD32 u4_bitstream_offset = ps_bitstrm->u4_ofst;
1002
3.31k
    UWORD32 u4_trailing_ones = u4_total_coeff_trail_one & 0xFFFF;
1003
3.31k
    UWORD32 u4_total_coeff = u4_total_coeff_trail_one >> 16;
1004
3.31k
    // To avoid error check at 4x4 level, allocating for 3 extra levels(4+3)
1005
3.31k
    // since u4_trailing_ones can at the max be 3. This will be required when
1006
3.31k
    // u4_total_coeff is less than u4_trailing_ones
1007
3.31k
    WORD16 ai2_level_arr[7];//
1008
3.31k
    WORD16 *i2_level_arr = &ai2_level_arr[3];
1009
3.31k
1010
3.31k
    tu_sblk4x4_coeff_data_t *ps_tu_4x4;
1011
3.31k
    WORD16 *pi2_coeff_data;
1012
3.31k
    dec_struct_t *ps_dec = (dec_struct_t *)ps_bitstrm->pv_codec_handle;
1013
3.31k
1014
3.31k
    ps_tu_4x4 = (tu_sblk4x4_coeff_data_t *)ps_dec->pv_parse_tu_coeff_data;
1015
3.31k
    ps_tu_4x4->u2_sig_coeff_map = 0;
1016
3.31k
    pi2_coeff_data = &ps_tu_4x4->ai2_level[0];
1017
3.31k
1018
3.31k
    i = u4_total_coeff - 1;
1019
3.31k
    if(u4_trailing_ones)
1020
1.44k
    {
1021
1.44k
        /*********************************************************************/
1022
1.44k
        /* Decode Trailing Ones                                              */
1023
1.44k
        /* read the sign of T1's and put them in level array                 */
1024
1.44k
        /*********************************************************************/
1025
1.44k
        UWORD32 u4_signs, u4_cnt = u4_trailing_ones;
1026
1.44k
        WORD16 (*ppi2_trlone_lkup)[3] =
1027
1.44k
                        (WORD16 (*)[3])gai2_ih264d_trailing_one_level;
1028
1.44k
        WORD16 *pi2_trlone_lkup;
1029
1.44k
1030
1.44k
        GETBITS(u4_signs, u4_bitstream_offset, pu4_bitstrm_buf, u4_cnt);
1031
1.44k
1032
1.44k
        pi2_trlone_lkup = ppi2_trlone_lkup[(1 << u4_cnt) - 2 + u4_signs];
1033
1.44k
1034
4.35k
        while(u4_cnt--)
1035
2.91k
            i2_level_arr[i--] = *pi2_trlone_lkup++;
1036
1.44k
    }
1037
3.31k
1038
3.31k
    /****************************************************************/
1039
3.31k
    /* Decoding Levels Begins                                       */
1040
3.31k
    /****************************************************************/
1041
3.31k
    if(i >= 0)
1042
2.69k
    {
1043
2.69k
        /****************************************************************/
1044
2.69k
        /* First level is decoded outside the loop as it has lot of     */
1045
2.69k
        /* special cases.                                               */
1046
2.69k
        /****************************************************************/
1047
2.69k
        UWORD32 u4_lev_suffix, u4_suffix_len, u4_lev_suffix_size;
1048
2.69k
        UWORD16 u2_lev_code, u2_abs_value;
1049
2.69k
        UWORD32 u4_lev_prefix;
1050
2.69k
1051
2.69k
        /***************************************************************/
1052
2.69k
        /* u4_suffix_len = 0,  Find leading zeros in next 32 bits      */
1053
2.69k
        /***************************************************************/
1054
2.69k
        FIND_ONE_IN_STREAM_32(u4_lev_prefix, u4_bitstream_offset,
1055
2.69k
                              pu4_bitstrm_buf);
1056
2.69k
1057
2.69k
        /*********************************************************/
1058
2.69k
        /* Special decoding case when trailing ones are 3        */
1059
2.69k
        /*********************************************************/
1060
2.69k
        u2_lev_code = MIN(15, u4_lev_prefix);
1061
2.69k
1062
2.69k
        u2_lev_code += (3 == u4_trailing_ones) ? 0 : (2);
1063
2.69k
1064
2.69k
        if(14 == u4_lev_prefix)
1065
187
            u4_lev_suffix_size = 4;
1066
2.50k
        else if(15 <= u4_lev_prefix)
1067
44
        {
1068
44
            u2_lev_code += 15;
1069
44
            u4_lev_suffix_size = u4_lev_prefix - 3;
1070
44
        }
1071
2.46k
        else
1072
2.46k
            u4_lev_suffix_size = 0;
1073
2.69k
1074
2.69k
        //HP_LEVEL_PREFIX
1075
2.69k
        if(16 <= u4_lev_prefix)
1076
0
        {
1077
0
            u2_lev_code += ((1 << (u4_lev_prefix - 3)) - 4096);
1078
0
        }
1079
2.69k
        if(u4_lev_suffix_size)
1080
231
        {
1081
231
            GETBITS(u4_lev_suffix, u4_bitstream_offset, pu4_bitstrm_buf,
1082
231
                    u4_lev_suffix_size);
1083
231
            u2_lev_code += u4_lev_suffix;
1084
231
        }
1085
2.69k
1086
2.69k
        u2_abs_value = (u2_lev_code + 2) >> 1;
1087
2.69k
        /*********************************************************/
1088
2.69k
        /* If Level code is odd, level is negative else positive */
1089
2.69k
        /*********************************************************/
1090
2.69k
        i2_level_arr[i--] = (u2_lev_code & 1) ? -u2_abs_value : u2_abs_value;
1091
2.69k
1092
2.69k
        u4_suffix_len = (u2_abs_value > 3) ? 2 : 1;
1093
2.69k
1094
2.69k
        /*********************************************************/
1095
2.69k
        /* Now loop over the remaining levels                    */
1096
2.69k
        /*********************************************************/
1097
7.26k
        while(i >= 0)
1098
4.56k
        {
1099
4.56k
1100
4.56k
            /***************************************************************/
1101
4.56k
            /* Find leading zeros in next 32 bits                          */
1102
4.56k
            /***************************************************************/
1103
4.56k
            FIND_ONE_IN_STREAM_32(u4_lev_prefix, u4_bitstream_offset,
1104
4.56k
                                  pu4_bitstrm_buf);
1105
4.56k
1106
4.56k
            u4_lev_suffix_size =
1107
4.56k
                            (15 <= u4_lev_prefix) ?
1108
4.40k
                                            (u4_lev_prefix - 3) : u4_suffix_len;
1109
4.56k
1110
4.56k
            /*********************************************************/
1111
4.56k
            /* Compute level code using prefix and suffix            */
1112
4.56k
            /*********************************************************/
1113
4.56k
            GETBITS(u4_lev_suffix, u4_bitstream_offset, pu4_bitstrm_buf,
1114
4.56k
                    u4_lev_suffix_size);
1115
4.56k
            u2_lev_code = (MIN(u4_lev_prefix,15) << u4_suffix_len)
1116
4.56k
                            + u4_lev_suffix;
1117
4.56k
1118
4.56k
            //HP_LEVEL_PREFIX
1119
4.56k
            if(16 <= u4_lev_prefix)
1120
0
            {
1121
0
                u2_lev_code += ((1 << (u4_lev_prefix - 3)) - 4096);
1122
0
            }
1123
4.56k
            u2_abs_value = (u2_lev_code + 2) >> 1;
1124
4.56k
1125
4.56k
            /*********************************************************/
1126
4.56k
            /* If Level code is odd, level is negative else positive */
1127
4.56k
            /*********************************************************/
1128
4.56k
            i2_level_arr[i--] =
1129
4.56k
                            (u2_lev_code & 1) ? -u2_abs_value : u2_abs_value;
1130
4.56k
1131
4.56k
            /*********************************************************/
1132
4.56k
            /* Increment suffix length if required                   */
1133
4.56k
            /*********************************************************/
1134
4.56k
            u4_suffix_len += (u2_abs_value > (3 << (u4_suffix_len - 1)));
1135
4.56k
        }
1136
2.69k
1137
2.69k
        /****************************************************************/
1138
2.69k
        /* Decoding Levels Ends                                         */
1139
2.69k
        /****************************************************************/
1140
2.69k
    }
1141
3.31k
1142
3.31k
    if(u4_total_coeff < 4)
1143
1.58k
    {
1144
1.58k
        UWORD32 u4_max_ldz = (4 - u4_total_coeff);
1145
1.58k
        FIND_ONE_IN_STREAM_LEN(u4_total_zeroes, u4_bitstream_offset,
1146
1.58k
                               pu4_bitstrm_buf, u4_max_ldz);
1147
1.58k
    }
1148
1.72k
    else
1149
1.72k
        u4_total_zeroes = 0;
1150
3.31k
1151
3.31k
    /**************************************************************/
1152
3.31k
    /* Decode the runs and form the coefficient buffer            */
1153
3.31k
    /**************************************************************/
1154
3.31k
    {
1155
3.31k
        const UWORD8 *pu1_table_runbefore;
1156
3.31k
        UWORD32 u4_run;
1157
3.31k
        UWORD32 u4_scan_pos = (u4_total_coeff + u4_total_zeroes - 1);
1158
3.31k
        UWORD32 u4_zeroes_left = u4_total_zeroes;
1159
3.31k
        i = u4_total_coeff - 1;
1160
3.31k
1161
3.31k
        /**************************************************************/
1162
3.31k
        /* Decoding Runs for 0 < zeros left <=6                       */
1163
3.31k
        /**************************************************************/
1164
3.31k
        pu1_table_runbefore = (UWORD8 *)gau1_ih264d_table_run_before;
1165
4.16k
        while(u4_zeroes_left && i)
1166
858
        {
1167
858
            UWORD32 u4_code;
1168
858
            NEXTBITS(u4_code, u4_bitstream_offset, pu4_bitstrm_buf, 3);
1169
858
1170
858
            u4_code = pu1_table_runbefore[u4_code + (u4_zeroes_left << 3)];
1171
858
            u4_run = u4_code >> 2;
1172
858
1173
858
            FLUSHBITS(u4_bitstream_offset, (u4_code & 0x03));
1174
858
            SET_BIT(ps_tu_4x4->u2_sig_coeff_map, u4_scan_pos);
1175
858
            *pi2_coeff_data++ = i2_level_arr[i--];
1176
858
            u4_zeroes_left -= u4_run;
1177
858
            u4_scan_pos -= (u4_run + 1);
1178
858
        }
1179
3.31k
        /**************************************************************/
1180
3.31k
        /* Decoding Runs End                                          */
1181
3.31k
        /**************************************************************/
1182
3.31k
1183
3.31k
        /**************************************************************/
1184
3.31k
        /* Copy the remaining coefficients                            */
1185
3.31k
        /**************************************************************/
1186
12.6k
        while(i >= 0)
1187
9.31k
        {
1188
9.31k
            SET_BIT(ps_tu_4x4->u2_sig_coeff_map, u4_scan_pos);
1189
9.31k
            *pi2_coeff_data++ = i2_level_arr[i--];
1190
9.31k
            u4_scan_pos--;
1191
9.31k
        }
1192
3.31k
    }
1193
3.31k
1194
3.31k
    {
1195
3.31k
        WORD32 offset;
1196
3.31k
        offset = (UWORD8 *)pi2_coeff_data - (UWORD8 *)ps_tu_4x4;
1197
3.31k
        offset = ALIGN4(offset);
1198
3.31k
        ps_dec->pv_parse_tu_coeff_data = (void *)((UWORD8 *)ps_dec->pv_parse_tu_coeff_data + offset);
1199
3.31k
    }
1200
3.31k
1201
3.31k
    ps_bitstrm->u4_ofst = u4_bitstream_offset;
1202
3.31k
}
1203
1204
/*!
1205
 **************************************************************************
1206
 * \if Function name : CavlcParsingInvScanInvQuant \endif
1207
 *
1208
 * \brief
1209
 *    This function do cavlc parsing of coefficient tokens for any block
1210
 *    type except chromDc and depending
1211
 *    on whenther any coefficients to be parsed calls module
1212
 *    RestOfResidualBlockCavlc.
1213
 *
1214
 * \return
1215
 *    Returns total number of non-zero coefficients.
1216
 *
1217
 **************************************************************************
1218
 */
1219
1220
WORD32 ih264d_cavlc_parse4x4coeff_n0to7(WORD16 *pi2_coeff_block,
1221
                                        UWORD32 u4_isdc, /* is it a DC block */
1222
                                        WORD32 u4_n,
1223
                                        dec_struct_t *ps_dec,
1224
                                        UWORD32 *pu4_total_coeff)
1225
32.0k
{
1226
32.0k
    dec_bit_stream_t *ps_bitstrm = ps_dec->ps_bitstrm;
1227
32.0k
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
1228
32.0k
    UWORD32 u4_bitstream_offset = ps_bitstrm->u4_ofst;
1229
32.0k
    UWORD32 u4_code, u4_index, u4_ldz;
1230
32.0k
    const UWORD16 *pu2_code = (const UWORD16*)gau2_ih264d_code_gx;
1231
32.0k
    const UWORD16 *pu2_offset_num_vlc =
1232
32.0k
                    (const UWORD16 *)gau2_ih264d_offset_num_vlc_tab;
1233
32.0k
    UWORD32 u4_offset_num_vlc = pu2_offset_num_vlc[u4_n];
1234
32.0k
1235
32.0k
1236
32.0k
    UNUSED(pi2_coeff_block);
1237
32.0k
    *pu4_total_coeff = 0;
1238
32.0k
    FIND_ONE_IN_STREAM_32(u4_ldz, u4_bitstream_offset, pu4_bitstrm_buf);
1239
32.0k
    NEXTBITS(u4_index, u4_bitstream_offset, pu4_bitstrm_buf, 3);
1240
32.0k
    u4_index += (u4_ldz << 3);
1241
32.0k
    u4_index += u4_offset_num_vlc;
1242
32.0k
1243
32.0k
    u4_index = MIN(u4_index, 303);
1244
32.0k
    u4_code = pu2_code[u4_index];
1245
32.0k
1246
32.0k
    FLUSHBITS(u4_bitstream_offset, (u4_code & 0x03));
1247
32.0k
    ps_bitstrm->u4_ofst = u4_bitstream_offset;
1248
32.0k
    *pu4_total_coeff = (u4_code >> 4);
1249
32.0k
1250
32.0k
    if(*pu4_total_coeff)
1251
12.1k
    {
1252
12.1k
        UWORD32 u4_trailing_ones, u4_offset, u4_total_coeff_tone;
1253
12.1k
        const UWORD8 *pu1_offset =
1254
12.1k
                        (UWORD8 *)gau1_ih264d_total_coeff_fn_ptr_offset;
1255
12.1k
        WORD32 ret;
1256
12.1k
        u4_trailing_ones = ((u4_code >> 2) & 0x03);
1257
12.1k
        u4_offset = pu1_offset[*pu4_total_coeff - 1];
1258
12.1k
        u4_total_coeff_tone = (*pu4_total_coeff << 16) | u4_trailing_ones;
1259
12.1k
1260
12.1k
        ret = ps_dec->pf_cavlc_4x4res_block[u4_offset](u4_isdc,
1261
12.1k
                                                       u4_total_coeff_tone,
1262
12.1k
                                                       ps_bitstrm);
1263
12.1k
        if(ret != 0)
1264
0
            return ERROR_CAVLC_NUM_COEFF_T;
1265
32.0k
    }
1266
32.0k
1267
32.0k
    return OK;
1268
32.0k
}
1269
1270
WORD32 ih264d_cavlc_parse4x4coeff_n8(WORD16 *pi2_coeff_block,
1271
                                     UWORD32 u4_isdc, /* is it a DC block */
1272
                                     WORD32 u4_n,
1273
                                     dec_struct_t *ps_dec,
1274
                                     UWORD32 *pu4_total_coeff)
1275
13.6k
{
1276
13.6k
1277
13.6k
    dec_bit_stream_t *ps_bitstrm = ps_dec->ps_bitstrm;
1278
13.6k
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
1279
13.6k
    UWORD32 u4_bitstream_offset = ps_bitstrm->u4_ofst;
1280
13.6k
    UWORD32 u4_code;
1281
13.6k
    UNUSED(u4_n);
1282
13.6k
    UNUSED(pi2_coeff_block);
1283
13.6k
    GETBITS(u4_code, u4_bitstream_offset, pu4_bitstrm_buf, 6);
1284
13.6k
    ps_bitstrm->u4_ofst = u4_bitstream_offset;
1285
13.6k
    *pu4_total_coeff = 0;
1286
13.6k
1287
13.6k
    if(u4_code != 3)
1288
11.8k
    {
1289
11.8k
        UWORD8 *pu1_offset = (UWORD8 *)gau1_ih264d_total_coeff_fn_ptr_offset;
1290
11.8k
        UWORD32 u4_trailing_ones, u4_offset, u4_total_coeff_tone;
1291
11.8k
1292
11.8k
        *pu4_total_coeff = (u4_code >> 2) + 1;
1293
11.8k
        u4_trailing_ones = u4_code & 0x03;
1294
11.8k
        u4_offset = pu1_offset[*pu4_total_coeff - 1];
1295
11.8k
        u4_total_coeff_tone = (*pu4_total_coeff << 16) | u4_trailing_ones;
1296
11.8k
1297
11.8k
        ps_dec->pf_cavlc_4x4res_block[u4_offset](u4_isdc,
1298
11.8k
                                                 u4_total_coeff_tone,
1299
11.8k
                                                 ps_bitstrm);
1300
11.8k
    }
1301
13.6k
1302
13.6k
    return OK;
1303
13.6k
}
1304
1305
/*!
1306
 **************************************************************************
1307
 * \if Function name : ih264d_cavlc_parse_chroma_dc \endif
1308
 *
1309
 * \brief
1310
 *    This function do cavlc parsing of coefficient tokens chromDc block
1311
 *    and depending  on whenther any coefficients to be parsed calls module
1312
 *    ih264d_rest_of_residual_cav_chroma_dc_block.
1313
 *
1314
 * \return
1315
 *    Returns total number of non-zero coefficients.
1316
 *
1317
 **************************************************************************
1318
 */
1319
1320
void ih264d_cavlc_parse_chroma_dc(dec_mb_info_t *ps_cur_mb_info,
1321
                                  WORD16 *pi2_coeff_block,
1322
                                  dec_bit_stream_t *ps_bitstrm,
1323
                                  UWORD32 u4_scale_u,
1324
                                  UWORD32 u4_scale_v,
1325
                                  WORD32 i4_mb_inter_inc)
1326
2.18k
{
1327
2.18k
    UWORD32 u4_total_coeff, u4_trailing_ones, u4_total_coeff_tone, u4_code;
1328
2.18k
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
1329
2.18k
    UWORD32 u4_bitstream_offset = ps_bitstrm->u4_ofst;
1330
2.18k
    const UWORD8 *pu1_cav_chromdc = (const UWORD8*)gau1_ih264d_cav_chromdc_vld;
1331
2.18k
    UNUSED(i4_mb_inter_inc);
1332
2.18k
    /******************************************************************/
1333
2.18k
    /*  Chroma DC Block for U component                               */
1334
2.18k
    /******************************************************************/
1335
2.18k
    NEXTBITS(u4_code, u4_bitstream_offset, pu4_bitstrm_buf, 8);
1336
2.18k
1337
2.18k
    u4_code = pu1_cav_chromdc[u4_code];
1338
2.18k
1339
2.18k
    FLUSHBITS(u4_bitstream_offset, ((u4_code & 0x7) + 1));
1340
2.18k
    ps_bitstrm->u4_ofst = u4_bitstream_offset;
1341
2.18k
1342
2.18k
    u4_total_coeff = (u4_code >> 5);
1343
2.18k
1344
2.18k
    if(u4_total_coeff)
1345
1.78k
    {
1346
1.78k
        WORD32 i_z0, i_z1, i_z2, i_z3;
1347
1.78k
        tu_sblk4x4_coeff_data_t *ps_tu_4x4;
1348
1.78k
        dec_struct_t *ps_dec = (dec_struct_t *)ps_bitstrm->pv_codec_handle;
1349
1.78k
        WORD16 ai2_dc_coef[4];
1350
1.78k
        UWORD8 pu1_inv_scan[4] =
1351
1.78k
                        { 0, 1, 2, 3 };
1352
1.78k
        WORD16 *pi2_coeff_data =
1353
1.78k
                                    (WORD16 *)ps_dec->pv_parse_tu_coeff_data;
1354
1.78k
1355
1.78k
        ps_tu_4x4 = (tu_sblk4x4_coeff_data_t *)ps_dec->pv_parse_tu_coeff_data;
1356
1.78k
1357
1.78k
        u4_trailing_ones = ((u4_code >> 3) & 0x3);
1358
1.78k
        u4_total_coeff_tone = (u4_total_coeff << 16) | u4_trailing_ones;
1359
1.78k
        ih264d_rest_of_residual_cav_chroma_dc_block(u4_total_coeff_tone,
1360
1.78k
                                                    ps_bitstrm);
1361
1.78k
1362
1.78k
        ai2_dc_coef[0] = 0;
1363
1.78k
        ai2_dc_coef[1] = 0;
1364
1.78k
        ai2_dc_coef[2] = 0;
1365
1.78k
        ai2_dc_coef[3] = 0;
1366
1.78k
1367
1.78k
        ih264d_unpack_coeff4x4_dc_4x4blk(ps_tu_4x4,
1368
1.78k
                                         ai2_dc_coef,
1369
1.78k
                                         pu1_inv_scan);
1370
1.78k
        /*-------------------------------------------------------------------*/
1371
1.78k
        /* Inverse 2x2 transform and scaling  of chroma DC                   */
1372
1.78k
        /*-------------------------------------------------------------------*/
1373
1.78k
        i_z0 = (ai2_dc_coef[0] + ai2_dc_coef[2]);
1374
1.78k
        i_z1 = (ai2_dc_coef[0] - ai2_dc_coef[2]);
1375
1.78k
        i_z2 = (ai2_dc_coef[1] - ai2_dc_coef[3]);
1376
1.78k
        i_z3 = (ai2_dc_coef[1] + ai2_dc_coef[3]);
1377
1.78k
1378
1.78k
        /*-----------------------------------------------------------*/
1379
1.78k
        /* Scaling and storing the values back                       */
1380
1.78k
        /*-----------------------------------------------------------*/
1381
1.78k
        *pi2_coeff_data++ = ((i_z0 + i_z3) * u4_scale_u) >> 5;
1382
1.78k
        *pi2_coeff_data++ = ((i_z0 - i_z3) * u4_scale_u) >> 5;
1383
1.78k
        *pi2_coeff_data++ = ((i_z1 + i_z2) * u4_scale_u) >> 5;
1384
1.78k
        *pi2_coeff_data++ = ((i_z1 - i_z2) * u4_scale_u) >> 5;
1385
1.78k
1386
1.78k
        ps_dec->pv_parse_tu_coeff_data = (void *)pi2_coeff_data;
1387
1.78k
1388
1.78k
        SET_BIT(ps_cur_mb_info->u1_yuv_dc_block_flag,1);
1389
1.78k
    }
1390
2.18k
1391
2.18k
    /******************************************************************/
1392
2.18k
    /*  Chroma DC Block for V component                               */
1393
2.18k
    /******************************************************************/
1394
2.18k
    pi2_coeff_block += 64;
1395
2.18k
    u4_bitstream_offset = ps_bitstrm->u4_ofst;
1396
2.18k
1397
2.18k
    NEXTBITS(u4_code, u4_bitstream_offset, pu4_bitstrm_buf, 8);
1398
2.18k
1399
2.18k
    u4_code = pu1_cav_chromdc[u4_code];
1400
2.18k
1401
2.18k
    FLUSHBITS(u4_bitstream_offset, ((u4_code & 0x7) + 1));
1402
2.18k
    ps_bitstrm->u4_ofst = u4_bitstream_offset;
1403
2.18k
1404
2.18k
    u4_total_coeff = (u4_code >> 5);
1405
2.18k
1406
2.18k
    if(u4_total_coeff)
1407
1.52k
    {
1408
1.52k
        WORD32 i_z0, i_z1, i_z2, i_z3;
1409
1.52k
        tu_sblk4x4_coeff_data_t *ps_tu_4x4;
1410
1.52k
        dec_struct_t *ps_dec = (dec_struct_t *)ps_bitstrm->pv_codec_handle;
1411
1.52k
        WORD16 ai2_dc_coef[4];
1412
1.52k
        UWORD8 pu1_inv_scan[4] =
1413
1.52k
                        { 0, 1, 2, 3 };
1414
1.52k
        WORD16 *pi2_coeff_data =
1415
1.52k
                                    (WORD16 *)ps_dec->pv_parse_tu_coeff_data;
1416
1.52k
1417
1.52k
        ps_tu_4x4 = (tu_sblk4x4_coeff_data_t *)ps_dec->pv_parse_tu_coeff_data;
1418
1.52k
1419
1.52k
        u4_trailing_ones = ((u4_code >> 3) & 0x3);
1420
1.52k
        u4_total_coeff_tone = (u4_total_coeff << 16) | u4_trailing_ones;
1421
1.52k
        ih264d_rest_of_residual_cav_chroma_dc_block(u4_total_coeff_tone,
1422
1.52k
                                                    ps_bitstrm);
1423
1.52k
1424
1.52k
        ai2_dc_coef[0] = 0;
1425
1.52k
        ai2_dc_coef[1] = 0;
1426
1.52k
        ai2_dc_coef[2] = 0;
1427
1.52k
        ai2_dc_coef[3] = 0;
1428
1.52k
1429
1.52k
        ih264d_unpack_coeff4x4_dc_4x4blk(ps_tu_4x4,
1430
1.52k
                                         ai2_dc_coef,
1431
1.52k
                                         pu1_inv_scan);
1432
1.52k
1433
1.52k
        /*-------------------------------------------------------------------*/
1434
1.52k
        /* Inverse 2x2 transform and scaling  of chroma DC                   */
1435
1.52k
        /*-------------------------------------------------------------------*/
1436
1.52k
        i_z0 = (ai2_dc_coef[0] + ai2_dc_coef[2]);
1437
1.52k
        i_z1 = (ai2_dc_coef[0] - ai2_dc_coef[2]);
1438
1.52k
        i_z2 = (ai2_dc_coef[1] - ai2_dc_coef[3]);
1439
1.52k
        i_z3 = (ai2_dc_coef[1] + ai2_dc_coef[3]);
1440
1.52k
1441
1.52k
        /*-----------------------------------------------------------*/
1442
1.52k
        /* Scaling and storing the values back                       */
1443
1.52k
        /*-----------------------------------------------------------*/
1444
1.52k
        *pi2_coeff_data++ = ((i_z0 + i_z3) * u4_scale_v) >> 5;
1445
1.52k
        *pi2_coeff_data++ = ((i_z0 - i_z3) * u4_scale_v) >> 5;
1446
1.52k
        *pi2_coeff_data++ = ((i_z1 + i_z2) * u4_scale_v) >> 5;
1447
1.52k
        *pi2_coeff_data++ = ((i_z1 - i_z2) * u4_scale_v) >> 5;
1448
1.52k
1449
1.52k
        ps_dec->pv_parse_tu_coeff_data = (void *)pi2_coeff_data;
1450
1.52k
1451
1.52k
        SET_BIT(ps_cur_mb_info->u1_yuv_dc_block_flag,2);
1452
1.52k
    }
1453
2.18k
}
1454
1455
/*****************************************************************************/
1456
/*                                                                           */
1457
/*  Function Name : ih264d_parse_pmb_ref_index_cavlc_range1                         */
1458
/*                                                                           */
1459
/*  Description   : This function does the Cavlc  TEV range =1 parsing of    */
1460
/*                  reference index  for a P MB. Range is 1 when             */
1461
/*                  num_ref_idx_active_minus1 is 0                           */
1462
/*                                                                           */
1463
/*  Inputs        : <What inputs does the function take?>                    */
1464
/*  Globals       : <Does it use any global variables?>                      */
1465
/*  Processing    : <Describe how the function operates - include algorithm  */
1466
/*                  description>                                             */
1467
/*  Outputs       : <What does the function produce?>                        */
1468
/*  Returns       : <What does the function return?>                         */
1469
/*                                                                           */
1470
/*  Issues        : <List any issues or problems with this function>         */
1471
/*                                                                           */
1472
/*  Revision History:                                                        */
1473
/*                                                                           */
1474
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1475
/*         19 09 2008   Jay          Draft                                   */
1476
/*                                                                           */
1477
/*****************************************************************************/
1478
void ih264d_parse_pmb_ref_index_cavlc_range1(UWORD32 u4_num_part, /* Number of partitions in MB      */
1479
                                             dec_bit_stream_t *ps_bitstrm, /* Pointer to bitstream Structure. */
1480
                                             WORD8 *pi1_ref_idx, /* pointer to reference index array */
1481
                                             UWORD32 u4_num_ref_idx_active_minus1 /* Not used for range 1    */
1482
                                             )
1483
0
{
1484
0
    UWORD32 u4_i;
1485
0
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
1486
0
    UWORD32 *pu4_bitstream_off = &ps_bitstrm->u4_ofst;
1487
0
    UNUSED(u4_num_ref_idx_active_minus1);
1488
0
    for(u4_i = 0; u4_i < u4_num_part; u4_i++)
1489
0
    {
1490
0
        UWORD32 u4_ref_idx;
1491
0
        u4_ref_idx = ih264d_tev_range1(pu4_bitstream_off, pu4_bitstrm_buf);
1492
0
1493
0
        /* Storing Reference Idx Information */
1494
0
        pi1_ref_idx[u4_i] = (WORD8)u4_ref_idx;
1495
0
    }
1496
0
}
1497
1498
/*****************************************************************************/
1499
/*                                                                           */
1500
/*  Function Name : ih264d_parse_pmb_ref_index_cavlc                                */
1501
/*                                                                           */
1502
/*  Description   : This function does the Cavlc  TEV range > 1 parsing of   */
1503
/*                  reference index  for a P MB.                             */
1504
/*                  Range > 1 when num_ref_idx_active_minus1 > 0             */
1505
/*                                                                           */
1506
/*  Inputs        : <What inputs does the function take?>                    */
1507
/*  Globals       : <Does it use any global variables?>                      */
1508
/*  Processing    : <Describe how the function operates - include algorithm  */
1509
/*                  description>                                             */
1510
/*  Outputs       : <What does the function produce?>                        */
1511
/*  Returns       : <What does the function return?>                         */
1512
/*                                                                           */
1513
/*  Issues        : <List any issues or problems with this function>         */
1514
/*                                                                           */
1515
/*  Revision History:                                                        */
1516
/*                                                                           */
1517
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1518
/*         19 09 2008   Jay          Draft                                   */
1519
/*                                                                           */
1520
/*****************************************************************************/
1521
1522
WORD32 ih264d_parse_pmb_ref_index_cavlc(UWORD32 u4_num_part, /* Number of partitions in MB      */
1523
                                      dec_bit_stream_t *ps_bitstrm, /* Pointer to bitstream Structure. */
1524
                                      WORD8 *pi1_ref_idx, /* pointer to reference index array */
1525
                                      UWORD32 u4_num_ref_idx_active_minus1 /* Number of active references - 1  */
1526
                                      )
1527
0
{
1528
0
    UWORD32 u4_i;
1529
0
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
1530
0
    UWORD32 *pu4_bitstream_off = &ps_bitstrm->u4_ofst;
1531
0
1532
0
    for(u4_i = 0; u4_i < u4_num_part; u4_i++)
1533
0
    {
1534
0
        UWORD32 u4_ref_idx;
1535
0
//Inlined ih264d_uev
1536
0
        UWORD32 u4_bitstream_offset = *pu4_bitstream_off;
1537
0
        UWORD32 u4_word, u4_ldz;
1538
0
1539
0
        /***************************************************************/
1540
0
        /* Find leading zeros in next 32 bits                          */
1541
0
        /***************************************************************/
1542
0
        NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
1543
0
        u4_ldz = CLZ(u4_word);
1544
0
        /* Flush the ps_bitstrm */
1545
0
        u4_bitstream_offset += (u4_ldz + 1);
1546
0
        /* Read the suffix from the ps_bitstrm */
1547
0
        u4_word = 0;
1548
0
        if(u4_ldz)
1549
0
            GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf, u4_ldz);
1550
0
        *pu4_bitstream_off = u4_bitstream_offset;
1551
0
        u4_ref_idx = ((1 << u4_ldz) + u4_word - 1);
1552
0
//Inlined ih264d_uev
1553
0
1554
0
        if(u4_ref_idx > u4_num_ref_idx_active_minus1)
1555
0
            return ERROR_REF_IDX;
1556
0
1557
0
        /* Storing Reference Idx Information */
1558
0
        pi1_ref_idx[u4_i] = (WORD8)u4_ref_idx;
1559
0
    }
1560
0
    return OK;
1561
0
}
1562
1563
/*****************************************************************************/
1564
/*                                                                           */
1565
/*  Function Name : ih264d_parse_bmb_ref_index_cavlc_range1                         */
1566
/*                                                                           */
1567
/*  Description   : This function does the Cavlc  TEV range =1 parsing of    */
1568
/*                  reference index  for a B MB. Range is 1 when             */
1569
/*                  num_ref_idx_active_minus1 is 0                           */
1570
/*                                                                           */
1571
/*  Inputs        : <What inputs does the function take?>                    */
1572
/*  Globals       : <Does it use any global variables?>                      */
1573
/*  Processing    : <Describe how the function operates - include algorithm  */
1574
/*                  description>                                             */
1575
/*  Outputs       : <What does the function produce?>                        */
1576
/*  Returns       : <What does the function return?>                         */
1577
/*                                                                           */
1578
/*  Issues        : <List any issues or problems with this function>         */
1579
/*                                                                           */
1580
/*  Revision History:                                                        */
1581
/*                                                                           */
1582
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1583
/*         19 09 2008   Jay          Draft                                   */
1584
/*                                                                           */
1585
/*****************************************************************************/
1586
void ih264d_parse_bmb_ref_index_cavlc_range1(UWORD32 u4_num_part, /* Number of partitions in MB      */
1587
                                             dec_bit_stream_t *ps_bitstrm, /* Pointer to bitstream Structure. */
1588
                                             WORD8 *pi1_ref_idx, /* pointer to reference index array */
1589
                                             UWORD32 u4_num_ref_idx_active_minus1 /* Not used for range 1    */
1590
                                             )
1591
0
{
1592
0
    UWORD32 u4_i;
1593
0
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
1594
0
    UWORD32 *pu4_bitstream_off = &ps_bitstrm->u4_ofst;
1595
0
    UNUSED(u4_num_ref_idx_active_minus1);
1596
0
    for(u4_i = 0; u4_i < u4_num_part; u4_i++)
1597
0
    {
1598
0
        if(pi1_ref_idx[u4_i] > -1)
1599
0
        {
1600
0
            UWORD32 u4_ref_idx;
1601
0
1602
0
            u4_ref_idx = ih264d_tev_range1(pu4_bitstream_off, pu4_bitstrm_buf);
1603
0
1604
0
            /* Storing Reference Idx Information */
1605
0
            pi1_ref_idx[u4_i] = (WORD8)u4_ref_idx;
1606
0
        }
1607
0
    }
1608
0
}
1609
1610
/*****************************************************************************/
1611
/*                                                                           */
1612
/*  Function Name : ih264d_parse_bmb_ref_index_cavlc                                */
1613
/*                                                                           */
1614
/*  Description   : This function does the Cavlc  TEV range > 1 parsing of   */
1615
/*                  reference index  for a B MB.                             */
1616
/*                  Range > 1 when num_ref_idx_active_minus1 > 0             */
1617
/*                                                                           */
1618
/*  Inputs        : <What inputs does the function take?>                    */
1619
/*  Globals       : <Does it use any global variables?>                      */
1620
/*  Processing    : <Describe how the function operates - include algorithm  */
1621
/*                  description>                                             */
1622
/*  Outputs       : <What does the function produce?>                        */
1623
/*  Returns       : <What does the function return?>                         */
1624
/*                                                                           */
1625
/*  Issues        : <List any issues or problems with this function>         */
1626
/*                                                                           */
1627
/*  Revision History:                                                        */
1628
/*                                                                           */
1629
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1630
/*         19 09 2008   Jay          Draft                                   */
1631
/*                                                                           */
1632
/*****************************************************************************/
1633
WORD32 ih264d_parse_bmb_ref_index_cavlc(UWORD32 u4_num_part, /* Number of partitions in MB      */
1634
                                      dec_bit_stream_t *ps_bitstrm, /* Pointer to bitstream Structure. */
1635
                                      WORD8 *pi1_ref_idx, /* pointer to reference index array */
1636
                                      UWORD32 u4_num_ref_idx_active_minus1 /* Number of active references - 1  */
1637
                                      )
1638
0
{
1639
0
    UWORD32 u4_i;
1640
0
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
1641
0
    UWORD32 *pu4_bitstream_off = &ps_bitstrm->u4_ofst;
1642
0
1643
0
    for(u4_i = 0; u4_i < u4_num_part; u4_i++)
1644
0
    {
1645
0
        if(pi1_ref_idx[u4_i] > -1)
1646
0
        {
1647
0
            UWORD32 u4_ref_idx;
1648
0
//inlining ih264d_uev
1649
0
            UWORD32 u4_bitstream_offset = *pu4_bitstream_off;
1650
0
            UWORD32 u4_word, u4_ldz;
1651
0
1652
0
            /***************************************************************/
1653
0
            /* Find leading zeros in next 32 bits                          */
1654
0
            /***************************************************************/
1655
0
            NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
1656
0
            u4_ldz = CLZ(u4_word);
1657
0
            /* Flush the ps_bitstrm */
1658
0
            u4_bitstream_offset += (u4_ldz + 1);
1659
0
            /* Read the suffix from the ps_bitstrm */
1660
0
            u4_word = 0;
1661
0
            if(u4_ldz)
1662
0
                GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf, u4_ldz);
1663
0
            *pu4_bitstream_off = u4_bitstream_offset;
1664
0
            u4_ref_idx = ((1 << u4_ldz) + u4_word - 1);
1665
0
//inlining ih264d_uev
1666
0
            if(u4_ref_idx > u4_num_ref_idx_active_minus1)
1667
0
                return ERROR_REF_IDX;
1668
0
1669
0
            /* Storing Reference Idx Information */
1670
0
            pi1_ref_idx[u4_i] = (WORD8)u4_ref_idx;
1671
0
        }
1672
0
    }
1673
0
    return OK;
1674
0
}
1675
/*****************************************************************************/
1676
/*                                                                           */
1677
/*  Function Name : ih264d_cavlc_parse_8x8block_both_available                      */
1678
/*                                                                           */
1679
/*  Description   : This function does the residual parsing of 4 subblocks   */
1680
/*                  in a 8x8 block when both top and left are available      */
1681
/*                                                                           */
1682
/*  Inputs        : pi2_coeff_block : pointer to residual block where        */
1683
/*                  decoded and inverse scan coefficients are updated        */
1684
/*                                                                           */
1685
/*                  u4_sub_block_strd : indicates the number of sublocks    */
1686
/*                  in a row. It is 4 for luma and 2 for chroma.             */
1687
/*                                                                           */
1688
/*                  u4_isdc : required to indicate 4x4 parse modules if the  */
1689
/*                  current  Mb is I_16x16/chroma DC coded.                  */
1690
/*                                                                           */
1691
/*                  ps_dec : pointer to Decstruct (decoder context)          */
1692
/*                                                                           */
1693
/*                  pu1_top_nnz : top nnz pointer                            */
1694
/*                                                                           */
1695
/*                  pu1_left_nnz : left nnz pointer                          */
1696
/*                                                                           */
1697
/*  Globals       : No                                                       */
1698
/*  Processing    : Parsing for four subblocks in unrolled, top and left nnz */
1699
/*                  are updated on the fly. csbp is set in accordance to     */
1700
/*                  decoded numcoeff for the subblock index in raster order  */
1701
/*                                                                           */
1702
/*  Outputs       : The updated residue buffer, nnzs and csbp current block  */
1703
/*                                                                           */
1704
/*  Returns       : Returns the coded sub block pattern csbp for the block   */
1705
/*                                                                           */
1706
/*  Issues        : <List any issues or problems with this function>         */
1707
/*                                                                           */
1708
/*  Revision History:                                                        */
1709
/*                                                                           */
1710
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1711
/*         09 10 2008   Jay          Draft                                   */
1712
/*                                                                           */
1713
/*****************************************************************************/
1714
WORD32 ih264d_cavlc_parse_8x8block_both_available(WORD16 *pi2_coeff_block,
1715
                                                  UWORD32 u4_sub_block_strd,
1716
                                                  UWORD32 u4_isdc,
1717
                                                  dec_struct_t * ps_dec,
1718
                                                  UWORD8 *pu1_top_nnz,
1719
                                                  UWORD8 *pu1_left_nnz,
1720
                                                  UWORD8 u1_tran_form8x8,
1721
                                                  UWORD8 u1_mb_field_decodingflag,
1722
                                                  UWORD32 *pu4_csbp)
1723
10.3k
{
1724
10.3k
    UWORD32 u4_num_coeff, u4_n, u4_subblock_coded;
1725
10.3k
    UWORD32 u4_top0, u4_top1;
1726
10.3k
    UWORD32 *pu4_dummy;
1727
10.3k
    WORD32 (**pf_cavlc_parse4x4coeff)(WORD16 *pi2_coeff_block,
1728
10.3k
                                      UWORD32 u4_isdc,
1729
10.3k
                                      WORD32 u4_n,
1730
10.3k
                                      struct _DecStruct *ps_dec,
1731
10.3k
                                      UWORD32 *pu4_dummy) =
1732
10.3k
                                      ps_dec->pf_cavlc_parse4x4coeff;
1733
10.3k
    UWORD32 u4_idx = 0;
1734
10.3k
    UWORD8 *puc_temp;
1735
10.3k
    WORD32 ret;
1736
10.3k
1737
10.3k
    *pu4_csbp = 0;
1738
10.3k
    /* need to change the inverse scan matrices here */
1739
10.3k
    puc_temp = ps_dec->pu1_inv_scan;
1740
10.3k
1741
10.3k
    /*------------------------------------------------------*/
1742
10.3k
    /* Residual 4x4 decoding: SubBlock 0                    */
1743
10.3k
    /*------------------------------------------------------*/
1744
10.3k
    if(u1_tran_form8x8)
1745
0
    {
1746
0
        if(!u1_mb_field_decodingflag)
1747
0
        {
1748
0
            ps_dec->pu1_inv_scan =
1749
0
                            (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[0];
1750
0
        }
1751
0
        else
1752
0
        {
1753
0
            ps_dec->pu1_inv_scan =
1754
0
                            (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[0];
1755
0
        }
1756
0
    }
1757
10.3k
    u4_n = (pu1_top_nnz[0] + pu1_left_nnz[0] + 1) >> 1;
1758
10.3k
    ret = pf_cavlc_parse4x4coeff[(u4_n > 7)](pi2_coeff_block, u4_isdc,
1759
10.3k
                                             u4_n, ps_dec, &u4_num_coeff);
1760
10.3k
    if(ret != OK)
1761
10.3k
        return ret;
1762
10.3k
1763
10.3k
    u4_top0 = u4_num_coeff;
1764
10.3k
    u4_subblock_coded = (u4_num_coeff != 0);
1765
10.3k
    INSERT_BIT(*pu4_csbp, u4_idx, u4_subblock_coded);
1766
10.3k
1767
10.3k
    /*------------------------------------------------------*/
1768
10.3k
    /* Residual 4x4 decoding: SubBlock 1                    */
1769
10.3k
    /*------------------------------------------------------*/
1770
10.3k
    u4_idx++;
1771
10.3k
    if(u1_tran_form8x8)
1772
0
    {
1773
0
        if(!u1_mb_field_decodingflag)
1774
0
        {
1775
0
            ps_dec->pu1_inv_scan =
1776
0
                            (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[1];
1777
0
        }
1778
0
        else
1779
0
        {
1780
0
            ps_dec->pu1_inv_scan =
1781
0
                            (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[1];
1782
0
        }
1783
0
    }
1784
10.3k
    else
1785
10.3k
    {
1786
10.3k
        pi2_coeff_block += NUM_COEFFS_IN_4x4BLK;
1787
10.3k
    }
1788
10.3k
    u4_n = (pu1_top_nnz[1] + u4_num_coeff + 1) >> 1;
1789
10.3k
    ret = pf_cavlc_parse4x4coeff[(u4_n > 7)](pi2_coeff_block, u4_isdc,
1790
10.3k
                                             u4_n, ps_dec, &u4_num_coeff);
1791
10.3k
    if(ret != OK)
1792
10.3k
        return ret;
1793
10.3k
1794
10.3k
    u4_top1 = pu1_left_nnz[0] = u4_num_coeff;
1795
10.3k
    u4_subblock_coded = (u4_num_coeff != 0);
1796
10.3k
    INSERT_BIT(*pu4_csbp, u4_idx, u4_subblock_coded);
1797
10.3k
1798
10.3k
    /*------------------------------------------------------*/
1799
10.3k
    /* Residual 4x4 decoding: SubBlock 2                    */
1800
10.3k
    /*------------------------------------------------------*/
1801
10.3k
    u4_idx += (u4_sub_block_strd - 1);
1802
10.3k
    if(u1_tran_form8x8)
1803
0
    {
1804
0
        if(!u1_mb_field_decodingflag)
1805
0
        {
1806
0
            ps_dec->pu1_inv_scan =
1807
0
                            (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[2];
1808
0
        }
1809
0
        else
1810
0
        {
1811
0
            ps_dec->pu1_inv_scan =
1812
0
                            (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[2];
1813
0
        }
1814
0
    }
1815
10.3k
    else
1816
10.3k
    {
1817
10.3k
        pi2_coeff_block += ((u4_sub_block_strd - 1) * NUM_COEFFS_IN_4x4BLK);
1818
10.3k
    }
1819
10.3k
    u4_n = (u4_top0 + pu1_left_nnz[1] + 1) >> 1;
1820
10.3k
    ret = pf_cavlc_parse4x4coeff[(u4_n > 7)](pi2_coeff_block, u4_isdc,
1821
10.3k
                                             u4_n, ps_dec, &u4_num_coeff);
1822
10.3k
    if(ret != OK)
1823
10.3k
        return ret;
1824
10.3k
1825
10.3k
    pu1_top_nnz[0] = u4_num_coeff;
1826
10.3k
    u4_subblock_coded = (u4_num_coeff != 0);
1827
10.3k
    INSERT_BIT(*pu4_csbp, u4_idx, u4_subblock_coded);
1828
10.3k
1829
10.3k
    /*------------------------------------------------------*/
1830
10.3k
    /* Residual 4x4 decoding: SubBlock 3                    */
1831
10.3k
    /*------------------------------------------------------*/
1832
10.3k
    u4_idx++;
1833
10.3k
    if(u1_tran_form8x8)
1834
0
    {
1835
0
        if(!u1_mb_field_decodingflag)
1836
0
        {
1837
0
            ps_dec->pu1_inv_scan =
1838
0
                            (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[3];
1839
0
        }
1840
0
        else
1841
0
        {
1842
0
            ps_dec->pu1_inv_scan =
1843
0
                            (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[3];
1844
0
        }
1845
0
    }
1846
10.3k
    else
1847
10.3k
    {
1848
10.3k
        pi2_coeff_block += NUM_COEFFS_IN_4x4BLK;
1849
10.3k
    }
1850
10.3k
    u4_n = (u4_top1 + u4_num_coeff + 1) >> 1;
1851
10.3k
    ret = pf_cavlc_parse4x4coeff[(u4_n > 7)](pi2_coeff_block, u4_isdc,
1852
10.3k
                                             u4_n, ps_dec, &u4_num_coeff);
1853
10.3k
    if(ret != OK)
1854
10.3k
        return ret;
1855
10.3k
1856
10.3k
    pu1_top_nnz[1] = pu1_left_nnz[1] = u4_num_coeff;
1857
10.3k
    u4_subblock_coded = (u4_num_coeff != 0);
1858
10.3k
    INSERT_BIT(*pu4_csbp, u4_idx, u4_subblock_coded);
1859
10.3k
1860
10.3k
    ps_dec->pu1_inv_scan = puc_temp;
1861
10.3k
1862
10.3k
    return OK;
1863
10.3k
}
1864
1865
/*****************************************************************************/
1866
/*                                                                           */
1867
/*  Function Name : ih264d_cavlc_parse_8x8block_left_available                      */
1868
/*                                                                           */
1869
/*  Description   : This function does the residual parsing of 4 subblocks   */
1870
/*                  in a 8x8 block when only left is available for block     */
1871
/*                                                                           */
1872
/*  Inputs        : pi2_coeff_block : pointer to residual block where        */
1873
/*                  decoded and inverse scan coefficients are updated        */
1874
/*                                                                           */
1875
/*                  u4_sub_block_strd : indicates the number of sublocks    */
1876
/*                  in a row. It is 4 for luma and 2 for chroma.             */
1877
/*                                                                           */
1878
/*                  u4_isdc : required to indicate 4x4 parse modules if the  */
1879
/*                  current  Mb is I_16x16/chroma DC coded.                  */
1880
/*                                                                           */
1881
/*                  ps_dec : pointer to Decstruct (decoder context)          */
1882
/*                                                                           */
1883
/*                  pu1_top_nnz : top nnz pointer                            */
1884
/*                                                                           */
1885
/*                  pu1_left_nnz : left nnz pointer                          */
1886
/*                                                                           */
1887
/*  Globals       : No                                                       */
1888
/*  Processing    : Parsing for four subblocks in unrolled, top and left nnz */
1889
/*                  are updated on the fly. csbp is set in accordance to     */
1890
/*                  decoded numcoeff for the subblock index in raster order  */
1891
/*                                                                           */
1892
/*  Outputs       : The updated residue buffer, nnzs and csbp current block  */
1893
/*                                                                           */
1894
/*  Returns       : Returns the coded sub block pattern csbp for the block   */
1895
/*                                                                           */
1896
/*  Issues        : <List any issues or problems with this function>         */
1897
/*                                                                           */
1898
/*  Revision History:                                                        */
1899
/*                                                                           */
1900
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1901
/*         09 10 2008   Jay          Draft                                   */
1902
/*                                                                           */
1903
/*****************************************************************************/
1904
WORD32 ih264d_cavlc_parse_8x8block_left_available(WORD16 *pi2_coeff_block,
1905
                                                  UWORD32 u4_sub_block_strd,
1906
                                                  UWORD32 u4_isdc,
1907
                                                  dec_struct_t * ps_dec,
1908
                                                  UWORD8 *pu1_top_nnz,
1909
                                                  UWORD8 *pu1_left_nnz,
1910
                                                  UWORD8 u1_tran_form8x8,
1911
                                                  UWORD8 u1_mb_field_decodingflag,
1912
                                                  UWORD32 *pu4_csbp)
1913
187
{
1914
187
    UWORD32 u4_num_coeff, u4_n, u4_subblock_coded;
1915
187
    UWORD32 u4_top0, u4_top1;
1916
187
    UWORD32 *pu4_dummy;
1917
187
    WORD32 (**pf_cavlc_parse4x4coeff)(WORD16 *pi2_coeff_block,
1918
187
                                      UWORD32 u4_isdc,
1919
187
                                      WORD32 u4_n,
1920
187
                                      struct _DecStruct *ps_dec,
1921
187
                                      UWORD32 *pu4_dummy) =
1922
187
                                      ps_dec->pf_cavlc_parse4x4coeff;
1923
187
    UWORD32 u4_idx = 0;
1924
187
    UWORD8 *puc_temp;
1925
187
    WORD32 ret;
1926
187
1927
187
    *pu4_csbp = 0;
1928
187
    puc_temp = ps_dec->pu1_inv_scan;
1929
187
1930
187
    /*------------------------------------------------------*/
1931
187
    /* Residual 4x4 decoding: SubBlock 0                    */
1932
187
    /*------------------------------------------------------*/
1933
187
    if(u1_tran_form8x8)
1934
0
    {
1935
0
        if(!u1_mb_field_decodingflag)
1936
0
        {
1937
0
            ps_dec->pu1_inv_scan =
1938
0
                            (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[0];
1939
0
        }
1940
0
        else
1941
0
        {
1942
0
            ps_dec->pu1_inv_scan =
1943
0
                            (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[0];
1944
0
        }
1945
0
    }
1946
187
    u4_n = pu1_left_nnz[0];
1947
187
    ret = pf_cavlc_parse4x4coeff[(u4_n > 7)](pi2_coeff_block, u4_isdc,
1948
187
                                             u4_n, ps_dec, &u4_num_coeff);
1949
187
    if(ret != OK)
1950
187
        return ret;
1951
187
1952
187
    u4_top0 = u4_num_coeff;
1953
187
    u4_subblock_coded = (u4_num_coeff != 0);
1954
187
    INSERT_BIT(*pu4_csbp, u4_idx, u4_subblock_coded);
1955
187
1956
187
    /*------------------------------------------------------*/
1957
187
    /* Residual 4x4 decoding: SubBlock 1                    */
1958
187
    /*------------------------------------------------------*/
1959
187
    u4_idx++;
1960
187
    if(u1_tran_form8x8)
1961
0
    {
1962
0
        if(!u1_mb_field_decodingflag)
1963
0
        {
1964
0
            ps_dec->pu1_inv_scan =
1965
0
                            (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[1];
1966
0
        }
1967
0
        else
1968
0
        {
1969
0
            ps_dec->pu1_inv_scan =
1970
0
                            (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[1];
1971
0
        }
1972
0
    }
1973
187
    else
1974
187
    {
1975
187
        pi2_coeff_block += NUM_COEFFS_IN_4x4BLK;
1976
187
    }
1977
187
    u4_n = u4_num_coeff;
1978
187
    ret = pf_cavlc_parse4x4coeff[(u4_n > 7)](pi2_coeff_block, u4_isdc,
1979
187
                                             u4_n, ps_dec, &u4_num_coeff);
1980
187
    if(ret != OK)
1981
187
        return ret;
1982
187
1983
187
    u4_top1 = pu1_left_nnz[0] = u4_num_coeff;
1984
187
    u4_subblock_coded = (u4_num_coeff != 0);
1985
187
    INSERT_BIT(*pu4_csbp, u4_idx, u4_subblock_coded);
1986
187
1987
187
    /*------------------------------------------------------*/
1988
187
    /* Residual 4x4 decoding: SubBlock 2                    */
1989
187
    /*------------------------------------------------------*/
1990
187
    u4_idx += (u4_sub_block_strd - 1);
1991
187
    if(u1_tran_form8x8)
1992
0
    {
1993
0
        if(!u1_mb_field_decodingflag)
1994
0
        {
1995
0
            ps_dec->pu1_inv_scan =
1996
0
                            (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[2];
1997
0
        }
1998
0
        else
1999
0
        {
2000
0
            ps_dec->pu1_inv_scan =
2001
0
                            (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[2];
2002
0
        }
2003
0
    }
2004
187
    else
2005
187
    {
2006
187
        pi2_coeff_block += ((u4_sub_block_strd - 1) * NUM_COEFFS_IN_4x4BLK);
2007
187
    }
2008
187
    u4_n = (u4_top0 + pu1_left_nnz[1] + 1) >> 1;
2009
187
    ret = pf_cavlc_parse4x4coeff[(u4_n > 7)](pi2_coeff_block, u4_isdc,
2010
187
                                             u4_n, ps_dec, &u4_num_coeff);
2011
187
    if(ret != OK)
2012
187
        return ret;
2013
187
2014
187
    pu1_top_nnz[0] = u4_num_coeff;
2015
187
    u4_subblock_coded = (u4_num_coeff != 0);
2016
187
    INSERT_BIT(*pu4_csbp, u4_idx, u4_subblock_coded);
2017
187
2018
187
    /*------------------------------------------------------*/
2019
187
    /* Residual 4x4 decoding: SubBlock 3                    */
2020
187
    /*------------------------------------------------------*/
2021
187
    u4_idx++;
2022
187
    if(u1_tran_form8x8)
2023
0
    {
2024
0
        if(!u1_mb_field_decodingflag)
2025
0
        {
2026
0
            ps_dec->pu1_inv_scan =
2027
0
                            (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[3];
2028
0
        }
2029
0
        else
2030
0
        {
2031
0
            ps_dec->pu1_inv_scan =
2032
0
                            (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[3];
2033
0
        }
2034
0
    }
2035
187
    else
2036
187
    {
2037
187
        pi2_coeff_block += NUM_COEFFS_IN_4x4BLK;
2038
187
    }
2039
187
    u4_n = (u4_top1 + u4_num_coeff + 1) >> 1;
2040
187
    ret = pf_cavlc_parse4x4coeff[(u4_n > 7)](pi2_coeff_block, u4_isdc,
2041
187
                                             u4_n, ps_dec, &u4_num_coeff);
2042
187
    if(ret != OK)
2043
187
        return ret;
2044
187
2045
187
    pu1_top_nnz[1] = pu1_left_nnz[1] = u4_num_coeff;
2046
187
    u4_subblock_coded = (u4_num_coeff != 0);
2047
187
    INSERT_BIT(*pu4_csbp, u4_idx, u4_subblock_coded);
2048
187
2049
187
    ps_dec->pu1_inv_scan = puc_temp;
2050
187
2051
187
    return OK;
2052
187
}
2053
2054
/*****************************************************************************/
2055
/*                                                                           */
2056
/*  Function Name : ih264d_cavlc_parse_8x8block_top_available                       */
2057
/*                                                                           */
2058
/*  Description   : This function does the residual parsing of 4 subblocks   */
2059
/*                  in a 8x8 block when only top is available for block      */
2060
/*                                                                           */
2061
/*  Inputs        : pi2_coeff_block : pointer to residual block where        */
2062
/*                  decoded and inverse scan coefficients are updated        */
2063
/*                                                                           */
2064
/*                  u4_sub_block_strd : indicates the number of sublocks    */
2065
/*                  in a row. It is 4 for luma and 2 for chroma.             */
2066
/*                                                                           */
2067
/*                  u4_isdc : required to indicate 4x4 parse modules if the  */
2068
/*                  current  Mb is I_16x16/chroma DC coded.                  */
2069
/*                                                                           */
2070
/*                  ps_dec : pointer to Decstruct (decoder context)          */
2071
/*                                                                           */
2072
/*                  pu1_top_nnz : top nnz pointer                            */
2073
/*                                                                           */
2074
/*                  pu1_left_nnz : left nnz pointer                          */
2075
/*                                                                           */
2076
/*  Globals       : No                                                       */
2077
/*  Processing    : Parsing for four subblocks in unrolled, top and left nnz */
2078
/*                  are updated on the fly. csbp is set in accordance to     */
2079
/*                  decoded numcoeff for the subblock index in raster order  */
2080
/*                                                                           */
2081
/*  Outputs       : The updated residue buffer, nnzs and csbp current block  */
2082
/*                                                                           */
2083
/*  Returns       : Returns the coded sub block pattern csbp for the block   */
2084
/*                                                                           */
2085
/*  Issues        : <List any issues or problems with this function>         */
2086
/*                                                                           */
2087
/*  Revision History:                                                        */
2088
/*                                                                           */
2089
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
2090
/*         09 10 2008   Jay          Draft                                   */
2091
/*                                                                           */
2092
/*****************************************************************************/
2093
WORD32 ih264d_cavlc_parse_8x8block_top_available(WORD16 *pi2_coeff_block,
2094
                                                 UWORD32 u4_sub_block_strd,
2095
                                                 UWORD32 u4_isdc,
2096
                                                 dec_struct_t * ps_dec,
2097
                                                 UWORD8 *pu1_top_nnz,
2098
                                                 UWORD8 *pu1_left_nnz,
2099
                                                 UWORD8 u1_tran_form8x8,
2100
                                                 UWORD8 u1_mb_field_decodingflag,
2101
                                                 UWORD32 *pu4_csbp)
2102
198
{
2103
198
    UWORD32 u4_num_coeff, u4_n, u4_subblock_coded;
2104
198
    UWORD32 u4_top0, u4_top1;
2105
198
    UWORD32 *pu4_dummy;
2106
198
    WORD32 (**pf_cavlc_parse4x4coeff)(WORD16 *pi2_coeff_block,
2107
198
                                      UWORD32 u4_isdc,
2108
198
                                      WORD32 u4_n,
2109
198
                                      struct _DecStruct *ps_dec,
2110
198
                                      UWORD32 *pu4_dummy) =
2111
198
                                      ps_dec->pf_cavlc_parse4x4coeff;
2112
198
    UWORD32 u4_idx = 0;
2113
198
    UWORD8 *puc_temp;
2114
198
    WORD32 ret;
2115
198
2116
198
    *pu4_csbp = 0;
2117
198
    puc_temp = ps_dec->pu1_inv_scan;
2118
198
2119
198
    /*------------------------------------------------------*/
2120
198
    /* Residual 4x4 decoding: SubBlock 0                    */
2121
198
    /*------------------------------------------------------*/
2122
198
    if(u1_tran_form8x8)
2123
0
    {
2124
0
        if(!u1_mb_field_decodingflag)
2125
0
        {
2126
0
            ps_dec->pu1_inv_scan =
2127
0
                            (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[0];
2128
0
        }
2129
0
        else
2130
0
        {
2131
0
            ps_dec->pu1_inv_scan =
2132
0
                            (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[0];
2133
0
        }
2134
0
    }
2135
198
    u4_n = pu1_top_nnz[0];
2136
198
    ret = pf_cavlc_parse4x4coeff[(u4_n > 7)](pi2_coeff_block, u4_isdc,
2137
198
                                             u4_n, ps_dec, &u4_num_coeff);
2138
198
    if(ret != OK)
2139
198
        return ret;
2140
198
2141
198
    u4_top0 = u4_num_coeff;
2142
198
    u4_subblock_coded = (u4_num_coeff != 0);
2143
198
    INSERT_BIT(*pu4_csbp, u4_idx, u4_subblock_coded);
2144
198
2145
198
    /*------------------------------------------------------*/
2146
198
    /* Residual 4x4 decoding: SubBlock 1                    */
2147
198
    /*------------------------------------------------------*/
2148
198
    u4_idx++;
2149
198
    if(u1_tran_form8x8)
2150
0
    {
2151
0
        if(!u1_mb_field_decodingflag)
2152
0
        {
2153
0
            ps_dec->pu1_inv_scan =
2154
0
                            (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[1];
2155
0
        }
2156
0
        else
2157
0
        {
2158
0
            ps_dec->pu1_inv_scan =
2159
0
                            (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[1];
2160
0
        }
2161
0
    }
2162
198
    else
2163
198
    {
2164
198
        pi2_coeff_block += NUM_COEFFS_IN_4x4BLK;
2165
198
    }
2166
198
    u4_n = (pu1_top_nnz[1] + u4_num_coeff + 1) >> 1;
2167
198
    ret = pf_cavlc_parse4x4coeff[(u4_n > 7)](pi2_coeff_block, u4_isdc,
2168
198
                                             u4_n, ps_dec, &u4_num_coeff);
2169
198
    if(ret != OK)
2170
198
        return ret;
2171
198
2172
198
    u4_top1 = pu1_left_nnz[0] = u4_num_coeff;
2173
198
    u4_subblock_coded = (u4_num_coeff != 0);
2174
198
    INSERT_BIT(*pu4_csbp, u4_idx, u4_subblock_coded);
2175
198
2176
198
    /*------------------------------------------------------*/
2177
198
    /* Residual 4x4 decoding: SubBlock 2                    */
2178
198
    /*------------------------------------------------------*/
2179
198
    u4_idx += (u4_sub_block_strd - 1);
2180
198
    if(u1_tran_form8x8)
2181
0
    {
2182
0
        if(!u1_mb_field_decodingflag)
2183
0
        {
2184
0
            ps_dec->pu1_inv_scan =
2185
0
                            (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[2];
2186
0
        }
2187
0
        else
2188
0
        {
2189
0
            ps_dec->pu1_inv_scan =
2190
0
                            (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[2];
2191
0
        }
2192
0
    }
2193
198
    else
2194
198
    {
2195
198
        pi2_coeff_block += ((u4_sub_block_strd - 1) * NUM_COEFFS_IN_4x4BLK);
2196
198
    }
2197
198
    u4_n = u4_top0;
2198
198
    ret = pf_cavlc_parse4x4coeff[(u4_n > 7)](pi2_coeff_block, u4_isdc,
2199
198
                                             u4_n, ps_dec, &u4_num_coeff);
2200
198
    if(ret != OK)
2201
198
        return ret;
2202
198
2203
198
    pu1_top_nnz[0] = u4_num_coeff;
2204
198
    u4_subblock_coded = (u4_num_coeff != 0);
2205
198
    INSERT_BIT(*pu4_csbp, u4_idx, u4_subblock_coded);
2206
198
2207
198
    /*------------------------------------------------------*/
2208
198
    /* Residual 4x4 decoding: SubBlock 3                    */
2209
198
    /*------------------------------------------------------*/
2210
198
    u4_idx++;
2211
198
    if(u1_tran_form8x8)
2212
0
    {
2213
0
        if(!u1_mb_field_decodingflag)
2214
0
        {
2215
0
            ps_dec->pu1_inv_scan =
2216
0
                            (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[3];
2217
0
        }
2218
0
        else
2219
0
        {
2220
0
            ps_dec->pu1_inv_scan =
2221
0
                            (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[3];
2222
0
        }
2223
0
    }
2224
198
    else
2225
198
    {
2226
198
        pi2_coeff_block += NUM_COEFFS_IN_4x4BLK;
2227
198
    }
2228
198
    u4_n = (u4_top1 + u4_num_coeff + 1) >> 1;
2229
198
    ret = pf_cavlc_parse4x4coeff[(u4_n > 7)](pi2_coeff_block, u4_isdc,
2230
198
                                             u4_n, ps_dec, &u4_num_coeff);
2231
198
    if(ret != OK)
2232
198
        return ret;
2233
198
2234
198
    pu1_top_nnz[1] = pu1_left_nnz[1] = u4_num_coeff;
2235
198
    u4_subblock_coded = (u4_num_coeff != 0);
2236
198
    INSERT_BIT(*pu4_csbp, u4_idx, u4_subblock_coded);
2237
198
2238
198
    ps_dec->pu1_inv_scan = puc_temp;
2239
198
2240
198
    return OK;
2241
198
}
2242
2243
/*****************************************************************************/
2244
/*                                                                           */
2245
/*  Function Name : ih264d_cavlc_parse_8x8block_none_available                      */
2246
/*                                                                           */
2247
/*  Description   : This function does the residual parsing of 4 subblocks   */
2248
/*                  in a 8x8 block when none of the neigbours are available  */
2249
/*                                                                           */
2250
/*  Inputs        : pi2_coeff_block : pointer to residual block where        */
2251
/*                  decoded and inverse scan coefficients are updated        */
2252
/*                                                                           */
2253
/*                  u4_sub_block_strd : indicates the number of sublocks    */
2254
/*                  in a row. It is 4 for luma and 2 for chroma.             */
2255
/*                                                                           */
2256
/*                  u4_isdc : required to indicate 4x4 parse modules if the  */
2257
/*                  current  Mb is I_16x16/chroma DC coded.                  */
2258
/*                                                                           */
2259
/*                  ps_dec : pointer to Decstruct (decoder context)          */
2260
/*                                                                           */
2261
/*                  pu1_top_nnz : top nnz pointer                            */
2262
/*                                                                           */
2263
/*                  pu1_left_nnz : left nnz pointer                          */
2264
/*                                                                           */
2265
/*  Globals       : No                                                       */
2266
/*  Processing    : Parsing for four subblocks in unrolled, top and left nnz */
2267
/*                  are updated on the fly. csbp is set in accordance to     */
2268
/*                  decoded numcoeff for the subblock index in raster order  */
2269
/*                                                                           */
2270
/*  Outputs       : The updated residue buffer, nnzs and csbp current block  */
2271
/*                                                                           */
2272
/*  Returns       : Returns the coded sub block pattern csbp for the block   */
2273
/*                                                                           */
2274
/*  Issues        : <List any issues or problems with this function>         */
2275
/*                                                                           */
2276
/*  Revision History:                                                        */
2277
/*                                                                           */
2278
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
2279
/*         09 10 2008   Jay          Draft                                   */
2280
/*                                                                           */
2281
/*****************************************************************************/
2282
WORD32 ih264d_cavlc_parse_8x8block_none_available(WORD16 *pi2_coeff_block,
2283
                                                  UWORD32 u4_sub_block_strd,
2284
                                                  UWORD32 u4_isdc,
2285
                                                  dec_struct_t * ps_dec,
2286
                                                  UWORD8 *pu1_top_nnz,
2287
                                                  UWORD8 *pu1_left_nnz,
2288
                                                  UWORD8 u1_tran_form8x8,
2289
                                                  UWORD8 u1_mb_field_decodingflag,
2290
                                                  UWORD32 *pu4_csbp)
2291
33
{
2292
33
    UWORD32 u4_num_coeff, u4_n, u4_subblock_coded;
2293
33
    UWORD32 u4_top0, u4_top1;
2294
33
    UWORD32 *pu4_dummy;
2295
33
    WORD32 (**pf_cavlc_parse4x4coeff)(WORD16 *pi2_coeff_block,
2296
33
                                      UWORD32 u4_isdc,
2297
33
                                      WORD32 u4_n,
2298
33
                                      struct _DecStruct *ps_dec,
2299
33
                                      UWORD32 *pu4_dummy) =
2300
33
                                      ps_dec->pf_cavlc_parse4x4coeff;
2301
33
    UWORD32 u4_idx = 0;
2302
33
    UWORD8 *puc_temp;
2303
33
    WORD32 ret;
2304
33
2305
33
    *pu4_csbp = 0;
2306
33
    puc_temp = ps_dec->pu1_inv_scan;
2307
33
2308
33
    /*------------------------------------------------------*/
2309
33
    /* Residual 4x4 decoding: SubBlock 0                    */
2310
33
    /*------------------------------------------------------*/
2311
33
    if(u1_tran_form8x8)
2312
0
    {
2313
0
        if(!u1_mb_field_decodingflag)
2314
0
        {
2315
0
            ps_dec->pu1_inv_scan =
2316
0
                            (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[0];
2317
0
        }
2318
0
        else
2319
0
        {
2320
0
            ps_dec->pu1_inv_scan =
2321
0
                            (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[0];
2322
0
        }
2323
0
    }
2324
33
    ret = pf_cavlc_parse4x4coeff[0](pi2_coeff_block, u4_isdc, 0,
2325
33
                                    ps_dec, &u4_num_coeff);
2326
33
    if(ret != OK)
2327
33
        return ret;
2328
33
2329
33
    u4_top0 = u4_num_coeff;
2330
33
    u4_subblock_coded = (u4_num_coeff != 0);
2331
33
    INSERT_BIT(*pu4_csbp, u4_idx, u4_subblock_coded);
2332
33
2333
33
    /*------------------------------------------------------*/
2334
33
    /* Residual 4x4 decoding: SubBlock 1                    */
2335
33
    /*------------------------------------------------------*/
2336
33
    u4_idx++;
2337
33
    if(u1_tran_form8x8)
2338
0
    {
2339
0
        if(!u1_mb_field_decodingflag)
2340
0
        {
2341
0
            ps_dec->pu1_inv_scan =
2342
0
                            (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[1];
2343
0
        }
2344
0
        else
2345
0
        {
2346
0
            ps_dec->pu1_inv_scan =
2347
0
                            (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[1];
2348
0
        }
2349
0
    }
2350
33
    else
2351
33
    {
2352
33
        pi2_coeff_block += NUM_COEFFS_IN_4x4BLK;
2353
33
    }
2354
33
    u4_n = u4_num_coeff;
2355
33
    ret = pf_cavlc_parse4x4coeff[(u4_n > 7)](pi2_coeff_block, u4_isdc,
2356
33
                                             u4_n, ps_dec, &u4_num_coeff);
2357
33
    if(ret != OK)
2358
33
        return ret;
2359
33
2360
33
    u4_top1 = pu1_left_nnz[0] = u4_num_coeff;
2361
33
    u4_subblock_coded = (u4_num_coeff != 0);
2362
33
    INSERT_BIT(*pu4_csbp, u4_idx, u4_subblock_coded);
2363
33
2364
33
    /*------------------------------------------------------*/
2365
33
    /* Residual 4x4 decoding: SubBlock 2                    */
2366
33
    /*------------------------------------------------------*/
2367
33
    u4_idx += (u4_sub_block_strd - 1);
2368
33
    if(u1_tran_form8x8)
2369
0
    {
2370
0
        if(!u1_mb_field_decodingflag)
2371
0
        {
2372
0
            ps_dec->pu1_inv_scan =
2373
0
                            (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[2];
2374
0
        }
2375
0
        else
2376
0
        {
2377
0
            ps_dec->pu1_inv_scan =
2378
0
                            (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[2];
2379
0
        }
2380
0
    }
2381
33
    else
2382
33
    {
2383
33
        pi2_coeff_block += ((u4_sub_block_strd - 1) * NUM_COEFFS_IN_4x4BLK);
2384
33
    }
2385
33
    u4_n = u4_top0;
2386
33
    ret = pf_cavlc_parse4x4coeff[(u4_n > 7)](pi2_coeff_block, u4_isdc,
2387
33
                                             u4_n, ps_dec, &u4_num_coeff);
2388
33
    if(ret != OK)
2389
33
        return ret;
2390
33
2391
33
    pu1_top_nnz[0] = u4_num_coeff;
2392
33
    u4_subblock_coded = (u4_num_coeff != 0);
2393
33
    INSERT_BIT(*pu4_csbp, u4_idx, u4_subblock_coded);
2394
33
2395
33
    /*------------------------------------------------------*/
2396
33
    /* Residual 4x4 decoding: SubBlock 3                    */
2397
33
    /*------------------------------------------------------*/
2398
33
    u4_idx++;
2399
33
    if(u1_tran_form8x8)
2400
0
    {
2401
0
        if(!u1_mb_field_decodingflag)
2402
0
        {
2403
0
            ps_dec->pu1_inv_scan =
2404
0
                            (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[3];
2405
0
        }
2406
0
        else
2407
0
        {
2408
0
            ps_dec->pu1_inv_scan =
2409
0
                            (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[3];
2410
0
        }
2411
0
    }
2412
33
    else
2413
33
    {
2414
33
        pi2_coeff_block += NUM_COEFFS_IN_4x4BLK;
2415
33
    }
2416
33
    u4_n = (u4_top1 + u4_num_coeff + 1) >> 1;
2417
33
    ret = pf_cavlc_parse4x4coeff[(u4_n > 7)](pi2_coeff_block, u4_isdc,
2418
33
                                             u4_n, ps_dec, &u4_num_coeff);
2419
33
    if(ret != OK)
2420
33
        return ret;
2421
33
2422
33
    pu1_top_nnz[1] = pu1_left_nnz[1] = u4_num_coeff;
2423
33
    u4_subblock_coded = (u4_num_coeff != 0);
2424
33
    INSERT_BIT(*pu4_csbp, u4_idx, u4_subblock_coded);
2425
33
2426
33
    ps_dec->pu1_inv_scan = puc_temp;
2427
33
2428
33
    return OK;
2429
33
}
2430
2431
/*!
2432
 **************************************************************************
2433
 * \if Function name : ih264d_parse_residual4x4_cavlc \endif
2434
 *
2435
 * \brief
2436
 *    This function parses CAVLC syntax of a Luma and Chroma AC Residuals.
2437
 *
2438
 * \return
2439
 *    0 on Success and Error code otherwise
2440
 **************************************************************************
2441
 */
2442
2443
WORD32 ih264d_parse_residual4x4_cavlc(dec_struct_t * ps_dec,
2444
                                      dec_mb_info_t *ps_cur_mb_info,
2445
                                      UWORD8 u1_offset)
2446
2.87k
{
2447
2.87k
    UWORD8 u1_cbp = ps_cur_mb_info->u1_cbp;
2448
2.87k
    UWORD16 ui16_csbp = 0;
2449
2.87k
    UWORD32 u4_nbr_avl;
2450
2.87k
    WORD16 *pi2_residual_buf;
2451
2.87k
2452
2.87k
    UWORD8 u1_is_top_mb_avail;
2453
2.87k
    UWORD8 u1_is_left_mb_avail;
2454
2.87k
2455
2.87k
    UWORD8 *pu1_top_nnz = ps_cur_mb_info->ps_curmb->pu1_nnz_y;
2456
2.87k
    UWORD8 *pu1_left_nnz = ps_dec->pu1_left_nnz_y;
2457
2.87k
    WORD16 *pi2_coeff_block = NULL;
2458
2.87k
    UWORD32 *pu4_dummy;
2459
2.87k
    WORD32 ret;
2460
2.87k
2461
2.87k
    WORD32 (**pf_cavlc_parse_8x8block)(WORD16 *pi2_coeff_block,
2462
2.87k
                                       UWORD32 u4_sub_block_strd,
2463
2.87k
                                       UWORD32 u4_isdc,
2464
2.87k
                                       struct _DecStruct *ps_dec,
2465
2.87k
                                       UWORD8 *pu1_top_nnz,
2466
2.87k
                                       UWORD8 *pu1_left_nnz,
2467
2.87k
                                       UWORD8 u1_tran_form8x8,
2468
2.87k
                                       UWORD8 u1_mb_field_decodingflag,
2469
2.87k
                                       UWORD32 *pu4_dummy) = ps_dec->pf_cavlc_parse_8x8block;
2470
2.87k
2471
2.87k
2472
2.87k
    {
2473
2.87k
        UWORD8 uc_temp = ps_dec->u1_mb_ngbr_availablity;
2474
2.87k
        u1_is_top_mb_avail = BOOLEAN(uc_temp & TOP_MB_AVAILABLE_MASK);
2475
2.87k
        u1_is_left_mb_avail = BOOLEAN(uc_temp & LEFT_MB_AVAILABLE_MASK);
2476
2.87k
        u4_nbr_avl = (u1_is_top_mb_avail << 1) | u1_is_left_mb_avail;
2477
2.87k
    }
2478
2.87k
2479
2.87k
    ps_cur_mb_info->u1_qp_div6 = ps_dec->u1_qp_y_div6;
2480
2.87k
    ps_cur_mb_info->u1_qp_rem6 = ps_dec->u1_qp_y_rem6;
2481
2.87k
    ps_cur_mb_info->u1_qpc_div6 = ps_dec->u1_qp_u_div6;
2482
2.87k
    ps_cur_mb_info->u1_qpc_rem6 = ps_dec->u1_qp_u_rem6;
2483
2.87k
    ps_cur_mb_info->u1_qpcr_div6 = ps_dec->u1_qp_v_div6;
2484
2.87k
    ps_cur_mb_info->u1_qpcr_rem6 = ps_dec->u1_qp_v_rem6;
2485
2.87k
2486
2.87k
    if(u1_cbp & 0xf)
2487
2.61k
    {
2488
2.61k
        pu1_top_nnz[0] = ps_cur_mb_info->ps_top_mb->pu1_nnz_y[0];
2489
2.61k
        pu1_top_nnz[1] = ps_cur_mb_info->ps_top_mb->pu1_nnz_y[1];
2490
2.61k
        pu1_top_nnz[2] = ps_cur_mb_info->ps_top_mb->pu1_nnz_y[2];
2491
2.61k
        pu1_top_nnz[3] = ps_cur_mb_info->ps_top_mb->pu1_nnz_y[3];
2492
2.61k
2493
2.61k
        /*******************************************************************/
2494
2.61k
        /* Block 0 residual decoding, check cbp and proceed (subblock = 0) */
2495
2.61k
        /*******************************************************************/
2496
2.61k
        if(!(u1_cbp & 0x1))
2497
1.05k
        {
2498
1.05k
            *(UWORD16 *)(pu1_top_nnz) = 0;
2499
1.05k
            *(UWORD16 *)(pu1_left_nnz) = 0;
2500
1.05k
2501
1.05k
        }
2502
1.56k
        else
2503
1.56k
        {
2504
1.56k
            UWORD32 u4_temp;
2505
1.56k
            ret = pf_cavlc_parse_8x8block[u4_nbr_avl](
2506
1.56k
                        pi2_coeff_block, 4, u1_offset, ps_dec, pu1_top_nnz,
2507
1.56k
                        pu1_left_nnz, ps_cur_mb_info->u1_tran_form8x8,
2508
1.56k
                        ps_cur_mb_info->u1_mb_field_decodingflag, &u4_temp);
2509
1.56k
            if(ret != OK)
2510
1.56k
                return ret;
2511
1.56k
            ui16_csbp = u4_temp;
2512
1.56k
        }
2513
2.61k
2514
2.61k
        /*******************************************************************/
2515
2.61k
        /* Block 1 residual decoding, check cbp and proceed (subblock = 2) */
2516
2.61k
        /*******************************************************************/
2517
2.61k
        if(ps_cur_mb_info->u1_tran_form8x8)
2518
0
        {
2519
0
            pi2_coeff_block += 64;
2520
0
        }
2521
2.61k
        else
2522
2.61k
        {
2523
2.61k
            pi2_coeff_block += (2 * NUM_COEFFS_IN_4x4BLK);
2524
2.61k
        }
2525
2.61k
2526
2.61k
        if(!(u1_cbp & 0x2))
2527
1.14k
        {
2528
1.14k
            *(UWORD16 *)(pu1_top_nnz + 2) = 0;
2529
1.14k
            *(UWORD16 *)(pu1_left_nnz) = 0;
2530
1.14k
        }
2531
1.47k
        else
2532
1.47k
        {
2533
1.47k
            UWORD32 u4_temp = (u4_nbr_avl | 0x1);
2534
1.47k
            ret = pf_cavlc_parse_8x8block[u4_temp](
2535
1.47k
                        pi2_coeff_block, 4, u1_offset, ps_dec,
2536
1.47k
                        (pu1_top_nnz + 2), pu1_left_nnz,
2537
1.47k
                        ps_cur_mb_info->u1_tran_form8x8,
2538
1.47k
                        ps_cur_mb_info->u1_mb_field_decodingflag, &u4_temp);
2539
1.47k
            if(ret != OK)
2540
1.47k
                return ret;
2541
1.47k
            ui16_csbp |= (u4_temp << 2);
2542
1.47k
        }
2543
2.61k
2544
2.61k
        /*******************************************************************/
2545
2.61k
        /* Block 2 residual decoding, check cbp and proceed (subblock = 8) */
2546
2.61k
        /*******************************************************************/
2547
2.61k
        if(ps_cur_mb_info->u1_tran_form8x8)
2548
0
        {
2549
0
            pi2_coeff_block += 64;
2550
0
        }
2551
2.61k
        else
2552
2.61k
        {
2553
2.61k
            pi2_coeff_block += (6 * NUM_COEFFS_IN_4x4BLK);
2554
2.61k
        }
2555
2.61k
2556
2.61k
        if(!(u1_cbp & 0x4))
2557
935
        {
2558
935
            *(UWORD16 *)(pu1_top_nnz) = 0;
2559
935
            *(UWORD16 *)(pu1_left_nnz + 2) = 0;
2560
935
        }
2561
1.68k
        else
2562
1.68k
        {
2563
1.68k
            UWORD32 u4_temp = (u4_nbr_avl | 0x2);
2564
1.68k
            ret = pf_cavlc_parse_8x8block[u4_temp](
2565
1.68k
                        pi2_coeff_block, 4, u1_offset, ps_dec, pu1_top_nnz,
2566
1.68k
                        (pu1_left_nnz + 2), ps_cur_mb_info->u1_tran_form8x8,
2567
1.68k
                        ps_cur_mb_info->u1_mb_field_decodingflag, &u4_temp);
2568
1.68k
            if(ret != OK)
2569
1.68k
                return ret;
2570
1.68k
            ui16_csbp |= (u4_temp << 8);
2571
1.68k
        }
2572
2.61k
2573
2.61k
        /*******************************************************************/
2574
2.61k
        /* Block 3 residual decoding, check cbp and proceed (subblock = 10)*/
2575
2.61k
        /*******************************************************************/
2576
2.61k
        if(ps_cur_mb_info->u1_tran_form8x8)
2577
0
        {
2578
0
            pi2_coeff_block += 64;
2579
0
        }
2580
2.61k
        else
2581
2.61k
        {
2582
2.61k
            pi2_coeff_block += (2 * NUM_COEFFS_IN_4x4BLK);
2583
2.61k
        }
2584
2.61k
2585
2.61k
        if(!(u1_cbp & 0x8))
2586
913
        {
2587
913
            *(UWORD16 *)(pu1_top_nnz + 2) = 0;
2588
913
            *(UWORD16 *)(pu1_left_nnz + 2) = 0;
2589
913
        }
2590
1.70k
        else
2591
1.70k
        {
2592
1.70k
            UWORD32 u4_temp;
2593
1.70k
            ret = pf_cavlc_parse_8x8block[0x3](
2594
1.70k
                        pi2_coeff_block, 4, u1_offset, ps_dec,
2595
1.70k
                        (pu1_top_nnz + 2), (pu1_left_nnz + 2),
2596
1.70k
                        ps_cur_mb_info->u1_tran_form8x8,
2597
1.70k
                        ps_cur_mb_info->u1_mb_field_decodingflag, &u4_temp);
2598
1.70k
            if(ret != OK)
2599
1.70k
                return ret;
2600
1.70k
            ui16_csbp |= (u4_temp << 10);
2601
1.70k
        }
2602
2.61k
    }
2603
253
    else
2604
253
    {
2605
253
        *(UWORD32 *)(pu1_top_nnz) = 0;
2606
253
        *(UWORD32 *)(pu1_left_nnz) = 0;
2607
253
    }
2608
2.87k
2609
2.87k
    ps_cur_mb_info->u2_luma_csbp = ui16_csbp;
2610
2.87k
    ps_cur_mb_info->ps_curmb->u2_luma_csbp = ui16_csbp;
2611
2.87k
2612
2.87k
    {
2613
2.87k
        UWORD16 u2_chroma_csbp = 0;
2614
2.87k
        ps_cur_mb_info->u2_chroma_csbp = 0;
2615
2.87k
        pu1_top_nnz = ps_cur_mb_info->ps_curmb->pu1_nnz_uv;
2616
2.87k
        pu1_left_nnz = ps_dec->pu1_left_nnz_uv;
2617
2.87k
2618
2.87k
        u1_cbp >>= 4;
2619
2.87k
        /*--------------------------------------------------------------------*/
2620
2.87k
        /* if Chroma Component not present OR no ac values present            */
2621
2.87k
        /* Set the values of N to zero                                        */
2622
2.87k
        /*--------------------------------------------------------------------*/
2623
2.87k
        if(u1_cbp == CBPC_ALLZERO || u1_cbp == CBPC_ACZERO)
2624
2.87k
        {
2625
682
            *(UWORD32 *)(pu1_top_nnz) = 0;
2626
682
            *(UWORD32 *)(pu1_left_nnz) = 0;
2627
682
        }
2628
2.87k
2629
2.87k
        if(u1_cbp == CBPC_ALLZERO)
2630
2.87k
        {
2631
682
            return (0);
2632
682
        }
2633
2.18k
        /*--------------------------------------------------------------------*/
2634
2.18k
        /* Decode Chroma DC values                                            */
2635
2.18k
        /*--------------------------------------------------------------------*/
2636
2.18k
        {
2637
2.18k
            WORD32 u4_scale_u;
2638
2.18k
            WORD32 u4_scale_v;
2639
2.18k
            WORD32 i4_mb_inter_inc;
2640
2.18k
            u4_scale_u = ps_dec->pu2_quant_scale_u[0] << ps_dec->u1_qp_u_div6;
2641
2.18k
            u4_scale_v = ps_dec->pu2_quant_scale_v[0] << ps_dec->u1_qp_v_div6;
2642
2.18k
            i4_mb_inter_inc = (!((ps_cur_mb_info->ps_curmb->u1_mb_type == I_4x4_MB)
2643
2.18k
                            || (ps_cur_mb_info->ps_curmb->u1_mb_type == I_16x16_MB)))
2644
2.18k
                            * 3;
2645
2.18k
2646
2.18k
            if(ps_dec->s_high_profile.u1_scaling_present)
2647
0
            {
2648
0
                u4_scale_u *=
2649
0
                                ps_dec->s_high_profile.i2_scalinglist4x4[i4_mb_inter_inc
2650
0
                                                + 1][0];
2651
0
                u4_scale_v *=
2652
0
                                ps_dec->s_high_profile.i2_scalinglist4x4[i4_mb_inter_inc
2653
0
                                                + 2][0];
2654
0
2655
0
            }
2656
2.18k
            else
2657
2.18k
            {
2658
2.18k
                u4_scale_u <<= 4;
2659
2.18k
                u4_scale_v <<= 4;
2660
2.18k
            }
2661
2.18k
2662
2.18k
            ih264d_cavlc_parse_chroma_dc(ps_cur_mb_info,pi2_coeff_block, ps_dec->ps_bitstrm,
2663
2.18k
                                         u4_scale_u, u4_scale_v,
2664
2.18k
                                         i4_mb_inter_inc);
2665
2.18k
        }
2666
2.18k
2667
2.18k
        if(u1_cbp == CBPC_ACZERO)
2668
2.18k
            return (0);
2669
2.18k
2670
2.18k
        pu1_top_nnz[0] = ps_cur_mb_info->ps_top_mb->pu1_nnz_uv[0];
2671
2.18k
        pu1_top_nnz[1] = ps_cur_mb_info->ps_top_mb->pu1_nnz_uv[1];
2672
2.18k
        pu1_top_nnz[2] = ps_cur_mb_info->ps_top_mb->pu1_nnz_uv[2];
2673
2.18k
        pu1_top_nnz[3] = ps_cur_mb_info->ps_top_mb->pu1_nnz_uv[3];
2674
2.18k
        /*--------------------------------------------------------------------*/
2675
2.18k
        /* Decode Chroma AC values                                            */
2676
2.18k
        /*--------------------------------------------------------------------*/
2677
2.18k
        {
2678
2.18k
            UWORD32 u4_temp;
2679
2.18k
            /*****************************************************************/
2680
2.18k
            /* U Block  residual decoding, check cbp and proceed (subblock=0)*/
2681
2.18k
            /*****************************************************************/
2682
2.18k
            ret = pf_cavlc_parse_8x8block[u4_nbr_avl](
2683
2.18k
                        pi2_coeff_block, 2, 1, ps_dec, pu1_top_nnz,
2684
2.18k
                        pu1_left_nnz, 0, 0, &u4_temp);
2685
2.18k
            if(ret != OK)
2686
2.18k
                return ret;
2687
2.18k
            u2_chroma_csbp = u4_temp;
2688
2.18k
2689
2.18k
            pi2_coeff_block += MB_CHROM_SIZE;
2690
2.18k
            /*****************************************************************/
2691
2.18k
            /* V Block  residual decoding, check cbp and proceed (subblock=1)*/
2692
2.18k
            /*****************************************************************/
2693
2.18k
            ret = pf_cavlc_parse_8x8block[u4_nbr_avl](pi2_coeff_block, 2, 1,
2694
2.18k
                                                      ps_dec,
2695
2.18k
                                                      (pu1_top_nnz + 2),
2696
2.18k
                                                      (pu1_left_nnz + 2), 0,
2697
2.18k
                                                      0, &u4_temp);
2698
2.18k
            if(ret != OK)
2699
2.18k
                return ret;
2700
2.18k
            u2_chroma_csbp |= (u4_temp << 4);
2701
2.18k
        }
2702
2.18k
2703
2.18k
        ps_cur_mb_info->u2_chroma_csbp = u2_chroma_csbp;
2704
2.18k
    }
2705
2.18k
    return OK;
2706
2.18k
}
/proc/self/cwd/external/libavc/decoder/ih264d_parse_headers.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/*!
21
 **************************************************************************
22
 * \file ih264d_parse_headers.c
23
 *
24
 * \brief
25
 *    Contains High level syntax[above slice] parsing routines
26
 *
27
 * \date
28
 *    19/12/2002
29
 *
30
 * \author  AI
31
 **************************************************************************
32
 */
33
#include <string.h>
34
35
#include "ih264_typedefs.h"
36
#include "ih264_macros.h"
37
#include "ih264_platform_macros.h"
38
#include "ih264d_bitstrm.h"
39
#include "ih264d_structs.h"
40
#include "ih264d_parse_cavlc.h"
41
#include "ih264d_defs.h"
42
#include "ih264d_defs.h"
43
#include "ih264d_defs.h"
44
#include "ih264d_parse_slice.h"
45
#include "ih264d_tables.h"
46
#include "ih264d_utils.h"
47
#include "ih264d_nal.h"
48
#include "ih264d_deblocking.h"
49
50
#include "ih264d_mem_request.h"
51
#include "ih264d_debug.h"
52
#include "ih264d_error_handler.h"
53
#include "ih264d_mb_utils.h"
54
#include "ih264d_sei.h"
55
#include "ih264d_vui.h"
56
#include "ih264d_thread_parse_decode.h"
57
#include "ih264d_thread_compute_bs.h"
58
#include "ih264d_quant_scaling.h"
59
#include "ih264d_defs.h"
60
#include "ivd.h"
61
#include "ih264d.h"
62
63
/*****************************************************************************/
64
/*                                                                           */
65
/*  Function Name : ih264d_parse_slice_partition                                     */
66
/*                                                                           */
67
/*  Description   : This function is intended to parse and decode slice part */
68
/*                  itions. Currently it's not implemented. Decoder will     */
69
/*                  print a message, skips this NAL and continues            */
70
/*  Inputs        : ps_dec    Decoder parameters                             */
71
/*                  ps_bitstrm    Bitstream                                */
72
/*  Globals       : None                                                     */
73
/*  Processing    : This functionality needs to be implemented               */
74
/*  Outputs       : None                                                     */
75
/*  Returns       : None                                                     */
76
/*                                                                           */
77
/*  Issues        : Not implemented                                          */
78
/*                                                                           */
79
/*  Revision History:                                                        */
80
/*                                                                           */
81
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
82
/*         06 05 2002   NS              Draft                                */
83
/*                                                                           */
84
/*****************************************************************************/
85
86
WORD32 ih264d_parse_slice_partition(dec_struct_t * ps_dec,
87
                                    dec_bit_stream_t * ps_bitstrm)
88
0
{
89
0
    H264_DEC_DEBUG_PRINT("\nSlice partition not supported");
90
0
    UNUSED(ps_dec);
91
0
    UNUSED(ps_bitstrm);
92
0
    return (0);
93
0
}
94
95
/*****************************************************************************/
96
/*                                                                           */
97
/*  Function Name : ih264d_parse_sei                                                */
98
/*                                                                           */
99
/*  Description   : This function is intended to parse and decode SEI        */
100
/*                  Currently it's not implemented. Decoder will print a     */
101
/*                  message, skips this NAL and continues                    */
102
/*  Inputs        : ps_dec    Decoder parameters                       */
103
/*                  ps_bitstrm    Bitstream                                */
104
/*  Globals       : None                                                     */
105
/*  Processing    : This functionality needs to be implemented               */
106
/*  Outputs       : None                                                     */
107
/*  Returns       : None                                                     */
108
/*                                                                           */
109
/*  Issues        : Not implemented                                          */
110
/*                                                                           */
111
/*  Revision History:                                                        */
112
/*                                                                           */
113
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
114
/*         06 05 2002   NS              Draft                                */
115
/*                                                                           */
116
/*****************************************************************************/
117
WORD32 ih264d_parse_sei(dec_struct_t * ps_dec, dec_bit_stream_t * ps_bitstrm)
118
0
{
119
0
    UNUSED(ps_dec);
120
0
    UNUSED(ps_bitstrm);
121
0
    return (0);
122
0
}
123
124
/*****************************************************************************/
125
/*                                                                           */
126
/*  Function Name : ih264d_parse_filler_data                                          */
127
/*                                                                           */
128
/*  Description   : This function is intended to parse and decode filler     */
129
/*                  data NAL. Currently it's not implemented. Decoder will   */
130
/*                  print a message, skips this NAL and continues            */
131
/*  Inputs        : ps_dec    Decoder parameters                       */
132
/*                  ps_bitstrm    Bitstream                                */
133
/*  Globals       : None                                                     */
134
/*  Processing    : This functionality needs to be implemented               */
135
/*  Outputs       : None                                                     */
136
/*  Returns       : None                                                     */
137
/*                                                                           */
138
/*  Issues        : Not implemented                                          */
139
/*                                                                           */
140
/*  Revision History:                                                        */
141
/*                                                                           */
142
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
143
/*         06 05 2002   NS              Draft                                */
144
/*                                                                           */
145
/*****************************************************************************/
146
WORD32 ih264d_parse_filler_data(dec_struct_t * ps_dec,
147
                                dec_bit_stream_t * ps_bitstrm)
148
0
{
149
0
    UNUSED(ps_dec);
150
0
    UNUSED(ps_bitstrm);
151
0
    return (0);
152
0
}
153
154
/*****************************************************************************/
155
/*                                                                           */
156
/*  Function Name : ih264d_parse_end_of_stream                                        */
157
/*                                                                           */
158
/*  Description   : This function is intended to parse and decode end of     */
159
/*                  sequence. Currently it's not implemented. Decoder will   */
160
/*                  print a message, skips this NAL and continues            */
161
/*  Inputs        : ps_dec    Decoder parameters                       */
162
/*  Globals       : None                                                     */
163
/*  Processing    : This functionality needs to be implemented               */
164
/*  Outputs       : None                                                     */
165
/*  Returns       : None                                                     */
166
/*                                                                           */
167
/*  Issues        : Not implemented                                          */
168
/*                                                                           */
169
/*  Revision History:                                                        */
170
/*                                                                           */
171
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
172
/*         06 05 2002   NS              Draft                                */
173
/*                                                                           */
174
/*****************************************************************************/
175
void ih264d_parse_end_of_stream(dec_struct_t * ps_dec)
176
0
{
177
0
    UNUSED(ps_dec);
178
0
    return;
179
0
}
180
181
/*!
182
 **************************************************************************
183
 * \if Function name : ih264d_parse_pps \endif
184
 *
185
 * \brief
186
 *    Decodes Picture Parameter set
187
 *
188
 * \return
189
 *    0 on Success and Error code otherwise
190
 **************************************************************************
191
 */
192
WORD32 ih264d_parse_pps(dec_struct_t * ps_dec, dec_bit_stream_t * ps_bitstrm)
193
1
{
194
1
    UWORD8 uc_temp;
195
1
    dec_seq_params_t * ps_sps = NULL;
196
1
    dec_pic_params_t * ps_pps = NULL;
197
1
    UWORD32 *pu4_bitstrm_buf = ps_dec->ps_bitstrm->pu4_buffer;
198
1
    UWORD32 *pu4_bitstrm_ofst = &ps_dec->ps_bitstrm->u4_ofst;
199
1
200
1
    /* Variables used for error resilience checks */
201
1
    UWORD32 u4_temp;
202
1
    WORD32 i_temp;
203
1
204
1
    /* For High profile related syntax elements */
205
1
    UWORD8 u1_more_data_flag;
206
1
    WORD32 i4_i;
207
1
208
1
    /*--------------------------------------------------------------------*/
209
1
    /* Decode pic_parameter_set_id and find corresponding pic params      */
210
1
    /*--------------------------------------------------------------------*/
211
1
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
212
1
    if(u4_temp & MASK_ERR_PIC_SET_ID)
213
1
        return ERROR_INV_SPS_PPS_T;
214
1
    ps_pps = ps_dec->pv_scratch_sps_pps;
215
1
    *ps_pps = ps_dec->ps_pps[u4_temp];
216
1
    ps_pps->u1_pic_parameter_set_id = (WORD8)u4_temp;
217
1
    COPYTHECONTEXT("PPS: pic_parameter_set_id",ps_pps->u1_pic_parameter_set_id);
218
1
219
1
    /************************************************/
220
1
    /* initilization of High profile syntax element */
221
1
    /************************************************/
222
1
    ps_pps->i4_transform_8x8_mode_flag = 0;
223
1
    ps_pps->i4_pic_scaling_matrix_present_flag = 0;
224
1
225
1
    /*--------------------------------------------------------------------*/
226
1
    /* Decode seq_parameter_set_id and map it to a seq_parameter_set      */
227
1
    /*--------------------------------------------------------------------*/
228
1
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
229
1
    if(u4_temp & MASK_ERR_SEQ_SET_ID)
230
1
        return ERROR_INV_SPS_PPS_T;
231
1
    COPYTHECONTEXT("PPS: seq_parameter_set_id",u4_temp);
232
1
    ps_sps = &ps_dec->ps_sps[u4_temp];
233
1
    ps_pps->ps_sps = ps_sps;
234
1
235
1
    /*--------------------------------------------------------------------*/
236
1
    /* Decode entropy_coding_mode                                         */
237
1
    /*--------------------------------------------------------------------*/
238
1
    ps_pps->u1_entropy_coding_mode = ih264d_get_bit_h264(ps_bitstrm);
239
1
    COPYTHECONTEXT("PPS: entropy_coding_mode_flag",ps_pps->u1_entropy_coding_mode);
240
1
241
1
    ps_pps->u1_pic_order_present_flag = ih264d_get_bit_h264(ps_bitstrm);
242
1
    COPYTHECONTEXT("PPS: pic_order_present_flag",ps_pps->u1_pic_order_present_flag);
243
1
244
1
    /*--------------------------------------------------------------------*/
245
1
    /* Decode num_slice_groups_minus1                                     */
246
1
    /*--------------------------------------------------------------------*/
247
1
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf) + 1;
248
1
    if(u4_temp != 1)
249
0
    {
250
0
        UWORD32 i4_error_code;
251
0
        i4_error_code = ERROR_FEATURE_UNAVAIL;
252
0
        return i4_error_code;
253
0
    }
254
1
    ps_pps->u1_num_slice_groups = u4_temp;
255
1
    COPYTHECONTEXT("PPS: num_slice_groups_minus1",ps_pps->u1_num_slice_groups -1);
256
1
257
1
    /*--------------------------------------------------------------------*/
258
1
    /* Other parameter set values                                         */
259
1
    /*--------------------------------------------------------------------*/
260
1
    u4_temp = 1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
261
1
    if(u4_temp > H264_MAX_REF_IDX)
262
1
        return ERROR_REF_IDX;
263
1
    ps_pps->u1_num_ref_idx_lx_active[0] = u4_temp;
264
1
    COPYTHECONTEXT("PPS: num_ref_idx_l0_active_minus1",
265
1
                    ps_pps->u1_num_ref_idx_lx_active[0] - 1);
266
1
267
1
    u4_temp = 1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
268
1
    if(u4_temp > H264_MAX_REF_IDX)
269
1
        return ERROR_REF_IDX;
270
1
    ps_pps->u1_num_ref_idx_lx_active[1] = u4_temp;
271
1
    COPYTHECONTEXT("PPS: num_ref_idx_l1_active_minus1",
272
1
                    ps_pps->u1_num_ref_idx_lx_active[1] - 1);
273
1
274
1
    ps_pps->u1_wted_pred_flag = ih264d_get_bit_h264(ps_bitstrm);
275
1
    COPYTHECONTEXT("PPS: weighted prediction u4_flag",ps_pps->u1_wted_pred_flag);
276
1
    uc_temp = ih264d_get_bits_h264(ps_bitstrm, 2);
277
1
    COPYTHECONTEXT("PPS: weighted_bipred_idc",uc_temp);
278
1
    ps_pps->u1_wted_bipred_idc = uc_temp;
279
1
280
1
    if(ps_pps->u1_wted_bipred_idc > MAX_WEIGHT_BIPRED_IDC)
281
1
        return ERROR_INV_SPS_PPS_T;
282
1
283
1
    i_temp = 26 + ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
284
1
285
1
    if((i_temp < 0) || (i_temp > 51))
286
0
        return ERROR_INV_RANGE_QP_T;
287
1
288
1
    ps_pps->u1_pic_init_qp = i_temp;
289
1
    COPYTHECONTEXT("PPS: pic_init_qp_minus26",ps_pps->u1_pic_init_qp - 26);
290
1
291
1
    i_temp = 26 + ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
292
1
293
1
    if((i_temp < 0) || (i_temp > 51))
294
0
        return ERROR_INV_RANGE_QP_T;
295
1
296
1
    ps_pps->u1_pic_init_qs = i_temp;
297
1
    COPYTHECONTEXT("PPS: pic_init_qs_minus26",ps_pps->u1_pic_init_qs - 26);
298
1
299
1
    i_temp = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
300
1
    if((i_temp < -12) || (i_temp > 12))
301
0
        return ERROR_INV_RANGE_QP_T;
302
1
    ps_pps->i1_chroma_qp_index_offset = i_temp;
303
1
    COPYTHECONTEXT("PPS: chroma_qp_index_offset",ps_pps->i1_chroma_qp_index_offset);
304
1
305
1
    /***************************************************************************/
306
1
    /* initialize second_chroma_qp_index_offset to i1_chroma_qp_index_offset if */
307
1
    /* second_chroma_qp_index_offset is not present in bit-ps_bitstrm              */
308
1
    /***************************************************************************/
309
1
    ps_pps->i1_second_chroma_qp_index_offset =
310
1
                    ps_pps->i1_chroma_qp_index_offset;
311
1
312
1
    ps_pps->u1_deblocking_filter_parameters_present_flag = ih264d_get_bit_h264(
313
1
                    ps_bitstrm);
314
1
    COPYTHECONTEXT("PPS: deblocking_filter_control_present_flag",
315
1
                    ps_pps->u1_deblocking_filter_parameters_present_flag);
316
1
    ps_pps->u1_constrained_intra_pred_flag = ih264d_get_bit_h264(ps_bitstrm);
317
1
    COPYTHECONTEXT("PPS: constrained_intra_pred_flag",
318
1
                    ps_pps->u1_constrained_intra_pred_flag);
319
1
    ps_pps->u1_redundant_pic_cnt_present_flag = ih264d_get_bit_h264(ps_bitstrm);
320
1
    COPYTHECONTEXT("PPS: redundant_pic_cnt_present_flag",
321
1
                    ps_pps->u1_redundant_pic_cnt_present_flag);
322
1
323
1
    /* High profile related syntax elements */
324
1
    u1_more_data_flag = MORE_RBSP_DATA(ps_bitstrm);
325
1
    if(u1_more_data_flag && (ps_pps->ps_sps->u1_profile_idc == HIGH_PROFILE_IDC))
326
0
    {
327
0
        /* read transform_8x8_mode_flag  */
328
0
        ps_pps->i4_transform_8x8_mode_flag = (WORD32)ih264d_get_bit_h264(
329
0
                        ps_bitstrm);
330
0
331
0
        /* read pic_scaling_matrix_present_flag */
332
0
        ps_pps->i4_pic_scaling_matrix_present_flag =
333
0
                        (WORD32)ih264d_get_bit_h264(ps_bitstrm);
334
0
335
0
        if(ps_pps->i4_pic_scaling_matrix_present_flag)
336
0
        {
337
0
            /* read the scaling matrices */
338
0
            for(i4_i = 0; i4_i < (6 + (ps_pps->i4_transform_8x8_mode_flag << 1)); i4_i++)
339
0
            {
340
0
                ps_pps->u1_pic_scaling_list_present_flag[i4_i] =
341
0
                                ih264d_get_bit_h264(ps_bitstrm);
342
0
343
0
                if(ps_pps->u1_pic_scaling_list_present_flag[i4_i])
344
0
                {
345
0
                    if(i4_i < 6)
346
0
                    {
347
0
                        ih264d_scaling_list(
348
0
                                        ps_pps->i2_pic_scalinglist4x4[i4_i],
349
0
                                        16,
350
0
                                        &ps_pps->u1_pic_use_default_scaling_matrix_flag[i4_i],
351
0
                                        ps_bitstrm);
352
0
                    }
353
0
                    else
354
0
                    {
355
0
                        ih264d_scaling_list(
356
0
                                        ps_pps->i2_pic_scalinglist8x8[i4_i - 6],
357
0
                                        64,
358
0
                                        &ps_pps->u1_pic_use_default_scaling_matrix_flag[i4_i],
359
0
                                        ps_bitstrm);
360
0
                    }
361
0
                }
362
0
            }
363
0
        }
364
0
365
0
        /* read second_chroma_qp_index_offset syntax element */
366
0
        i_temp = ih264d_sev(
367
0
                        pu4_bitstrm_ofst, pu4_bitstrm_buf);
368
0
369
0
        if((i_temp < -12) || (i_temp > 12))
370
0
            return ERROR_INV_RANGE_QP_T;
371
0
372
0
        ps_pps->i1_second_chroma_qp_index_offset = i_temp;
373
0
    }
374
1
375
1
    /* In case bitstream read has exceeded the filled size, then
376
1
       return an error */
377
1
    if(ps_bitstrm->u4_ofst > ps_bitstrm->u4_max_ofst + 8)
378
0
    {
379
0
        return ERROR_INV_SPS_PPS_T;
380
0
    }
381
1
    ps_pps->u1_is_valid = TRUE;
382
1
    ps_dec->ps_pps[ps_pps->u1_pic_parameter_set_id] = *ps_pps;
383
1
    return OK;
384
1
}
385
386
/*!
387
 **************************************************************************
388
 * \if Function name : ih264d_parse_sps \endif
389
 *
390
 * \brief
391
 *    Decodes Sequence parameter set from the bitstream
392
 *
393
 * \return
394
 *    0 on Success and Error code otherwise
395
 **************************************************************************
396
 */
397
UWORD32 ih264d_correct_level_idc(UWORD32 u4_level_idc, UWORD32 u4_total_mbs)
398
1
{
399
1
    UWORD32 u4_max_mbs_allowed;
400
1
401
1
    switch(u4_level_idc)
402
1
    {
403
1
        case H264_LEVEL_1_0:
404
0
            u4_max_mbs_allowed = MAX_MBS_LEVEL_10;
405
0
            break;
406
1
        case H264_LEVEL_1_1:
407
0
            u4_max_mbs_allowed = MAX_MBS_LEVEL_11;
408
0
            break;
409
1
        case H264_LEVEL_1_2:
410
0
            u4_max_mbs_allowed = MAX_MBS_LEVEL_12;
411
0
            break;
412
1
        case H264_LEVEL_1_3:
413
0
            u4_max_mbs_allowed = MAX_MBS_LEVEL_13;
414
0
            break;
415
1
        case H264_LEVEL_2_0:
416
0
            u4_max_mbs_allowed = MAX_MBS_LEVEL_20;
417
0
            break;
418
1
        case H264_LEVEL_2_1:
419
0
            u4_max_mbs_allowed = MAX_MBS_LEVEL_21;
420
0
            break;
421
1
        case H264_LEVEL_2_2:
422
0
            u4_max_mbs_allowed = MAX_MBS_LEVEL_22;
423
0
            break;
424
1
        case H264_LEVEL_3_0:
425
0
            u4_max_mbs_allowed = MAX_MBS_LEVEL_30;
426
0
            break;
427
1
        case H264_LEVEL_3_1:
428
1
            u4_max_mbs_allowed = MAX_MBS_LEVEL_31;
429
1
            break;
430
1
        case H264_LEVEL_3_2:
431
0
            u4_max_mbs_allowed = MAX_MBS_LEVEL_32;
432
0
            break;
433
1
        case H264_LEVEL_4_0:
434
0
            u4_max_mbs_allowed = MAX_MBS_LEVEL_40;
435
0
            break;
436
1
        case H264_LEVEL_4_1:
437
0
            u4_max_mbs_allowed = MAX_MBS_LEVEL_41;
438
0
            break;
439
1
        case H264_LEVEL_4_2:
440
0
            u4_max_mbs_allowed = MAX_MBS_LEVEL_42;
441
0
            break;
442
1
        case H264_LEVEL_5_0:
443
0
            u4_max_mbs_allowed = MAX_MBS_LEVEL_50;
444
0
            break;
445
1
        case H264_LEVEL_5_1:
446
0
        default:
447
0
            u4_max_mbs_allowed = MAX_MBS_LEVEL_51;
448
0
            break;
449
1
450
1
    }
451
1
452
1
    /*correct of the level is incorrect*/
453
1
    if(u4_total_mbs > u4_max_mbs_allowed)
454
0
    {
455
0
        if(u4_total_mbs > MAX_MBS_LEVEL_50)
456
0
            u4_level_idc = H264_LEVEL_5_1;
457
0
        else if(u4_total_mbs > MAX_MBS_LEVEL_42)
458
0
            u4_level_idc = H264_LEVEL_5_0;
459
0
        else if(u4_total_mbs > MAX_MBS_LEVEL_41)
460
0
            u4_level_idc = H264_LEVEL_4_2;
461
0
        else if(u4_total_mbs > MAX_MBS_LEVEL_40)
462
0
            u4_level_idc = H264_LEVEL_4_1;
463
0
        else if(u4_total_mbs > MAX_MBS_LEVEL_32)
464
0
            u4_level_idc = H264_LEVEL_4_0;
465
0
        else if(u4_total_mbs > MAX_MBS_LEVEL_31)
466
0
            u4_level_idc = H264_LEVEL_3_2;
467
0
        else if(u4_total_mbs > MAX_MBS_LEVEL_30)
468
0
            u4_level_idc = H264_LEVEL_3_1;
469
0
        else if(u4_total_mbs > MAX_MBS_LEVEL_21)
470
0
            u4_level_idc = H264_LEVEL_3_0;
471
0
        else if(u4_total_mbs > MAX_MBS_LEVEL_20)
472
0
            u4_level_idc = H264_LEVEL_2_1;
473
0
        else if(u4_total_mbs > MAX_MBS_LEVEL_10)
474
0
            u4_level_idc = H264_LEVEL_2_0;
475
0
    }
476
1
477
1
    return (u4_level_idc);
478
1
479
1
}
480
WORD32 ih264d_parse_sps(dec_struct_t *ps_dec, dec_bit_stream_t *ps_bitstrm)
481
1
{
482
1
    UWORD8 i;
483
1
    dec_seq_params_t *ps_seq = NULL;
484
1
    UWORD8 u1_profile_idc, u1_level_idc, u1_seq_parameter_set_id, u1_mb_aff_flag = 0;
485
1
    UWORD16 i2_max_frm_num;
486
1
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
487
1
    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
488
1
    UWORD8 u1_frm, uc_constraint_set0_flag, uc_constraint_set1_flag;
489
1
    WORD32 i4_cropped_ht, i4_cropped_wd;
490
1
    UWORD32 u4_temp;
491
1
    WORD32 pic_height_in_map_units_minus1 = 0;
492
1
    UWORD32 u2_pic_wd = 0;
493
1
    UWORD32 u2_pic_ht = 0;
494
1
    UWORD32 u2_frm_wd_y = 0;
495
1
    UWORD32 u2_frm_ht_y = 0;
496
1
    UWORD32 u2_frm_wd_uv = 0;
497
1
    UWORD32 u2_frm_ht_uv = 0;
498
1
    UWORD32 u2_crop_offset_y = 0;
499
1
    UWORD32 u2_crop_offset_uv = 0;
500
1
    WORD32 ret;
501
1
    UWORD32 u4_num_reorder_frames;
502
1
    /* High profile related syntax element */
503
1
    WORD32 i4_i;
504
1
    /* G050 */
505
1
    UWORD8 u1_frame_cropping_flag, u1_frame_cropping_rect_left_ofst,
506
1
                    u1_frame_cropping_rect_right_ofst,
507
1
                    u1_frame_cropping_rect_top_ofst,
508
1
                    u1_frame_cropping_rect_bottom_ofst;
509
1
    /* G050 */
510
1
    /*--------------------------------------------------------------------*/
511
1
    /* Decode seq_parameter_set_id and profile and level values           */
512
1
    /*--------------------------------------------------------------------*/
513
1
    SWITCHONTRACE;
514
1
    u1_profile_idc = ih264d_get_bits_h264(ps_bitstrm, 8);
515
1
    COPYTHECONTEXT("SPS: profile_idc",u1_profile_idc);
516
1
517
1
    /* G050 */
518
1
    uc_constraint_set0_flag = ih264d_get_bit_h264(ps_bitstrm);
519
1
    uc_constraint_set1_flag = ih264d_get_bit_h264(ps_bitstrm);
520
1
    ih264d_get_bit_h264(ps_bitstrm);
521
1
522
1
    /*****************************************************/
523
1
    /* Read 5 bits for uc_constraint_set3_flag (1 bit)   */
524
1
    /* and reserved_zero_4bits (4 bits) - Sushant        */
525
1
    /*****************************************************/
526
1
    ih264d_get_bits_h264(ps_bitstrm, 5);
527
1
    /* G050 */
528
1
529
1
    /* Check whether particular profile is suported or not */
530
1
    /* Check whether particular profile is suported or not */
531
1
    if((u1_profile_idc != MAIN_PROFILE_IDC) &&
532
1
533
1
    (u1_profile_idc != BASE_PROFILE_IDC) &&
534
1
535
1
    (u1_profile_idc != HIGH_PROFILE_IDC)
536
0
537
0
    )
538
0
    {
539
0
540
0
        /* Apart from Baseline, main and high profile,
541
0
         * only extended profile is supported provided
542
0
         * uc_constraint_set0_flag or uc_constraint_set1_flag are set to 1
543
0
         */
544
0
        if((u1_profile_idc != EXTENDED_PROFILE_IDC) ||
545
0
           ((uc_constraint_set1_flag != 1) && (uc_constraint_set0_flag != 1)))
546
0
        {
547
0
            return (ERROR_FEATURE_UNAVAIL);
548
0
        }
549
1
    }
550
1
551
1
    u1_level_idc = ih264d_get_bits_h264(ps_bitstrm, 8);
552
1
553
1
554
1
555
1
    COPYTHECONTEXT("SPS: u4_level_idc",u1_level_idc);
556
1
557
1
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
558
1
    if(u4_temp & MASK_ERR_SEQ_SET_ID)
559
1
        return ERROR_INV_SPS_PPS_T;
560
1
    u1_seq_parameter_set_id = u4_temp;
561
1
    COPYTHECONTEXT("SPS: seq_parameter_set_id",
562
1
                    u1_seq_parameter_set_id);
563
1
564
1
    /*--------------------------------------------------------------------*/
565
1
    /* Find an seq param entry in seqparam array of decStruct             */
566
1
    /*--------------------------------------------------------------------*/
567
1
568
1
    ps_seq = ps_dec->pv_scratch_sps_pps;
569
1
    memset(ps_seq, 0, sizeof(dec_seq_params_t));
570
1
571
1
    if(ps_dec->i4_header_decoded & 1)
572
0
    {
573
0
        *ps_seq = *ps_dec->ps_cur_sps;
574
0
    }
575
1
576
1
577
1
    if((ps_dec->i4_header_decoded & 1) && (ps_seq->u1_profile_idc != u1_profile_idc))
578
0
    {
579
0
        ps_dec->u1_res_changed = 1;
580
0
        return IVD_RES_CHANGED;
581
0
    }
582
1
583
1
    if((ps_dec->i4_header_decoded & 1) && (ps_seq->u1_level_idc != u1_level_idc))
584
0
    {
585
0
        ps_dec->u1_res_changed = 1;
586
0
        return IVD_RES_CHANGED;
587
0
    }
588
1
589
1
    ps_seq->u1_profile_idc = u1_profile_idc;
590
1
    ps_seq->u1_level_idc = u1_level_idc;
591
1
    ps_seq->u1_seq_parameter_set_id = u1_seq_parameter_set_id;
592
1
593
1
    /*******************************************************************/
594
1
    /* Initializations for high profile - Sushant                      */
595
1
    /*******************************************************************/
596
1
    ps_seq->i4_chroma_format_idc = 1;
597
1
    ps_seq->i4_bit_depth_luma_minus8 = 0;
598
1
    ps_seq->i4_bit_depth_chroma_minus8 = 0;
599
1
    ps_seq->i4_qpprime_y_zero_transform_bypass_flag = 0;
600
1
    ps_seq->i4_seq_scaling_matrix_present_flag = 0;
601
1
    if(u1_profile_idc == HIGH_PROFILE_IDC)
602
1
    {
603
0
604
0
        /* reading chroma_format_idc   */
605
0
        ps_seq->i4_chroma_format_idc = ih264d_uev(pu4_bitstrm_ofst,
606
0
                                                  pu4_bitstrm_buf);
607
0
608
0
        /* Monochrome is not supported */
609
0
        if(ps_seq->i4_chroma_format_idc != 1)
610
0
        {
611
0
            return ERROR_INV_SPS_PPS_T;
612
0
        }
613
0
614
0
        /* reading bit_depth_luma_minus8   */
615
0
        ps_seq->i4_bit_depth_luma_minus8 = ih264d_uev(pu4_bitstrm_ofst,
616
0
                                                      pu4_bitstrm_buf);
617
0
618
0
        if(ps_seq->i4_bit_depth_luma_minus8 != 0)
619
0
        {
620
0
            return ERROR_INV_SPS_PPS_T;
621
0
        }
622
0
623
0
        /* reading bit_depth_chroma_minus8   */
624
0
        ps_seq->i4_bit_depth_chroma_minus8 = ih264d_uev(pu4_bitstrm_ofst,
625
0
                                                        pu4_bitstrm_buf);
626
0
627
0
        if(ps_seq->i4_bit_depth_chroma_minus8 != 0)
628
0
        {
629
0
            return ERROR_INV_SPS_PPS_T;
630
0
        }
631
0
632
0
        /* reading qpprime_y_zero_transform_bypass_flag   */
633
0
        ps_seq->i4_qpprime_y_zero_transform_bypass_flag =
634
0
                        (WORD32)ih264d_get_bit_h264(ps_bitstrm);
635
0
636
0
        if(ps_seq->i4_qpprime_y_zero_transform_bypass_flag != 0)
637
0
        {
638
0
            return ERROR_INV_SPS_PPS_T;
639
0
        }
640
0
641
0
        /* reading seq_scaling_matrix_present_flag   */
642
0
        ps_seq->i4_seq_scaling_matrix_present_flag =
643
0
                        (WORD32)ih264d_get_bit_h264(ps_bitstrm);
644
0
645
0
        if(ps_seq->i4_seq_scaling_matrix_present_flag)
646
0
        {
647
0
            for(i4_i = 0; i4_i < 8; i4_i++)
648
0
            {
649
0
                ps_seq->u1_seq_scaling_list_present_flag[i4_i] =
650
0
                                ih264d_get_bit_h264(ps_bitstrm);
651
0
652
0
                /* initialize u1_use_default_scaling_matrix_flag[i4_i] to zero */
653
0
                /* before calling scaling list                             */
654
0
                ps_seq->u1_use_default_scaling_matrix_flag[i4_i] = 0;
655
0
656
0
                if(ps_seq->u1_seq_scaling_list_present_flag[i4_i])
657
0
                {
658
0
                    if(i4_i < 6)
659
0
                    {
660
0
                        ih264d_scaling_list(
661
0
                                        ps_seq->i2_scalinglist4x4[i4_i],
662
0
                                        16,
663
0
                                        &ps_seq->u1_use_default_scaling_matrix_flag[i4_i],
664
0
                                        ps_bitstrm);
665
0
                    }
666
0
                    else
667
0
                    {
668
0
                        ih264d_scaling_list(
669
0
                                        ps_seq->i2_scalinglist8x8[i4_i - 6],
670
0
                                        64,
671
0
                                        &ps_seq->u1_use_default_scaling_matrix_flag[i4_i],
672
0
                                        ps_bitstrm);
673
0
                    }
674
0
                }
675
0
            }
676
0
        }
677
0
    }
678
1
    /*--------------------------------------------------------------------*/
679
1
    /* Decode MaxFrameNum                                                 */
680
1
    /*--------------------------------------------------------------------*/
681
1
    u4_temp = 4 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
682
1
    if(u4_temp > MAX_BITS_IN_FRAME_NUM)
683
1
    {
684
0
        return ERROR_INV_SPS_PPS_T;
685
0
    }
686
1
    ps_seq->u1_bits_in_frm_num = u4_temp;
687
1
    COPYTHECONTEXT("SPS: log2_max_frame_num_minus4",
688
1
                    (ps_seq->u1_bits_in_frm_num - 4));
689
1
690
1
    i2_max_frm_num = (1 << (ps_seq->u1_bits_in_frm_num));
691
1
    ps_seq->u2_u4_max_pic_num_minus1 = i2_max_frm_num - 1;
692
1
    /*--------------------------------------------------------------------*/
693
1
    /* Decode picture order count and related values                      */
694
1
    /*--------------------------------------------------------------------*/
695
1
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
696
1
697
1
    if(u4_temp > MAX_PIC_ORDER_CNT_TYPE)
698
1
    {
699
0
        return ERROR_INV_POC_TYPE_T;
700
0
    }
701
1
    ps_seq->u1_pic_order_cnt_type = u4_temp;
702
1
    COPYTHECONTEXT("SPS: pic_order_cnt_type",ps_seq->u1_pic_order_cnt_type);
703
1
704
1
    ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle = 1;
705
1
    if(ps_seq->u1_pic_order_cnt_type == 0)
706
1
    {
707
1
        u4_temp = 4 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
708
1
        if(u4_temp > MAX_BITS_IN_POC_LSB)
709
1
        {
710
0
            return ERROR_INV_SPS_PPS_T;
711
0
        }
712
1
        ps_seq->u1_log2_max_pic_order_cnt_lsb_minus = u4_temp;
713
1
        ps_seq->i4_max_pic_order_cntLsb = (1 << u4_temp);
714
1
        COPYTHECONTEXT("SPS: log2_max_pic_order_cnt_lsb_minus4",(u4_temp - 4));
715
1
    }
716
0
    else if(ps_seq->u1_pic_order_cnt_type == 1)
717
0
    {
718
0
        ps_seq->u1_delta_pic_order_always_zero_flag = ih264d_get_bit_h264(
719
0
                        ps_bitstrm);
720
0
        COPYTHECONTEXT("SPS: delta_pic_order_always_zero_flag",
721
0
                        ps_seq->u1_delta_pic_order_always_zero_flag);
722
0
723
0
        ps_seq->i4_ofst_for_non_ref_pic = ih264d_sev(pu4_bitstrm_ofst,
724
0
                                                     pu4_bitstrm_buf);
725
0
        COPYTHECONTEXT("SPS: offset_for_non_ref_pic",
726
0
                        ps_seq->i4_ofst_for_non_ref_pic);
727
0
728
0
        ps_seq->i4_ofst_for_top_to_bottom_field = ih264d_sev(
729
0
                        pu4_bitstrm_ofst, pu4_bitstrm_buf);
730
0
        COPYTHECONTEXT("SPS: offset_for_top_to_bottom_field",
731
0
                        ps_seq->i4_ofst_for_top_to_bottom_field);
732
0
733
0
        u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
734
0
        if(u4_temp > 255)
735
0
            return ERROR_INV_SPS_PPS_T;
736
0
        ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle = u4_temp;
737
0
        COPYTHECONTEXT("SPS: num_ref_frames_in_pic_order_cnt_cycle",
738
0
                        ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle);
739
0
740
0
        for(i = 0; i < ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle; i++)
741
0
        {
742
0
            ps_seq->i4_ofst_for_ref_frame[i] = ih264d_sev(
743
0
                            pu4_bitstrm_ofst, pu4_bitstrm_buf);
744
0
            COPYTHECONTEXT("SPS: offset_for_ref_frame",
745
0
                            ps_seq->i4_ofst_for_ref_frame[i]);
746
0
        }
747
0
    }
748
1
749
1
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
750
1
751
1
    if((u4_temp > H264_MAX_REF_PICS))
752
0
    {
753
0
        return ERROR_NUM_REF;
754
0
    }
755
1
756
1
    /* Compare with older num_ref_frames is header is already once */
757
1
    if((ps_dec->i4_header_decoded & 1) && (ps_seq->u1_num_ref_frames != u4_temp))
758
0
    {
759
0
        ps_dec->u1_res_changed = 1;
760
0
        return IVD_RES_CHANGED;
761
0
    }
762
1
763
1
    ps_seq->u1_num_ref_frames = u4_temp;
764
1
    COPYTHECONTEXT("SPS: num_ref_frames",ps_seq->u1_num_ref_frames);
765
1
766
1
    ps_seq->u1_gaps_in_frame_num_value_allowed_flag = ih264d_get_bit_h264(
767
1
                    ps_bitstrm);
768
1
    COPYTHECONTEXT("SPS: gaps_in_frame_num_value_allowed_flag",
769
1
                    ps_seq->u1_gaps_in_frame_num_value_allowed_flag);
770
1
771
1
    /*--------------------------------------------------------------------*/
772
1
    /* Decode FrameWidth and FrameHeight and related values               */
773
1
    /*--------------------------------------------------------------------*/
774
1
    ps_seq->u2_frm_wd_in_mbs = 1
775
1
                    + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
776
1
    COPYTHECONTEXT("SPS: pic_width_in_mbs_minus1",
777
1
                    ps_seq->u2_frm_wd_in_mbs - 1);
778
1
    u2_pic_wd = (ps_seq->u2_frm_wd_in_mbs << 4);
779
1
780
1
    pic_height_in_map_units_minus1 = ih264d_uev(pu4_bitstrm_ofst,
781
1
                                                pu4_bitstrm_buf);
782
1
    ps_seq->u2_frm_ht_in_mbs = 1 + pic_height_in_map_units_minus1;
783
1
784
1
    u2_pic_ht = (ps_seq->u2_frm_ht_in_mbs << 4);
785
1
786
1
    /*--------------------------------------------------------------------*/
787
1
    /* Get the value of MaxMbAddress and Number of bits needed for it     */
788
1
    /*--------------------------------------------------------------------*/
789
1
    ps_seq->u2_max_mb_addr = (ps_seq->u2_frm_wd_in_mbs
790
1
                    * ps_seq->u2_frm_ht_in_mbs) - 1;
791
1
792
1
    ps_seq->u2_total_num_of_mbs = ps_seq->u2_max_mb_addr + 1;
793
1
794
1
    ps_seq->u1_level_idc = ih264d_correct_level_idc(
795
1
                    u1_level_idc, ps_seq->u2_total_num_of_mbs);
796
1
797
1
    u1_frm = ih264d_get_bit_h264(ps_bitstrm);
798
1
    if((ps_dec->i4_header_decoded & 1) && (ps_seq->u1_frame_mbs_only_flag != u1_frm))
799
0
    {
800
0
        ps_dec->u1_res_changed = 1;
801
0
        return IVD_RES_CHANGED;
802
0
    }
803
1
804
1
    ps_seq->u1_frame_mbs_only_flag = u1_frm;
805
1
806
1
    COPYTHECONTEXT("SPS: frame_mbs_only_flag", u1_frm);
807
1
808
1
    if(!u1_frm)
809
0
        u1_mb_aff_flag = ih264d_get_bit_h264(ps_bitstrm);
810
1
811
1
    if((ps_dec->i4_header_decoded & 1)
812
1
                    && (ps_seq->u1_mb_aff_flag != u1_mb_aff_flag))
813
0
    {
814
0
        ps_dec->u1_res_changed = 1;
815
0
        return IVD_RES_CHANGED;
816
0
    }
817
1
818
1
    if(!u1_frm)
819
0
    {
820
0
        u2_pic_ht <<= 1;
821
0
        ps_seq->u1_mb_aff_flag = u1_mb_aff_flag;
822
0
        COPYTHECONTEXT("SPS: mb_adaptive_frame_field_flag",
823
0
                        ps_seq->u1_mb_aff_flag);
824
0
825
0
    }
826
1
    else
827
1
        ps_seq->u1_mb_aff_flag = 0;
828
1
829
1
    ps_seq->u1_direct_8x8_inference_flag = ih264d_get_bit_h264(ps_bitstrm);
830
1
831
1
    COPYTHECONTEXT("SPS: direct_8x8_inference_flag",
832
1
                    ps_seq->u1_direct_8x8_inference_flag);
833
1
834
1
    /* G050 */
835
1
    u1_frame_cropping_flag = ih264d_get_bit_h264(ps_bitstrm);
836
1
    COPYTHECONTEXT("SPS: frame_cropping_flag",u1_frame_cropping_flag);
837
1
838
1
    if(u1_frame_cropping_flag)
839
1
    {
840
1
        u1_frame_cropping_rect_left_ofst = ih264d_uev(pu4_bitstrm_ofst,
841
1
                                                      pu4_bitstrm_buf);
842
1
        COPYTHECONTEXT("SPS: frame_cropping_rect_left_offset",
843
1
                        u1_frame_cropping_rect_left_ofst);
844
1
        u1_frame_cropping_rect_right_ofst = ih264d_uev(pu4_bitstrm_ofst,
845
1
                                                       pu4_bitstrm_buf);
846
1
        COPYTHECONTEXT("SPS: frame_cropping_rect_right_offset",
847
1
                        u1_frame_cropping_rect_right_ofst);
848
1
        u1_frame_cropping_rect_top_ofst = ih264d_uev(pu4_bitstrm_ofst,
849
1
                                                     pu4_bitstrm_buf);
850
1
        COPYTHECONTEXT("SPS: frame_cropping_rect_top_offset",
851
1
                        u1_frame_cropping_rect_top_ofst);
852
1
        u1_frame_cropping_rect_bottom_ofst = ih264d_uev(pu4_bitstrm_ofst,
853
1
                                                        pu4_bitstrm_buf);
854
1
        COPYTHECONTEXT("SPS: frame_cropping_rect_bottom_offset",
855
1
                        u1_frame_cropping_rect_bottom_ofst);
856
1
    }
857
1
    /* G050 */
858
1
859
1
    ps_seq->u1_vui_parameters_present_flag = ih264d_get_bit_h264(ps_bitstrm);
860
1
    COPYTHECONTEXT("SPS: vui_parameters_present_flag",
861
1
                    ps_seq->u1_vui_parameters_present_flag);
862
1
863
1
    u2_frm_wd_y = u2_pic_wd + (UWORD8)(PAD_LEN_Y_H << 1);
864
1
    if(1 == ps_dec->u4_share_disp_buf)
865
0
    {
866
0
        if(ps_dec->u4_app_disp_width > u2_frm_wd_y)
867
0
            u2_frm_wd_y = ps_dec->u4_app_disp_width;
868
0
    }
869
1
870
1
    u2_frm_ht_y = u2_pic_ht + (UWORD8)(PAD_LEN_Y_V << 2);
871
1
    u2_frm_wd_uv = u2_pic_wd + (UWORD8)(PAD_LEN_UV_H << 2);
872
1
    u2_frm_wd_uv = MAX(u2_frm_wd_uv, u2_frm_wd_y);
873
1
874
1
    u2_frm_ht_uv = (u2_pic_ht >> 1) + (UWORD8)(PAD_LEN_UV_V << 2);
875
1
    u2_frm_ht_uv = MAX(u2_frm_ht_uv, (u2_frm_ht_y >> 1));
876
1
877
1
878
1
    /* Calculate display picture width, height and start u4_ofst from YUV420 */
879
1
    /* pictute buffers as per cropping information parsed above             */
880
1
    {
881
1
        UWORD16 u2_rgt_ofst = 0;
882
1
        UWORD16 u2_lft_ofst = 0;
883
1
        UWORD16 u2_top_ofst = 0;
884
1
        UWORD16 u2_btm_ofst = 0;
885
1
        UWORD8 u1_frm_mbs_flag;
886
1
        UWORD8 u1_vert_mult_factor;
887
1
888
1
        if(u1_frame_cropping_flag)
889
1
        {
890
1
            /* Calculate right and left u4_ofst for cropped picture           */
891
1
            u2_rgt_ofst = u1_frame_cropping_rect_right_ofst << 1;
892
1
            u2_lft_ofst = u1_frame_cropping_rect_left_ofst << 1;
893
1
894
1
            /* Know frame MBs only u4_flag                                      */
895
1
            u1_frm_mbs_flag = (1 == ps_seq->u1_frame_mbs_only_flag);
896
1
897
1
            /* Simplify the vertical u4_ofst calculation from field/frame     */
898
1
            u1_vert_mult_factor = (2 - u1_frm_mbs_flag);
899
1
900
1
            /* Calculate bottom and top u4_ofst for cropped  picture          */
901
1
            u2_btm_ofst = (u1_frame_cropping_rect_bottom_ofst
902
1
                            << u1_vert_mult_factor);
903
1
            u2_top_ofst = (u1_frame_cropping_rect_top_ofst
904
1
                            << u1_vert_mult_factor);
905
1
        }
906
1
907
1
        /* Calculate u4_ofst from start of YUV 420 picture buffer to start of*/
908
1
        /* cropped picture buffer                                           */
909
1
        u2_crop_offset_y = (u2_frm_wd_y * u2_top_ofst) + (u2_lft_ofst);
910
1
        u2_crop_offset_uv = (u2_frm_wd_uv * (u2_top_ofst >> 1))
911
1
                        + (u2_lft_ofst >> 1) * YUV420SP_FACTOR;
912
1
        /* Calculate the display picture width and height based on crop      */
913
1
        /* information                                                       */
914
1
        i4_cropped_ht = u2_pic_ht - (u2_btm_ofst + u2_top_ofst);
915
1
        i4_cropped_wd = u2_pic_wd - (u2_rgt_ofst + u2_lft_ofst);
916
1
917
1
        if((i4_cropped_ht < MB_SIZE) || (i4_cropped_wd < MB_SIZE))
918
0
        {
919
0
            return ERROR_INV_SPS_PPS_T;
920
0
        }
921
1
922
1
        if((ps_dec->i4_header_decoded & 1) && (ps_dec->u2_pic_wd != u2_pic_wd))
923
0
        {
924
0
            ps_dec->u1_res_changed = 1;
925
0
            return IVD_RES_CHANGED;
926
0
        }
927
1
        if((ps_dec->i4_header_decoded & 1) && (ps_dec->u2_pic_ht != u2_pic_ht))
928
0
        {
929
0
            ps_dec->u1_res_changed = 1;
930
0
            return IVD_RES_CHANGED;
931
0
        }
932
1
933
1
        /* Check for unsupported resolutions */
934
1
        if((u2_pic_wd > H264_MAX_FRAME_WIDTH) || (u2_pic_ht > H264_MAX_FRAME_HEIGHT)
935
1
                || (u2_pic_wd < H264_MIN_FRAME_WIDTH) || (u2_pic_ht < H264_MIN_FRAME_HEIGHT)
936
1
                || (u2_pic_wd * (UWORD32)u2_pic_ht > H264_MAX_FRAME_SIZE))
937
0
        {
938
0
            return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
939
0
        }
940
1
941
1
        /* If MBAff is enabled, decoder support is limited to streams with
942
1
         * width less than half of H264_MAX_FRAME_WIDTH.
943
1
         * In case of MBAff decoder processes two rows at a time
944
1
         */
945
1
        if((u2_pic_wd << ps_seq->u1_mb_aff_flag) > H264_MAX_FRAME_WIDTH)
946
1
        {
947
0
            return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
948
0
        }
949
1
950
1
    }
951
1
952
1
    /* Backup u4_num_reorder_frames if header is already decoded */
953
1
    if((ps_dec->i4_header_decoded & 1) &&
954
1
                    (1 == ps_seq->u1_vui_parameters_present_flag) &&
955
1
                    (1 == ps_seq->s_vui.u1_bitstream_restriction_flag))
956
0
    {
957
0
        u4_num_reorder_frames =  ps_seq->s_vui.u4_num_reorder_frames;
958
0
    }
959
1
    else
960
1
    {
961
1
        u4_num_reorder_frames = -1;
962
1
    }
963
1
    if(1 == ps_seq->u1_vui_parameters_present_flag)
964
1
    {
965
1
        ret = ih264d_parse_vui_parametres(&ps_seq->s_vui, ps_bitstrm);
966
1
        if(ret != OK)
967
1
            return ret;
968
1
    }
969
1
970
1
    /* Compare older u4_num_reorder_frames with the new one if header is already decoded */
971
1
    if((ps_dec->i4_header_decoded & 1) &&
972
1
                    (-1 != (WORD32)u4_num_reorder_frames) &&
973
1
                    (1 == ps_seq->u1_vui_parameters_present_flag) &&
974
1
                    (1 == ps_seq->s_vui.u1_bitstream_restriction_flag) &&
975
1
                    (ps_seq->s_vui.u4_num_reorder_frames != u4_num_reorder_frames))
976
0
    {
977
0
        ps_dec->u1_res_changed = 1;
978
0
        return IVD_RES_CHANGED;
979
0
    }
980
1
981
1
    /* In case bitstream read has exceeded the filled size, then
982
1
     return an error */
983
1
    if (ps_bitstrm->u4_ofst > ps_bitstrm->u4_max_ofst)
984
0
    {
985
0
        return ERROR_INV_SPS_PPS_T;
986
0
    }
987
1
988
1
    /*--------------------------------------------------------------------*/
989
1
    /* All initializations to ps_dec are beyond this point                */
990
1
    /*--------------------------------------------------------------------*/
991
1
    ps_dec->u2_disp_height = i4_cropped_ht;
992
1
    ps_dec->u2_disp_width = i4_cropped_wd;
993
1
994
1
    ps_dec->u2_pic_wd = u2_pic_wd;
995
1
    ps_dec->u2_pic_ht = u2_pic_ht;
996
1
997
1
    /* Determining the Width and Height of Frame from that of Picture */
998
1
    ps_dec->u2_frm_wd_y = u2_frm_wd_y;
999
1
    ps_dec->u2_frm_ht_y = u2_frm_ht_y;
1000
1
1001
1
    ps_dec->u2_frm_wd_uv = u2_frm_wd_uv;
1002
1
    ps_dec->u2_frm_ht_uv = u2_frm_ht_uv;
1003
1
    ps_dec->s_pad_mgr.u1_pad_len_y_v = (UWORD8)(PAD_LEN_Y_V << (1 - u1_frm));
1004
1
    ps_dec->s_pad_mgr.u1_pad_len_cr_v = (UWORD8)(PAD_LEN_UV_V << (1 - u1_frm));
1005
1
1006
1
    ps_dec->u2_frm_wd_in_mbs = ps_seq->u2_frm_wd_in_mbs;
1007
1
    ps_dec->u2_frm_ht_in_mbs = ps_seq->u2_frm_ht_in_mbs;
1008
1
1009
1
    ps_dec->u2_crop_offset_y = u2_crop_offset_y;
1010
1
    ps_dec->u2_crop_offset_uv = u2_crop_offset_uv;
1011
1
1012
1
    ps_seq->u1_is_valid = TRUE;
1013
1
    ps_dec->ps_sps[u1_seq_parameter_set_id] = *ps_seq;
1014
1
    ps_dec->ps_cur_sps = &ps_dec->ps_sps[u1_seq_parameter_set_id];
1015
1
1016
1
    return OK;
1017
1
}
1018
1019
/*!
1020
 **************************************************************************
1021
 * \if Function name : ih264d_parse_end_of_sequence \endif
1022
 *
1023
 * \brief
1024
 *    Decodes End of Sequence.
1025
 *
1026
 * \param ps_bitstrm   : Pointer to bit ps_bitstrm containing the NAL unit
1027
 *
1028
 * \return
1029
 *    0 on Success and error code otherwise
1030
 **************************************************************************
1031
 */
1032
WORD32 ih264d_parse_end_of_sequence(dec_struct_t * ps_dec)
1033
0
{
1034
0
    WORD32 ret;
1035
0
1036
0
    ret = ih264d_end_of_pic_processing(ps_dec);
1037
0
    return ret;
1038
0
}
1039
1040
/*!
1041
 **************************************************************************
1042
 * \if Function name : AcessUnitDelimiterRbsp \endif
1043
 *
1044
 * \brief
1045
 *    Decodes AcessUnitDelimiterRbsp.
1046
 *
1047
 * \param ps_bitstrm   : Pointer to bit ps_bitstrm containing the NAL unit
1048
 *
1049
 * \return
1050
 *    0 on Success and error code otherwise
1051
 **************************************************************************
1052
 */
1053
1054
WORD32 ih264d_access_unit_delimiter_rbsp(dec_struct_t * ps_dec)
1055
0
{
1056
0
    UWORD8 u1_primary_pic_type;
1057
0
    u1_primary_pic_type = ih264d_get_bits_h264(ps_dec->ps_bitstrm, 3);
1058
0
    switch(u1_primary_pic_type)
1059
0
    {
1060
0
        case I_PIC:
1061
0
        case SI_PIC:
1062
0
        case ISI_PIC:
1063
0
            ps_dec->ps_dec_err_status->u1_pic_aud_i = PIC_TYPE_I;
1064
0
            break;
1065
0
        default:
1066
0
            ps_dec->ps_dec_err_status->u1_pic_aud_i = PIC_TYPE_UNKNOWN;
1067
0
    }
1068
0
    return (0);
1069
0
}
1070
/*!
1071
 **************************************************************************
1072
 * \if Function name : ih264d_parse_nal_unit \endif
1073
 *
1074
 * \brief
1075
 *    Decodes NAL unit
1076
 *
1077
 * \return
1078
 *    0 on Success and error code otherwise
1079
 **************************************************************************
1080
 */
1081
1082
WORD32 ih264d_parse_nal_unit(iv_obj_t *dec_hdl,
1083
                          ivd_video_decode_op_t *ps_dec_op,
1084
                          UWORD8 *pu1_buf,
1085
                          UWORD32 u4_length)
1086
13
{
1087
13
1088
13
    dec_bit_stream_t *ps_bitstrm;
1089
13
1090
13
1091
13
    dec_struct_t *ps_dec = (dec_struct_t *)dec_hdl->pv_codec_handle;
1092
13
    ivd_video_decode_ip_t *ps_dec_in =
1093
13
                    (ivd_video_decode_ip_t *)ps_dec->pv_dec_in;
1094
13
    dec_slice_params_t * ps_cur_slice = ps_dec->ps_cur_slice;
1095
13
    UWORD8 u1_first_byte, u1_nal_ref_idc;
1096
13
    UWORD8 u1_nal_unit_type;
1097
13
    WORD32 i_status = OK;
1098
13
    ps_bitstrm = ps_dec->ps_bitstrm;
1099
13
1100
13
    if(pu1_buf)
1101
13
    {
1102
13
        if(u4_length)
1103
13
        {
1104
13
            ps_dec_op->u4_frame_decoded_flag = 0;
1105
13
            ih264d_process_nal_unit(ps_dec->ps_bitstrm, pu1_buf,
1106
13
                                    u4_length);
1107
13
1108
13
            SWITCHOFFTRACE;
1109
13
            u1_first_byte = ih264d_get_bits_h264(ps_bitstrm, 8);
1110
13
1111
13
            if(NAL_FORBIDDEN_BIT(u1_first_byte))
1112
13
            {
1113
0
                H264_DEC_DEBUG_PRINT("\nForbidden bit set in Nal Unit, Let's try\n");
1114
0
            }
1115
13
            u1_nal_unit_type = NAL_UNIT_TYPE(u1_first_byte);
1116
13
            // if any other nal unit other than slice nal is encountered in between a
1117
13
            // frame break out of loop without consuming header
1118
13
            if ((ps_dec->u4_slice_start_code_found == 1)
1119
13
                    && (ps_dec->u1_pic_decode_done != 1)
1120
13
                    && (u1_nal_unit_type > IDR_SLICE_NAL))
1121
0
            {
1122
0
                return ERROR_INCOMPLETE_FRAME;
1123
0
            }
1124
13
            ps_dec->u1_nal_unit_type = u1_nal_unit_type;
1125
13
            u1_nal_ref_idc = (UWORD8)(NAL_REF_IDC(u1_first_byte));
1126
13
            //Skip all NALUs if SPS and PPS are not decoded
1127
13
            switch(u1_nal_unit_type)
1128
13
            {
1129
13
                case SLICE_DATA_PARTITION_A_NAL:
1130
0
                case SLICE_DATA_PARTITION_B_NAL:
1131
0
                case SLICE_DATA_PARTITION_C_NAL:
1132
0
                    if(!ps_dec->i4_decode_header)
1133
0
                        ih264d_parse_slice_partition(ps_dec, ps_bitstrm);
1134
0
1135
0
                    break;
1136
0
1137
11
                case IDR_SLICE_NAL:
1138
11
                case SLICE_NAL:
1139
11
1140
11
                    /* ! */
1141
11
                    DEBUG_THREADS_PRINTF("Decoding  a slice NAL\n");
1142
11
                    if(!ps_dec->i4_decode_header)
1143
11
                    {
1144
11
                        if(ps_dec->i4_header_decoded == 3)
1145
11
                        {
1146
11
                            /* ! */
1147
11
                            ps_dec->u4_slice_start_code_found = 1;
1148
11
1149
11
                            ih264d_rbsp_to_sodb(ps_dec->ps_bitstrm);
1150
11
1151
11
                            i_status = ih264d_parse_decode_slice(
1152
11
                                            (UWORD8)(u1_nal_unit_type
1153
11
                                                            == IDR_SLICE_NAL),
1154
11
                                            u1_nal_ref_idc, ps_dec);
1155
11
1156
11
                            if(i_status != OK)
1157
11
                            {
1158
0
                                return i_status;
1159
0
                            }
1160
0
                        }
1161
0
                        else
1162
0
                        {
1163
0
                            H264_DEC_DEBUG_PRINT(
1164
0
                                            "\nSlice NAL Supplied but no header has been supplied\n");
1165
0
                        }
1166
11
                    }
1167
11
                    break;
1168
11
1169
11
                case SEI_NAL:
1170
0
                    if(!ps_dec->i4_decode_header)
1171
0
                    {
1172
0
                        ih264d_rbsp_to_sodb(ps_dec->ps_bitstrm);
1173
0
                        i_status = ih264d_parse_sei_message(ps_dec, ps_bitstrm);
1174
0
                        if(i_status != OK)
1175
0
                            return i_status;
1176
0
                        ih264d_parse_sei(ps_dec, ps_bitstrm);
1177
0
                    }
1178
0
                    break;
1179
1
                case SEQ_PARAM_NAL:
1180
1
                    /* ! */
1181
1
                    ih264d_rbsp_to_sodb(ps_dec->ps_bitstrm);
1182
1
                    i_status = ih264d_parse_sps(ps_dec, ps_bitstrm);
1183
1
                    ps_dec->u4_sps_cnt_in_process++;
1184
1
                    /*If a resolution change happens within a process call, due to multiple sps
1185
1
                     * we will not support it.
1186
1
                     */
1187
1
                    if((ps_dec->u4_sps_cnt_in_process > 1 ) &&
1188
1
                                    (i_status == IVD_RES_CHANGED))
1189
0
                    {
1190
0
                        i_status = ERROR_INV_SPS_PPS_T;
1191
0
                        ps_dec->u1_res_changed = 0;
1192
0
                    }
1193
1
                    if(i_status == ERROR_INV_SPS_PPS_T)
1194
0
                        return i_status;
1195
1
                    if(!i_status)
1196
1
                        ps_dec->i4_header_decoded |= 0x1;
1197
1
                    break;
1198
1
1199
1
                case PIC_PARAM_NAL:
1200
1
                    /* ! */
1201
1
                    ih264d_rbsp_to_sodb(ps_dec->ps_bitstrm);
1202
1
                    i_status = ih264d_parse_pps(ps_dec, ps_bitstrm);
1203
1
                    if(i_status == ERROR_INV_SPS_PPS_T)
1204
0
                        return i_status;
1205
1
                    if(!i_status)
1206
1
                        ps_dec->i4_header_decoded |= 0x2;
1207
1
                    break;
1208
1
                case ACCESS_UNIT_DELIMITER_RBSP:
1209
0
                    if(!ps_dec->i4_decode_header)
1210
0
                    {
1211
0
                        ih264d_access_unit_delimiter_rbsp(ps_dec);
1212
0
                    }
1213
0
                    break;
1214
1
                    //Let us ignore the END_OF_SEQ_RBSP NAL and decode even after this NAL
1215
1
                case END_OF_STREAM_RBSP:
1216
0
                    if(!ps_dec->i4_decode_header)
1217
0
                    {
1218
0
                        ih264d_parse_end_of_stream(ps_dec);
1219
0
                    }
1220
0
                    break;
1221
1
                case FILLER_DATA_NAL:
1222
0
                    if(!ps_dec->i4_decode_header)
1223
0
                    {
1224
0
                        ih264d_parse_filler_data(ps_dec, ps_bitstrm);
1225
0
                    }
1226
0
                    break;
1227
1
                default:
1228
0
                    H264_DEC_DEBUG_PRINT("\nUnknown NAL type %d\n", u1_nal_unit_type);
1229
0
                    break;
1230
13
            }
1231
13
1232
13
        }
1233
13
1234
13
    }
1235
13
1236
13
    return i_status;
1237
13
1238
13
}
1239
/proc/self/cwd/external/libavc/decoder/ih264d_parse_islice.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
21
/*!
22
 **************************************************************************
23
 * \file ih264d_parse_islice.c
24
 *
25
 * \brief
26
 *    Contains routines that decode a I slice type
27
 *
28
 * Detailed_description
29
 *
30
 * \date
31
 *    07/07/2003
32
 *
33
 * \author  NS
34
 **************************************************************************
35
 */
36
#include "ih264d_error_handler.h"
37
#include "ih264d_debug.h"
38
#include <string.h>
39
#include "ih264d_bitstrm.h"
40
#include "ih264d_defs.h"
41
#include "ih264d_debug.h"
42
#include "ih264d_tables.h"
43
#include "ih264d_structs.h"
44
#include "ih264d_defs.h"
45
#include "ih264d_parse_cavlc.h"
46
#include "ih264d_mb_utils.h"
47
#include "ih264d_deblocking.h"
48
#include "ih264d_cabac.h"
49
#include "ih264d_parse_cabac.h"
50
#include "ih264d_parse_mb_header.h"
51
#include "ih264d_parse_slice.h"
52
#include "ih264d_process_pslice.h"
53
#include "ih264d_process_intra_mb.h"
54
#include "ih264d_parse_islice.h"
55
#include "ih264d_error_handler.h"
56
#include "ih264d_mvpred.h"
57
#include "ih264d_defs.h"
58
#include "ih264d_thread_parse_decode.h"
59
#include "ithread.h"
60
#include "ih264d_parse_mb_header.h"
61
#include "assert.h"
62
#include "ih264d_utils.h"
63
#include "ih264d_format_conv.h"
64
65
void ih264d_init_cabac_contexts(UWORD8 u1_slice_type, dec_struct_t * ps_dec);
66
67
void ih264d_itrans_recon_luma_dc(dec_struct_t *ps_dec,
68
                                 WORD16* pi2_src,
69
                                 WORD16* pi2_coeff_block,
70
                                 const UWORD16 *pu2_weigh_mat);
71
72
73
74
/*!
75
 **************************************************************************
76
 * \if Function name : ParseIMb \endif
77
 *
78
 * \brief
79
 *    This function parses CAVLC syntax of a I MB. If 16x16 Luma DC transform
80
 *    is also done here. Transformed Luma DC values are copied in their
81
 *    0th pixel location of corrosponding CoeffBlock.
82
 *
83
 * \return
84
 *    0 on Success and Error code otherwise
85
 **************************************************************************
86
 */
87
WORD32 ih264d_parse_imb_cavlc(dec_struct_t * ps_dec,
88
                              dec_mb_info_t * ps_cur_mb_info,
89
                              UWORD8 u1_mb_num,
90
                              UWORD8 u1_mb_type)
91
5.06k
{
92
5.06k
    WORD32 i4_delta_qp;
93
5.06k
    UWORD32 u4_temp;
94
5.06k
    UWORD32 ui_is_top_mb_available;
95
5.06k
    UWORD32 ui_is_left_mb_available;
96
5.06k
    UWORD32 u4_cbp;
97
5.06k
    UWORD32 u4_offset;
98
5.06k
    UWORD32 *pu4_bitstrm_buf;
99
5.06k
    WORD32 ret;
100
5.06k
101
5.06k
    dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
102
5.06k
    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
103
5.06k
    UNUSED(u1_mb_num);
104
5.06k
    ps_cur_mb_info->u1_tran_form8x8 = 0;
105
5.06k
    ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0;
106
5.06k
107
5.06k
    ps_cur_mb_info->u1_yuv_dc_block_flag = 0;
108
5.06k
109
5.06k
    u4_temp = ps_dec->u1_mb_ngbr_availablity;
110
5.06k
    ui_is_top_mb_available = BOOLEAN(u4_temp & TOP_MB_AVAILABLE_MASK);
111
5.06k
    ui_is_left_mb_available = BOOLEAN(u4_temp & LEFT_MB_AVAILABLE_MASK);
112
5.06k
113
5.06k
    pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
114
5.06k
115
5.06k
    if(u1_mb_type == I_4x4_MB)
116
5.06k
    {
117
2.54k
        ps_cur_mb_info->ps_curmb->u1_mb_type = I_4x4_MB;
118
2.54k
        u4_offset = 0;
119
2.54k
120
2.54k
        /*--------------------------------------------------------------------*/
121
2.54k
        /* Read transform_size_8x8_flag if present                            */
122
2.54k
        /*--------------------------------------------------------------------*/
123
2.54k
        if(ps_dec->s_high_profile.u1_transform8x8_present)
124
0
        {
125
0
            ps_cur_mb_info->u1_tran_form8x8 = ih264d_get_bit_h264(ps_bitstrm);
126
0
            COPYTHECONTEXT("transform_size_8x8_flag", ps_cur_mb_info->u1_tran_form8x8);
127
0
            ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = ps_cur_mb_info->u1_tran_form8x8;
128
0
        }
129
2.54k
130
2.54k
        /*--------------------------------------------------------------------*/
131
2.54k
        /* Read the IntraPrediction modes for LUMA                            */
132
2.54k
        /*--------------------------------------------------------------------*/
133
2.54k
        if (!ps_cur_mb_info->u1_tran_form8x8)
134
2.54k
        {
135
2.54k
            UWORD8 *pu1_temp;
136
2.54k
            ih264d_read_intra_pred_modes(ps_dec,
137
2.54k
                                          ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data),
138
2.54k
                                          ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data+16),
139
2.54k
                                          ps_cur_mb_info->u1_tran_form8x8);
140
2.54k
            pu1_temp = (UWORD8 *)ps_dec->pv_parse_tu_coeff_data;
141
2.54k
            pu1_temp += 32;
142
2.54k
            ps_dec->pv_parse_tu_coeff_data = (void *)pu1_temp;
143
2.54k
        }
144
0
        else
145
0
        {
146
0
            UWORD8 *pu1_temp;
147
0
            ih264d_read_intra_pred_modes(ps_dec,
148
0
                                          ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data),
149
0
                                          ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data+4),
150
0
                                          ps_cur_mb_info->u1_tran_form8x8);
151
0
            pu1_temp = (UWORD8 *)ps_dec->pv_parse_tu_coeff_data;
152
0
            pu1_temp += 8;
153
0
            ps_dec->pv_parse_tu_coeff_data = (void *)pu1_temp;
154
0
        }
155
2.54k
        /*--------------------------------------------------------------------*/
156
2.54k
        /* Read the IntraPrediction mode for CHROMA                           */
157
2.54k
        /*--------------------------------------------------------------------*/
158
2.54k
//Inlined ih264d_uev
159
2.54k
        {
160
2.54k
            UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
161
2.54k
            UWORD32 u4_word, u4_ldz, u4_temp;
162
2.54k
163
2.54k
            /***************************************************************/
164
2.54k
            /* Find leading zeros in next 32 bits                          */
165
2.54k
            /***************************************************************/
166
2.54k
            NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
167
2.54k
            u4_ldz = CLZ(u4_word);
168
2.54k
            /* Flush the ps_bitstrm */
169
2.54k
            u4_bitstream_offset += (u4_ldz + 1);
170
2.54k
            /* Read the suffix from the ps_bitstrm */
171
2.54k
            u4_word = 0;
172
2.54k
            if(u4_ldz)
173
1.48k
            {
174
1.48k
                GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
175
1.48k
                        u4_ldz);
176
1.48k
            }
177
2.54k
            *pu4_bitstrm_ofst = u4_bitstream_offset;
178
2.54k
            u4_temp = ((1 << u4_ldz) + u4_word - 1);
179
2.54k
            if(u4_temp > 3)
180
0
            {
181
0
                return ERROR_CHROMA_PRED_MODE;
182
0
            }
183
2.54k
            ps_cur_mb_info->u1_chroma_pred_mode = u4_temp;
184
2.54k
            COPYTHECONTEXT("intra_chroma_pred_mode", ps_cur_mb_info->u1_chroma_pred_mode);
185
2.54k
        }
186
2.54k
        /*--------------------------------------------------------------------*/
187
2.54k
        /* Read the Coded block pattern                                       */
188
2.54k
        /*--------------------------------------------------------------------*/
189
2.54k
        {
190
2.54k
            UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
191
2.54k
            UWORD32 u4_word, u4_ldz;
192
2.54k
193
2.54k
            /***************************************************************/
194
2.54k
            /* Find leading zeros in next 32 bits                          */
195
2.54k
            /***************************************************************/
196
2.54k
            NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
197
2.54k
            u4_ldz = CLZ(u4_word);
198
2.54k
            /* Flush the ps_bitstrm */
199
2.54k
            u4_bitstream_offset += (u4_ldz + 1);
200
2.54k
            /* Read the suffix from the ps_bitstrm */
201
2.54k
            u4_word = 0;
202
2.54k
            if(u4_ldz)
203
1.93k
            {
204
1.93k
                GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
205
1.93k
                        u4_ldz);
206
1.93k
            }
207
2.54k
            *pu4_bitstrm_ofst = u4_bitstream_offset;
208
2.54k
            u4_cbp = ((1 << u4_ldz) + u4_word - 1);
209
2.54k
        }
210
2.54k
        if(u4_cbp > 47)
211
0
        {
212
0
            return ERROR_CBP;
213
0
        }
214
2.54k
215
2.54k
        u4_cbp = gau1_ih264d_cbp_table[u4_cbp][0];
216
2.54k
        COPYTHECONTEXT("coded_block_pattern", u1_cbp);
217
2.54k
        ps_cur_mb_info->u1_cbp = u4_cbp;
218
2.54k
219
2.54k
        /*--------------------------------------------------------------------*/
220
2.54k
        /* Read mb_qp_delta                                                   */
221
2.54k
        /*--------------------------------------------------------------------*/
222
2.54k
        if(ps_cur_mb_info->u1_cbp)
223
2.51k
        {
224
2.51k
            UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
225
2.51k
            UWORD32 u4_word, u4_ldz, u4_abs_val;
226
2.51k
227
2.51k
            /***************************************************************/
228
2.51k
            /* Find leading zeros in next 32 bits                          */
229
2.51k
            /***************************************************************/
230
2.51k
            NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
231
2.51k
            u4_ldz = CLZ(u4_word);
232
2.51k
233
2.51k
            /* Flush the ps_bitstrm */
234
2.51k
            u4_bitstream_offset += (u4_ldz + 1);
235
2.51k
236
2.51k
            /* Read the suffix from the ps_bitstrm */
237
2.51k
            u4_word = 0;
238
2.51k
            if(u4_ldz)
239
0
            {
240
0
                GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
241
0
                        u4_ldz);
242
0
            }
243
2.51k
244
2.51k
            *pu4_bitstrm_ofst = u4_bitstream_offset;
245
2.51k
            u4_abs_val = ((1 << u4_ldz) + u4_word) >> 1;
246
2.51k
247
2.51k
            if(u4_word & 0x1)
248
0
            {
249
0
                i4_delta_qp = (-(WORD32)u4_abs_val);
250
0
            }
251
2.51k
            else
252
2.51k
            {
253
2.51k
                i4_delta_qp = (u4_abs_val);
254
2.51k
            }
255
2.51k
256
2.51k
            if((i4_delta_qp < -26) || (i4_delta_qp > 25))
257
0
            {
258
0
                return ERROR_INV_RANGE_QP_T;
259
0
            }
260
2.51k
261
2.51k
            COPYTHECONTEXT("mb_qp_delta", i1_delta_qp);
262
2.51k
            if(i4_delta_qp != 0)
263
0
            {
264
0
                ret = ih264d_update_qp(ps_dec, (WORD8)i4_delta_qp);
265
0
                if(ret != OK)
266
0
                    return ret;
267
2.51k
            }
268
2.51k
        }
269
2.51k
270
2.51k
    }
271
2.51k
    else
272
2.51k
    {
273
2.51k
        u4_offset = 1;
274
2.51k
        ps_cur_mb_info->ps_curmb->u1_mb_type = I_16x16_MB;
275
2.51k
        /*-------------------------------------------------------------------*/
276
2.51k
        /* Read the IntraPrediction mode for CHROMA                          */
277
2.51k
        /*-------------------------------------------------------------------*/
278
2.51k
        {
279
2.51k
            UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
280
2.51k
            UWORD32 u4_word, u4_ldz;
281
2.51k
282
2.51k
            /***************************************************************/
283
2.51k
            /* Find leading zeros in next 32 bits                          */
284
2.51k
            /***************************************************************/
285
2.51k
            NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
286
2.51k
            u4_ldz = CLZ(u4_word);
287
2.51k
            /* Flush the ps_bitstrm */
288
2.51k
            u4_bitstream_offset += (u4_ldz + 1);
289
2.51k
            /* Read the suffix from the ps_bitstrm */
290
2.51k
            u4_word = 0;
291
2.51k
            if(u4_ldz)
292
1.12k
            {
293
1.12k
                GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
294
1.12k
                        u4_ldz);
295
1.12k
            }
296
2.51k
            *pu4_bitstrm_ofst = u4_bitstream_offset;
297
2.51k
            u4_temp = ((1 << u4_ldz) + u4_word - 1);
298
2.51k
299
2.51k
//Inlined ih264d_uev
300
2.51k
301
2.51k
            if(u4_temp > 3)
302
0
            {
303
0
                return ERROR_CHROMA_PRED_MODE;
304
0
            }
305
2.51k
            ps_cur_mb_info->u1_chroma_pred_mode = u4_temp;
306
2.51k
            COPYTHECONTEXT("intra_chroma_pred_mode", ps_cur_mb_info->u1_chroma_pred_mode);
307
2.51k
        }
308
2.51k
        /*-------------------------------------------------------------------*/
309
2.51k
        /* Read the Coded block pattern                                      */
310
2.51k
        /*-------------------------------------------------------------------*/
311
2.51k
        u4_cbp = gau1_ih264d_cbp_tab[(u1_mb_type - 1) >> 2];
312
2.51k
        ps_cur_mb_info->u1_cbp = u4_cbp;
313
2.51k
314
2.51k
        /*-------------------------------------------------------------------*/
315
2.51k
        /* Read mb_qp_delta                                                  */
316
2.51k
        /*-------------------------------------------------------------------*/
317
2.51k
        {
318
2.51k
            UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
319
2.51k
            UWORD32 u4_word, u4_ldz, u4_abs_val;
320
2.51k
321
2.51k
            /***************************************************************/
322
2.51k
            /* Find leading zeros in next 32 bits                          */
323
2.51k
            /***************************************************************/
324
2.51k
            NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
325
2.51k
            u4_ldz = CLZ(u4_word);
326
2.51k
327
2.51k
            /* Flush the ps_bitstrm */
328
2.51k
            u4_bitstream_offset += (u4_ldz + 1);
329
2.51k
330
2.51k
            /* Read the suffix from the ps_bitstrm */
331
2.51k
            u4_word = 0;
332
2.51k
            if(u4_ldz)
333
2.51k
                GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
334
2.51k
                        u4_ldz);
335
2.51k
336
2.51k
            *pu4_bitstrm_ofst = u4_bitstream_offset;
337
2.51k
            u4_abs_val = ((1 << u4_ldz) + u4_word) >> 1;
338
2.51k
339
2.51k
            if(u4_word & 0x1)
340
0
                i4_delta_qp = (-(WORD32)u4_abs_val);
341
2.51k
            else
342
2.51k
                i4_delta_qp = (u4_abs_val);
343
2.51k
344
2.51k
            if((i4_delta_qp < -26) || (i4_delta_qp > 25))
345
0
                return ERROR_INV_RANGE_QP_T;
346
2.51k
347
2.51k
        }
348
2.51k
//inlinined ih264d_sev
349
2.51k
        COPYTHECONTEXT("Delta quant", i1_delta_qp);
350
2.51k
351
2.51k
        if(i4_delta_qp != 0)
352
0
        {
353
0
            ret = ih264d_update_qp(ps_dec, (WORD8)i4_delta_qp);
354
0
            if(ret != OK)
355
0
                return ret;
356
2.51k
        }
357
2.51k
358
2.51k
        {
359
2.51k
            WORD16 i_scaleFactor;
360
2.51k
            UWORD32 ui_N = 0;
361
2.51k
            WORD16 *pi2_scale_matrix_ptr;
362
2.51k
            /*******************************************************************/
363
2.51k
            /* for luma DC coefficients the scaling is done during the parsing */
364
2.51k
            /* to preserve the precision                                       */
365
2.51k
            /*******************************************************************/
366
2.51k
            if(ps_dec->s_high_profile.u1_scaling_present)
367
0
            {
368
0
                pi2_scale_matrix_ptr =
369
0
                                ps_dec->s_high_profile.i2_scalinglist4x4[0];
370
0
            }
371
2.51k
            else
372
2.51k
            {
373
2.51k
                i_scaleFactor = 16;
374
2.51k
                pi2_scale_matrix_ptr = &i_scaleFactor;
375
2.51k
            }
376
2.51k
377
2.51k
            /*---------------------------------------------------------------*/
378
2.51k
            /* Decode DC coefficients                                        */
379
2.51k
            /*---------------------------------------------------------------*/
380
2.51k
            /*---------------------------------------------------------------*/
381
2.51k
            /* Calculation of N                                              */
382
2.51k
            /*---------------------------------------------------------------*/
383
2.51k
            if(ui_is_left_mb_available)
384
2.42k
            {
385
2.42k
386
2.42k
                if(ui_is_top_mb_available)
387
2.22k
                {
388
2.22k
                    ui_N = ((ps_cur_mb_info->ps_top_mb->pu1_nnz_y[0]
389
2.22k
                                    + ps_dec->pu1_left_nnz_y[0] + 1) >> 1);
390
2.22k
                }
391
198
                else
392
198
                {
393
198
                    ui_N = ps_dec->pu1_left_nnz_y[0];
394
198
                }
395
2.42k
            }
396
99
            else if(ui_is_top_mb_available)
397
99
            {
398
99
                ui_N = ps_cur_mb_info->ps_top_mb->pu1_nnz_y[0];
399
99
            }
400
2.51k
401
2.51k
            {
402
2.51k
                WORD16 pi2_dc_coef[16];
403
2.51k
                WORD32 pi4_tmp[16];
404
2.51k
                tu_sblk4x4_coeff_data_t *ps_tu_4x4 =
405
2.51k
                                (tu_sblk4x4_coeff_data_t *)ps_dec->pv_parse_tu_coeff_data;
406
2.51k
                WORD16 *pi2_coeff_block =
407
2.51k
                                (WORD16 *)ps_dec->pv_parse_tu_coeff_data;
408
2.51k
                UWORD32 u4_num_coeff;
409
2.51k
                ps_tu_4x4->u2_sig_coeff_map = 0;
410
2.51k
411
2.51k
                ret = ps_dec->pf_cavlc_parse4x4coeff[(ui_N > 7)](pi2_dc_coef, 0, ui_N,
412
2.51k
                                                                 ps_dec, &u4_num_coeff);
413
2.51k
                if(ret != OK)
414
2.51k
                    return ret;
415
2.51k
416
2.51k
                if(EXCEED_OFFSET(ps_bitstrm))
417
2.51k
                    return ERROR_EOB_TERMINATE_T;
418
2.51k
                if(ps_tu_4x4->u2_sig_coeff_map)
419
0
                {
420
0
                    memset(pi2_dc_coef,0,sizeof(pi2_dc_coef));
421
0
                    ih264d_unpack_coeff4x4_dc_4x4blk(ps_tu_4x4,
422
0
                                                     pi2_dc_coef,
423
0
                                                     ps_dec->pu1_inv_scan);
424
0
425
0
                    PROFILE_DISABLE_IQ_IT_RECON()
426
0
                    ps_dec->pf_ihadamard_scaling_4x4(pi2_dc_coef,
427
0
                                                     pi2_coeff_block,
428
0
                                                     ps_dec->pu2_quant_scale_y,
429
0
                                                     (UWORD16 *)pi2_scale_matrix_ptr,
430
0
                                                     ps_dec->u1_qp_y_div6,
431
0
                                                     pi4_tmp);
432
0
                    pi2_coeff_block += 16;
433
0
                    ps_dec->pv_parse_tu_coeff_data = (void *)pi2_coeff_block;
434
0
                    SET_BIT(ps_cur_mb_info->u1_yuv_dc_block_flag,0);
435
0
                }
436
2.51k
437
2.51k
            }
438
2.51k
        }
439
2.51k
    }
440
5.06k
441
5.06k
442
5.06k
    if(u4_cbp)
443
2.87k
    {
444
2.87k
445
2.87k
        ret = ih264d_parse_residual4x4_cavlc(ps_dec, ps_cur_mb_info,
446
2.87k
                                       (UWORD8)u4_offset);
447
2.87k
        if(ret != OK)
448
2.87k
            return ret;
449
2.87k
        if(EXCEED_OFFSET(ps_bitstrm))
450
2.87k
            return ERROR_EOB_TERMINATE_T;
451
2.18k
452
2.18k
        /* Store Left Mb NNZ and TOP chroma NNZ */
453
2.18k
    }
454
2.18k
    else
455
2.18k
    {
456
2.18k
        ps_cur_mb_info->u1_qp_div6 = ps_dec->u1_qp_y_div6;
457
2.18k
        ps_cur_mb_info->u1_qpc_div6 = ps_dec->u1_qp_u_div6;
458
2.18k
        ps_cur_mb_info->u1_qpcr_div6 = ps_dec->u1_qp_v_div6;
459
2.18k
        ps_cur_mb_info->u1_qp_rem6 = ps_dec->u1_qp_y_rem6;
460
2.18k
        ps_cur_mb_info->u1_qpc_rem6 = ps_dec->u1_qp_u_rem6;
461
2.18k
        ps_cur_mb_info->u1_qpcr_rem6 = ps_dec->u1_qp_v_rem6;
462
2.18k
        ih264d_update_nnz_for_skipmb(ps_dec, ps_cur_mb_info, CAVLC);
463
2.18k
    }
464
5.06k
465
5.06k
    return OK;
466
5.06k
}
467
468
/*!
469
 **************************************************************************
470
 * \if Function name : ParseIMbCab \endif
471
 *
472
 * \brief
473
 *    This function parses CABAC syntax of a I MB. If 16x16 Luma DC transform
474
 *    is also done here. Transformed Luma DC values are copied in their
475
 *    0th pixel location of corrosponding CoeffBlock.
476
 *
477
 * \return
478
 *    0 on Success and Error code otherwise
479
 **************************************************************************
480
 */
481
WORD32 ih264d_parse_imb_cabac(dec_struct_t * ps_dec,
482
                              dec_mb_info_t * ps_cur_mb_info,
483
                              UWORD8 u1_mb_type)
484
0
{
485
0
    WORD8 i1_delta_qp;
486
0
    UWORD8 u1_cbp;
487
0
    UWORD8 u1_offset;
488
0
    /* Variables for handling Cabac contexts */
489
0
    ctxt_inc_mb_info_t *p_curr_ctxt = ps_dec->ps_curr_ctxt_mb_info;
490
0
    ctxt_inc_mb_info_t *ps_left_ctxt = ps_dec->p_left_ctxt_mb_info;
491
0
    dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
492
0
    bin_ctxt_model_t *p_bin_ctxt;
493
0
494
0
    UWORD8 u1_intra_chrom_pred_mode;
495
0
    UWORD8 u1_dc_block_flag = 0;
496
0
    WORD32 ret;
497
0
498
0
    ps_cur_mb_info->u1_yuv_dc_block_flag = 0;
499
0
500
0
    if(ps_left_ctxt == ps_dec->ps_def_ctxt_mb_info)
501
0
    {
502
0
        ps_dec->pu1_left_yuv_dc_csbp[0] = 0xf;
503
0
    }
504
0
505
0
    if(ps_dec->ps_cur_slice->u1_slice_type != I_SLICE)
506
0
    {
507
0
        WORD32 *pi4_buf;
508
0
        WORD8 *pi1_buf;
509
0
        MEMSET_16BYTES(&ps_dec->pu1_left_mv_ctxt_inc[0][0], 0);
510
0
        *((UWORD32 *)ps_dec->pi1_left_ref_idx_ctxt_inc) = 0;
511
0
        MEMSET_16BYTES(p_curr_ctxt->u1_mv, 0);
512
0
        memset(p_curr_ctxt->i1_ref_idx, 0, 4);
513
0
    }
514
0
515
0
    if(u1_mb_type == I_4x4_MB)
516
0
    {
517
0
        ps_cur_mb_info->ps_curmb->u1_mb_type = I_4x4_MB;
518
0
        p_curr_ctxt->u1_mb_type = CAB_I4x4;
519
0
        u1_offset = 0;
520
0
521
0
        ps_cur_mb_info->u1_tran_form8x8 = 0;
522
0
        ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0;
523
0
524
0
        /*--------------------------------------------------------------------*/
525
0
        /* Read transform_size_8x8_flag if present                            */
526
0
        /*--------------------------------------------------------------------*/
527
0
        if(ps_dec->s_high_profile.u1_transform8x8_present)
528
0
        {
529
0
            ps_cur_mb_info->u1_tran_form8x8 = ih264d_parse_transform8x8flag_cabac(
530
0
                            ps_dec, ps_cur_mb_info);
531
0
            COPYTHECONTEXT("transform_size_8x8_flag", ps_cur_mb_info->u1_tran_form8x8);
532
0
            p_curr_ctxt->u1_transform8x8_ctxt = ps_cur_mb_info->u1_tran_form8x8;
533
0
            ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = ps_cur_mb_info->u1_tran_form8x8;
534
0
        }
535
0
        else
536
0
        {
537
0
            p_curr_ctxt->u1_transform8x8_ctxt = 0;
538
0
        }
539
0
540
0
        /*--------------------------------------------------------------------*/
541
0
        /* Read the IntraPrediction modes for LUMA                            */
542
0
        /*--------------------------------------------------------------------*/
543
0
        if (!ps_cur_mb_info->u1_tran_form8x8)
544
0
        {
545
0
            UWORD8 *pu1_temp;
546
0
            ih264d_read_intra_pred_modes_cabac(
547
0
                            ps_dec,
548
0
                            ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data),
549
0
                            ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data+16),
550
0
                            ps_cur_mb_info->u1_tran_form8x8);
551
0
            pu1_temp = (UWORD8 *)ps_dec->pv_parse_tu_coeff_data;
552
0
            pu1_temp += 32;
553
0
            ps_dec->pv_parse_tu_coeff_data = (void *)pu1_temp;
554
0
        }
555
0
        else
556
0
        {
557
0
            UWORD8 *pu1_temp;
558
0
            ih264d_read_intra_pred_modes_cabac(
559
0
                            ps_dec,
560
0
                            ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data),
561
0
                            ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data+4),
562
0
                            ps_cur_mb_info->u1_tran_form8x8);
563
0
            pu1_temp = (UWORD8 *)ps_dec->pv_parse_tu_coeff_data;
564
0
            pu1_temp += 8;
565
0
            ps_dec->pv_parse_tu_coeff_data = (void *)pu1_temp;
566
0
        }
567
0
        /*--------------------------------------------------------------------*/
568
0
        /* Read the IntraPrediction mode for CHROMA                           */
569
0
        /*--------------------------------------------------------------------*/
570
0
        u1_intra_chrom_pred_mode = ih264d_parse_chroma_pred_mode_cabac(ps_dec);
571
0
        COPYTHECONTEXT("intra_chroma_pred_mode", u1_intra_chrom_pred_mode);
572
0
        p_curr_ctxt->u1_intra_chroma_pred_mode = ps_cur_mb_info->u1_chroma_pred_mode =
573
0
                        u1_intra_chrom_pred_mode;
574
0
575
0
        /*--------------------------------------------------------------------*/
576
0
        /* Read the Coded block pattern                                       */
577
0
        /*--------------------------------------------------------------------*/
578
0
        u1_cbp = ih264d_parse_ctx_cbp_cabac(ps_dec);
579
0
        COPYTHECONTEXT("coded_block_pattern", u1_cbp);
580
0
        ps_cur_mb_info->u1_cbp = u1_cbp;
581
0
        p_curr_ctxt->u1_cbp = u1_cbp;
582
0
583
0
        /*--------------------------------------------------------------------*/
584
0
        /* Read mb_qp_delta                                                   */
585
0
        /*--------------------------------------------------------------------*/
586
0
        if(ps_cur_mb_info->u1_cbp)
587
0
        {
588
0
            ret = ih264d_parse_mb_qp_delta_cabac(ps_dec, &i1_delta_qp);
589
0
            if(ret != OK)
590
0
                return ret;
591
0
            COPYTHECONTEXT("mb_qp_delta", i1_delta_qp);
592
0
            if(i1_delta_qp != 0)
593
0
            {
594
0
                ret = ih264d_update_qp(ps_dec, i1_delta_qp);
595
0
                if(ret != OK)
596
0
                    return ret;
597
0
            }
598
0
        }
599
0
        else
600
0
            ps_dec->i1_prev_mb_qp_delta = 0;
601
0
        p_curr_ctxt->u1_yuv_dc_csbp &= 0xFE;
602
0
    }
603
0
    else
604
0
    {
605
0
        u1_offset = 1;
606
0
        ps_cur_mb_info->ps_curmb->u1_mb_type = I_16x16_MB;
607
0
        p_curr_ctxt->u1_mb_type = CAB_I16x16;
608
0
        ps_cur_mb_info->u1_tran_form8x8 = 0;
609
0
        p_curr_ctxt->u1_transform8x8_ctxt = 0;
610
0
        ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0;
611
0
        /*--------------------------------------------------------------------*/
612
0
        /* Read the IntraPrediction mode for CHROMA                           */
613
0
        /*--------------------------------------------------------------------*/
614
0
        u1_intra_chrom_pred_mode = ih264d_parse_chroma_pred_mode_cabac(ps_dec);
615
0
        if(u1_intra_chrom_pred_mode > 3)
616
0
            return ERROR_CHROMA_PRED_MODE;
617
0
618
0
        COPYTHECONTEXT("Chroma intra_chroma_pred_mode pred mode", u1_intra_chrom_pred_mode);
619
0
        p_curr_ctxt->u1_intra_chroma_pred_mode = ps_cur_mb_info->u1_chroma_pred_mode =
620
0
                        u1_intra_chrom_pred_mode;
621
0
622
0
        /*--------------------------------------------------------------------*/
623
0
        /* Read the Coded block pattern                                       */
624
0
        /*--------------------------------------------------------------------*/
625
0
        u1_cbp = gau1_ih264d_cbp_tab[(u1_mb_type - 1) >> 2];
626
0
        ps_cur_mb_info->u1_cbp = u1_cbp;
627
0
        p_curr_ctxt->u1_cbp = u1_cbp;
628
0
629
0
        /*--------------------------------------------------------------------*/
630
0
        /* Read mb_qp_delta                                                   */
631
0
        /*--------------------------------------------------------------------*/
632
0
        ret = ih264d_parse_mb_qp_delta_cabac(ps_dec, &i1_delta_qp);
633
0
        if(ret != OK)
634
0
            return ret;
635
0
        COPYTHECONTEXT("mb_qp_delta", i1_delta_qp);
636
0
        if(i1_delta_qp != 0)
637
0
        {
638
0
            ret = ih264d_update_qp(ps_dec, i1_delta_qp);
639
0
            if(ret != OK)
640
0
                return ret;
641
0
        }
642
0
643
0
        {
644
0
            WORD16 i_scaleFactor;
645
0
            WORD16* pi2_scale_matrix_ptr;
646
0
            /*******************************************************************/
647
0
            /* for luma DC coefficients the scaling is done during the parsing */
648
0
            /* to preserve the precision                                       */
649
0
            /*******************************************************************/
650
0
            if(ps_dec->s_high_profile.u1_scaling_present)
651
0
            {
652
0
                pi2_scale_matrix_ptr =
653
0
                                ps_dec->s_high_profile.i2_scalinglist4x4[0];
654
0
655
0
            }
656
0
            else
657
0
            {
658
0
                i_scaleFactor = 16;
659
0
                pi2_scale_matrix_ptr = &i_scaleFactor;
660
0
            }
661
0
            {
662
0
                ctxt_inc_mb_info_t *ps_top_ctxt = ps_dec->p_top_ctxt_mb_info;
663
0
                UWORD8 uc_a, uc_b;
664
0
                UWORD32 u4_ctx_inc;
665
0
666
0
                INC_SYM_COUNT(&(ps_dec->s_cab_dec_env));
667
0
668
0
                /* if MbAddrN not available then CondTermN = 1 */
669
0
                uc_b = ((ps_top_ctxt->u1_yuv_dc_csbp) & 0x01);
670
0
671
0
                /* if MbAddrN not available then CondTermN = 1 */
672
0
                uc_a = ((ps_dec->pu1_left_yuv_dc_csbp[0]) & 0x01);
673
0
674
0
                u4_ctx_inc = (uc_a + (uc_b << 1));
675
0
676
0
                {
677
0
                    WORD16 pi2_dc_coef[16];
678
0
                    tu_sblk4x4_coeff_data_t *ps_tu_4x4 =
679
0
                                    (tu_sblk4x4_coeff_data_t *)ps_dec->pv_parse_tu_coeff_data;
680
0
                    WORD16 *pi2_coeff_block =
681
0
                                    (WORD16 *)ps_dec->pv_parse_tu_coeff_data;
682
0
683
0
                    p_bin_ctxt = (ps_dec->p_cbf_t[LUMA_DC_CTXCAT]) + u4_ctx_inc;
684
0
685
0
                    u1_dc_block_flag =
686
0
                                    ih264d_read_coeff4x4_cabac(ps_bitstrm,
687
0
                                                    LUMA_DC_CTXCAT,
688
0
                                                    ps_dec->p_significant_coeff_flag_t[LUMA_DC_CTXCAT],
689
0
                                                    ps_dec, p_bin_ctxt);
690
0
691
0
                    /* Store coded_block_flag */
692
0
                    p_curr_ctxt->u1_yuv_dc_csbp &= 0xFE;
693
0
                    p_curr_ctxt->u1_yuv_dc_csbp |= u1_dc_block_flag;
694
0
                    if(u1_dc_block_flag)
695
0
                    {
696
0
                        WORD32 pi4_tmp[16];
697
0
                        memset(pi2_dc_coef,0,sizeof(pi2_dc_coef));
698
0
                        ih264d_unpack_coeff4x4_dc_4x4blk(ps_tu_4x4,
699
0
                                                         pi2_dc_coef,
700
0
                                                         ps_dec->pu1_inv_scan);
701
0
702
0
                        PROFILE_DISABLE_IQ_IT_RECON()
703
0
                        ps_dec->pf_ihadamard_scaling_4x4(pi2_dc_coef,
704
0
                                                         pi2_coeff_block,
705
0
                                                         ps_dec->pu2_quant_scale_y,
706
0
                                                         (UWORD16 *)pi2_scale_matrix_ptr,
707
0
                                                         ps_dec->u1_qp_y_div6,
708
0
                                                         pi4_tmp);
709
0
                        pi2_coeff_block += 16;
710
0
                        ps_dec->pv_parse_tu_coeff_data = (void *)pi2_coeff_block;
711
0
                        SET_BIT(ps_cur_mb_info->u1_yuv_dc_block_flag,0);
712
0
                    }
713
0
714
0
                }
715
0
716
0
            }
717
0
        }
718
0
    }
719
0
720
0
    ps_dec->pu1_left_yuv_dc_csbp[0] &= 0x6;
721
0
    ps_dec->pu1_left_yuv_dc_csbp[0] |= u1_dc_block_flag;
722
0
723
0
    ih264d_parse_residual4x4_cabac(ps_dec, ps_cur_mb_info, u1_offset);
724
0
    if(EXCEED_OFFSET(ps_bitstrm))
725
0
        return ERROR_EOB_TERMINATE_T;
726
0
    return OK;
727
0
}
728
729
/*****************************************************************************/
730
/*                                                                           */
731
/*  Function Name : ih264d_parse_islice_data_cavlc                                  */
732
/*                                                                           */
733
/*  Description   : This function parses cabac syntax of a inter slice on    */
734
/*                  N MB basis.                                              */
735
/*                                                                           */
736
/*  Inputs        : ps_dec                                                   */
737
/*                  sliceparams                                              */
738
/*                  firstMbInSlice                                           */
739
/*                                                                           */
740
/*  Processing    : 1. After parsing syntax for N MBs those N MBs are        */
741
/*                     decoded till the end of slice.                        */
742
/*                                                                           */
743
/*  Returns       : 0                                                        */
744
/*                                                                           */
745
/*  Issues        : <List any issues or problems with this function>         */
746
/*                                                                           */
747
/*  Revision History:                                                        */
748
/*                                                                           */
749
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
750
/*         24 06 2005   ARNY            Draft                                */
751
/*                                                                           */
752
/*****************************************************************************/
753
WORD32 ih264d_parse_islice_data_cavlc(dec_struct_t * ps_dec,
754
                                      dec_slice_params_t * ps_slice,
755
                                      UWORD16 u2_first_mb_in_slice)
756
11
{
757
11
    UWORD8 uc_more_data_flag;
758
11
    UWORD8 u1_num_mbs, u1_mb_idx;
759
11
    dec_mb_info_t *ps_cur_mb_info;
760
11
    deblk_mb_t *ps_cur_deblk_mb;
761
11
    dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
762
11
    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
763
11
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
764
11
    UWORD16 i2_pic_wdin_mbs = ps_dec->u2_frm_wd_in_mbs;
765
11
    WORD16 i2_cur_mb_addr;
766
11
    UWORD8 u1_mbaff;
767
11
    UWORD8 u1_num_mbs_next, u1_end_of_row, u1_tfr_n_mb;
768
11
    WORD32 ret = OK;
769
11
770
11
    ps_dec->u1_qp = ps_slice->u1_slice_qp;
771
11
    ih264d_update_qp(ps_dec, 0);
772
11
    u1_mbaff = ps_slice->u1_mbaff_frame_flag;
773
11
774
11
    /* initializations */
775
11
    u1_mb_idx = ps_dec->u1_mb_idx;
776
11
    u1_num_mbs = u1_mb_idx;
777
11
778
11
    uc_more_data_flag = 1;
779
11
    i2_cur_mb_addr = u2_first_mb_in_slice << u1_mbaff;
780
11
781
11
    do
782
5.06k
    {
783
5.06k
        UWORD8 u1_mb_type;
784
5.06k
785
5.06k
        ps_dec->pv_prev_mb_parse_tu_coeff_data = ps_dec->pv_parse_tu_coeff_data;
786
5.06k
787
5.06k
        if(i2_cur_mb_addr > ps_dec->ps_cur_sps->u2_max_mb_addr)
788
0
        {
789
0
            break;
790
0
        }
791
5.06k
792
5.06k
        ps_cur_mb_info = ps_dec->ps_nmb_info + u1_num_mbs;
793
5.06k
        ps_dec->u4_num_mbs_cur_nmb = u1_num_mbs;
794
5.06k
        ps_dec->u4_num_pmbair = (u1_num_mbs >> u1_mbaff);
795
5.06k
796
5.06k
        ps_cur_mb_info->u1_end_of_slice = 0;
797
5.06k
798
5.06k
        /***************************************************************/
799
5.06k
        /* Get the required information for decoding of MB             */
800
5.06k
        /* mb_x, mb_y , neighbour availablity,                         */
801
5.06k
        /***************************************************************/
802
5.06k
        ps_dec->pf_get_mb_info(ps_dec, i2_cur_mb_addr, ps_cur_mb_info, 0);
803
5.06k
804
5.06k
        /***************************************************************/
805
5.06k
        /* Set the deblocking parameters for this MB                   */
806
5.06k
        /***************************************************************/
807
5.06k
        ps_cur_deblk_mb = ps_dec->ps_deblk_mbn + u1_num_mbs;
808
5.06k
809
5.06k
        if(ps_dec->u4_app_disable_deblk_frm == 0)
810
5.06k
            ih264d_set_deblocking_parameters(ps_cur_deblk_mb, ps_slice,
811
5.06k
                                             ps_dec->u1_mb_ngbr_availablity,
812
5.06k
                                             ps_dec->u1_cur_mb_fld_dec_flag);
813
5.06k
814
5.06k
        ps_cur_deblk_mb->u1_mb_type = ps_cur_deblk_mb->u1_mb_type | D_INTRA_MB;
815
5.06k
816
5.06k
        /**************************************************************/
817
5.06k
        /* Macroblock Layer Begins, Decode the u1_mb_type                */
818
5.06k
        /**************************************************************/
819
5.06k
//Inlined ih264d_uev
820
5.06k
        {
821
5.06k
            UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
822
5.06k
            UWORD32 u4_word, u4_ldz, u4_temp;
823
5.06k
824
5.06k
            /***************************************************************/
825
5.06k
            /* Find leading zeros in next 32 bits                          */
826
5.06k
            /***************************************************************/
827
5.06k
            NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
828
5.06k
            u4_ldz = CLZ(u4_word);
829
5.06k
            /* Flush the ps_bitstrm */
830
5.06k
            u4_bitstream_offset += (u4_ldz + 1);
831
5.06k
            /* Read the suffix from the ps_bitstrm */
832
5.06k
            u4_word = 0;
833
5.06k
            if(u4_ldz)
834
5.06k
                GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
835
5.06k
                        u4_ldz);
836
5.06k
            *pu4_bitstrm_ofst = u4_bitstream_offset;
837
5.06k
            u4_temp = ((1 << u4_ldz) + u4_word - 1);
838
5.06k
            if(u4_temp > 25)
839
0
                return ERROR_MB_TYPE;
840
5.06k
            u1_mb_type = u4_temp;
841
5.06k
842
5.06k
        }
843
5.06k
//Inlined ih264d_uev
844
5.06k
        ps_cur_mb_info->u1_mb_type = u1_mb_type;
845
5.06k
        COPYTHECONTEXT("u1_mb_type", u1_mb_type);
846
5.06k
847
5.06k
        /**************************************************************/
848
5.06k
        /* Parse Macroblock data                                      */
849
5.06k
        /**************************************************************/
850
5.06k
        if(25 == u1_mb_type)
851
0
        {
852
0
            /* I_PCM_MB */
853
0
            ps_cur_mb_info->ps_curmb->u1_mb_type = I_PCM_MB;
854
0
            ret = ih264d_parse_ipcm_mb(ps_dec, ps_cur_mb_info, u1_num_mbs);
855
0
            if(ret != OK)
856
0
                return ret;
857
0
            ps_cur_deblk_mb->u1_mb_qp = 0;
858
0
        }
859
5.06k
        else
860
5.06k
        {
861
5.06k
            ret = ih264d_parse_imb_cavlc(ps_dec, ps_cur_mb_info, u1_num_mbs, u1_mb_type);
862
5.06k
            if(ret != OK)
863
5.06k
                return ret;
864
5.06k
            ps_cur_deblk_mb->u1_mb_qp = ps_dec->u1_qp;
865
5.06k
        }
866
5.06k
867
5.06k
        uc_more_data_flag = MORE_RBSP_DATA(ps_bitstrm);
868
5.06k
869
5.06k
        if(u1_mbaff)
870
0
        {
871
0
            ih264d_update_mbaff_left_nnz(ps_dec, ps_cur_mb_info);
872
0
            if(!uc_more_data_flag && (0 == (i2_cur_mb_addr & 1)))
873
0
            {
874
0
                return ERROR_EOB_FLUSHBITS_T;
875
0
            }
876
5.06k
        }
877
5.06k
        /**************************************************************/
878
5.06k
        /* Get next Macroblock address                                */
879
5.06k
        /**************************************************************/
880
5.06k
881
5.06k
        i2_cur_mb_addr++;
882
5.06k
883
5.06k
884
5.06k
        /* Store the colocated information */
885
5.06k
        {
886
5.06k
            mv_pred_t *ps_mv_nmb_start = ps_dec->ps_mv_cur + (u1_num_mbs << 4);
887
5.06k
888
5.06k
            mv_pred_t s_mvPred =
889
5.06k
                {
890
5.06k
                    { 0, 0, 0, 0 },
891
5.06k
                      { -1, -1 }, 0, 0};
892
5.06k
            ih264d_rep_mv_colz(ps_dec, &s_mvPred, ps_mv_nmb_start, 0,
893
5.06k
                               (UWORD8)(ps_dec->u1_cur_mb_fld_dec_flag << 1), 4,
894
5.06k
                               4);
895
5.06k
        }
896
5.06k
897
5.06k
        /*if num _cores is set to 3,compute bs will be done in another thread*/
898
5.06k
        if(ps_dec->u4_num_cores < 3)
899
0
        {
900
0
            if(ps_dec->u4_app_disable_deblk_frm == 0)
901
0
                ps_dec->pf_compute_bs(ps_dec, ps_cur_mb_info,
902
0
                                     (UWORD16)(u1_num_mbs >> u1_mbaff));
903
0
        }
904
5.06k
        u1_num_mbs++;
905
5.06k
906
5.06k
        /****************************************************************/
907
5.06k
        /* Check for End Of Row                                         */
908
5.06k
        /****************************************************************/
909
5.06k
        u1_num_mbs_next = i2_pic_wdin_mbs - ps_dec->u2_mbx - 1;
910
5.06k
        u1_end_of_row = (!u1_num_mbs_next) && (!(u1_mbaff && (u1_num_mbs & 0x01)));
911
5.06k
        u1_tfr_n_mb = (u1_num_mbs == ps_dec->u1_recon_mb_grp) || u1_end_of_row
912
5.06k
                        || (!uc_more_data_flag);
913
5.06k
        ps_cur_mb_info->u1_end_of_slice = (!uc_more_data_flag);
914
5.06k
915
5.06k
        /*H264_DEC_DEBUG_PRINT("Pic: %d Mb_X=%d Mb_Y=%d",
916
5.06k
         ps_slice->i4_poc >> ps_slice->u1_field_pic_flag,
917
5.06k
         ps_dec->u2_mbx,ps_dec->u2_mby + (1 - ps_cur_mb_info->u1_topmb));
918
5.06k
         H264_DEC_DEBUG_PRINT("u1_tfr_n_mb || (!uc_more_data_flag): %d", u1_tfr_n_mb || (!uc_more_data_flag));*/
919
5.06k
        if(u1_tfr_n_mb || (!uc_more_data_flag))
920
220
        {
921
220
922
220
            if(ps_dec->u1_separate_parse)
923
220
            {
924
220
                ih264d_parse_tfr_nmb(ps_dec, u1_mb_idx, u1_num_mbs,
925
220
                                     u1_num_mbs_next, u1_tfr_n_mb, u1_end_of_row);
926
220
                ps_dec->ps_nmb_info +=  u1_num_mbs;
927
220
            }
928
0
            else
929
0
            {
930
0
                ih264d_decode_recon_tfr_nmb(ps_dec, u1_mb_idx, u1_num_mbs,
931
0
                                            u1_num_mbs_next, u1_tfr_n_mb,
932
0
                                            u1_end_of_row);
933
0
            }
934
220
            ps_dec->u2_total_mbs_coded += u1_num_mbs;
935
220
            if(u1_tfr_n_mb)
936
220
                u1_num_mbs = 0;
937
220
            u1_mb_idx = u1_num_mbs;
938
220
            ps_dec->u1_mb_idx = u1_num_mbs;
939
220
940
220
        }
941
5.06k
    }
942
5.06k
    while(uc_more_data_flag);
943
11
944
11
    ps_dec->u4_num_mbs_cur_nmb = 0;
945
11
    ps_dec->ps_cur_slice->u4_mbs_in_slice = i2_cur_mb_addr
946
11
947
11
                        - (u2_first_mb_in_slice << u1_mbaff);
948
11
949
11
    return ret;
950
11
}
951
952
/*****************************************************************************/
953
/*                                                                           */
954
/*  Function Name : ih264d_parse_islice_data_cabac                                  */
955
/*                                                                           */
956
/*  Description   : This function parses cabac syntax of a inter slice on    */
957
/*                  N MB basis.                                              */
958
/*                                                                           */
959
/*  Inputs        : ps_dec                                                   */
960
/*                  sliceparams                                              */
961
/*                  firstMbInSlice                                           */
962
/*                                                                           */
963
/*  Processing    : 1. After parsing syntax for N MBs those N MBs are        */
964
/*                     decoded till the end of slice.                        */
965
/*                                                                           */
966
/*  Returns       : 0                                                        */
967
/*                                                                           */
968
/*  Issues        : <List any issues or problems with this function>         */
969
/*                                                                           */
970
/*  Revision History:                                                        */
971
/*                                                                           */
972
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
973
/*         24 06 2005   ARNY            Draft                                */
974
/*                                                                           */
975
/*****************************************************************************/
976
WORD32 ih264d_parse_islice_data_cabac(dec_struct_t * ps_dec,
977
                                      dec_slice_params_t * ps_slice,
978
                                      UWORD16 u2_first_mb_in_slice)
979
0
{
980
0
    UWORD8 uc_more_data_flag;
981
0
    UWORD8 u1_num_mbs, u1_mb_idx;
982
0
    dec_mb_info_t *ps_cur_mb_info;
983
0
    deblk_mb_t *ps_cur_deblk_mb;
984
0
985
0
    dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
986
0
    UWORD16 i2_pic_wdin_mbs = ps_dec->u2_frm_wd_in_mbs;
987
0
    WORD16 i2_cur_mb_addr;
988
0
    UWORD8 u1_mbaff;
989
0
    UWORD8 u1_num_mbs_next, u1_end_of_row, u1_tfr_n_mb;
990
0
    WORD32 ret = OK;
991
0
992
0
    ps_dec->u1_qp = ps_slice->u1_slice_qp;
993
0
    ih264d_update_qp(ps_dec, 0);
994
0
    u1_mbaff = ps_slice->u1_mbaff_frame_flag;
995
0
996
0
    if(ps_bitstrm->u4_ofst & 0x07)
997
0
    {
998
0
        ps_bitstrm->u4_ofst += 8;
999
0
        ps_bitstrm->u4_ofst &= 0xFFFFFFF8;
1000
0
    }
1001
0
    ret = ih264d_init_cabac_dec_envirnoment(&(ps_dec->s_cab_dec_env), ps_bitstrm);
1002
0
    if(ret != OK)
1003
0
        return ret;
1004
0
    ih264d_init_cabac_contexts(I_SLICE, ps_dec);
1005
0
1006
0
    ps_dec->i1_prev_mb_qp_delta = 0;
1007
0
1008
0
    /* initializations */
1009
0
    u1_mb_idx = ps_dec->u1_mb_idx;
1010
0
    u1_num_mbs = u1_mb_idx;
1011
0
1012
0
    uc_more_data_flag = 1;
1013
0
    i2_cur_mb_addr = u2_first_mb_in_slice << u1_mbaff;
1014
0
    do
1015
0
    {
1016
0
        UWORD16 u2_mbx;
1017
0
1018
0
        ps_dec->pv_prev_mb_parse_tu_coeff_data = ps_dec->pv_parse_tu_coeff_data;
1019
0
1020
0
        if(i2_cur_mb_addr > ps_dec->ps_cur_sps->u2_max_mb_addr)
1021
0
        {
1022
0
            break;
1023
0
        }
1024
0
1025
0
        {
1026
0
            UWORD8 u1_mb_type;
1027
0
1028
0
            ps_cur_mb_info = ps_dec->ps_nmb_info + u1_num_mbs;
1029
0
            ps_dec->u4_num_mbs_cur_nmb = u1_num_mbs;
1030
0
            ps_dec->u4_num_pmbair = (u1_num_mbs >> u1_mbaff);
1031
0
1032
0
            ps_cur_mb_info->u1_end_of_slice = 0;
1033
0
1034
0
            /***************************************************************/
1035
0
            /* Get the required information for decoding of MB                  */
1036
0
            /* mb_x, mb_y , neighbour availablity,                              */
1037
0
            /***************************************************************/
1038
0
            ps_dec->pf_get_mb_info(ps_dec, i2_cur_mb_addr, ps_cur_mb_info, 0);
1039
0
            u2_mbx = ps_dec->u2_mbx;
1040
0
1041
0
            /*********************************************************************/
1042
0
            /* initialize u1_tran_form8x8 to zero to aviod uninitialized accesses */
1043
0
            /*********************************************************************/
1044
0
            ps_cur_mb_info->u1_tran_form8x8 = 0;
1045
0
            ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0;
1046
0
1047
0
            /***************************************************************/
1048
0
            /* Set the deblocking parameters for this MB                   */
1049
0
            /***************************************************************/
1050
0
            ps_cur_deblk_mb = ps_dec->ps_deblk_mbn + u1_num_mbs;
1051
0
            if(ps_dec->u4_app_disable_deblk_frm == 0)
1052
0
                ih264d_set_deblocking_parameters(
1053
0
                                ps_cur_deblk_mb, ps_slice,
1054
0
                                ps_dec->u1_mb_ngbr_availablity,
1055
0
                                ps_dec->u1_cur_mb_fld_dec_flag);
1056
0
1057
0
            ps_cur_deblk_mb->u1_mb_type = ps_cur_deblk_mb->u1_mb_type
1058
0
                            | D_INTRA_MB;
1059
0
1060
0
            /* Macroblock Layer Begins */
1061
0
            /* Decode the u1_mb_type */
1062
0
            u1_mb_type = ih264d_parse_mb_type_intra_cabac(0, ps_dec);
1063
0
            if(u1_mb_type > 25)
1064
0
                return ERROR_MB_TYPE;
1065
0
            ps_cur_mb_info->u1_mb_type = u1_mb_type;
1066
0
            COPYTHECONTEXT("u1_mb_type", u1_mb_type);
1067
0
1068
0
            /* Parse Macroblock Data */
1069
0
            if(25 == u1_mb_type)
1070
0
            {
1071
0
                /* I_PCM_MB */
1072
0
                ps_cur_mb_info->ps_curmb->u1_mb_type = I_PCM_MB;
1073
0
                ret = ih264d_parse_ipcm_mb(ps_dec, ps_cur_mb_info, u1_num_mbs);
1074
0
                if(ret != OK)
1075
0
                    return ret;
1076
0
                ps_cur_deblk_mb->u1_mb_qp = 0;
1077
0
            }
1078
0
            else
1079
0
            {
1080
0
                ret = ih264d_parse_imb_cabac(ps_dec, ps_cur_mb_info, u1_mb_type);
1081
0
                if(ret != OK)
1082
0
                    return ret;
1083
0
                ps_cur_deblk_mb->u1_mb_qp = ps_dec->u1_qp;
1084
0
            }
1085
0
1086
0
            if(u1_mbaff)
1087
0
            {
1088
0
                ih264d_update_mbaff_left_nnz(ps_dec, ps_cur_mb_info);
1089
0
            }
1090
0
1091
0
1092
0
            if(ps_cur_mb_info->u1_topmb && u1_mbaff)
1093
0
                uc_more_data_flag = 1;
1094
0
            else
1095
0
            {
1096
0
                uc_more_data_flag = ih264d_decode_terminate(&ps_dec->s_cab_dec_env,
1097
0
                                                          ps_bitstrm);
1098
0
                uc_more_data_flag = !uc_more_data_flag;
1099
0
                COPYTHECONTEXT("Decode Sliceterm",!uc_more_data_flag);
1100
0
            }
1101
0
1102
0
            if(u1_mbaff)
1103
0
            {
1104
0
                if(!uc_more_data_flag && (0 == (i2_cur_mb_addr & 1)))
1105
0
                {
1106
0
                    return ERROR_EOB_FLUSHBITS_T;
1107
0
                }
1108
0
            }
1109
0
            /* Next macroblock information */
1110
0
            i2_cur_mb_addr++;
1111
0
            /* Store the colocated information */
1112
0
            {
1113
0
1114
0
                mv_pred_t *ps_mv_nmb_start = ps_dec->ps_mv_cur + (u1_num_mbs << 4);
1115
0
                mv_pred_t s_mvPred =
1116
0
                    {
1117
0
                        { 0, 0, 0, 0 },
1118
0
                          { -1, -1 }, 0, 0};
1119
0
                ih264d_rep_mv_colz(
1120
0
                                ps_dec, &s_mvPred, ps_mv_nmb_start, 0,
1121
0
                                (UWORD8)(ps_dec->u1_cur_mb_fld_dec_flag << 1),
1122
0
                                4, 4);
1123
0
            }
1124
0
            /*if num _cores is set to 3,compute bs will be done in another thread*/
1125
0
            if(ps_dec->u4_num_cores < 3)
1126
0
            {
1127
0
                if(ps_dec->u4_app_disable_deblk_frm == 0)
1128
0
                    ps_dec->pf_compute_bs(ps_dec, ps_cur_mb_info,
1129
0
                                         (UWORD16)(u1_num_mbs >> u1_mbaff));
1130
0
            }
1131
0
            u1_num_mbs++;
1132
0
1133
0
        }
1134
0
1135
0
        /****************************************************************/
1136
0
        /* Check for End Of Row                                         */
1137
0
        /****************************************************************/
1138
0
        u1_num_mbs_next = i2_pic_wdin_mbs - u2_mbx - 1;
1139
0
        u1_end_of_row = (!u1_num_mbs_next) && (!(u1_mbaff && (u1_num_mbs & 0x01)));
1140
0
        u1_tfr_n_mb = (u1_num_mbs == ps_dec->u1_recon_mb_grp) || u1_end_of_row
1141
0
                        || (!uc_more_data_flag);
1142
0
        ps_cur_mb_info->u1_end_of_slice = (!uc_more_data_flag);
1143
0
1144
0
        if(u1_tfr_n_mb || (!uc_more_data_flag))
1145
0
        {
1146
0
1147
0
1148
0
            if(ps_dec->u1_separate_parse)
1149
0
            {
1150
0
                ih264d_parse_tfr_nmb(ps_dec, u1_mb_idx, u1_num_mbs,
1151
0
                                     u1_num_mbs_next, u1_tfr_n_mb, u1_end_of_row);
1152
0
                ps_dec->ps_nmb_info +=  u1_num_mbs;
1153
0
            }
1154
0
            else
1155
0
            {
1156
0
                ih264d_decode_recon_tfr_nmb(ps_dec, u1_mb_idx, u1_num_mbs,
1157
0
                                            u1_num_mbs_next, u1_tfr_n_mb,
1158
0
                                            u1_end_of_row);
1159
0
            }
1160
0
            ps_dec->u2_total_mbs_coded += u1_num_mbs;
1161
0
            if(u1_tfr_n_mb)
1162
0
                u1_num_mbs = 0;
1163
0
            u1_mb_idx = u1_num_mbs;
1164
0
            ps_dec->u1_mb_idx = u1_num_mbs;
1165
0
1166
0
        }
1167
0
    }
1168
0
    while(uc_more_data_flag);
1169
0
1170
0
    ps_dec->u4_num_mbs_cur_nmb = 0;
1171
0
    ps_dec->ps_cur_slice->u4_mbs_in_slice = i2_cur_mb_addr
1172
0
1173
0
                        - (u2_first_mb_in_slice << u1_mbaff);
1174
0
1175
0
    return ret;
1176
0
}
1177
1178
/*****************************************************************************/
1179
/*                                                                           */
1180
/*  Function Name : ih264d_parse_ipcm_mb                                       */
1181
/*                                                                           */
1182
/*  Description   : This function decodes the pixel values of I_PCM Mb.      */
1183
/*                                                                           */
1184
/*  Inputs        : ps_dec,  ps_cur_mb_info and mb number                          */
1185
/*                                                                           */
1186
/*  Description   : This function reads the luma and chroma pixels directly  */
1187
/*                  from the bitstream when the mbtype is I_PCM and stores   */
1188
/*                  them in recon buffer. If the entropy coding mode is      */
1189
/*                  cabac, decoding engine is re-initialized. The nnzs and   */
1190
/*                  cabac contexts are appropriately modified.               */
1191
/*  Returns       : void                                                     */
1192
/*                                                                           */
1193
/*  Revision History:                                                        */
1194
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1195
/*         13 07 2002   Jay                                                  */
1196
/*                                                                           */
1197
/*****************************************************************************/
1198
1199
WORD32 ih264d_parse_ipcm_mb(dec_struct_t * ps_dec,
1200
                          dec_mb_info_t *ps_cur_mb_info,
1201
                          UWORD8 u1_mbNum)
1202
0
{
1203
0
    dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
1204
0
    UWORD8 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
1205
0
    UWORD8 *pu1_y, *pu1_u, *pu1_v;
1206
0
    WORD32 ret;
1207
0
1208
0
    UWORD32 u4_rec_width_y, u4_rec_width_uv;
1209
0
    UWORD32 u1_num_mb_pair;
1210
0
    UWORD8 u1_x, u1_y;
1211
0
    /* CHANGED CODE */
1212
0
    tfr_ctxt_t *ps_frame_buf;
1213
0
    UWORD8 u1_mb_field_decoding_flag;
1214
0
    UWORD32 *pu4_buf;
1215
0
    UWORD8 *pu1_buf;
1216
0
    /* CHANGED CODE */
1217
0
1218
0
    if(ps_dec->u1_separate_parse)
1219
0
    {
1220
0
        ps_frame_buf = &ps_dec->s_tran_addrecon_parse;
1221
0
    }
1222
0
    else
1223
0
    {
1224
0
        ps_frame_buf = &ps_dec->s_tran_addrecon;
1225
0
    }
1226
0
    /* align bistream to byte boundary. */
1227
0
    /* pcm_alignment_zero_bit discarded */
1228
0
    /* For XX GotoByteBoundary */
1229
0
    if(ps_bitstrm->u4_ofst & 0x07)
1230
0
    {
1231
0
        ps_bitstrm->u4_ofst += 8;
1232
0
        ps_bitstrm->u4_ofst &= 0xFFFFFFF8;
1233
0
    }
1234
0
1235
0
    /*  Store left Nnz as 16 for each 4x4 blk */
1236
0
1237
0
    pu1_buf = ps_dec->pu1_left_nnz_y;
1238
0
    pu4_buf = (UWORD32 *)pu1_buf;
1239
0
    *pu4_buf = 0x10101010;
1240
0
    pu1_buf = ps_cur_mb_info->ps_curmb->pu1_nnz_y;
1241
0
    pu4_buf = (UWORD32 *)pu1_buf;
1242
0
    *pu4_buf = 0x10101010;
1243
0
    pu1_buf = ps_cur_mb_info->ps_curmb->pu1_nnz_uv;
1244
0
    pu4_buf = (UWORD32 *)pu1_buf;
1245
0
    *pu4_buf = 0x10101010;
1246
0
    pu1_buf = ps_dec->pu1_left_nnz_uv;
1247
0
    pu4_buf = (UWORD32 *)pu1_buf;
1248
0
    *pu4_buf = 0x10101010;
1249
0
    ps_cur_mb_info->u1_cbp = 0xff;
1250
0
1251
0
    ps_dec->i1_prev_mb_qp_delta = 0;
1252
0
    /* Get neighbour MB's */
1253
0
    u1_num_mb_pair = (u1_mbNum >> u1_mbaff);
1254
0
1255
0
    /*****************************************************************************/
1256
0
    /* calculate the RECON buffer YUV pointers for the PCM data                  */
1257
0
    /*****************************************************************************/
1258
0
    /* CHANGED CODE  */
1259
0
    u1_mb_field_decoding_flag = ps_cur_mb_info->u1_mb_field_decodingflag;
1260
0
    pu1_y = ps_frame_buf->pu1_dest_y + (u1_num_mb_pair << 4);
1261
0
    pu1_u = ps_frame_buf->pu1_dest_u + (u1_num_mb_pair << 4);
1262
0
    pu1_v = pu1_u + 1;
1263
0
1264
0
    u4_rec_width_y = ps_dec->u2_frm_wd_y << u1_mb_field_decoding_flag;
1265
0
    u4_rec_width_uv = ps_dec->u2_frm_wd_uv << u1_mb_field_decoding_flag;
1266
0
    /* CHANGED CODE  */
1267
0
1268
0
    if(u1_mbaff)
1269
0
    {
1270
0
        UWORD8 u1_top_mb;
1271
0
1272
0
        u1_top_mb = ps_cur_mb_info->u1_topmb;
1273
0
1274
0
        if(u1_top_mb == 0)
1275
0
        {
1276
0
            pu1_y += (u1_mb_field_decoding_flag ?
1277
0
                            (u4_rec_width_y >> 1) : (u4_rec_width_y << 4));
1278
0
            pu1_u += (u1_mb_field_decoding_flag ?
1279
0
                            (u4_rec_width_uv) : (u4_rec_width_uv << 4));
1280
0
            pu1_v = pu1_u + 1;
1281
0
        }
1282
0
    }
1283
0
1284
0
    /* Read Luma samples */
1285
0
    for(u1_y = 0; u1_y < 16; u1_y++)
1286
0
    {
1287
0
        for(u1_x = 0; u1_x < 16; u1_x++)
1288
0
            pu1_y[u1_x] = ih264d_get_bits_h264(ps_bitstrm, 8);
1289
0
1290
0
        pu1_y += u4_rec_width_y;
1291
0
    }
1292
0
1293
0
    /* Read Chroma samples */
1294
0
    for(u1_y = 0; u1_y < 8; u1_y++)
1295
0
    {
1296
0
        for(u1_x = 0; u1_x < 8; u1_x++)
1297
0
            pu1_u[u1_x * YUV420SP_FACTOR] = ih264d_get_bits_h264(ps_bitstrm, 8);
1298
0
1299
0
        pu1_u += u4_rec_width_uv;
1300
0
    }
1301
0
1302
0
    for(u1_y = 0; u1_y < 8; u1_y++)
1303
0
    {
1304
0
        for(u1_x = 0; u1_x < 8; u1_x++)
1305
0
            pu1_v[u1_x * YUV420SP_FACTOR] = ih264d_get_bits_h264(ps_bitstrm, 8);
1306
0
1307
0
        pu1_v += u4_rec_width_uv;
1308
0
    }
1309
0
1310
0
    if(CABAC == ps_dec->ps_cur_pps->u1_entropy_coding_mode)
1311
0
    {
1312
0
        UWORD32 *pu4_buf;
1313
0
        UWORD8 *pu1_buf;
1314
0
        ctxt_inc_mb_info_t *p_curr_ctxt = ps_dec->ps_curr_ctxt_mb_info;
1315
0
        /* Re-initialize the cabac decoding engine. */
1316
0
        ret = ih264d_init_cabac_dec_envirnoment(&(ps_dec->s_cab_dec_env), ps_bitstrm);
1317
0
        if(ret != OK)
1318
0
            return ret;
1319
0
        /* update the cabac contetxs */
1320
0
        p_curr_ctxt->u1_mb_type = CAB_I_PCM;
1321
0
        p_curr_ctxt->u1_cbp = 47;
1322
0
        p_curr_ctxt->u1_intra_chroma_pred_mode = 0;
1323
0
        p_curr_ctxt->u1_transform8x8_ctxt = 0;
1324
0
        ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0;
1325
0
1326
0
        pu1_buf = ps_dec->pu1_left_nnz_y;
1327
0
        pu4_buf = (UWORD32 *)pu1_buf;
1328
0
        *pu4_buf = 0x01010101;
1329
0
1330
0
        pu1_buf = ps_cur_mb_info->ps_curmb->pu1_nnz_y;
1331
0
        pu4_buf = (UWORD32 *)pu1_buf;
1332
0
        *pu4_buf = 0x01010101;
1333
0
1334
0
        pu1_buf = ps_cur_mb_info->ps_curmb->pu1_nnz_uv;
1335
0
        pu4_buf = (UWORD32 *)pu1_buf;
1336
0
        *pu4_buf = 0x01010101;
1337
0
1338
0
        pu1_buf = ps_dec->pu1_left_nnz_uv;
1339
0
        pu4_buf = (UWORD32 *)pu1_buf;
1340
0
        *pu4_buf = 0x01010101;
1341
0
1342
0
        p_curr_ctxt->u1_yuv_dc_csbp = 0x7;
1343
0
        ps_dec->pu1_left_yuv_dc_csbp[0] = 0x7;
1344
0
        if(ps_dec->ps_cur_slice->u1_slice_type != I_SLICE)
1345
0
        {
1346
0
1347
0
            MEMSET_16BYTES(&ps_dec->pu1_left_mv_ctxt_inc[0][0], 0);
1348
0
            memset(ps_dec->pi1_left_ref_idx_ctxt_inc, 0, 4);
1349
0
            MEMSET_16BYTES(p_curr_ctxt->u1_mv, 0);
1350
0
            memset(p_curr_ctxt->i1_ref_idx, 0, 4);
1351
0
1352
0
        }
1353
0
    }
1354
0
    return OK;
1355
0
}
1356
1357
/*!
1358
 **************************************************************************
1359
 * \if Function name : ih264d_decode_islice \endif
1360
 *
1361
 * \brief
1362
 *    Decodes an I Slice
1363
 *
1364
 *
1365
 * \return
1366
 *    0 on Success and Error code otherwise
1367
 **************************************************************************
1368
 */
1369
WORD32 ih264d_parse_islice(dec_struct_t *ps_dec,
1370
                            UWORD16 u2_first_mb_in_slice)
1371
11
{
1372
11
    dec_pic_params_t * ps_pps = ps_dec->ps_cur_pps;
1373
11
    dec_slice_params_t * ps_slice = ps_dec->ps_cur_slice;
1374
11
    UWORD32 *pu4_bitstrm_buf = ps_dec->ps_bitstrm->pu4_buffer;
1375
11
    UWORD32 *pu4_bitstrm_ofst = &ps_dec->ps_bitstrm->u4_ofst;
1376
11
    UWORD32 u4_temp;
1377
11
    WORD32 i_temp;
1378
11
    WORD32 ret;
1379
11
1380
11
    /*--------------------------------------------------------------------*/
1381
11
    /* Read remaining contents of the slice header                        */
1382
11
    /*--------------------------------------------------------------------*/
1383
11
    /* dec_ref_pic_marking function */
1384
11
    /* G050 */
1385
11
    if(ps_slice->u1_nal_ref_idc != 0)
1386
11
    {
1387
11
        if(!ps_dec->ps_dpb_cmds->u1_dpb_commands_read)
1388
11
        {
1389
11
            i_temp = ih264d_read_mmco_commands(ps_dec);
1390
11
            if (i_temp < 0)
1391
0
            {
1392
0
                return ERROR_DBP_MANAGER_T;
1393
0
            }
1394
11
            ps_dec->u4_bitoffset = i_temp;
1395
11
        }
1396
0
        else
1397
0
            ps_dec->ps_bitstrm->u4_ofst += ps_dec->u4_bitoffset;
1398
11
    }
1399
11
    /* G050 */
1400
11
1401
11
    /* Read slice_qp_delta */
1402
11
    i_temp = ps_pps->u1_pic_init_qp
1403
11
                    + ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1404
11
    if((i_temp < 0) || (i_temp > 51))
1405
0
        return ERROR_INV_RANGE_QP_T;
1406
11
    ps_slice->u1_slice_qp = i_temp;
1407
11
    COPYTHECONTEXT("SH: slice_qp_delta",
1408
11
                    ps_slice->u1_slice_qp - ps_pps->u1_pic_init_qp);
1409
11
1410
11
    if(ps_pps->u1_deblocking_filter_parameters_present_flag == 1)
1411
11
    {
1412
11
        u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1413
11
        COPYTHECONTEXT("SH: disable_deblocking_filter_idc", u4_temp);
1414
11
1415
11
        if(u4_temp > SLICE_BOUNDARY_DBLK_DISABLED)
1416
11
        {
1417
0
            return ERROR_INV_SLICE_HDR_T;
1418
0
        }
1419
11
        ps_slice->u1_disable_dblk_filter_idc = u4_temp;
1420
11
        if(u4_temp != 1)
1421
11
        {
1422
11
            i_temp = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf)
1423
11
                            << 1;
1424
11
            if((MIN_DBLK_FIL_OFF > i_temp) || (i_temp > MAX_DBLK_FIL_OFF))
1425
0
            {
1426
0
                return ERROR_INV_SLICE_HDR_T;
1427
0
            }
1428
11
            ps_slice->i1_slice_alpha_c0_offset = i_temp;
1429
11
            COPYTHECONTEXT("SH: slice_alpha_c0_offset_div2",
1430
11
                            ps_slice->i1_slice_alpha_c0_offset >> 1);
1431
11
1432
11
            i_temp = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf)
1433
11
                            << 1;
1434
11
            if((MIN_DBLK_FIL_OFF > i_temp) || (i_temp > MAX_DBLK_FIL_OFF))
1435
0
            {
1436
0
                return ERROR_INV_SLICE_HDR_T;
1437
0
            }
1438
11
            ps_slice->i1_slice_beta_offset = i_temp;
1439
11
            COPYTHECONTEXT("SH: slice_beta_offset_div2",
1440
11
                            ps_slice->i1_slice_beta_offset >> 1);
1441
11
1442
11
        }
1443
0
        else
1444
0
        {
1445
0
            ps_slice->i1_slice_alpha_c0_offset = 0;
1446
0
            ps_slice->i1_slice_beta_offset = 0;
1447
0
        }
1448
11
    }
1449
0
    else
1450
0
    {
1451
0
        ps_slice->u1_disable_dblk_filter_idc = 0;
1452
0
        ps_slice->i1_slice_alpha_c0_offset = 0;
1453
0
        ps_slice->i1_slice_beta_offset = 0;
1454
0
    }
1455
11
1456
11
    /* Initialization to check if number of motion vector per 2 Mbs */
1457
11
    /* are exceeding the range or not */
1458
11
    ps_dec->u2_mv_2mb[0] = 0;
1459
11
    ps_dec->u2_mv_2mb[1] = 0;
1460
11
1461
11
1462
11
    /*set slice header cone to 2 ,to indicate  correct header*/
1463
11
    ps_dec->u1_slice_header_done = 2;
1464
11
1465
11
    if(ps_pps->u1_entropy_coding_mode)
1466
0
    {
1467
0
        SWITCHOFFTRACE; SWITCHONTRACECABAC;
1468
0
        if(ps_dec->ps_cur_slice->u1_mbaff_frame_flag)
1469
0
        {
1470
0
            ps_dec->pf_get_mb_info = ih264d_get_mb_info_cabac_mbaff;
1471
0
        }
1472
0
        else
1473
0
            ps_dec->pf_get_mb_info = ih264d_get_mb_info_cabac_nonmbaff;
1474
0
1475
0
        ret = ih264d_parse_islice_data_cabac(ps_dec, ps_slice,
1476
0
                                             u2_first_mb_in_slice);
1477
0
        if(ret != OK)
1478
0
            return ret;
1479
0
        SWITCHONTRACE; SWITCHOFFTRACECABAC;
1480
0
    }
1481
11
    else
1482
11
    {
1483
11
        if(ps_dec->ps_cur_slice->u1_mbaff_frame_flag)
1484
0
        {
1485
0
            ps_dec->pf_get_mb_info = ih264d_get_mb_info_cavlc_mbaff;
1486
0
        }
1487
11
        else
1488
11
            ps_dec->pf_get_mb_info = ih264d_get_mb_info_cavlc_nonmbaff;
1489
11
        ret = ih264d_parse_islice_data_cavlc(ps_dec, ps_slice,
1490
11
                                       u2_first_mb_in_slice);
1491
11
        if(ret != OK)
1492
11
            return ret;
1493
11
    }
1494
11
1495
11
    return OK;
1496
11
}
/proc/self/cwd/external/libavc/decoder/ih264d_parse_mb_header.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/*!
21
 ***************************************************************************
22
 * \file ih264d_parse_mb_header.c
23
 *
24
 * \brief
25
 *    This file contains context identifier encoding routines.
26
 *
27
 * \date
28
 *    04/02/2003
29
 *
30
 * \author  NS
31
 ***************************************************************************
32
 */
33
#include <string.h>
34
#include "ih264d_structs.h"
35
#include "ih264d_bitstrm.h"
36
#include "ih264d_cabac.h"
37
#include "ih264_typedefs.h"
38
#include "ih264_macros.h"
39
#include "ih264_platform_macros.h"
40
#include "ih264d_defs.h"
41
#include "ih264d_error_handler.h"
42
#include "ih264d_tables.h"
43
#include "ih264d_debug.h"
44
#include "ih264d_defs.h"
45
#include "ih264d_defs.h"
46
#include "ih264d_mb_utils.h"
47
#include "ih264d_parse_mb_header.h"
48
#include "ih264d_defs.h"
49
50
/*! < CtxtInc index 0 - CtxMbTypeI, CtxMbTypeSISuffix
51
 index 1 - CtxMbTypePSuffix, CtxMbTypeBSuffix
52
 */
53
54
55
56
/*!
57
 **************************************************************************
58
 * \if Function name : ih264d_parse_mb_type_intra_cabac \endif
59
 *
60
 * \brief
61
 *    This function decodes MB type using CABAC entropy coding mode.
62
 *
63
 * \return
64
 *    MBType.
65
 *
66
 **************************************************************************
67
 */
68
UWORD8 ih264d_parse_mb_type_intra_cabac(UWORD8 u1_inter,
69
                                        struct _DecStruct * ps_dec)
70
0
{
71
0
    decoding_envirnoment_t * ps_cab_env = &ps_dec->s_cab_dec_env;
72
0
    dec_bit_stream_t * ps_bitstrm = ps_dec->ps_bitstrm;
73
0
    ctxt_inc_mb_info_t * ps_left_ctxt = ps_dec->p_left_ctxt_mb_info;
74
0
    ctxt_inc_mb_info_t * ps_top_ctxt = ps_dec->p_top_ctxt_mb_info;
75
0
    bin_ctxt_model_t *ps_mb_bin_ctxt = ps_dec->p_mb_type_t;
76
0
    WORD8 u1_mb_type, u1_bin;
77
0
    UWORD32 u4_cxt_inc;
78
0
79
0
    u4_cxt_inc = 0;
80
0
    if(!u1_inter)
81
0
    {
82
0
        if(ps_left_ctxt != ps_dec->ps_def_ctxt_mb_info)
83
0
            u4_cxt_inc += ((ps_left_ctxt->u1_mb_type != CAB_I4x4) ? 1 : 0);
84
0
        if(ps_top_ctxt != ps_dec->ps_def_ctxt_mb_info)
85
0
            u4_cxt_inc += ((ps_top_ctxt->u1_mb_type != CAB_I4x4) ? 1 : 0);
86
0
    }
87
0
    else
88
0
    {
89
0
        ps_mb_bin_ctxt = ps_mb_bin_ctxt + 3 + (ps_dec->u1_B << 1);
90
0
    }
91
0
92
0
    /* b0 */
93
0
    u1_mb_type = (UWORD8)ih264d_decode_bin(u4_cxt_inc, ps_mb_bin_ctxt, ps_bitstrm,
94
0
                                          ps_cab_env);
95
0
    if(u1_mb_type)
96
0
    {
97
0
        /* I16x16 or I_PCM mode */
98
0
        /* b1 */
99
0
        u1_bin = ih264d_decode_terminate(ps_cab_env, ps_bitstrm);
100
0
        if(u1_bin == 0)
101
0
        {
102
0
            /* I16x16 mode */
103
0
            /* Read b2 and b3 */
104
0
            u4_cxt_inc = (u1_inter) ? 0x021 : 0x043;
105
0
106
0
            u1_bin = ih264d_decode_bins(2, u4_cxt_inc, ps_mb_bin_ctxt, ps_bitstrm,
107
0
                                        ps_cab_env);
108
0
109
0
            if(u1_bin & 0x01)
110
0
                u1_mb_type += 4;
111
0
112
0
            if(u1_bin & 0x02)
113
0
                u1_mb_type += 12;
114
0
115
0
            if(u1_bin & 0x01)
116
0
            {
117
0
                /* since b3=1, Read three bins */
118
0
                u4_cxt_inc = (u1_inter) ? 0x0332 : 0x0765;
119
0
                u1_bin = (UWORD8)ih264d_decode_bins(3, u4_cxt_inc, ps_mb_bin_ctxt,
120
0
                                                    ps_bitstrm, ps_cab_env);
121
0
122
0
            }
123
0
            else
124
0
            {
125
0
                /* Read two bins */
126
0
                u4_cxt_inc = (u1_inter) ? 0x033 : 0x076;
127
0
                u1_bin = (UWORD8)ih264d_decode_bins(2, u4_cxt_inc, ps_mb_bin_ctxt,
128
0
                                                    ps_bitstrm, ps_cab_env);
129
0
            }
130
0
            u1_mb_type += u1_bin;
131
0
        }
132
0
        else
133
0
        {
134
0
            /* I_PCM mode */
135
0
            /* b1=1 */
136
0
            u1_mb_type = 25;
137
0
        }
138
0
    }
139
0
    return (u1_mb_type);
140
0
}
141
142
/*!
143
 **************************************************************************
144
 * \if Function name : ih264d_parse_mb_type_cabac \endif
145
 *
146
 * \brief
147
 *    This function decodes MB type using CABAC entropy coding mode.
148
 *
149
 * \return
150
 *    MBType.
151
 *
152
 **************************************************************************
153
 */
154
UWORD32 ih264d_parse_mb_type_cabac(struct _DecStruct * ps_dec)
155
0
{
156
0
    const UWORD8 uc_slice_type = ps_dec->ps_cur_slice->u1_slice_type;
157
0
    decoding_envirnoment_t *ps_cab_env = &ps_dec->s_cab_dec_env;
158
0
    dec_bit_stream_t *ps_bitstrm = ps_dec->ps_bitstrm;
159
0
    ctxt_inc_mb_info_t *ps_left_ctxt = ps_dec->p_left_ctxt_mb_info;
160
0
    ctxt_inc_mb_info_t *ps_top_ctxt = ps_dec->p_top_ctxt_mb_info;
161
0
    WORD8 c_ctxt_inc;
162
0
    bin_ctxt_model_t *ps_mb_bin_ctxt = ps_dec->p_mb_type_t;
163
0
    WORD8 u1_mb_type = 0, u1_bin;
164
0
    UWORD32 u4_cxt_inc;
165
0
166
0
    INC_SYM_COUNT(ps_cab_env);
167
0
168
0
    c_ctxt_inc = 0;
169
0
170
0
    if(uc_slice_type == SI_SLICE)
171
0
    {
172
0
        /* b0 */
173
0
        if(ps_left_ctxt != ps_dec->ps_def_ctxt_mb_info)
174
0
            c_ctxt_inc += ((ps_left_ctxt->u1_mb_type != CAB_SI4x4) ? 1 : 0);
175
0
        if(ps_top_ctxt != ps_dec->ps_def_ctxt_mb_info)
176
0
            c_ctxt_inc += ((ps_top_ctxt->u1_mb_type != CAB_SI4x4) ? 1 : 0);
177
0
178
0
        u4_cxt_inc = c_ctxt_inc;
179
0
        u1_bin = (UWORD8)ih264d_decode_bin(u4_cxt_inc, ps_mb_bin_ctxt, ps_bitstrm,
180
0
                                           ps_cab_env);
181
0
        if(u1_bin == 0)
182
0
        {
183
0
            /* SI MB */
184
0
            u1_mb_type = 0;
185
0
        }
186
0
        else
187
0
        {
188
0
            u1_mb_type = 1 + ih264d_parse_mb_type_intra_cabac(0, ps_dec);
189
0
        }
190
0
    }
191
0
    else if(uc_slice_type == P_SLICE)
192
0
    {
193
0
        /* P Slice */
194
0
        /* b0 */
195
0
        u4_cxt_inc = 0;
196
0
        u1_bin = (UWORD8)ih264d_decode_bin(u4_cxt_inc, ps_mb_bin_ctxt, ps_bitstrm,
197
0
                                           ps_cab_env);
198
0
        if(!u1_bin)
199
0
        {
200
0
            /* Inter MB types */
201
0
            /* b1 */
202
0
            u4_cxt_inc = 0x01;
203
0
            u1_bin = (UWORD8)ih264d_decode_bin(u4_cxt_inc, ps_mb_bin_ctxt,
204
0
                                               ps_bitstrm, ps_cab_env);
205
0
            /* b2 */
206
0
            u4_cxt_inc = u1_bin + 2;
207
0
            u1_mb_type = (UWORD8)ih264d_decode_bin(u4_cxt_inc, ps_mb_bin_ctxt,
208
0
                                                  ps_bitstrm, ps_cab_env);
209
0
            u1_mb_type = (u1_bin << 1) + u1_mb_type;
210
0
            if(u1_mb_type)
211
0
                u1_mb_type = 4 - u1_mb_type;
212
0
        }
213
0
        else
214
0
        {
215
0
            /* Intra Prefix 1 found */
216
0
            /* Intra MB type */
217
0
            u1_mb_type = 5 + ih264d_parse_mb_type_intra_cabac(1, ps_dec);
218
0
        }
219
0
    }
220
0
    else if(uc_slice_type == B_SLICE)
221
0
    {
222
0
        WORD8 a, b;
223
0
        /* B Slice */
224
0
        /* b0 */
225
0
        /* a = b = 0, if B slice and MB is a SKIP or B_DIRECT16x16 */
226
0
        a = 0;
227
0
        b = 0;
228
0
        u1_mb_type = 0;
229
0
        if(ps_left_ctxt != ps_dec->ps_def_ctxt_mb_info)
230
0
            a = ((ps_left_ctxt->u1_mb_type & CAB_BD16x16_MASK) != CAB_BD16x16);
231
0
        if(ps_top_ctxt != ps_dec->ps_def_ctxt_mb_info)
232
0
            b = ((ps_top_ctxt->u1_mb_type & CAB_BD16x16_MASK) != CAB_BD16x16);
233
0
234
0
        u4_cxt_inc = a + b;
235
0
236
0
        u1_bin = (UWORD8)ih264d_decode_bin(u4_cxt_inc, ps_mb_bin_ctxt, ps_bitstrm,
237
0
                                           ps_cab_env);
238
0
239
0
        if(u1_bin)
240
0
        {
241
0
242
0
            /* b1 */
243
0
            u4_cxt_inc = 0x03;
244
0
            u1_bin = (UWORD8)ih264d_decode_bin(u4_cxt_inc, ps_mb_bin_ctxt,
245
0
                                               ps_bitstrm, ps_cab_env);
246
0
247
0
            if(!u1_bin)
248
0
            {
249
0
                /* b2 */
250
0
                u4_cxt_inc = 0x05;
251
0
                u1_bin = (UWORD8)ih264d_decode_bin(u4_cxt_inc, ps_mb_bin_ctxt,
252
0
                                                   ps_bitstrm, ps_cab_env);
253
0
254
0
                u1_mb_type = u1_bin + 1;
255
0
            }
256
0
            else
257
0
            {
258
0
                u1_mb_type = 3;
259
0
                /* b2 */
260
0
                u4_cxt_inc = 0x04;
261
0
                u1_bin = (UWORD8)ih264d_decode_bin(u4_cxt_inc, ps_mb_bin_ctxt,
262
0
                                                   ps_bitstrm, ps_cab_env);
263
0
264
0
                if(u1_bin)
265
0
                {
266
0
                    u1_mb_type += 8;
267
0
                    /* b3 */
268
0
                    u4_cxt_inc = 0x05;
269
0
                    u1_bin = (UWORD8)ih264d_decode_bin(u4_cxt_inc, ps_mb_bin_ctxt,
270
0
                                                       ps_bitstrm, ps_cab_env);
271
0
272
0
                    if(!u1_bin)
273
0
                    {
274
0
                        u1_mb_type++;
275
0
                        /* b4, b5, b6 */
276
0
                        u4_cxt_inc = 0x0555;
277
0
                        u1_bin = (UWORD8)ih264d_decode_bins(3, u4_cxt_inc,
278
0
                                                            ps_mb_bin_ctxt,
279
0
                                                            ps_bitstrm,
280
0
                                                            ps_cab_env);
281
0
282
0
283
0
284
0
                        u1_mb_type += u1_bin;
285
0
                    }
286
0
                    else
287
0
                    {
288
0
                        /* b4 */
289
0
                        u4_cxt_inc = 0x05;
290
0
                        u1_bin = (UWORD8)ih264d_decode_bin(u4_cxt_inc,
291
0
                                                           ps_mb_bin_ctxt,
292
0
                                                           ps_bitstrm,
293
0
                                                           ps_cab_env);
294
0
295
0
                        if(u1_bin)
296
0
                        {
297
0
                            /* b5 */
298
0
                            u1_bin = (UWORD8)ih264d_decode_bin(u4_cxt_inc,
299
0
                                                               ps_mb_bin_ctxt,
300
0
                                                               ps_bitstrm,
301
0
                                                               ps_cab_env);
302
0
303
0
                            u1_mb_type += (u1_bin ? 11 : 0);
304
0
                        }
305
0
                        else
306
0
                        {
307
0
                            u1_mb_type = 20;
308
0
                            /* b5 */
309
0
                            u1_bin = (UWORD8)ih264d_decode_bin(u4_cxt_inc,
310
0
                                                               ps_mb_bin_ctxt,
311
0
                                                               ps_bitstrm,
312
0
                                                               ps_cab_env);
313
0
314
0
                            if(!u1_bin)
315
0
                            {
316
0
                                /* b6 */
317
0
                                u1_bin = (UWORD8)ih264d_decode_bin(u4_cxt_inc,
318
0
                                                                   ps_mb_bin_ctxt,
319
0
                                                                   ps_bitstrm,
320
0
                                                                   ps_cab_env);
321
0
322
0
                                u1_mb_type += u1_bin;
323
0
                            }
324
0
                            else
325
0
                            {
326
0
                                /* Intra Prefix 111101 found */
327
0
                                /* Intra MB type */
328
0
                                u1_mb_type =
329
0
                                                23
330
0
                                                                + ih264d_parse_mb_type_intra_cabac(
331
0
                                                                                1,
332
0
                                                                                ps_dec);
333
0
                            }
334
0
                        }
335
0
                    }
336
0
                }
337
0
                else
338
0
                {
339
0
                    /* b3, b4, b5 */
340
0
                    u4_cxt_inc = 0x0555;
341
0
                    u1_bin = (UWORD8)ih264d_decode_bins(3, u4_cxt_inc,
342
0
                                                        ps_mb_bin_ctxt, ps_bitstrm,
343
0
                                                        ps_cab_env);
344
0
345
0
346
0
347
0
348
0
                    u1_mb_type += u1_bin;
349
0
                }
350
0
            }
351
0
        }
352
0
    }
353
0
    return ((UWORD32)u1_mb_type);
354
0
}
355
356
/*!
357
 **************************************************************************
358
 * \if Function name : DecSubMBType \endif
359
 *
360
 * \brief
361
 *    This function decodes MB type using CABAC entropy coding mode.
362
 *
363
 * \return
364
 *    MBType.
365
 *
366
 **************************************************************************
367
 */
368
UWORD32 ih264d_parse_submb_type_cabac(const UWORD8 u1_slc_type_b,
369
                                      decoding_envirnoment_t * ps_cab_env,
370
                                      dec_bit_stream_t * ps_bitstrm,
371
                                      bin_ctxt_model_t * ps_sub_mb_cxt)
372
0
{
373
0
    WORD8 u1_sub_mb_type, u1_bin;
374
0
375
0
    INC_SYM_COUNT(ps_cab_env);
376
0
377
0
    u1_sub_mb_type = 0;
378
0
    u1_bin = (UWORD8)ih264d_decode_bin(0, ps_sub_mb_cxt, ps_bitstrm,
379
0
                                       ps_cab_env);
380
0
381
0
    if(u1_slc_type_b ^ u1_bin)
382
0
        return 0;
383
0
384
0
    if(!u1_slc_type_b)
385
0
    {
386
0
        /* P Slice */
387
0
        u1_sub_mb_type = 1;
388
0
        u1_bin = (UWORD8)ih264d_decode_bin(1, ps_sub_mb_cxt, ps_bitstrm,
389
0
                                           ps_cab_env);
390
0
        if(u1_bin == 1)
391
0
        {
392
0
            u1_bin = (UWORD8)ih264d_decode_bin(2, ps_sub_mb_cxt, ps_bitstrm,
393
0
                                               ps_cab_env);
394
0
            u1_sub_mb_type = (2 + (!u1_bin));
395
0
        }
396
0
397
0
        return u1_sub_mb_type;
398
0
    }
399
0
    else
400
0
    {
401
0
        /* B Slice */
402
0
403
0
        /* b1 */
404
0
        u1_bin = (UWORD8)ih264d_decode_bin(1, ps_sub_mb_cxt, ps_bitstrm,
405
0
                                           ps_cab_env);
406
0
        if(u1_bin)
407
0
        {
408
0
            /* b2 */
409
0
            u1_bin = (UWORD8)ih264d_decode_bin(2, ps_sub_mb_cxt, ps_bitstrm,
410
0
                                               ps_cab_env);
411
0
            if(u1_bin)
412
0
            {
413
0
                /* b3 */
414
0
                u1_sub_mb_type = 7;
415
0
                u1_bin = (UWORD8)ih264d_decode_bin(3, ps_sub_mb_cxt, ps_bitstrm,
416
0
                                                   ps_cab_env);
417
0
                u1_sub_mb_type += u1_bin << 2;
418
0
                u1_bin = !u1_bin;
419
0
                /* b4 */
420
0
                if(u1_bin == 0)
421
0
                {
422
0
                    u1_bin = ih264d_decode_bin(3, ps_sub_mb_cxt, ps_bitstrm,
423
0
                                               ps_cab_env);
424
0
                }
425
0
                else
426
0
                {
427
0
                    u1_bin = (UWORD8)ih264d_decode_bins(2, 0x33, ps_sub_mb_cxt,
428
0
                                                        ps_bitstrm, ps_cab_env);
429
0
                }
430
0
431
0
                return (u1_sub_mb_type + u1_bin);
432
0
            }
433
0
            else
434
0
            {
435
0
                /* b3 */
436
0
                u1_bin = (UWORD8)ih264d_decode_bins(2, 0x33, ps_sub_mb_cxt,
437
0
                                                    ps_bitstrm, ps_cab_env);
438
0
                return (3 + u1_bin);
439
0
            }
440
0
        }
441
0
        else
442
0
        {
443
0
            /* b2 */
444
0
            u1_bin = (UWORD8)ih264d_decode_bin(3, ps_sub_mb_cxt, ps_bitstrm,
445
0
                                               ps_cab_env);
446
0
            return (1 + u1_bin);
447
0
        }
448
0
    }
449
0
}
450
451
/*!
452
 **************************************************************************
453
 * \if Function name : ih264d_parse_ref_idx_cabac \endif
454
 *
455
 * \brief
456
 *    This function decodes Reference Index using CABAC entropy coding mode.
457
 *
458
 * \return
459
 *    None
460
 *
461
 **************************************************************************
462
 */
463
WORD32 ih264d_parse_ref_idx_cabac(const UWORD8 u1_num_part,
464
                                const UWORD8 u1_b2,
465
                                const UWORD8 u1_max_ref_minus1,
466
                                const UWORD8 u1_mb_mode,
467
                                WORD8 * pi1_ref_idx,
468
                                WORD8 * const pi1_lft_cxt,
469
                                WORD8 * const pi1_top_cxt,
470
                                decoding_envirnoment_t * const ps_cab_env,
471
                                dec_bit_stream_t * const ps_bitstrm,
472
                                bin_ctxt_model_t * const ps_ref_cxt)
473
0
{
474
0
    UWORD8 u1_a, u1_b;
475
0
    UWORD32 u4_cxt_inc;
476
0
    UWORD8 u1_blk_no, u1_i, u1_idx_lft, u1_idx_top;
477
0
    WORD8 i1_ref_idx;
478
0
479
0
    for(u1_blk_no = 0, u1_i = 0; u1_i < u1_num_part; u1_i++, pi1_ref_idx++)
480
0
    {
481
0
        u1_idx_lft = ((u1_blk_no & 0x02) >> 1) + u1_b2;
482
0
        u1_idx_top = (u1_blk_no & 0x01) + u1_b2;
483
0
        i1_ref_idx = *pi1_ref_idx;
484
0
485
0
        if(i1_ref_idx > 0)
486
0
        {
487
0
            u1_a = pi1_lft_cxt[u1_idx_lft] > 0;
488
0
            u1_b = pi1_top_cxt[u1_idx_top] > 0;
489
0
490
0
            u4_cxt_inc = u1_a + (u1_b << 1);
491
0
            u4_cxt_inc = (u4_cxt_inc | 0x55540);
492
0
493
0
            i1_ref_idx = (WORD8)ih264d_decode_bins_unary(32, u4_cxt_inc,
494
0
                                                         ps_ref_cxt, ps_bitstrm,
495
0
                                                         ps_cab_env);
496
0
497
0
            if((i1_ref_idx > u1_max_ref_minus1) || (i1_ref_idx < 0))
498
0
            {
499
0
                return ERROR_REF_IDX;
500
0
            }
501
0
502
0
            *pi1_ref_idx = i1_ref_idx;
503
0
504
0
            INC_SYM_COUNT(ps_cab_env);
505
0
506
0
        }
507
0
508
0
        /* Storing Reference Idx Information */
509
0
        pi1_lft_cxt[u1_idx_lft] = i1_ref_idx;
510
0
        pi1_top_cxt[u1_idx_top] = i1_ref_idx;
511
0
        u1_blk_no = u1_blk_no + 1 + (u1_mb_mode & 0x01);
512
0
    }
513
0
    /* if(!u1_sub_mb) */
514
0
    if(u1_num_part != 4)
515
0
    {
516
0
        pi1_lft_cxt[(!(u1_mb_mode & 0x1)) + u1_b2] = pi1_lft_cxt[u1_b2];
517
0
        pi1_top_cxt[(!(u1_mb_mode & 0x2)) + u1_b2] = pi1_top_cxt[u1_b2];
518
0
    }
519
0
    return OK;
520
0
}
521
522
/*!
523
 **************************************************************************
524
 * \if Function name : ih264d_parse_mb_qp_delta_cabac \endif
525
 *
526
 * \brief
527
 *    This function decodes MB Qp delta using CABAC entropy coding mode.
528
 *
529
 * \return
530
 *    None
531
 *
532
 **************************************************************************
533
 */
534
WORD32 ih264d_parse_mb_qp_delta_cabac(struct _DecStruct * ps_dec,
535
                                      WORD8 *pi1_mb_qp_delta)
536
0
{
537
0
    decoding_envirnoment_t * ps_cab_env = &ps_dec->s_cab_dec_env;
538
0
    dec_bit_stream_t * ps_bitstrm = ps_dec->ps_bitstrm;
539
0
540
0
    UWORD8 u1_code_num;
541
0
    bin_ctxt_model_t *ps_mb_qp_delta_ctxt = ps_dec->p_mb_qp_delta_t;
542
0
    UWORD32 u4_cxt_inc;
543
0
544
0
    INC_SYM_COUNT(ps_cab_env);
545
0
546
0
    u4_cxt_inc = (!(!(ps_dec->i1_prev_mb_qp_delta)));
547
0
548
0
    u1_code_num = 0;
549
0
    u4_cxt_inc = (u4_cxt_inc | 0x33320);
550
0
    /* max number of bins = 53,
551
0
     since Range for MbQpDelta= -26 to +25 inclusive, UNARY code */
552
0
    u1_code_num = ih264d_decode_bins_unary(32, u4_cxt_inc, ps_mb_qp_delta_ctxt,
553
0
                                          ps_bitstrm, ps_cab_env);
554
0
    if(u1_code_num == 32)
555
0
    {
556
0
        /* Read remaining 21 bins */
557
0
        UWORD8 uc_codeNumX;
558
0
        u4_cxt_inc = 0x33333;
559
0
        uc_codeNumX = ih264d_decode_bins_unary(21, u4_cxt_inc, ps_mb_qp_delta_ctxt,
560
0
                                               ps_bitstrm, ps_cab_env);
561
0
        u1_code_num = u1_code_num + uc_codeNumX;
562
0
    }
563
0
564
0
    *pi1_mb_qp_delta = (u1_code_num + 1) >> 1;
565
0
    /* Table 9.3: If code_num is even Syntax Element has -ve value */
566
0
    if(!(u1_code_num & 0x01))
567
0
        *pi1_mb_qp_delta = -(*pi1_mb_qp_delta);
568
0
569
0
    /* Range of MbQpDelta= -26 to +25 inclusive */
570
0
    if((*pi1_mb_qp_delta < -26) || (*pi1_mb_qp_delta > 25))
571
0
        return ERROR_INV_RANGE_QP_T;
572
0
    ps_dec->i1_prev_mb_qp_delta = *pi1_mb_qp_delta;
573
0
    return OK;
574
0
}
575
/*!
576
 **************************************************************************
577
 * \if Function name : ih264d_parse_chroma_pred_mode_cabac \endif
578
 *
579
 * \brief
580
 *    This function decodes Chroma Pred mode using CABAC entropy coding mode.
581
 *
582
 * \return
583
 *    None
584
 *
585
 **************************************************************************
586
 */
587
WORD8 ih264d_parse_chroma_pred_mode_cabac(struct _DecStruct * ps_dec)
588
0
{
589
0
    decoding_envirnoment_t * ps_cab_env = &ps_dec->s_cab_dec_env;
590
0
    dec_bit_stream_t * ps_bitstrm = ps_dec->ps_bitstrm;
591
0
    ctxt_inc_mb_info_t * ps_left_ctxt = ps_dec->p_left_ctxt_mb_info;
592
0
    ctxt_inc_mb_info_t * ps_top_ctxt = ps_dec->p_top_ctxt_mb_info;
593
0
    WORD8 i1_chroma_pred_mode, a, b;
594
0
    UWORD32 u4_cxt_inc;
595
0
596
0
    INC_SYM_COUNT(ps_cab_env);
597
0
598
0
    /* Binarization is TU and Cmax=3 */
599
0
    i1_chroma_pred_mode = 0;
600
0
    a = 0;
601
0
    b = 0;
602
0
603
0
    a = ((ps_left_ctxt->u1_intra_chroma_pred_mode != 0) ? 1 : 0);
604
0
605
0
    b = ((ps_top_ctxt->u1_intra_chroma_pred_mode != 0) ? 1 : 0);
606
0
    u4_cxt_inc = a + b;
607
0
608
0
    u4_cxt_inc = (u4_cxt_inc | 0x330);
609
0
610
0
    i1_chroma_pred_mode = ih264d_decode_bins_tunary(
611
0
                    3, u4_cxt_inc, ps_dec->p_intra_chroma_pred_mode_t,
612
0
                    ps_bitstrm, ps_cab_env);
613
0
614
0
    return (i1_chroma_pred_mode);
615
0
}
616
617
/*****************************************************************************/
618
/*                                                                           */
619
/*  Function Name : ih264d_parse_transform8x8flag_cabac                                     */
620
/*                                                                           */
621
/*  Description   :                                                          */
622
/*  Inputs        :                                                          */
623
/*                                                                           */
624
/*                                                                           */
625
/*  Returns       :                                                          */
626
/*                                                                           */
627
/*  Revision History:                                                        */
628
/*                                                                           */
629
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
630
/*                      Rajasekhar      Creation                             */
631
/*                                                                           */
632
/*****************************************************************************/
633
UWORD8 ih264d_parse_transform8x8flag_cabac(struct _DecStruct * ps_dec,
634
                                           dec_mb_info_t * ps_cur_mb_info)
635
0
{
636
0
    decoding_envirnoment_t * ps_cab_env = &ps_dec->s_cab_dec_env;
637
0
    dec_bit_stream_t * ps_bitstrm = ps_dec->ps_bitstrm;
638
0
    ctxt_inc_mb_info_t * ps_left_ctxt = ps_dec->p_left_ctxt_mb_info;
639
0
    ctxt_inc_mb_info_t * ps_top_ctxt = ps_dec->p_top_ctxt_mb_info;
640
0
    UWORD8 u1_transform_8x8flag;
641
0
    UWORD8 u1_mb_ngbr_avail = ps_cur_mb_info->u1_mb_ngbr_availablity;
642
0
643
0
    WORD8 a, b;
644
0
    UWORD32 u4_cxt_inc;
645
0
646
0
    /* for calculating the context increment for transform8x8 u4_flag */
647
0
    /* it reads transform8x8 u4_flag of the neighbors through */
648
0
649
0
    /* Binarization is FLC */
650
0
    a = 0;
651
0
    b = 0;
652
0
653
0
    if(u1_mb_ngbr_avail & LEFT_MB_AVAILABLE_MASK)
654
0
    {
655
0
        a = ps_left_ctxt->u1_transform8x8_ctxt;
656
0
    }
657
0
    if(u1_mb_ngbr_avail & TOP_MB_AVAILABLE_MASK)
658
0
    {
659
0
        b = ps_top_ctxt->u1_transform8x8_ctxt;
660
0
661
0
    }
662
0
663
0
    u4_cxt_inc = a + b;
664
0
665
0
    u1_transform_8x8flag = ih264d_decode_bin(
666
0
                    u4_cxt_inc, ps_dec->s_high_profile.ps_transform8x8_flag,
667
0
                    ps_bitstrm, ps_cab_env);
668
0
669
0
    return (u1_transform_8x8flag);
670
0
}
671
672
/*!
673
 **************************************************************************
674
 * \if Function name : ih264d_read_intra_pred_modes_cabac \endif
675
 *
676
 * \brief
677
 *    Reads the intra pred mode related values of I4x4 MB from bitstream.
678
 *
679
 *    This function will read the prev intra pred mode flags and
680
 *    stores it in pu1_prev_intra4x4_pred_mode_flag. If the u4_flag
681
 *    indicates that most probable mode is not intra pred mode, then
682
 *    the rem_intra4x4_pred_mode is read and stored in
683
 *    pu1_rem_intra4x4_pred_mode array.
684
 *
685
 *
686
 * \return
687
 *    0 on success and Error code otherwise
688
 *
689
 **************************************************************************
690
 */
691
WORD32 ih264d_read_intra_pred_modes_cabac(dec_struct_t * ps_dec,
692
                                          UWORD8 * pu1_prev_intra4x4_pred_mode_flag,
693
                                          UWORD8 * pu1_rem_intra4x4_pred_mode,
694
                                          UWORD8 u1_tran_form8x8)
695
0
{
696
0
    WORD32 i4x4_luma_blk_idx = 0;
697
0
    dec_bit_stream_t * ps_bitstrm = ps_dec->ps_bitstrm;
698
0
    decoding_envirnoment_t * ps_cab_env = &ps_dec->s_cab_dec_env;
699
0
    bin_ctxt_model_t *ps_ctxt_ipred_luma_mpm, *ps_ctx_ipred_luma_rm;
700
0
    WORD32 i4_rem_intra4x4_pred_mode;
701
0
    UWORD32 u4_prev_intra4x4_pred_mode_flag;
702
0
    UWORD32 u4_code_int_range, u4_code_int_val_ofst;
703
0
    const UWORD32 *pu4_table = (const UWORD32 *)ps_cab_env->cabac_table;
704
0
705
0
    ps_ctxt_ipred_luma_mpm = ps_dec->p_prev_intra4x4_pred_mode_flag_t;
706
0
    ps_ctx_ipred_luma_rm = ps_dec->p_rem_intra4x4_pred_mode_t;
707
0
    SWITCHOFFTRACE;
708
0
709
0
    i4x4_luma_blk_idx = (0 == u1_tran_form8x8) ? 16 : 4;
710
0
711
0
    u4_code_int_range = ps_cab_env->u4_code_int_range;
712
0
    u4_code_int_val_ofst = ps_cab_env->u4_code_int_val_ofst;
713
0
714
0
    do
715
0
    {
716
0
717
0
        DECODE_ONE_BIN_MACRO(ps_ctxt_ipred_luma_mpm, u4_code_int_range,
718
0
                             u4_code_int_val_ofst, pu4_table, ps_bitstrm,
719
0
                             u4_prev_intra4x4_pred_mode_flag)
720
0
        *pu1_prev_intra4x4_pred_mode_flag = u4_prev_intra4x4_pred_mode_flag;
721
0
722
0
        i4_rem_intra4x4_pred_mode = -1;
723
0
        if(!u4_prev_intra4x4_pred_mode_flag)
724
0
        {
725
0
726
0
            /*inlining DecodeDecisionBins_FLC*/
727
0
728
0
            {
729
0
730
0
                UWORD8 u1_max_bins = 3;
731
0
                UWORD32 u4_value;
732
0
                UWORD32 u4_symbol, i;
733
0
734
0
                i = 0;
735
0
                u4_value = 0;
736
0
737
0
                do
738
0
                {
739
0
740
0
                    DECODE_ONE_BIN_MACRO(ps_ctx_ipred_luma_rm, u4_code_int_range,
741
0
                                         u4_code_int_val_ofst, pu4_table,
742
0
                                         ps_bitstrm, u4_symbol)
743
0
744
0
                    INC_BIN_COUNT(ps_cab_env);INC_DECISION_BINS(ps_cab_env);
745
0
746
0
                    u4_value = u4_value | (u4_symbol << i);
747
0
748
0
                    i++;
749
0
                }
750
0
                while(i < u1_max_bins);
751
0
752
0
                i4_rem_intra4x4_pred_mode = (u4_value);
753
0
754
0
            }
755
0
756
0
        }
757
0
758
0
        (*pu1_rem_intra4x4_pred_mode) = i4_rem_intra4x4_pred_mode;
759
0
760
0
        COPYTHECONTEXT("intra4x4_pred_mode", i4_rem_intra4x4_pred_mode);
761
0
762
0
        pu1_prev_intra4x4_pred_mode_flag++;
763
0
        pu1_rem_intra4x4_pred_mode++;
764
0
765
0
        i4x4_luma_blk_idx--;
766
0
    }
767
0
    while(i4x4_luma_blk_idx);
768
0
769
0
    ps_cab_env->u4_code_int_range = u4_code_int_range;
770
0
    ps_cab_env->u4_code_int_val_ofst = u4_code_int_val_ofst;
771
0
772
0
    return (0);
773
0
774
0
}
775
776
/*!
777
 **************************************************************************
778
 * \if Function name : ih264d_parse_ctx_cbp_cabac \endif
779
 *
780
 * \brief
781
 *    This function decodes CtxCbpLuma and CtxCbpChroma (CBP of a Macroblock).
782
 *    using CABAC entropy coding mode.
783
 *
784
 * \return
785
 *    CBP of a MB.
786
 *
787
 **************************************************************************
788
 */
789
UWORD32 ih264d_parse_ctx_cbp_cabac(struct _DecStruct * ps_dec)
790
0
{
791
0
792
0
    UWORD32 u4_cxt_inc;
793
0
    decoding_envirnoment_t * ps_cab_env = &ps_dec->s_cab_dec_env;
794
0
    dec_bit_stream_t * ps_bitstrm = ps_dec->ps_bitstrm;
795
0
    ctxt_inc_mb_info_t * ps_left_ctxt = ps_dec->p_left_ctxt_mb_info;
796
0
    ctxt_inc_mb_info_t * ps_top_ctxt = ps_dec->p_top_ctxt_mb_info;
797
0
    bin_ctxt_model_t *ps_ctxt_cbp_luma = ps_dec->p_cbp_luma_t, *ps_bin_ctxt;
798
0
    WORD8 c_Cbp; //,i,j;
799
0
    UWORD32 u4_code_int_range, u4_code_int_val_ofst;
800
0
    UWORD32 u4_offset, *pu4_buffer;
801
0
    const UWORD32 *pu4_table = (const UWORD32 *)ps_cab_env->cabac_table;
802
0
803
0
    INC_SYM_COUNT(ps_cab_env);
804
0
805
0
806
0
807
0
    /* CBP Luma, FL, Cmax = 15, L = 4 */
808
0
    u4_cxt_inc = (!((ps_top_ctxt->u1_cbp >> 2) & 0x01)) << 1;
809
0
    u4_cxt_inc += !((ps_left_ctxt->u1_cbp >> 1) & 0x01);
810
0
811
0
    u4_offset = ps_bitstrm->u4_ofst;
812
0
    pu4_buffer = ps_bitstrm->pu4_buffer;
813
0
814
0
    u4_code_int_range = ps_cab_env->u4_code_int_range;
815
0
    u4_code_int_val_ofst = ps_cab_env->u4_code_int_val_ofst;
816
0
    /*renormalize to ensure there 23 bits more in the u4_code_int_val_ofst*/
817
0
    {
818
0
        UWORD32 u4_clz, read_bits;
819
0
820
0
        u4_clz = CLZ(u4_code_int_range);
821
0
        FLUSHBITS(u4_offset, u4_clz)
822
0
        NEXTBITS(read_bits, u4_offset, pu4_buffer, 23)
823
0
        u4_code_int_range = u4_code_int_range << u4_clz;
824
0
        u4_code_int_val_ofst = (u4_code_int_val_ofst << u4_clz) | read_bits;
825
0
    }
826
0
827
0
    ps_bin_ctxt = ps_ctxt_cbp_luma + u4_cxt_inc;
828
0
829
0
    /*inlining DecodeDecision_onebin without renorm*/
830
0
    {
831
0
832
0
        UWORD32 u4_qnt_int_range, u4_int_range_lps;
833
0
        UWORD32 u4_symbol, u1_mps_state;
834
0
        UWORD32 table_lookup;
835
0
        UWORD32 u4_clz;
836
0
837
0
        u1_mps_state = (ps_bin_ctxt->u1_mps_state);
838
0
839
0
        u4_clz = CLZ(u4_code_int_range);
840
0
        u4_qnt_int_range = u4_code_int_range << u4_clz;
841
0
        u4_qnt_int_range = (u4_qnt_int_range >> 29) & 0x3;
842
0
843
0
        table_lookup = pu4_table[(u1_mps_state << 2) + u4_qnt_int_range];
844
0
        u4_int_range_lps = table_lookup & 0xff;
845
0
846
0
        u4_int_range_lps = u4_int_range_lps << (23 - u4_clz);
847
0
        u4_code_int_range = u4_code_int_range - u4_int_range_lps;
848
0
849
0
        u4_symbol = ((u1_mps_state >> 6) & 0x1);
850
0
851
0
        /*if mps*/
852
0
        u1_mps_state = (table_lookup >> 8) & 0x7F;
853
0
854
0
        CHECK_IF_LPS(u4_code_int_range, u4_code_int_val_ofst, u4_symbol,
855
0
                     u4_int_range_lps, u1_mps_state, table_lookup)
856
0
857
0
        INC_BIN_COUNT(ps_cab_env);
858
0
859
0
        ps_bin_ctxt->u1_mps_state = u1_mps_state;
860
0
861
0
        c_Cbp = u4_symbol;
862
0
863
0
    }
864
0
865
0
    u4_cxt_inc = (!((ps_top_ctxt->u1_cbp >> 3) & 0x01)) << 1;
866
0
    u4_cxt_inc += !(c_Cbp & 0x01);
867
0
    ps_bin_ctxt = ps_ctxt_cbp_luma + u4_cxt_inc;
868
0
    /*inlining DecodeDecision_onebin without renorm*/
869
0
870
0
    {
871
0
872
0
        UWORD32 u4_qnt_int_range, u4_int_range_lps;
873
0
        UWORD32 u4_symbol, u1_mps_state;
874
0
        UWORD32 table_lookup;
875
0
        UWORD32 u4_clz;
876
0
877
0
        u1_mps_state = (ps_bin_ctxt->u1_mps_state);
878
0
879
0
        u4_clz = CLZ(u4_code_int_range);
880
0
        u4_qnt_int_range = u4_code_int_range << u4_clz;
881
0
        u4_qnt_int_range = (u4_qnt_int_range >> 29) & 0x3;
882
0
883
0
        table_lookup = pu4_table[(u1_mps_state << 2) + u4_qnt_int_range];
884
0
        u4_int_range_lps = table_lookup & 0xff;
885
0
886
0
        u4_int_range_lps = u4_int_range_lps << (23 - u4_clz);
887
0
        u4_code_int_range = u4_code_int_range - u4_int_range_lps;
888
0
889
0
        u4_symbol = ((u1_mps_state >> 6) & 0x1);
890
0
891
0
        /*if mps*/
892
0
        u1_mps_state = (table_lookup >> 8) & 0x7F;
893
0
894
0
        CHECK_IF_LPS(u4_code_int_range, u4_code_int_val_ofst, u4_symbol,
895
0
                     u4_int_range_lps, u1_mps_state, table_lookup)
896
0
897
0
        INC_BIN_COUNT(ps_cab_env);
898
0
899
0
        ps_bin_ctxt->u1_mps_state = u1_mps_state;
900
0
901
0
        c_Cbp |= u4_symbol << 1;
902
0
903
0
    }
904
0
905
0
    u4_cxt_inc = (!(c_Cbp & 0x01)) << 1;
906
0
    u4_cxt_inc += !((ps_left_ctxt->u1_cbp >> 3) & 0x01);
907
0
    ps_bin_ctxt = ps_ctxt_cbp_luma + u4_cxt_inc;
908
0
    /*inlining DecodeDecision_onebin without renorm*/
909
0
910
0
    {
911
0
912
0
        UWORD32 u4_qnt_int_range, u4_int_range_lps;
913
0
        UWORD32 u4_symbol, u1_mps_state;
914
0
        UWORD32 table_lookup;
915
0
        UWORD32 u4_clz;
916
0
917
0
        u1_mps_state = (ps_bin_ctxt->u1_mps_state);
918
0
919
0
        u4_clz = CLZ(u4_code_int_range);
920
0
        u4_qnt_int_range = u4_code_int_range << u4_clz;
921
0
        u4_qnt_int_range = (u4_qnt_int_range >> 29) & 0x3;
922
0
923
0
        table_lookup = pu4_table[(u1_mps_state << 2) + u4_qnt_int_range];
924
0
        u4_int_range_lps = table_lookup & 0xff;
925
0
926
0
        u4_int_range_lps = u4_int_range_lps << (23 - u4_clz);
927
0
        u4_code_int_range = u4_code_int_range - u4_int_range_lps;
928
0
929
0
        u4_symbol = ((u1_mps_state >> 6) & 0x1);
930
0
931
0
        /*if mps*/
932
0
        u1_mps_state = (table_lookup >> 8) & 0x7F;
933
0
934
0
        CHECK_IF_LPS(u4_code_int_range, u4_code_int_val_ofst, u4_symbol,
935
0
                     u4_int_range_lps, u1_mps_state, table_lookup)
936
0
937
0
        INC_BIN_COUNT(ps_cab_env);
938
0
939
0
        ps_bin_ctxt->u1_mps_state = u1_mps_state;
940
0
941
0
        c_Cbp |= u4_symbol << 2;
942
0
943
0
    }
944
0
945
0
    u4_cxt_inc = (!((c_Cbp >> 1) & 0x01)) << 1;
946
0
    u4_cxt_inc += !((c_Cbp >> 2) & 0x01);
947
0
    ps_bin_ctxt = ps_ctxt_cbp_luma + u4_cxt_inc;
948
0
    /*inlining DecodeDecision_onebin without renorm*/
949
0
950
0
    {
951
0
952
0
        UWORD32 u4_qnt_int_range, u4_int_range_lps;
953
0
        UWORD32 u4_symbol, u1_mps_state;
954
0
        UWORD32 table_lookup;
955
0
        UWORD32 u4_clz;
956
0
957
0
        u1_mps_state = (ps_bin_ctxt->u1_mps_state);
958
0
959
0
        u4_clz = CLZ(u4_code_int_range);
960
0
        u4_qnt_int_range = u4_code_int_range << u4_clz;
961
0
        u4_qnt_int_range = (u4_qnt_int_range >> 29) & 0x3;
962
0
963
0
        table_lookup = pu4_table[(u1_mps_state << 2) + u4_qnt_int_range];
964
0
        u4_int_range_lps = table_lookup & 0xff;
965
0
966
0
        u4_int_range_lps = u4_int_range_lps << (23 - u4_clz);
967
0
        u4_code_int_range = u4_code_int_range - u4_int_range_lps;
968
0
969
0
        u4_symbol = ((u1_mps_state >> 6) & 0x1);
970
0
971
0
        /*if mps*/
972
0
        u1_mps_state = (table_lookup >> 8) & 0x7F;
973
0
974
0
        CHECK_IF_LPS(u4_code_int_range, u4_code_int_val_ofst, u4_symbol,
975
0
                     u4_int_range_lps, u1_mps_state, table_lookup)
976
0
977
0
        INC_BIN_COUNT(ps_cab_env);
978
0
979
0
        ps_bin_ctxt->u1_mps_state = u1_mps_state;
980
0
981
0
        c_Cbp |= u4_symbol << 3;
982
0
983
0
    }
984
0
985
0
    if(u4_code_int_range < ONE_RIGHT_SHIFTED_BY_8)
986
0
    {
987
0
988
0
        RENORM_RANGE_OFFSET(u4_code_int_range, u4_code_int_val_ofst, u4_offset,
989
0
                            pu4_buffer)
990
0
991
0
    }
992
0
993
0
    {
994
0
        UWORD32 u4_cxt_inc;
995
0
        WORD8 a, b, c, d;
996
0
        bin_ctxt_model_t *p_CtxtCbpChroma = ps_dec->p_cbp_chroma_t;
997
0
998
0
        /* CBP Chroma, TU, Cmax = 2 */
999
0
        a = 0;
1000
0
        b = 0;
1001
0
        c = 0;
1002
0
        d = 0;
1003
0
1004
0
        {
1005
0
            a = (ps_top_ctxt->u1_cbp > 15) ? 2 : 0;
1006
0
            c = (ps_top_ctxt->u1_cbp > 31) ? 2 : 0;
1007
0
        }
1008
0
1009
0
        {
1010
0
            b = (ps_left_ctxt->u1_cbp > 15) ? 1 : 0;
1011
0
            d = (ps_left_ctxt->u1_cbp > 31) ? 1 : 0;
1012
0
        }
1013
0
        u4_cxt_inc = a + b;
1014
0
        u4_cxt_inc = (u4_cxt_inc | ((4 + c + d) << 4));
1015
0
1016
0
        /*inlining ih264d_decode_bins_tunary */
1017
0
1018
0
        {
1019
0
1020
0
            UWORD8 u1_max_bins = 2;
1021
0
            UWORD32 u4_ctx_inc = u4_cxt_inc;
1022
0
1023
0
            UWORD32 u4_value;
1024
0
            UWORD32 u4_symbol;
1025
0
            UWORD8 u4_ctx_Inc;
1026
0
            bin_ctxt_model_t *ps_bin_ctxt;
1027
0
            u4_value = 0;
1028
0
1029
0
            do
1030
0
            {
1031
0
                u4_ctx_Inc = u4_ctx_inc & 0xF;
1032
0
                u4_ctx_inc = u4_ctx_inc >> 4;
1033
0
1034
0
                ps_bin_ctxt = p_CtxtCbpChroma + u4_ctx_Inc;
1035
0
                /*inlining DecodeDecision_onebin*/
1036
0
                {
1037
0
1038
0
                    UWORD32 u4_qnt_int_range, u4_int_range_lps;
1039
0
1040
0
                    UWORD32 u1_mps_state;
1041
0
                    UWORD32 table_lookup;
1042
0
                    UWORD32 u4_clz;
1043
0
1044
0
                    u1_mps_state = (ps_bin_ctxt->u1_mps_state);
1045
0
1046
0
                    u4_clz = CLZ(u4_code_int_range);
1047
0
                    u4_qnt_int_range = u4_code_int_range << u4_clz;
1048
0
                    u4_qnt_int_range = (u4_qnt_int_range >> 29) & 0x3;
1049
0
1050
0
                    table_lookup = pu4_table[(u1_mps_state << 2)
1051
0
                                    + u4_qnt_int_range];
1052
0
                    u4_int_range_lps = table_lookup & 0xff;
1053
0
1054
0
                    u4_int_range_lps = u4_int_range_lps << (23 - u4_clz);
1055
0
                    u4_code_int_range = u4_code_int_range - u4_int_range_lps;
1056
0
1057
0
                    u4_symbol = ((u1_mps_state >> 6) & 0x1);
1058
0
1059
0
                    /*if mps*/
1060
0
                    u1_mps_state = (table_lookup >> 8) & 0x7F;
1061
0
1062
0
                    CHECK_IF_LPS(u4_code_int_range, u4_code_int_val_ofst,
1063
0
                                 u4_symbol, u4_int_range_lps, u1_mps_state,
1064
0
                                 table_lookup)
1065
0
1066
0
                    if(u4_code_int_range < ONE_RIGHT_SHIFTED_BY_8)
1067
0
                    {
1068
0
                        RENORM_RANGE_OFFSET(u4_code_int_range,
1069
0
                                            u4_code_int_val_ofst, u4_offset,
1070
0
                                            pu4_buffer)
1071
0
                    }
1072
0
                    ps_bin_ctxt->u1_mps_state = u1_mps_state;
1073
0
                }
1074
0
1075
0
                INC_BIN_COUNT(ps_cab_env);INC_DECISION_BINS(
1076
0
                                ps_cab_env);
1077
0
1078
0
                u4_value++;
1079
0
            }
1080
0
            while((u4_value < u1_max_bins) & (u4_symbol));
1081
0
1082
0
            u4_value = u4_value - 1 + u4_symbol;
1083
0
1084
0
            a = (u4_value);
1085
0
1086
0
        }
1087
0
1088
0
c_Cbp = (c_Cbp | (a << 4));
1089
0
}
1090
0
1091
0
ps_bitstrm->u4_ofst = u4_offset;
1092
0
1093
0
ps_cab_env->u4_code_int_range = u4_code_int_range;
1094
0
ps_cab_env->u4_code_int_val_ofst = u4_code_int_val_ofst;
1095
0
1096
0
return (c_Cbp);
1097
0
}
1098
1099
/*!
1100
 **************************************************************************
1101
 * \if Function name : ih264d_get_mvd_cabac \endif
1102
 *
1103
 * \brief
1104
 *    This function decodes Horz and Vert mvd_l0 and mvd_l1 using CABAC entropy
1105
 *    coding mode as defined in 9.3.2.3.
1106
 *
1107
 * \return
1108
 *    None
1109
 *
1110
 **************************************************************************
1111
 */
1112
void ih264d_get_mvd_cabac(UWORD8 u1_sub_mb,
1113
                          UWORD8 u1_b2,
1114
                          UWORD8 u1_part_wd,
1115
                          UWORD8 u1_part_ht,
1116
                          UWORD8 u1_dec_mvd,
1117
                          dec_struct_t *ps_dec,
1118
                          mv_pred_t *ps_mv)
1119
0
{
1120
0
    UWORD8 u1_abs_mvd_x = 0, u1_abs_mvd_y = 0;
1121
0
    UWORD8 u1_sub_mb_x, u1_sub_mb_y;
1122
0
    UWORD8 *pu1_top_mv_ctxt, *pu1_lft_mv_ctxt;
1123
0
    WORD16 *pi2_mv;
1124
0
1125
0
    u1_sub_mb_x = (UWORD8)(u1_sub_mb & 0x03);
1126
0
    u1_sub_mb_y = (UWORD8)(u1_sub_mb >> 2);
1127
0
    pu1_top_mv_ctxt = &ps_dec->ps_curr_ctxt_mb_info->u1_mv[u1_sub_mb_x][u1_b2];
1128
0
    pu1_lft_mv_ctxt = &ps_dec->pu1_left_mv_ctxt_inc[u1_sub_mb_y][u1_b2];
1129
0
    pi2_mv = &ps_mv->i2_mv[u1_b2];
1130
0
1131
0
    if(u1_dec_mvd)
1132
0
    {
1133
0
        WORD16 i2_mv_x, i2_mv_y;
1134
0
        WORD32 i2_temp;
1135
0
        {
1136
0
            decoding_envirnoment_t * ps_cab_env = &ps_dec->s_cab_dec_env;
1137
0
            dec_bit_stream_t * ps_bitstrm = ps_dec->ps_bitstrm;
1138
0
            UWORD16 u2_abs_mvd_x_a, u2_abs_mvd_x_b, u2_abs_mvd_y_a,
1139
0
                            u2_abs_mvd_y_b;
1140
0
1141
0
            u2_abs_mvd_x_b = (UWORD16)pu1_top_mv_ctxt[0];
1142
0
            u2_abs_mvd_y_b = (UWORD16)pu1_top_mv_ctxt[1];
1143
0
            u2_abs_mvd_x_a = (UWORD16)pu1_lft_mv_ctxt[0];
1144
0
            u2_abs_mvd_y_a = (UWORD16)pu1_lft_mv_ctxt[1];
1145
0
1146
0
            i2_temp = u2_abs_mvd_x_a + u2_abs_mvd_x_b;
1147
0
1148
0
            i2_mv_x = ih264d_parse_mvd_cabac(ps_bitstrm, ps_cab_env,
1149
0
                                             ps_dec->p_mvd_x_t, i2_temp);
1150
0
1151
0
            i2_temp = u2_abs_mvd_y_a + u2_abs_mvd_y_b;
1152
0
1153
0
            i2_mv_y = ih264d_parse_mvd_cabac(ps_bitstrm, ps_cab_env,
1154
0
                                             ps_dec->p_mvd_y_t, i2_temp);
1155
0
        }
1156
0
1157
0
        /***********************************************************************/
1158
0
        /* Store the abs_mvd_values in cabac contexts                          */
1159
0
        /* The follownig code can be easily optimzed if mvX, mvY clip values   */
1160
0
        /* are packed in 16 bits follwed by memcpy                             */
1161
0
        /***********************************************************************/
1162
0
        u1_abs_mvd_x = CLIP3(0, 127, ABS(i2_mv_x));
1163
0
        u1_abs_mvd_y = CLIP3(0, 127, ABS(i2_mv_y));
1164
0
1165
0
        COPYTHECONTEXT("MVD", i2_mv_x);COPYTHECONTEXT("MVD", i2_mv_y);
1166
0
1167
0
        /* Storing Mv residuals */
1168
0
        pi2_mv[0] = i2_mv_x;
1169
0
        pi2_mv[1] = i2_mv_y;
1170
0
    }
1171
0
1172
0
    /***************************************************************/
1173
0
    /* Store abs_mvd_values cabac contexts                         */
1174
0
    /***************************************************************/
1175
0
    {
1176
0
        UWORD8 u1_i;
1177
0
        for(u1_i = 0; u1_i < u1_part_wd; u1_i++, pu1_top_mv_ctxt += 4)
1178
0
        {
1179
0
            pu1_top_mv_ctxt[0] = u1_abs_mvd_x;
1180
0
            pu1_top_mv_ctxt[1] = u1_abs_mvd_y;
1181
0
        }
1182
0
1183
0
        for(u1_i = 0; u1_i < u1_part_ht; u1_i++, pu1_lft_mv_ctxt += 4)
1184
0
        {
1185
0
            pu1_lft_mv_ctxt[0] = u1_abs_mvd_x;
1186
0
            pu1_lft_mv_ctxt[1] = u1_abs_mvd_y;
1187
0
        }
1188
0
    }
1189
0
}
1190
1191
/*****************************************************************************/
1192
/*                                                                           */
1193
/*  Function Name : ih264d_parse_mvd_cabac                                                  */
1194
/*                                                                           */
1195
/*  Description   : This cabac function decodes the mvd in a given direction */
1196
/*                  direction ( x or y ) as defined in 9.3.2.3.              */
1197
/*                                                                           */
1198
/*  Inputs        : 1. pointer to Bitstream                                  */
1199
/*                  2. pointer to cabac decoding environmnet                 */
1200
/*                  3. pointer to Mvd context                                */
1201
/*                  4. abs(Top mvd) = u2_abs_mvd_b                           */
1202
/*                  5. abs(left mvd)= u2_abs_mvd_a                           */
1203
/*                                                                           */
1204
/*  Processing    : see section 9.3.2.3 of the standard                      */
1205
/*                                                                           */
1206
/*  Outputs       : i2_mvd                                                   */
1207
/*  Returns       : i2_mvd                                                   */
1208
/*                                                                           */
1209
/*  Issues        : none                                                     */
1210
/*                                                                           */
1211
/*  Revision History:                                                        */
1212
/*                                                                           */
1213
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1214
/*         16 06 2005   Jay          Draft                                   */
1215
/*                                                                           */
1216
/*****************************************************************************/
1217
WORD16 ih264d_parse_mvd_cabac(dec_bit_stream_t * ps_bitstrm,
1218
                              decoding_envirnoment_t * ps_cab_env,
1219
                              bin_ctxt_model_t * p_ctxt_mvd,
1220
                              UWORD32 i4_temp)
1221
1222
0
{
1223
0
    WORD8 k;
1224
0
    WORD16 i2_suf;
1225
0
    WORD16 i2_mvd;
1226
0
    UWORD16 u2_abs_mvd;
1227
0
    UWORD32 u4_ctx_inc;
1228
0
    UWORD32 u4_prefix;
1229
0
    const UWORD32 *pu4_table = (const UWORD32 *)ps_cab_env->cabac_table;
1230
0
    UWORD32 u4_code_int_range, u4_code_int_val_ofst;
1231
0
1232
0
    /*  if mvd < 9                                                  */
1233
0
    /*  mvd =  Prefix                                                   */
1234
0
    /*  else                                                            */
1235
0
    /*  mvd = Prefix + Suffix                                           */
1236
0
    /*  decode sign bit                                                 */
1237
0
    /*  Prefix TU decoding Cmax =Ucoff and Suffix 3rd order Exp-Golomb  */
1238
0
1239
0
    u2_abs_mvd = (UWORD16)i4_temp;
1240
0
    u4_ctx_inc = 1;
1241
0
1242
0
    if(u2_abs_mvd < 3)
1243
0
        u4_ctx_inc = 0;
1244
0
    else if(u2_abs_mvd > 32)
1245
0
        u4_ctx_inc = 2;
1246
0
1247
0
    u4_ctx_inc = (u4_ctx_inc | 0x65430);
1248
0
1249
0
    /*inlining modified version of ih264d_decode_bins_unary*/
1250
0
1251
0
    {
1252
0
        UWORD8 u1_max_bins = 9;
1253
0
        UWORD32 u4_value;
1254
0
        UWORD32 u4_symbol;
1255
0
        bin_ctxt_model_t *ps_bin_ctxt;
1256
0
        UWORD32 u4_ctx_Inc;
1257
0
1258
0
        u4_value = 0;
1259
0
        u4_code_int_range = ps_cab_env->u4_code_int_range;
1260
0
        u4_code_int_val_ofst = ps_cab_env->u4_code_int_val_ofst;
1261
0
1262
0
        do
1263
0
        {
1264
0
            u4_ctx_Inc = u4_ctx_inc & 0xf;
1265
0
            u4_ctx_inc = u4_ctx_inc >> 4;
1266
0
1267
0
            ps_bin_ctxt = p_ctxt_mvd + u4_ctx_Inc;
1268
0
1269
0
            DECODE_ONE_BIN_MACRO(ps_bin_ctxt, u4_code_int_range,
1270
0
                                 u4_code_int_val_ofst, pu4_table, ps_bitstrm,
1271
0
                                 u4_symbol)
1272
0
1273
0
            INC_BIN_COUNT(ps_cab_env);INC_DECISION_BINS(ps_cab_env);
1274
0
1275
0
            u4_value++;
1276
0
1277
0
        }
1278
0
        while(u4_symbol && u4_value < 5);
1279
0
1280
0
        ps_bin_ctxt = p_ctxt_mvd + 6;
1281
0
1282
0
        if(u4_symbol && (u4_value < u1_max_bins))
1283
0
        {
1284
0
1285
0
            do
1286
0
            {
1287
0
1288
0
                DECODE_ONE_BIN_MACRO(ps_bin_ctxt, u4_code_int_range,
1289
0
                                     u4_code_int_val_ofst, pu4_table,
1290
0
                                     ps_bitstrm, u4_symbol)
1291
0
1292
0
                INC_BIN_COUNT(ps_cab_env);INC_DECISION_BINS(ps_cab_env);
1293
0
                u4_value++;
1294
0
            }
1295
0
            while(u4_symbol && (u4_value < u1_max_bins));
1296
0
1297
0
        }
1298
0
1299
0
        ps_cab_env->u4_code_int_range = u4_code_int_range;
1300
0
        ps_cab_env->u4_code_int_val_ofst = u4_code_int_val_ofst;
1301
0
        u4_value = u4_value - 1 + u4_symbol;
1302
0
        u4_prefix = (u4_value);
1303
0
    }
1304
0
1305
0
    i2_mvd = u4_prefix;
1306
0
1307
0
    if(i2_mvd == 9)
1308
0
    {
1309
0
        /* Read Suffix */
1310
0
        k = ih264d_decode_bypass_bins_unary(ps_cab_env, ps_bitstrm);
1311
0
        i2_suf = (1 << k) - 1;
1312
0
        k = k + 3;
1313
0
        i2_suf = (i2_suf << 3);
1314
0
        i2_mvd += i2_suf;
1315
0
        i2_suf = ih264d_decode_bypass_bins(ps_cab_env, k, ps_bitstrm);
1316
0
        i2_mvd += i2_suf;
1317
0
    }
1318
0
    /* Read Sign bit */
1319
0
    if(!i2_mvd)
1320
0
        return (i2_mvd);
1321
0
1322
0
    else
1323
0
    {
1324
0
        UWORD32 u4_code_int_val_ofst, u4_code_int_range;
1325
0
1326
0
        u4_code_int_val_ofst = ps_cab_env->u4_code_int_val_ofst;
1327
0
        u4_code_int_range = ps_cab_env->u4_code_int_range;
1328
0
1329
0
        if(u4_code_int_range < ONE_RIGHT_SHIFTED_BY_9)
1330
0
        {
1331
0
            UWORD32 *pu4_buffer, u4_offset;
1332
0
1333
0
            pu4_buffer = ps_bitstrm->pu4_buffer;
1334
0
            u4_offset = ps_bitstrm->u4_ofst;
1335
0
1336
0
            RENORM_RANGE_OFFSET(u4_code_int_range, u4_code_int_val_ofst,
1337
0
                                u4_offset, pu4_buffer)
1338
0
            ps_bitstrm->u4_ofst = u4_offset;
1339
0
        }
1340
0
1341
0
        u4_code_int_range = u4_code_int_range >> 1;
1342
0
1343
0
        if(u4_code_int_val_ofst >= u4_code_int_range)
1344
0
        {
1345
0
            /* S=1 */
1346
0
            u4_code_int_val_ofst -= u4_code_int_range;
1347
0
            i2_mvd = (-i2_mvd);
1348
0
        }
1349
0
1350
0
        ps_cab_env->u4_code_int_val_ofst = u4_code_int_val_ofst;
1351
0
        ps_cab_env->u4_code_int_range = u4_code_int_range;
1352
0
1353
0
        return (i2_mvd);
1354
0
1355
0
    }
1356
0
}
/proc/self/cwd/external/libavc/decoder/ih264d_parse_pslice.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
21
/*!
22
 **************************************************************************
23
 * \file ih264d_parse_pslice.c
24
 *
25
 * \brief
26
 *    Contains routines that decode a I slice type
27
 *
28
 * Detailed_description
29
 *
30
 * \date
31
 *    07/07/2003
32
 *
33
 * \author  NS
34
 **************************************************************************
35
 */
36
37
#include <string.h>
38
#include "ih264d_bitstrm.h"
39
#include "ih264d_defs.h"
40
#include "ih264d_debug.h"
41
#include "ih264d_tables.h"
42
#include "ih264d_structs.h"
43
#include "ih264d_defs.h"
44
#include "ih264d_parse_cavlc.h"
45
#include "ih264d_mb_utils.h"
46
#include "ih264d_parse_slice.h"
47
#include "ih264d_mvpred.h"
48
#include "ih264d_parse_islice.h"
49
#include "ih264d_process_intra_mb.h"
50
#include "ih264d_inter_pred.h"
51
#include "ih264d_process_pslice.h"
52
#include "ih264d_deblocking.h"
53
#include "ih264d_cabac.h"
54
#include "ih264d_parse_mb_header.h"
55
#include "ih264d_error_handler.h"
56
#include "ih264d_defs.h"
57
#include "ih264d_format_conv.h"
58
#include "ih264d_quant_scaling.h"
59
#include "ih264d_thread_parse_decode.h"
60
#include "ih264d_thread_compute_bs.h"
61
#include "ih264d_process_bslice.h"
62
#include "ithread.h"
63
#include "ih264d_utils.h"
64
#include "ih264d_format_conv.h"
65
66
void ih264d_init_cabac_contexts(UWORD8 u1_slice_type, dec_struct_t * ps_dec);
67
void ih264d_deblock_mb_level(dec_struct_t *ps_dec,
68
                             dec_mb_info_t *ps_cur_mb_info,
69
                             UWORD32 nmb_index);
70
71
/*!
72
 **************************************************************************
73
 * \if Function name : ih264d_parse_pmb_cavlc \endif
74
 *
75
 * \brief
76
 *    This function parses CAVLC syntax of a P MB.
77
 *
78
 * \return
79
 *    0 on Success and Error code otherwise
80
 **************************************************************************
81
 */
82
WORD32 ih264d_parse_pmb_cavlc(dec_struct_t * ps_dec,
83
                              dec_mb_info_t * ps_cur_mb_info,
84
                              UWORD8 u1_mb_num,
85
                              UWORD8 u1_num_mbsNby2)
86
0
{
87
0
    UWORD32 u1_num_mb_part;
88
0
    UWORD32 uc_sub_mb;
89
0
    dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
90
0
    UWORD32 * const pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
91
0
    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
92
0
93
0
    parse_pmbarams_t * ps_parse_mb_data = ps_dec->ps_parse_mb_data
94
0
                    + u1_num_mbsNby2;
95
0
    WORD8 * pi1_ref_idx = ps_parse_mb_data->i1_ref_idx[0];
96
0
    const UWORD8 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
97
0
    const UWORD8 * pu1_num_mb_part = (const UWORD8 *)gau1_ih264d_num_mb_part;
98
0
    UWORD8 * pu1_col_info = ps_parse_mb_data->u1_col_info;
99
0
100
0
    UWORD32 u1_mb_type = ps_cur_mb_info->u1_mb_type;
101
0
    UWORD32 u4_sum_mb_mode_pack = 0;
102
0
    WORD32 ret;
103
0
104
0
    UWORD8 u1_no_submb_part_size_lt8x8_flag = 1;
105
0
    ps_cur_mb_info->u1_tran_form8x8 = 0;
106
0
    ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0;
107
0
108
0
    ps_cur_mb_info->u1_yuv_dc_block_flag = 0;
109
0
110
0
    ps_cur_mb_info->u1_mb_mc_mode = u1_mb_type;
111
0
    uc_sub_mb = ((u1_mb_type == PRED_8x8) | (u1_mb_type == PRED_8x8R0));
112
0
113
0
    /* Reading the subMB type */
114
0
    if(uc_sub_mb)
115
0
    {
116
0
        WORD32 i;
117
0
        UWORD8 u1_colz = (PRED_8x8 << 6);
118
0
119
0
        for(i = 0; i < 4; i++)
120
0
        {
121
0
            UWORD32 ui_sub_mb_mode;
122
0
123
0
            //Inlined ih264d_uev
124
0
            UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
125
0
            UWORD32 u4_word, u4_ldz;
126
0
127
0
            /***************************************************************/
128
0
            /* Find leading zeros in next 32 bits                          */
129
0
            /***************************************************************/
130
0
            NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
131
0
            u4_ldz = CLZ(u4_word);
132
0
            /* Flush the ps_bitstrm */
133
0
            u4_bitstream_offset += (u4_ldz + 1);
134
0
            /* Read the suffix from the ps_bitstrm */
135
0
            u4_word = 0;
136
0
            if(u4_ldz)
137
0
                GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
138
0
                        u4_ldz);
139
0
            *pu4_bitstrm_ofst = u4_bitstream_offset;
140
0
            ui_sub_mb_mode = ((1 << u4_ldz) + u4_word - 1);
141
0
            //Inlined ih264d_uev
142
0
143
0
            if(ui_sub_mb_mode > 3)
144
0
            {
145
0
                return ERROR_SUB_MB_TYPE;
146
0
            }
147
0
            else
148
0
            {
149
0
                u4_sum_mb_mode_pack = (u4_sum_mb_mode_pack << 8) | ui_sub_mb_mode;
150
0
                /* Storing collocated information */
151
0
                *pu1_col_info++ = u1_colz | (UWORD8)(ui_sub_mb_mode << 4);
152
0
153
0
                COPYTHECONTEXT("sub_mb_type", ui_sub_mb_mode);
154
0
            }
155
0
156
0
            /* check if Motion compensation is done below 8x8 */
157
0
            if(ui_sub_mb_mode != P_L0_8x8)
158
0
            {
159
0
                u1_no_submb_part_size_lt8x8_flag = 0;
160
0
            }
161
0
        }
162
0
163
0
        //
164
0
        u1_num_mb_part = 4;
165
0
    }
166
0
    else
167
0
    {
168
0
        *pu1_col_info++ = (u1_mb_type << 6);
169
0
        if(u1_mb_type)
170
0
            *pu1_col_info++ = (u1_mb_type << 6);
171
0
        u1_num_mb_part = pu1_num_mb_part[u1_mb_type];
172
0
173
0
    }
174
0
175
0
    /* Decoding reference index 0: For simple profile the following   */
176
0
    /* conditions are always true (mb_field_decoding_flag == 0);      */
177
0
    /* (MbPartPredMode != PredL1)                                     */
178
0
179
0
    {
180
0
181
0
        UWORD8 uc_field = ps_cur_mb_info->u1_mb_field_decodingflag;
182
0
        UWORD8 uc_num_ref_idx_l0_active_minus1 =
183
0
                        (ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[0]
184
0
                                        << (u1_mbaff & uc_field)) - 1;
185
0
186
0
        if((uc_num_ref_idx_l0_active_minus1 > 0) & (u1_mb_type != PRED_8x8R0))
187
0
        {
188
0
            if(1 == uc_num_ref_idx_l0_active_minus1)
189
0
                ih264d_parse_pmb_ref_index_cavlc_range1(
190
0
                                u1_num_mb_part, ps_bitstrm, pi1_ref_idx,
191
0
                                uc_num_ref_idx_l0_active_minus1);
192
0
            else
193
0
            {
194
0
                ret = ih264d_parse_pmb_ref_index_cavlc(
195
0
                                u1_num_mb_part, ps_bitstrm, pi1_ref_idx,
196
0
                                uc_num_ref_idx_l0_active_minus1);
197
0
                if(ret != OK)
198
0
                    return ret;
199
0
            }
200
0
        }
201
0
        else
202
0
        {
203
0
            /* When there exists only a single frame to predict from */
204
0
            UWORD8 uc_i;
205
0
            for(uc_i = 0; uc_i < u1_num_mb_part; uc_i++)
206
0
                /* Storing Reference Idx Information */
207
0
                pi1_ref_idx[uc_i] = 0;
208
0
        }
209
0
    }
210
0
211
0
    {
212
0
        UWORD8 u1_p_idx, uc_i;
213
0
        parse_part_params_t * ps_part = ps_dec->ps_part;
214
0
        UWORD8 u1_sub_mb_mode, u1_num_subpart, u1_mb_part_width, u1_mb_part_height;
215
0
        UWORD8 u1_sub_mb_num;
216
0
        const UWORD8 * pu1_top_left_sub_mb_indx;
217
0
        mv_pred_t * ps_mv, *ps_mv_start = ps_dec->ps_mv_cur + (u1_mb_num << 4);
218
0
        /* Loading the table pointers */
219
0
        const UWORD8 * pu1_mb_partw = (const UWORD8 *)gau1_ih264d_mb_partw;
220
0
        const UWORD8 * pu1_mb_parth = (const UWORD8 *)gau1_ih264d_mb_parth;
221
0
        const UWORD8 * pu1_sub_mb_indx_mod =
222
0
                        (const UWORD8 *)(gau1_ih264d_submb_indx_mod)
223
0
                                        + (uc_sub_mb * 6);
224
0
        const UWORD8 * pu1_sub_mb_partw = (const UWORD8 *)gau1_ih264d_submb_partw;
225
0
        const UWORD8 * pu1_sub_mb_parth = (const UWORD8 *)gau1_ih264d_submb_parth;
226
0
        const UWORD8 * pu1_num_sub_mb_part =
227
0
                        (const UWORD8 *)gau1_ih264d_num_submb_part;
228
0
229
0
        UWORD16 u2_sub_mb_num = 0x028A;
230
0
231
0
        /*********************************************************/
232
0
        /* default initialisations for condition (uc_sub_mb == 0) */
233
0
        /* i.e. all are subpartitions of 8x8                     */
234
0
        /*********************************************************/
235
0
        u1_sub_mb_mode = 0;
236
0
        u1_num_subpart = 1;
237
0
        u1_mb_part_width = pu1_mb_partw[u1_mb_type];
238
0
        u1_mb_part_height = pu1_mb_parth[u1_mb_type];
239
0
        pu1_top_left_sub_mb_indx = pu1_sub_mb_indx_mod + (u1_mb_type << 1);
240
0
        u1_sub_mb_num = 0;
241
0
242
0
        /* Loop on number of partitions */
243
0
        for(uc_i = 0, u1_p_idx = 0; uc_i < u1_num_mb_part; uc_i++)
244
0
        {
245
0
            UWORD8 uc_j;
246
0
            if(uc_sub_mb)
247
0
            {
248
0
                u1_sub_mb_mode = u4_sum_mb_mode_pack >> 24;
249
0
                u1_num_subpart = pu1_num_sub_mb_part[u1_sub_mb_mode];
250
0
                u1_mb_part_width = pu1_sub_mb_partw[u1_sub_mb_mode];
251
0
                u1_mb_part_height = pu1_sub_mb_parth[u1_sub_mb_mode];
252
0
                pu1_top_left_sub_mb_indx = pu1_sub_mb_indx_mod + (u1_sub_mb_mode << 1);
253
0
                u1_sub_mb_num = u2_sub_mb_num >> 12;
254
0
                u4_sum_mb_mode_pack <<= 8;
255
0
                u2_sub_mb_num <<= 4;
256
0
            }
257
0
258
0
            /* Loop on Number of sub-partitions */
259
0
            for(uc_j = 0; uc_j < u1_num_subpart; uc_j++, pu1_top_left_sub_mb_indx++)
260
0
            {
261
0
                WORD16 i2_mvx, i2_mvy;
262
0
                u1_sub_mb_num += *pu1_top_left_sub_mb_indx;
263
0
                ps_mv = ps_mv_start + u1_sub_mb_num;
264
0
265
0
                /* Reading the differential Mv from the bitstream */
266
0
                //i2_mvx = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
267
0
                //inlining ih264d_sev
268
0
                {
269
0
                    UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
270
0
                    UWORD32 u4_word, u4_ldz, u4_abs_val;
271
0
272
0
                    /***************************************************************/
273
0
                    /* Find leading zeros in next 32 bits                          */
274
0
                    /***************************************************************/
275
0
                    NEXTBITS_32(u4_word, u4_bitstream_offset,
276
0
                                pu4_bitstrm_buf);
277
0
                    u4_ldz = CLZ(u4_word);
278
0
279
0
                    /* Flush the ps_bitstrm */
280
0
                    u4_bitstream_offset += (u4_ldz + 1);
281
0
282
0
                    /* Read the suffix from the ps_bitstrm */
283
0
                    u4_word = 0;
284
0
                    if(u4_ldz)
285
0
                        GETBITS(u4_word, u4_bitstream_offset,
286
0
                                pu4_bitstrm_buf, u4_ldz);
287
0
288
0
                    *pu4_bitstrm_ofst = u4_bitstream_offset;
289
0
                    u4_abs_val = ((1 << u4_ldz) + u4_word) >> 1;
290
0
291
0
                    if(u4_word & 0x1)
292
0
                        i2_mvx = (-(WORD32)u4_abs_val);
293
0
                    else
294
0
                        i2_mvx = (u4_abs_val);
295
0
                }
296
0
                //inlinined ih264d_sev
297
0
                COPYTHECONTEXT("MVD", i2_mvx);
298
0
                i2_mvy = ih264d_sev(pu4_bitstrm_ofst,
299
0
                                     pu4_bitstrm_buf);
300
0
                COPYTHECONTEXT("MVD", i2_mvy);
301
0
302
0
                /* Storing Info for partitions */
303
0
                ps_part->u1_is_direct = PART_NOT_DIRECT;
304
0
                ps_part->u1_sub_mb_num = u1_sub_mb_num;
305
0
                ps_part->u1_partheight = u1_mb_part_height;
306
0
                ps_part->u1_partwidth = u1_mb_part_width;
307
0
308
0
                /* Storing Mv residuals */
309
0
                ps_mv->i2_mv[0] = i2_mvx;
310
0
                ps_mv->i2_mv[1] = i2_mvy;
311
0
312
0
                /* Increment partition Index */
313
0
                u1_p_idx++;
314
0
                ps_part++;
315
0
            }
316
0
        }
317
0
        ps_parse_mb_data->u1_num_part = u1_p_idx;
318
0
        ps_dec->ps_part = ps_part;
319
0
    }
320
0
321
0
    {
322
0
        UWORD32 u4_cbp;
323
0
324
0
        /* Read the Coded block pattern */
325
0
        UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
326
0
        UWORD32 u4_word, u4_ldz;
327
0
328
0
        /***************************************************************/
329
0
        /* Find leading zeros in next 32 bits                          */
330
0
        /***************************************************************/
331
0
        NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
332
0
        u4_ldz = CLZ(u4_word);
333
0
        /* Flush the ps_bitstrm */
334
0
        u4_bitstream_offset += (u4_ldz + 1);
335
0
        /* Read the suffix from the ps_bitstrm */
336
0
        u4_word = 0;
337
0
        if(u4_ldz)
338
0
            GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf, u4_ldz);
339
0
        *pu4_bitstrm_ofst = u4_bitstream_offset;
340
0
        u4_cbp = ((1 << u4_ldz) + u4_word - 1);
341
0
342
0
        if(u4_cbp > 47)
343
0
            return ERROR_CBP;
344
0
345
0
        u4_cbp = *((UWORD8*)gau1_ih264d_cbp_inter + u4_cbp);
346
0
        COPYTHECONTEXT("coded_block_pattern", u4_cbp);
347
0
        ps_cur_mb_info->u1_cbp = u4_cbp;
348
0
349
0
        /* Read the transform8x8 u4_flag if present */
350
0
        if((ps_dec->s_high_profile.u1_transform8x8_present) && (u4_cbp & 0xf)
351
0
                        && u1_no_submb_part_size_lt8x8_flag)
352
0
        {
353
0
            ps_cur_mb_info->u1_tran_form8x8 = ih264d_get_bit_h264(ps_bitstrm);
354
0
            COPYTHECONTEXT("transform_size_8x8_flag", ps_cur_mb_info->u1_tran_form8x8);
355
0
            ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = ps_cur_mb_info->u1_tran_form8x8;
356
0
        }
357
0
358
0
        /* Read mb_qp_delta */
359
0
        if(u4_cbp)
360
0
        {
361
0
            WORD32 i_temp;
362
0
363
0
            UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
364
0
            UWORD32 u4_word, u4_ldz, u4_abs_val;
365
0
366
0
            /***************************************************************/
367
0
            /* Find leading zeros in next 32 bits                          */
368
0
            /***************************************************************/
369
0
            NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
370
0
            u4_ldz = CLZ(u4_word);
371
0
372
0
            /* Flush the ps_bitstrm */
373
0
            u4_bitstream_offset += (u4_ldz + 1);
374
0
375
0
            /* Read the suffix from the ps_bitstrm */
376
0
            u4_word = 0;
377
0
            if(u4_ldz)
378
0
                GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
379
0
                        u4_ldz);
380
0
381
0
            *pu4_bitstrm_ofst = u4_bitstream_offset;
382
0
            u4_abs_val = ((1 << u4_ldz) + u4_word) >> 1;
383
0
384
0
            if(u4_word & 0x1)
385
0
                i_temp = (-(WORD32)u4_abs_val);
386
0
            else
387
0
                i_temp = (u4_abs_val);
388
0
389
0
            if((i_temp < -26) || (i_temp > 25))
390
0
                return ERROR_INV_RANGE_QP_T;
391
0
            //inlinined ih264d_sev
392
0
393
0
            COPYTHECONTEXT("mb_qp_delta", i_temp);
394
0
            if(i_temp)
395
0
            {
396
0
                ret = ih264d_update_qp(ps_dec, (WORD8)i_temp);
397
0
                if(ret != OK)
398
0
                    return ret;
399
0
            }
400
0
401
0
            ret = ih264d_parse_residual4x4_cavlc(ps_dec, ps_cur_mb_info, 0);
402
0
            if(ret != OK)
403
0
                return ret;
404
0
            if(EXCEED_OFFSET(ps_bitstrm))
405
0
                return ERROR_EOB_TERMINATE_T;
406
0
        }
407
0
        else
408
0
        {
409
0
            ih264d_update_nnz_for_skipmb(ps_dec, ps_cur_mb_info, CAVLC);
410
0
        }
411
0
412
0
413
0
414
0
    }
415
0
416
0
    return OK;
417
0
}
418
419
/*!
420
 **************************************************************************
421
 * \if Function name : ih264d_parse_pmb_cabac \endif
422
 *
423
 * \brief
424
 *    This function parses CABAC syntax of a P MB.
425
 *
426
 * \return
427
 *    0 on Success and Error code otherwise
428
 **************************************************************************
429
 */
430
WORD32 ih264d_parse_pmb_cabac(dec_struct_t * ps_dec,
431
                              dec_mb_info_t * ps_cur_mb_info,
432
                              UWORD8 u1_mb_num,
433
                              UWORD8 u1_num_mbsNby2)
434
0
{
435
0
    UWORD32 u1_num_mb_part;
436
0
    UWORD32 uc_sub_mb;
437
0
    parse_pmbarams_t * ps_parse_mb_data = ps_dec->ps_parse_mb_data
438
0
                    + u1_num_mbsNby2;
439
0
    WORD8 * pi1_ref_idx = ps_parse_mb_data->i1_ref_idx[0];
440
0
    const UWORD8 * pu1_num_mb_part = (const UWORD8 *)gau1_ih264d_num_mb_part;
441
0
    const UWORD32 u1_mb_type = ps_cur_mb_info->u1_mb_type;
442
0
    UWORD8 * pu1_col_info = ps_parse_mb_data->u1_col_info;
443
0
    UWORD32 u1_mb_mc_mode = u1_mb_type;
444
0
    ctxt_inc_mb_info_t * p_curr_ctxt = ps_dec->ps_curr_ctxt_mb_info;
445
0
    decoding_envirnoment_t * ps_cab_env = &ps_dec->s_cab_dec_env;
446
0
    dec_bit_stream_t * ps_bitstrm = ps_dec->ps_bitstrm;
447
0
    UWORD32 u4_sub_mb_pack = 0;
448
0
    WORD32 ret;
449
0
450
0
    UWORD8 u1_no_submb_part_size_lt8x8_flag = 1;
451
0
    ps_cur_mb_info->u1_tran_form8x8 = 0;
452
0
    ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0;
453
0
454
0
    ps_cur_mb_info->u1_yuv_dc_block_flag = 0;
455
0
456
0
    p_curr_ctxt->u1_mb_type = CAB_P;
457
0
    ps_cur_mb_info->u1_mb_mc_mode = u1_mb_type;
458
0
    uc_sub_mb = ((u1_mb_type == PRED_8x8) | (u1_mb_type == PRED_8x8R0));
459
0
460
0
    /* Reading the subMB type */
461
0
    if(uc_sub_mb)
462
0
    {
463
0
464
0
        UWORD8 u1_colz = (PRED_8x8 << 6);
465
0
        u1_mb_mc_mode = 0;
466
0
467
0
        {
468
0
            UWORD8 u1_sub_mb_mode;
469
0
            u1_sub_mb_mode = ih264d_parse_submb_type_cabac(
470
0
                            0, ps_cab_env, ps_bitstrm,
471
0
                            ps_dec->p_sub_mb_type_t);
472
0
            if(u1_sub_mb_mode > 3)
473
0
                return ERROR_SUB_MB_TYPE;
474
0
475
0
            u4_sub_mb_pack = (u4_sub_mb_pack << 8) | u1_sub_mb_mode;
476
0
            /* Storing collocated information */
477
0
            *pu1_col_info++ = u1_colz | ((UWORD8)(u1_sub_mb_mode << 4));
478
0
            COPYTHECONTEXT("sub_mb_type", u1_sub_mb_mode);
479
0
            /* check if Motion compensation is done below 8x8 */
480
0
            if(u1_sub_mb_mode != P_L0_8x8)
481
0
            {
482
0
                u1_no_submb_part_size_lt8x8_flag = 0;
483
0
            }
484
0
        }
485
0
        {
486
0
            UWORD8 u1_sub_mb_mode;
487
0
            u1_sub_mb_mode = ih264d_parse_submb_type_cabac(
488
0
                            0, ps_cab_env, ps_bitstrm,
489
0
                            ps_dec->p_sub_mb_type_t);
490
0
            if(u1_sub_mb_mode > 3)
491
0
                return ERROR_SUB_MB_TYPE;
492
0
493
0
            u4_sub_mb_pack = (u4_sub_mb_pack << 8) | u1_sub_mb_mode;
494
0
            /* Storing collocated information */
495
0
            *pu1_col_info++ = u1_colz | ((UWORD8)(u1_sub_mb_mode << 4));
496
0
            COPYTHECONTEXT("sub_mb_type", u1_sub_mb_mode);
497
0
            /* check if Motion compensation is done below 8x8 */
498
0
            if(u1_sub_mb_mode != P_L0_8x8)
499
0
            {
500
0
                u1_no_submb_part_size_lt8x8_flag = 0;
501
0
            }
502
0
        }
503
0
        {
504
0
            UWORD8 u1_sub_mb_mode;
505
0
            u1_sub_mb_mode = ih264d_parse_submb_type_cabac(
506
0
                            0, ps_cab_env, ps_bitstrm,
507
0
                            ps_dec->p_sub_mb_type_t);
508
0
            if(u1_sub_mb_mode > 3)
509
0
                return ERROR_SUB_MB_TYPE;
510
0
511
0
            u4_sub_mb_pack = (u4_sub_mb_pack << 8) | u1_sub_mb_mode;
512
0
            /* Storing collocated information */
513
0
            *pu1_col_info++ = u1_colz | ((UWORD8)(u1_sub_mb_mode << 4));
514
0
            COPYTHECONTEXT("sub_mb_type", u1_sub_mb_mode);
515
0
            /* check if Motion compensation is done below 8x8 */
516
0
            if(u1_sub_mb_mode != P_L0_8x8)
517
0
            {
518
0
                u1_no_submb_part_size_lt8x8_flag = 0;
519
0
            }
520
0
        }
521
0
        {
522
0
            UWORD8 u1_sub_mb_mode;
523
0
            u1_sub_mb_mode = ih264d_parse_submb_type_cabac(
524
0
                            0, ps_cab_env, ps_bitstrm,
525
0
                            ps_dec->p_sub_mb_type_t);
526
0
            if(u1_sub_mb_mode > 3)
527
0
                return ERROR_SUB_MB_TYPE;
528
0
529
0
            u4_sub_mb_pack = (u4_sub_mb_pack << 8) | u1_sub_mb_mode;
530
0
            /* Storing collocated information */
531
0
            *pu1_col_info++ = u1_colz | ((UWORD8)(u1_sub_mb_mode << 4));
532
0
            COPYTHECONTEXT("sub_mb_type", u1_sub_mb_mode);
533
0
            /* check if Motion compensation is done below 8x8 */
534
0
            if(u1_sub_mb_mode != P_L0_8x8)
535
0
            {
536
0
                u1_no_submb_part_size_lt8x8_flag = 0;
537
0
            }
538
0
        }
539
0
        u1_num_mb_part = 4;
540
0
    }
541
0
    else
542
0
    {
543
0
        u1_num_mb_part = pu1_num_mb_part[u1_mb_type];
544
0
        /* Storing collocated Mb and SubMb mode information */
545
0
        *pu1_col_info++ = (u1_mb_type << 6);
546
0
        if(u1_mb_type)
547
0
            *pu1_col_info++ = (u1_mb_type << 6);
548
0
    }
549
0
    /* Decoding reference index 0: For simple profile the following   */
550
0
    /* conditions are always true (mb_field_decoding_flag == 0);      */
551
0
    /* (MbPartPredMode != PredL1)                                     */
552
0
    {
553
0
        WORD8 * pi1_top_ref_idx_ctx_inc_arr = p_curr_ctxt->i1_ref_idx;
554
0
        WORD8 * pi1_left_ref_idx_ctxt_inc = ps_dec->pi1_left_ref_idx_ctxt_inc;
555
0
        UWORD8 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
556
0
        UWORD8 uc_field = ps_cur_mb_info->u1_mb_field_decodingflag;
557
0
        UWORD8 uc_num_ref_idx_l0_active_minus1 =
558
0
                        (ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[0]
559
0
                                        << (u1_mbaff & uc_field)) - 1;
560
0
561
0
        if((uc_num_ref_idx_l0_active_minus1 > 0) & (u1_mb_type != PRED_8x8R0))
562
0
        {
563
0
            /* force the routine to decode ref idx for each partition */
564
0
            *((UWORD32 *)pi1_ref_idx) = 0x01010101;
565
0
            ret = ih264d_parse_ref_idx_cabac(u1_num_mb_part, 0,
566
0
                                             uc_num_ref_idx_l0_active_minus1,
567
0
                                             u1_mb_mc_mode, pi1_ref_idx,
568
0
                                             pi1_left_ref_idx_ctxt_inc,
569
0
                                             pi1_top_ref_idx_ctx_inc_arr, ps_cab_env,
570
0
                                             ps_bitstrm, ps_dec->p_ref_idx_t);
571
0
            if(ret != OK)
572
0
                return ret;
573
0
        }
574
0
        else
575
0
        {
576
0
            /* When there exists only a single frame to predict from */
577
0
            pi1_left_ref_idx_ctxt_inc[0] = 0;
578
0
            pi1_left_ref_idx_ctxt_inc[1] = 0;
579
0
            pi1_top_ref_idx_ctx_inc_arr[0] = 0;
580
0
            pi1_top_ref_idx_ctx_inc_arr[1] = 0;
581
0
            *((UWORD32 *)pi1_ref_idx) = 0;
582
0
        }
583
0
    }
584
0
585
0
    {
586
0
        UWORD8 u1_p_idx, uc_i;
587
0
        parse_part_params_t * ps_part = ps_dec->ps_part;
588
0
        UWORD8 u1_sub_mb_mode, u1_num_subpart, u1_mb_part_width, u1_mb_part_height;
589
0
        UWORD8 u1_sub_mb_num;
590
0
        const UWORD8 * pu1_top_left_sub_mb_indx;
591
0
        mv_pred_t *ps_mv_start = ps_dec->ps_mv_cur + (u1_mb_num << 4);
592
0
        UWORD16 u2_sub_mb_num_pack = 0x028A;
593
0
594
0
        /* Loading the table pointers */
595
0
        const UWORD8 * pu1_mb_partw = (const UWORD8 *)gau1_ih264d_mb_partw;
596
0
        const UWORD8 * pu1_mb_parth = (const UWORD8 *)gau1_ih264d_mb_parth;
597
0
        const UWORD8 * pu1_sub_mb_indx_mod =
598
0
                        (const UWORD8 *)(gau1_ih264d_submb_indx_mod)
599
0
                                        + (uc_sub_mb * 6);
600
0
        const UWORD8 * pu1_sub_mb_partw = (const UWORD8 *)gau1_ih264d_submb_partw;
601
0
        const UWORD8 * pu1_sub_mb_parth = (const UWORD8 *)gau1_ih264d_submb_parth;
602
0
        const UWORD8 * pu1_num_sub_mb_part =
603
0
                        (const UWORD8 *)gau1_ih264d_num_submb_part;
604
0
605
0
        /*********************************************************/
606
0
        /* default initialisations for condition (uc_sub_mb == 0) */
607
0
        /* i.e. all are subpartitions of 8x8                     */
608
0
        /*********************************************************/
609
0
        u1_sub_mb_mode = 0;
610
0
        u1_num_subpart = 1;
611
0
        u1_mb_part_width = pu1_mb_partw[u1_mb_type];
612
0
        u1_mb_part_height = pu1_mb_parth[u1_mb_type];
613
0
        pu1_top_left_sub_mb_indx = pu1_sub_mb_indx_mod + (u1_mb_type << 1);
614
0
        u1_sub_mb_num = 0;
615
0
616
0
        /* Loop on number of partitions */
617
0
        for(uc_i = 0, u1_p_idx = 0; uc_i < u1_num_mb_part; uc_i++)
618
0
        {
619
0
            UWORD8 uc_j;
620
0
            if(uc_sub_mb)
621
0
            {
622
0
                u1_sub_mb_mode = u4_sub_mb_pack >> 24;
623
0
                u1_num_subpart = pu1_num_sub_mb_part[u1_sub_mb_mode];
624
0
                u1_mb_part_width = pu1_sub_mb_partw[u1_sub_mb_mode];
625
0
                u1_mb_part_height = pu1_sub_mb_parth[u1_sub_mb_mode];
626
0
                pu1_top_left_sub_mb_indx = pu1_sub_mb_indx_mod + (u1_sub_mb_mode << 1);
627
0
                u1_sub_mb_num = u2_sub_mb_num_pack >> 12;
628
0
                u4_sub_mb_pack <<= 8;
629
0
                u2_sub_mb_num_pack <<= 4;
630
0
            }
631
0
            /* Loop on Number of sub-partitions */
632
0
            for(uc_j = 0; uc_j < u1_num_subpart; uc_j++, pu1_top_left_sub_mb_indx++)
633
0
            {
634
0
                mv_pred_t * ps_mv;
635
0
636
0
                u1_sub_mb_num += *pu1_top_left_sub_mb_indx;
637
0
                ps_mv = ps_mv_start + u1_sub_mb_num;
638
0
639
0
                /* Storing Info for partitions */
640
0
                ps_part->u1_is_direct = PART_NOT_DIRECT;
641
0
                ps_part->u1_sub_mb_num = u1_sub_mb_num;
642
0
                ps_part->u1_partheight = u1_mb_part_height;
643
0
                ps_part->u1_partwidth = u1_mb_part_width;
644
0
645
0
                /* Increment partition Index */
646
0
                u1_p_idx++;
647
0
                ps_part++;
648
0
649
0
                ih264d_get_mvd_cabac(u1_sub_mb_num, 0, u1_mb_part_width,
650
0
                                     u1_mb_part_height, 1, ps_dec, ps_mv);
651
0
            }
652
0
        }
653
0
        ps_parse_mb_data->u1_num_part = u1_p_idx;
654
0
        ps_dec->ps_part = ps_part;
655
0
    }
656
0
    {
657
0
        UWORD8 u1_cbp;
658
0
659
0
        /* Read the Coded block pattern */
660
0
        u1_cbp = (WORD8)ih264d_parse_ctx_cbp_cabac(ps_dec);
661
0
        COPYTHECONTEXT("coded_block_pattern", u1_cbp);
662
0
        ps_cur_mb_info->u1_cbp = u1_cbp;
663
0
        p_curr_ctxt->u1_cbp = u1_cbp;
664
0
        p_curr_ctxt->u1_intra_chroma_pred_mode = 0;
665
0
        p_curr_ctxt->u1_yuv_dc_csbp &= 0xFE;
666
0
        ps_dec->pu1_left_yuv_dc_csbp[0] &= 0x6;
667
0
668
0
        if(u1_cbp > 47)
669
0
            return ERROR_CBP;
670
0
671
0
        ps_cur_mb_info->u1_tran_form8x8 = 0;
672
0
        ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0;
673
0
674
0
        /* Read the transform8x8 u4_flag if present */
675
0
        if((ps_dec->s_high_profile.u1_transform8x8_present) && (u1_cbp & 0xf)
676
0
                        && u1_no_submb_part_size_lt8x8_flag)
677
0
        {
678
0
            ps_cur_mb_info->u1_tran_form8x8 = ih264d_parse_transform8x8flag_cabac(
679
0
                            ps_dec, ps_cur_mb_info);
680
0
            COPYTHECONTEXT("transform_size_8x8_flag", ps_cur_mb_info->u1_tran_form8x8);
681
0
            p_curr_ctxt->u1_transform8x8_ctxt = ps_cur_mb_info->u1_tran_form8x8;
682
0
            ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = ps_cur_mb_info->u1_tran_form8x8;
683
0
684
0
        }
685
0
        else
686
0
        {
687
0
            p_curr_ctxt->u1_transform8x8_ctxt = 0;
688
0
        }
689
0
690
0
        /* Read mb_qp_delta */
691
0
        if(u1_cbp)
692
0
        {
693
0
            WORD8 c_temp;
694
0
            ret = ih264d_parse_mb_qp_delta_cabac(ps_dec, &c_temp);
695
0
            if(ret != OK)
696
0
                return ret;
697
0
            COPYTHECONTEXT("mb_qp_delta", c_temp);
698
0
            if(c_temp != 0)
699
0
            {
700
0
                ret = ih264d_update_qp(ps_dec, c_temp);
701
0
                if(ret != OK)
702
0
                    return ret;
703
0
            }
704
0
        }
705
0
        else
706
0
            ps_dec->i1_prev_mb_qp_delta = 0;
707
0
708
0
709
0
710
0
        ih264d_parse_residual4x4_cabac(ps_dec, ps_cur_mb_info, 0);
711
0
        if(EXCEED_OFFSET(ps_dec->ps_bitstrm))
712
0
            return ERROR_EOB_TERMINATE_T;
713
0
    }
714
0
    return OK;
715
0
}
716
717
/*!
718
 **************************************************************************
719
 * \if Function name : parsePSliceData \endif
720
 *
721
 * \brief
722
 *    This function parses CAVLC syntax of N MB's of a P slice.
723
 *    1. After parsing syntax of N MB's, for those N MB's (less than N, incase
724
 *       of end of slice or end of row), MB is decoded. This process is carried
725
 *       for one complete MB row or till end of slice.
726
 *    2. Bottom one row of current MB is copied to IntraPredLine buffers.
727
 *       IntraPredLine buffers are used for Intra prediction of next row.
728
 *    3. Current MB row along with previous 4 rows of Luma (and 2 of Chroma) are
729
 *       deblocked.
730
 *    4. 4 rows (2 for Chroma) previous row and 12 rows (6 for Chroma) are
731
 *       DMA'ed to picture buffers.
732
 *
733
 * \return
734
 *    0 on Success and Error code otherwise
735
 **************************************************************************
736
 */
737
738
/*!
739
 **************************************************************************
740
 * \if Function name : ih264d_update_nnz_for_skipmb \endif
741
 *
742
 * \brief
743
 *
744
 * \return
745
 *    None
746
 *
747
 **************************************************************************
748
 */
749
void ih264d_update_nnz_for_skipmb(dec_struct_t * ps_dec,
750
                                  dec_mb_info_t * ps_cur_mb_info,
751
                                  UWORD8 u1_entrpy)
752
2.18k
{
753
2.18k
    UWORD32 *pu4_buf;
754
2.18k
    UWORD8 *pu1_buf;
755
2.18k
    UNUSED(u1_entrpy);
756
2.18k
    pu1_buf = ps_dec->pu1_left_nnz_y;
757
2.18k
    pu4_buf = (UWORD32 *)pu1_buf;
758
2.18k
    *pu4_buf = 0;
759
2.18k
    pu1_buf = ps_dec->pu1_left_nnz_uv;
760
2.18k
    pu4_buf = (UWORD32 *)pu1_buf;
761
2.18k
    *pu4_buf = 0;
762
2.18k
    pu1_buf = ps_cur_mb_info->ps_curmb->pu1_nnz_y;
763
2.18k
    pu4_buf = (UWORD32 *)pu1_buf;
764
2.18k
    *pu4_buf = 0;
765
2.18k
    pu1_buf = ps_cur_mb_info->ps_curmb->pu1_nnz_uv;
766
2.18k
    pu4_buf = (UWORD32 *)pu1_buf;
767
2.18k
    *pu4_buf = 0;
768
2.18k
    ps_cur_mb_info->ps_curmb->u2_luma_csbp = 0;
769
2.18k
    ps_cur_mb_info->u2_luma_csbp = 0;
770
2.18k
    ps_cur_mb_info->u2_chroma_csbp = 0;
771
2.18k
}
772
773
774
775
/*****************************************************************************/
776
/*                                                                           */
777
/*  Function Name : ih264d_parse_inter_slice_data_cabac                             */
778
/*                                                                           */
779
/*  Description   : This function parses cabac syntax of a inter slice on    */
780
/*                  N MB basis.                                              */
781
/*                                                                           */
782
/*  Inputs        : ps_dec                                                   */
783
/*                  sliceparams                                              */
784
/*                  firstMbInSlice                                           */
785
/*                                                                           */
786
/*  Processing    : 1. After parsing syntax for N MBs those N MBs are        */
787
/*                     decoded till the end of slice.                        */
788
/*                  2. MV prediction and DMA happens on a N/2 MB basis.      */
789
/*                                                                           */
790
/*  Returns       : 0                                                        */
791
/*                                                                           */
792
/*  Issues        : <List any issues or problems with this function>         */
793
/*                                                                           */
794
/*  Revision History:                                                        */
795
/*                                                                           */
796
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
797
/*         13 07 2002   Jay             Draft                                */
798
/*                                                                           */
799
/*****************************************************************************/
800
WORD32 ih264d_parse_inter_slice_data_cabac(dec_struct_t * ps_dec,
801
                                           dec_slice_params_t * ps_slice,
802
                                           UWORD16 u2_first_mb_in_slice)
803
0
{
804
0
    UWORD32 uc_more_data_flag;
805
0
    WORD32 i2_cur_mb_addr;
806
0
    UWORD32 u1_num_mbs, u1_num_mbsNby2, u1_mb_idx;
807
0
    UWORD32 u1_mbaff;
808
0
    UWORD32 u1_num_mbs_next, u1_end_of_row;
809
0
    const UWORD16 i2_pic_wdin_mbs = ps_dec->u2_frm_wd_in_mbs;
810
0
    UWORD32 u1_slice_end = 0;
811
0
    UWORD32 u1_tfr_n_mb = 0;
812
0
    UWORD32 u1_decode_nmb = 0;
813
0
814
0
815
0
    deblk_mb_t *ps_cur_deblk_mb;
816
0
    dec_mb_info_t *ps_cur_mb_info;
817
0
818
0
    parse_pmbarams_t *ps_parse_mb_data = ps_dec->ps_parse_mb_data;
819
0
    UWORD32 u1_inter_mb_skip_type;
820
0
    UWORD32 u1_inter_mb_type;
821
0
    UWORD32 u1_deblk_mb_type;
822
0
    UWORD32 u1_mb_threshold;
823
0
    dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
824
0
    WORD32 ret = OK;
825
0
826
0
    /******************************************************/
827
0
    /* Initialisations specific to B or P slice           */
828
0
    /******************************************************/
829
0
    if(ps_slice->u1_slice_type == P_SLICE)
830
0
    {
831
0
        u1_inter_mb_skip_type = CAB_P_SKIP;
832
0
        u1_inter_mb_type = P_MB;
833
0
        u1_deblk_mb_type = D_INTER_MB;
834
0
        u1_mb_threshold = 5;
835
0
    }
836
0
    else // B_SLICE
837
0
    {
838
0
        u1_inter_mb_skip_type = CAB_B_SKIP;
839
0
        u1_inter_mb_type = B_MB;
840
0
        u1_deblk_mb_type = D_B_SLICE;
841
0
        u1_mb_threshold = 23;
842
0
    }
843
0
844
0
    /******************************************************/
845
0
    /* Slice Level Initialisations                        */
846
0
    /******************************************************/
847
0
    i2_cur_mb_addr = u2_first_mb_in_slice;
848
0
    ps_dec->u1_qp = ps_slice->u1_slice_qp;
849
0
    ih264d_update_qp(ps_dec, 0);
850
0
    u1_mb_idx = ps_dec->u1_mb_idx;
851
0
    u1_num_mbs = u1_mb_idx;
852
0
    u1_num_mbsNby2 = 0;
853
0
    u1_mbaff = ps_slice->u1_mbaff_frame_flag;
854
0
    i2_cur_mb_addr = u2_first_mb_in_slice << u1_mbaff;
855
0
    uc_more_data_flag = 1;
856
0
857
0
    /* Initialisations specific to cabac */
858
0
    if(ps_bitstrm->u4_ofst & 0x07)
859
0
    {
860
0
        ps_bitstrm->u4_ofst += 8;
861
0
        ps_bitstrm->u4_ofst &= 0xFFFFFFF8;
862
0
    }
863
0
864
0
    ret = ih264d_init_cabac_dec_envirnoment(&(ps_dec->s_cab_dec_env), ps_bitstrm);
865
0
    if(ret != OK)
866
0
        return ret;
867
0
868
0
    ps_dec->i1_prev_mb_qp_delta = 0;
869
0
870
0
    while(!u1_slice_end)
871
0
    {
872
0
        UWORD8 u1_mb_type;
873
0
        UWORD32 u4_mb_skip;
874
0
875
0
        ps_dec->pv_prev_mb_parse_tu_coeff_data = ps_dec->pv_parse_tu_coeff_data;
876
0
877
0
        if(i2_cur_mb_addr > ps_dec->ps_cur_sps->u2_max_mb_addr)
878
0
        {
879
0
            break;
880
0
        }
881
0
882
0
        ps_cur_mb_info = ps_dec->ps_nmb_info + u1_num_mbs;
883
0
        ps_dec->u4_num_mbs_cur_nmb = u1_num_mbs;
884
0
885
0
        ps_cur_mb_info->u1_Mux = 0;
886
0
        ps_dec->u4_num_pmbair = (u1_num_mbs >> u1_mbaff);
887
0
        ps_cur_deblk_mb = ps_dec->ps_deblk_mbn + u1_num_mbs;
888
0
889
0
        ps_cur_mb_info->u1_end_of_slice = 0;
890
0
891
0
        /* Storing Default partition info */
892
0
        ps_parse_mb_data->u1_num_part = 1;
893
0
        ps_parse_mb_data->u1_isI_mb = 0;
894
0
895
0
        /***************************************************************/
896
0
        /* Get the required information for decoding of MB             */
897
0
        /* mb_x, mb_y , neighbour availablity,                         */
898
0
        /***************************************************************/
899
0
        u4_mb_skip = ps_dec->pf_get_mb_info(ps_dec, i2_cur_mb_addr, ps_cur_mb_info, 1);
900
0
901
0
        /*********************************************************************/
902
0
        /* initialize u1_tran_form8x8 to zero to aviod uninitialized accesses */
903
0
        /*********************************************************************/
904
0
        ps_cur_mb_info->u1_tran_form8x8 = 0;
905
0
        ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0;
906
0
907
0
        /***************************************************************/
908
0
        /* Set the deblocking parameters for this MB                   */
909
0
        /***************************************************************/
910
0
        if(ps_dec->u4_app_disable_deblk_frm == 0)
911
0
            ih264d_set_deblocking_parameters(ps_cur_deblk_mb, ps_slice,
912
0
                                             ps_dec->u1_mb_ngbr_availablity,
913
0
                                             ps_dec->u1_cur_mb_fld_dec_flag);
914
0
915
0
        if(u4_mb_skip)
916
0
        {
917
0
918
0
            /* Set appropriate flags in ps_cur_mb_info and ps_dec */
919
0
            memset(ps_dec->ps_curr_ctxt_mb_info, 0, sizeof(ctxt_inc_mb_info_t));
920
0
            ps_dec->ps_curr_ctxt_mb_info->u1_mb_type = u1_inter_mb_skip_type;
921
0
922
0
            MEMSET_16BYTES(&ps_dec->pu1_left_mv_ctxt_inc[0][0], 0);
923
0
924
0
            *((UWORD32 *)ps_dec->pi1_left_ref_idx_ctxt_inc) = 0;
925
0
            *(ps_dec->pu1_left_yuv_dc_csbp) = 0;
926
0
927
0
            ps_dec->i1_prev_mb_qp_delta = 0;
928
0
            ps_cur_mb_info->u1_mb_type = MB_SKIP;
929
0
            ps_cur_mb_info->u1_cbp = 0;
930
0
931
0
            {
932
0
                /* Storing Skip partition info */
933
0
                parse_part_params_t *ps_part_info = ps_dec->ps_part;
934
0
                ps_part_info->u1_is_direct = PART_DIRECT_16x16;
935
0
                ps_part_info->u1_sub_mb_num = 0;
936
0
                ps_dec->ps_part++;
937
0
            }
938
0
939
0
            /* Update Nnzs */
940
0
            ih264d_update_nnz_for_skipmb(ps_dec, ps_cur_mb_info, CABAC);
941
0
942
0
            ps_cur_mb_info->ps_curmb->u1_mb_type = u1_inter_mb_type;
943
0
            ps_cur_deblk_mb->u1_mb_type |= u1_deblk_mb_type;
944
0
            ps_cur_deblk_mb->u1_mb_qp = ps_dec->u1_qp;
945
0
946
0
        }
947
0
        else
948
0
        {
949
0
950
0
            /* Macroblock Layer Begins */
951
0
            /* Decode the u1_mb_type */
952
0
            u1_mb_type = ih264d_parse_mb_type_cabac(ps_dec);
953
0
            ps_cur_mb_info->u1_mb_type = u1_mb_type;
954
0
            if(u1_mb_type > (25 + u1_mb_threshold))
955
0
                return ERROR_MB_TYPE;
956
0
957
0
            /* Parse Macroblock Data */
958
0
            if(u1_mb_type < u1_mb_threshold)
959
0
            {
960
0
                ps_cur_mb_info->ps_curmb->u1_mb_type = u1_inter_mb_type;
961
0
                *(ps_dec->pu1_left_yuv_dc_csbp) &= 0x6;
962
0
963
0
                ret = ps_dec->pf_parse_inter_mb(ps_dec, ps_cur_mb_info, u1_num_mbs,
964
0
                                          u1_num_mbsNby2);
965
0
                if(ret != OK)
966
0
                    return ret;
967
0
                ps_cur_deblk_mb->u1_mb_qp = ps_dec->u1_qp;
968
0
                ps_cur_deblk_mb->u1_mb_type |= u1_deblk_mb_type;
969
0
            }
970
0
            else
971
0
            {
972
0
                /* Storing Intra partition info */
973
0
                ps_parse_mb_data->u1_num_part = 0;
974
0
                ps_parse_mb_data->u1_isI_mb = 1;
975
0
976
0
                if((25 + u1_mb_threshold) == u1_mb_type)
977
0
                {
978
0
                    /* I_PCM_MB */
979
0
                    ps_cur_mb_info->ps_curmb->u1_mb_type = I_PCM_MB;
980
0
                    ret = ih264d_parse_ipcm_mb(ps_dec, ps_cur_mb_info, u1_num_mbs);
981
0
                    if(ret != OK)
982
0
                        return ret;
983
0
                    ps_cur_deblk_mb->u1_mb_qp = 0;
984
0
                }
985
0
                else
986
0
                {
987
0
                    if(u1_mb_type == u1_mb_threshold)
988
0
                        ps_cur_mb_info->ps_curmb->u1_mb_type = I_4x4_MB;
989
0
                    else
990
0
                        ps_cur_mb_info->ps_curmb->u1_mb_type = I_16x16_MB;
991
0
992
0
                    ret = ih264d_parse_imb_cabac(
993
0
                                    ps_dec, ps_cur_mb_info,
994
0
                                    (UWORD8)(u1_mb_type - u1_mb_threshold));
995
0
                    if(ret != OK)
996
0
                        return ret;
997
0
                    ps_cur_deblk_mb->u1_mb_qp = ps_dec->u1_qp;
998
0
                }
999
0
                ps_cur_deblk_mb->u1_mb_type |= D_INTRA_MB;
1000
0
1001
0
            }
1002
0
1003
0
        }
1004
0
1005
0
        if(u1_mbaff)
1006
0
        {
1007
0
            ih264d_update_mbaff_left_nnz(ps_dec, ps_cur_mb_info);
1008
0
        }
1009
0
1010
0
1011
0
        if(ps_cur_mb_info->u1_topmb && u1_mbaff)
1012
0
            uc_more_data_flag = 1;
1013
0
        else
1014
0
        {
1015
0
            uc_more_data_flag = ih264d_decode_terminate(&ps_dec->s_cab_dec_env,
1016
0
                                                      ps_bitstrm);
1017
0
            uc_more_data_flag = !uc_more_data_flag;
1018
0
            COPYTHECONTEXT("Decode Sliceterm",!uc_more_data_flag);
1019
0
        }
1020
0
1021
0
        if(u1_mbaff)
1022
0
        {
1023
0
            if(!uc_more_data_flag && (0 == (i2_cur_mb_addr & 1)))
1024
0
            {
1025
0
                return ERROR_EOB_FLUSHBITS_T;
1026
0
            }
1027
0
        }
1028
0
        /* Next macroblock information */
1029
0
        i2_cur_mb_addr++;
1030
0
        u1_num_mbs++;
1031
0
        u1_num_mbsNby2++;
1032
0
        ps_parse_mb_data++;
1033
0
1034
0
        /****************************************************************/
1035
0
        /* Check for End Of Row and other flags that determine when to  */
1036
0
        /* do DMA setup for N/2-Mb, Decode for N-Mb, and Transfer for   */
1037
0
        /* N-Mb                                                         */
1038
0
        /****************************************************************/
1039
0
        u1_num_mbs_next = i2_pic_wdin_mbs - ps_dec->u2_mbx - 1;
1040
0
        u1_end_of_row = (!u1_num_mbs_next) && (!(u1_mbaff && (u1_num_mbs & 0x01)));
1041
0
        u1_slice_end = !uc_more_data_flag;
1042
0
        u1_tfr_n_mb = (u1_num_mbs == ps_dec->u1_recon_mb_grp) || u1_end_of_row
1043
0
                        || u1_slice_end;
1044
0
        u1_decode_nmb = u1_tfr_n_mb || u1_slice_end;
1045
0
        ps_cur_mb_info->u1_end_of_slice = u1_slice_end;
1046
0
        /*u1_dma_nby2mb   = u1_decode_nmb ||
1047
0
         (u1_num_mbsNby2 == ps_dec->u1_recon_mb_grp_pair);*/
1048
0
1049
0
//if(u1_dma_nby2mb)
1050
0
        if(u1_decode_nmb)
1051
0
        {
1052
0
1053
0
            ps_dec->pf_mvpred_ref_tfr_nby2mb(ps_dec, u1_mb_idx, u1_num_mbs);
1054
0
            u1_num_mbsNby2 = 0;
1055
0
1056
0
            {
1057
0
                ps_parse_mb_data = ps_dec->ps_parse_mb_data;
1058
0
                ps_dec->ps_part = ps_dec->ps_parse_part_params;
1059
0
            }
1060
0
        }
1061
0
1062
0
        /*H264_DEC_DEBUG_PRINT("Pic: %d Mb_X=%d Mb_Y=%d",
1063
0
         ps_slice->i4_poc >> ps_slice->u1_field_pic_flag,
1064
0
         ps_dec->u2_mbx,ps_dec->u2_mby + (1 - ps_cur_mb_info->u1_topmb));
1065
0
         H264_DEC_DEBUG_PRINT("u1_decode_nmb: %d, u1_num_mbs: %d", u1_decode_nmb, u1_num_mbs);*/
1066
0
        if(u1_decode_nmb)
1067
0
        {
1068
0
1069
0
            if(ps_dec->u1_separate_parse)
1070
0
            {
1071
0
                ih264d_parse_tfr_nmb(ps_dec, u1_mb_idx, u1_num_mbs,
1072
0
                                     u1_num_mbs_next, u1_tfr_n_mb, u1_end_of_row);
1073
0
                ps_dec->ps_nmb_info +=  u1_num_mbs;
1074
0
            }
1075
0
            else
1076
0
            {
1077
0
                ih264d_decode_recon_tfr_nmb(ps_dec, u1_mb_idx, u1_num_mbs,
1078
0
                                            u1_num_mbs_next, u1_tfr_n_mb,
1079
0
                                            u1_end_of_row);
1080
0
            }
1081
0
            ps_dec->u2_total_mbs_coded += u1_num_mbs;
1082
0
            if(u1_tfr_n_mb)
1083
0
                u1_num_mbs = 0;
1084
0
            u1_mb_idx = u1_num_mbs;
1085
0
            ps_dec->u1_mb_idx = u1_num_mbs;
1086
0
1087
0
        }
1088
0
    }
1089
0
1090
0
1091
0
    ps_dec->u4_num_mbs_cur_nmb = 0;
1092
0
    ps_dec->ps_cur_slice->u4_mbs_in_slice = i2_cur_mb_addr
1093
0
1094
0
                        - (u2_first_mb_in_slice << u1_mbaff);
1095
0
1096
0
    return ret;
1097
0
}
1098
1099
/*****************************************************************************/
1100
/*                                                                           */
1101
/*  Function Name : ih264d_parse_inter_slice_data_cavlc                             */
1102
/*                                                                           */
1103
/*  Description   : This function parses cavlc syntax of a inter slice on    */
1104
/*                  N MB basis.                                              */
1105
/*                                                                           */
1106
/*  Inputs        : ps_dec                                                   */
1107
/*                  sliceparams                                              */
1108
/*                  firstMbInSlice                                           */
1109
/*                                                                           */
1110
/*  Processing    : 1. After parsing syntax for N MBs those N MBs are        */
1111
/*                     decoded till the end of slice.                        */
1112
/*                  2. MV prediction and DMA happens on a N/2 MB basis.      */
1113
/*                                                                           */
1114
/*  Returns       : 0                                                        */
1115
/*                                                                           */
1116
/*  Issues        : <List any issues or problems with this function>         */
1117
/*                                                                           */
1118
/*  Revision History:                                                        */
1119
/*                                                                           */
1120
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1121
/*         13 07 2002   Jay             Draft                                */
1122
/*                                                                           */
1123
/*****************************************************************************/
1124
1125
WORD32 ih264d_parse_inter_slice_data_cavlc(dec_struct_t * ps_dec,
1126
                                           dec_slice_params_t * ps_slice,
1127
                                           UWORD16 u2_first_mb_in_slice)
1128
0
{
1129
0
    UWORD32 uc_more_data_flag;
1130
0
    WORD32 i2_cur_mb_addr;
1131
0
    UWORD32 u1_num_mbs, u1_num_mbsNby2, u1_mb_idx;
1132
0
    UWORD32 i2_mb_skip_run;
1133
0
    UWORD32 u1_read_mb_type;
1134
0
1135
0
    UWORD32 u1_mbaff;
1136
0
    UWORD32 u1_num_mbs_next, u1_end_of_row;
1137
0
    const UWORD32 i2_pic_wdin_mbs = ps_dec->u2_frm_wd_in_mbs;
1138
0
    UWORD32 u1_slice_end = 0;
1139
0
    UWORD32 u1_tfr_n_mb = 0;
1140
0
    UWORD32 u1_decode_nmb = 0;
1141
0
1142
0
    dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
1143
0
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
1144
0
    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
1145
0
    deblk_mb_t *ps_cur_deblk_mb;
1146
0
    dec_mb_info_t *ps_cur_mb_info;
1147
0
    parse_pmbarams_t *ps_parse_mb_data = ps_dec->ps_parse_mb_data;
1148
0
    UWORD32 u1_inter_mb_type;
1149
0
    UWORD32 u1_deblk_mb_type;
1150
0
    UWORD32 u1_mb_threshold;
1151
0
    WORD32 ret = OK;
1152
0
1153
0
    /******************************************************/
1154
0
    /* Initialisations specific to B or P slice           */
1155
0
    /******************************************************/
1156
0
1157
0
    if(ps_slice->u1_slice_type == P_SLICE)
1158
0
    {
1159
0
        u1_inter_mb_type = P_MB;
1160
0
        u1_deblk_mb_type = D_INTER_MB;
1161
0
        u1_mb_threshold = 5;
1162
0
    }
1163
0
    else // B_SLICE
1164
0
    {
1165
0
        u1_inter_mb_type = B_MB;
1166
0
        u1_deblk_mb_type = D_B_SLICE;
1167
0
        u1_mb_threshold = 23;
1168
0
    }
1169
0
    /******************************************************/
1170
0
    /* Slice Level Initialisations                        */
1171
0
    /******************************************************/
1172
0
    ps_dec->u1_qp = ps_slice->u1_slice_qp;
1173
0
    ih264d_update_qp(ps_dec, 0);
1174
0
    u1_mb_idx = ps_dec->u1_mb_idx;
1175
0
    u1_num_mbs = u1_mb_idx;
1176
0
1177
0
    u1_num_mbsNby2 = 0;
1178
0
    u1_mbaff = ps_slice->u1_mbaff_frame_flag;
1179
0
    i2_cur_mb_addr = u2_first_mb_in_slice << u1_mbaff;
1180
0
    i2_mb_skip_run = 0;
1181
0
    uc_more_data_flag = 1;
1182
0
    u1_read_mb_type = 0;
1183
0
1184
0
    while(!u1_slice_end)
1185
0
    {
1186
0
        UWORD8 u1_mb_type;
1187
0
1188
0
        ps_dec->pv_prev_mb_parse_tu_coeff_data = ps_dec->pv_parse_tu_coeff_data;
1189
0
1190
0
        if(i2_cur_mb_addr > ps_dec->ps_cur_sps->u2_max_mb_addr)
1191
0
        {
1192
0
            break;
1193
0
        }
1194
0
1195
0
1196
0
        ps_cur_mb_info = ps_dec->ps_nmb_info + u1_num_mbs;
1197
0
        ps_dec->u4_num_mbs_cur_nmb = u1_num_mbs;
1198
0
1199
0
        ps_cur_mb_info->u1_Mux = 0;
1200
0
        ps_dec->u4_num_pmbair = (u1_num_mbs >> u1_mbaff);
1201
0
        ps_cur_deblk_mb = ps_dec->ps_deblk_mbn + u1_num_mbs;
1202
0
1203
0
        ps_cur_mb_info->u1_end_of_slice = 0;
1204
0
1205
0
        /* Storing Default partition info */
1206
0
        ps_parse_mb_data->u1_num_part = 1;
1207
0
        ps_parse_mb_data->u1_isI_mb = 0;
1208
0
1209
0
        if((!i2_mb_skip_run) && (!u1_read_mb_type))
1210
0
        {
1211
0
1212
0
            //Inlined ih264d_uev
1213
0
            UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
1214
0
            UWORD32 u4_word, u4_ldz;
1215
0
1216
0
            /***************************************************************/
1217
0
            /* Find leading zeros in next 32 bits                          */
1218
0
            /***************************************************************/
1219
0
            NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
1220
0
1221
0
            u4_ldz = CLZ(u4_word);
1222
0
1223
0
            /* Flush the ps_bitstrm */
1224
0
            u4_bitstream_offset += (u4_ldz + 1);
1225
0
            /* Read the suffix from the ps_bitstrm */
1226
0
            u4_word = 0;
1227
0
            if(u4_ldz)
1228
0
            {
1229
0
                GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
1230
0
                        u4_ldz);
1231
0
            }
1232
0
            *pu4_bitstrm_ofst = u4_bitstream_offset;
1233
0
            i2_mb_skip_run = ((1 << u4_ldz) + u4_word - 1);
1234
0
            //Inlined ih264d_uev
1235
0
            COPYTHECONTEXT("mb_skip_run", i2_mb_skip_run);
1236
0
            uc_more_data_flag = MORE_RBSP_DATA(ps_bitstrm);
1237
0
            u1_read_mb_type = uc_more_data_flag;
1238
0
        }
1239
0
1240
0
        /***************************************************************/
1241
0
        /* Get the required information for decoding of MB                  */
1242
0
        /* mb_x, mb_y , neighbour availablity,                              */
1243
0
        /***************************************************************/
1244
0
        ps_dec->pf_get_mb_info(ps_dec, i2_cur_mb_addr, ps_cur_mb_info, i2_mb_skip_run);
1245
0
1246
0
        /***************************************************************/
1247
0
        /* Set the deblocking parameters for this MB                   */
1248
0
        /***************************************************************/
1249
0
        if(ps_dec->u4_app_disable_deblk_frm == 0)
1250
0
            ih264d_set_deblocking_parameters(ps_cur_deblk_mb, ps_slice,
1251
0
                                             ps_dec->u1_mb_ngbr_availablity,
1252
0
                                             ps_dec->u1_cur_mb_fld_dec_flag);
1253
0
1254
0
        if(i2_mb_skip_run)
1255
0
        {
1256
0
            /* Set appropriate flags in ps_cur_mb_info and ps_dec */
1257
0
            ps_dec->i1_prev_mb_qp_delta = 0;
1258
0
            ps_dec->u1_sub_mb_num = 0;
1259
0
            ps_cur_mb_info->u1_mb_type = MB_SKIP;
1260
0
            ps_cur_mb_info->u1_mb_mc_mode = PRED_16x16;
1261
0
            ps_cur_mb_info->u1_cbp = 0;
1262
0
1263
0
            {
1264
0
                /* Storing Skip partition info */
1265
0
                parse_part_params_t *ps_part_info = ps_dec->ps_part;
1266
0
                ps_part_info->u1_is_direct = PART_DIRECT_16x16;
1267
0
                ps_part_info->u1_sub_mb_num = 0;
1268
0
                ps_dec->ps_part++;
1269
0
            }
1270
0
1271
0
            /* Update Nnzs */
1272
0
            ih264d_update_nnz_for_skipmb(ps_dec, ps_cur_mb_info, CAVLC);
1273
0
1274
0
            ps_cur_mb_info->ps_curmb->u1_mb_type = u1_inter_mb_type;
1275
0
            ps_cur_deblk_mb->u1_mb_type |= u1_deblk_mb_type;
1276
0
1277
0
            i2_mb_skip_run--;
1278
0
        }
1279
0
        else
1280
0
        {
1281
0
            u1_read_mb_type = 0;
1282
0
            /**************************************************************/
1283
0
            /* Macroblock Layer Begins, Decode the u1_mb_type                */
1284
0
            /**************************************************************/
1285
0
            {
1286
0
                UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
1287
0
                UWORD32 u4_word, u4_ldz, u4_temp;
1288
0
1289
0
1290
0
                //Inlined ih264d_uev
1291
0
                /***************************************************************/
1292
0
                /* Find leading zeros in next 32 bits                          */
1293
0
                /***************************************************************/
1294
0
                NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
1295
0
                u4_ldz = CLZ(u4_word);
1296
0
                /* Flush the ps_bitstrm */
1297
0
                u4_bitstream_offset += (u4_ldz + 1);
1298
0
                /* Read the suffix from the ps_bitstrm */
1299
0
                u4_word = 0;
1300
0
                if(u4_ldz)
1301
0
                    GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
1302
0
                            u4_ldz);
1303
0
                *pu4_bitstrm_ofst = u4_bitstream_offset;
1304
0
                u4_temp = ((1 << u4_ldz) + u4_word - 1);
1305
0
                //Inlined ih264d_uev
1306
0
                if(u4_temp > (UWORD32)(25 + u1_mb_threshold))
1307
0
                    return ERROR_MB_TYPE;
1308
0
                u1_mb_type = u4_temp;
1309
0
                COPYTHECONTEXT("u1_mb_type", u1_mb_type);
1310
0
            }
1311
0
            ps_cur_mb_info->u1_mb_type = u1_mb_type;
1312
0
1313
0
            /**************************************************************/
1314
0
            /* Parse Macroblock data                                      */
1315
0
            /**************************************************************/
1316
0
            if(u1_mb_type < u1_mb_threshold)
1317
0
            {
1318
0
                ps_cur_mb_info->ps_curmb->u1_mb_type = u1_inter_mb_type;
1319
0
1320
0
                ret = ps_dec->pf_parse_inter_mb(ps_dec, ps_cur_mb_info, u1_num_mbs,
1321
0
                                          u1_num_mbsNby2);
1322
0
                if(ret != OK)
1323
0
                    return ret;
1324
0
                ps_cur_deblk_mb->u1_mb_type |= u1_deblk_mb_type;
1325
0
            }
1326
0
            else
1327
0
            {
1328
0
                /* Storing Intra partition info */
1329
0
                ps_parse_mb_data->u1_num_part = 0;
1330
0
                ps_parse_mb_data->u1_isI_mb = 1;
1331
0
1332
0
                if((25 + u1_mb_threshold) == u1_mb_type)
1333
0
                {
1334
0
                    /* I_PCM_MB */
1335
0
                    ps_cur_mb_info->ps_curmb->u1_mb_type = I_PCM_MB;
1336
0
                    ret = ih264d_parse_ipcm_mb(ps_dec, ps_cur_mb_info, u1_num_mbs);
1337
0
                    if(ret != OK)
1338
0
                         return ret;
1339
0
                    ps_dec->u1_qp = 0;
1340
0
                }
1341
0
                else
1342
0
                {
1343
0
                    ret = ih264d_parse_imb_cavlc(
1344
0
                                    ps_dec, ps_cur_mb_info, u1_num_mbs,
1345
0
                                    (UWORD8)(u1_mb_type - u1_mb_threshold));
1346
0
                    if(ret != OK)
1347
0
                        return ret;
1348
0
                }
1349
0
1350
0
                ps_cur_deblk_mb->u1_mb_type |= D_INTRA_MB;
1351
0
            }
1352
0
            uc_more_data_flag = MORE_RBSP_DATA(ps_bitstrm);
1353
0
        }
1354
0
        ps_cur_deblk_mb->u1_mb_qp = ps_dec->u1_qp;
1355
0
1356
0
        if(u1_mbaff)
1357
0
        {
1358
0
            ih264d_update_mbaff_left_nnz(ps_dec, ps_cur_mb_info);
1359
0
            if(!uc_more_data_flag && !i2_mb_skip_run && (0 == (i2_cur_mb_addr & 1)))
1360
0
            {
1361
0
                return ERROR_EOB_FLUSHBITS_T;
1362
0
            }
1363
0
        }
1364
0
        /**************************************************************/
1365
0
        /* Get next Macroblock address                                */
1366
0
        /**************************************************************/
1367
0
        i2_cur_mb_addr++;
1368
0
1369
0
        u1_num_mbs++;
1370
0
        u1_num_mbsNby2++;
1371
0
        ps_parse_mb_data++;
1372
0
1373
0
        /****************************************************************/
1374
0
        /* Check for End Of Row and other flags that determine when to  */
1375
0
        /* do DMA setup for N/2-Mb, Decode for N-Mb, and Transfer for   */
1376
0
        /* N-Mb                                                         */
1377
0
        /****************************************************************/
1378
0
        u1_num_mbs_next = i2_pic_wdin_mbs - ps_dec->u2_mbx - 1;
1379
0
        u1_end_of_row = (!u1_num_mbs_next) && (!(u1_mbaff && (u1_num_mbs & 0x01)));
1380
0
        u1_slice_end = (!(uc_more_data_flag || i2_mb_skip_run));
1381
0
        u1_tfr_n_mb = (u1_num_mbs == ps_dec->u1_recon_mb_grp) || u1_end_of_row
1382
0
                        || u1_slice_end;
1383
0
        u1_decode_nmb = u1_tfr_n_mb || u1_slice_end;
1384
0
        ps_cur_mb_info->u1_end_of_slice = u1_slice_end;
1385
0
1386
0
        /*u1_dma_nby2mb   = u1_decode_nmb ||
1387
0
         (u1_num_mbsNby2 == ps_dec->u1_recon_mb_grp_pair);*/
1388
0
1389
0
//if(u1_dma_nby2mb)
1390
0
        if(u1_decode_nmb)
1391
0
        {
1392
0
            ps_dec->pf_mvpred_ref_tfr_nby2mb(ps_dec, u1_mb_idx, u1_num_mbs);
1393
0
            u1_num_mbsNby2 = 0;
1394
0
1395
0
            {
1396
0
                ps_parse_mb_data = ps_dec->ps_parse_mb_data;
1397
0
                ps_dec->ps_part = ps_dec->ps_parse_part_params;
1398
0
            }
1399
0
        }
1400
0
1401
0
        /*H264_DEC_DEBUG_PRINT("Pic: %d Mb_X=%d Mb_Y=%d",
1402
0
         ps_slice->i4_poc >> ps_slice->u1_field_pic_flag,
1403
0
         ps_dec->u2_mbx,ps_dec->u2_mby + (1 - ps_cur_mb_info->u1_topmb));
1404
0
         H264_DEC_DEBUG_PRINT("u1_decode_nmb: %d", u1_decode_nmb);*/
1405
0
        if(u1_decode_nmb)
1406
0
        {
1407
0
1408
0
1409
0
1410
0
            if(ps_dec->u1_separate_parse)
1411
0
            {
1412
0
                ih264d_parse_tfr_nmb(ps_dec, u1_mb_idx, u1_num_mbs,
1413
0
                                     u1_num_mbs_next, u1_tfr_n_mb, u1_end_of_row);
1414
0
                ps_dec->ps_nmb_info +=  u1_num_mbs;
1415
0
            }
1416
0
            else
1417
0
            {
1418
0
                ih264d_decode_recon_tfr_nmb(ps_dec, u1_mb_idx, u1_num_mbs,
1419
0
                                            u1_num_mbs_next, u1_tfr_n_mb,
1420
0
                                            u1_end_of_row);
1421
0
            }
1422
0
            ps_dec->u2_total_mbs_coded += u1_num_mbs;
1423
0
            if(u1_tfr_n_mb)
1424
0
                u1_num_mbs = 0;
1425
0
            u1_mb_idx = u1_num_mbs;
1426
0
            ps_dec->u1_mb_idx = u1_num_mbs;
1427
0
1428
0
        }
1429
0
//ps_dec->ps_pred++;
1430
0
    }
1431
0
1432
0
    ps_dec->u4_num_mbs_cur_nmb = 0;
1433
0
    ps_dec->ps_cur_slice->u4_mbs_in_slice = i2_cur_mb_addr
1434
0
                        - (u2_first_mb_in_slice << u1_mbaff);
1435
0
1436
0
1437
0
    return ret;
1438
0
}
1439
1440
WORD32 ih264d_mark_err_slice_skip(dec_struct_t * ps_dec,
1441
                                WORD32 num_mb_skip,
1442
                                UWORD8 u1_is_idr_slice,
1443
                                UWORD16 u2_frame_num,
1444
                                pocstruct_t *ps_cur_poc,
1445
                                WORD32 prev_slice_err)
1446
0
{
1447
0
    WORD32 i2_cur_mb_addr;
1448
0
    UWORD32 u1_num_mbs, u1_num_mbsNby2;
1449
0
    UWORD32 u1_mb_idx = ps_dec->u1_mb_idx;
1450
0
    UWORD32 i2_mb_skip_run;
1451
0
1452
0
    UWORD32 u1_num_mbs_next, u1_end_of_row;
1453
0
    const UWORD32 i2_pic_wdin_mbs = ps_dec->u2_frm_wd_in_mbs;
1454
0
    UWORD32 u1_slice_end;
1455
0
    UWORD32 u1_tfr_n_mb;
1456
0
    UWORD32 u1_decode_nmb;
1457
0
    dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
1458
0
    dec_slice_params_t * ps_slice = ps_dec->ps_cur_slice;
1459
0
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
1460
0
    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
1461
0
    deblk_mb_t *ps_cur_deblk_mb;
1462
0
    dec_mb_info_t *ps_cur_mb_info;
1463
0
    parse_pmbarams_t *ps_parse_mb_data;
1464
0
    UWORD32 u1_inter_mb_type;
1465
0
    UWORD32 u1_deblk_mb_type;
1466
0
    UWORD16 u2_total_mbs_coded;
1467
0
    UWORD32 u1_mbaff;
1468
0
    parse_part_params_t *ps_part_info;
1469
0
    WORD32 ret;
1470
0
    UNUSED(u1_is_idr_slice);
1471
0
1472
0
    if(ps_dec->ps_dec_err_status->u1_err_flag & REJECT_CUR_PIC)
1473
0
    {
1474
0
        ih264d_err_pic_dispbuf_mgr(ps_dec);
1475
0
        return 0;
1476
0
    }
1477
0
1478
0
    if(ps_dec->ps_cur_slice->u1_mbaff_frame_flag && (num_mb_skip & 1))
1479
0
    {
1480
0
        num_mb_skip++;
1481
0
    }
1482
0
    ps_dec->ps_dpb_cmds->u1_long_term_reference_flag = 0;
1483
0
    if(prev_slice_err == 1)
1484
0
    {
1485
0
        /* first slice - missing/header corruption */
1486
0
        ps_dec->ps_cur_slice->u2_frame_num = u2_frame_num;
1487
0
        {
1488
0
            WORD32 i, j, poc = 0;
1489
0
1490
0
            ps_dec->ps_cur_slice->u2_first_mb_in_slice = 0;
1491
0
1492
0
            ps_dec->pf_mvpred = ih264d_mvpred_nonmbaff;
1493
0
            ps_dec->p_form_mb_part_info = ih264d_form_mb_part_info_bp;
1494
0
            ps_dec->p_motion_compensate = ih264d_motion_compensate_bp;
1495
0
1496
0
            if(ps_dec->ps_cur_pic != NULL)
1497
0
                poc = ps_dec->ps_cur_pic->i4_poc + 2;
1498
0
1499
0
            j = -1;
1500
0
            for(i = 0; i < MAX_NUM_PIC_PARAMS; i++)
1501
0
            {
1502
0
                   if(ps_dec->ps_pps[i].u1_is_valid == TRUE)
1503
0
                   {
1504
0
                       if(ps_dec->ps_pps[i].ps_sps->u1_is_valid == TRUE)
1505
0
                       {
1506
0
                           j = i;
1507
0
                           break;
1508
0
                       }
1509
0
                   }
1510
0
            }
1511
0
1512
0
            //if valid SPS PPS is not found return error
1513
0
            if(j == -1)
1514
0
            {
1515
0
                return ERROR_INV_SLICE_HDR_T;
1516
0
            }
1517
0
1518
0
            /* call ih264d_start_of_pic only if it was not called earlier*/
1519
0
            if(ps_dec->u4_pic_buf_got == 0)
1520
0
            {
1521
0
                //initialize slice params required by ih264d_start_of_pic to valid values
1522
0
                ps_dec->ps_cur_slice->u1_slice_type = P_SLICE;
1523
0
                ps_dec->ps_cur_slice->u1_nal_ref_idc = 1;
1524
0
                ps_dec->ps_cur_slice->u1_nal_unit_type = 1;
1525
0
                ret = ih264d_start_of_pic(ps_dec, poc, ps_cur_poc,
1526
0
                        ps_dec->ps_cur_slice->u2_frame_num,
1527
0
                        &ps_dec->ps_pps[j]);
1528
0
1529
0
                if(ret != OK)
1530
0
                {
1531
0
                    return ret;
1532
0
                }
1533
0
            }
1534
0
1535
0
            ps_dec->ps_ref_pic_buf_lx[0][0]->u1_pic_buf_id = 0;
1536
0
1537
0
            ps_dec->u4_output_present = 0;
1538
0
1539
0
            {
1540
0
                ih264d_get_next_display_field(ps_dec,
1541
0
                                              ps_dec->ps_out_buffer,
1542
0
                                              &(ps_dec->s_disp_op));
1543
0
                /* If error code is non-zero then there is no buffer available for display,
1544
0
                 hence avoid format conversion */
1545
0
1546
0
                if(0 != ps_dec->s_disp_op.u4_error_code)
1547
0
                {
1548
0
                    ps_dec->u4_fmt_conv_cur_row = ps_dec->s_disp_frame_info.u4_y_ht;
1549
0
                }
1550
0
                else
1551
0
                    ps_dec->u4_output_present = 1;
1552
0
            }
1553
0
1554
0
            if(ps_dec->u1_separate_parse == 1)
1555
0
            {
1556
0
                if(ps_dec->u4_dec_thread_created == 0)
1557
0
                {
1558
0
                    ithread_create(ps_dec->pv_dec_thread_handle, NULL,
1559
0
                                   (void *)ih264d_decode_picture_thread,
1560
0
                                   (void *)ps_dec);
1561
0
1562
0
                    ps_dec->u4_dec_thread_created = 1;
1563
0
                }
1564
0
1565
0
                if((ps_dec->u4_num_cores == 3) &&
1566
0
                                ((ps_dec->u4_app_disable_deblk_frm == 0) || ps_dec->i1_recon_in_thread3_flag)
1567
0
                                && (ps_dec->u4_bs_deblk_thread_created == 0))
1568
0
                {
1569
0
                    ps_dec->u4_start_recon_deblk = 0;
1570
0
                    ithread_create(ps_dec->pv_bs_deblk_thread_handle, NULL,
1571
0
                                   (void *)ih264d_recon_deblk_thread,
1572
0
                                   (void *)ps_dec);
1573
0
                    ps_dec->u4_bs_deblk_thread_created = 1;
1574
0
                }
1575
0
            }
1576
0
        }
1577
0
    }
1578
0
    else
1579
0
    {
1580
0
        // Middle / last slice
1581
0
1582
0
        dec_slice_struct_t *ps_parse_cur_slice;
1583
0
        ps_parse_cur_slice = ps_dec->ps_dec_slice_buf + ps_dec->u2_cur_slice_num;
1584
0
1585
0
        if(ps_dec->u1_slice_header_done
1586
0
            && ps_parse_cur_slice == ps_dec->ps_parse_cur_slice)
1587
0
        {
1588
0
            // Slice data corrupted
1589
0
            // in the case of mbaff, conceal from the even mb.
1590
0
            if((ps_dec->ps_cur_slice->u1_mbaff_frame_flag) && (ps_dec->u4_num_mbs_cur_nmb & 1))
1591
0
            {
1592
0
                ps_dec->u4_num_mbs_cur_nmb = ps_dec->u4_num_mbs_cur_nmb - 1;
1593
0
                ps_dec->u2_cur_mb_addr--;
1594
0
            }
1595
0
1596
0
            u1_num_mbs = ps_dec->u4_num_mbs_cur_nmb;
1597
0
            if(u1_num_mbs)
1598
0
            {
1599
0
                ps_cur_mb_info = ps_dec->ps_nmb_info + u1_num_mbs - 1;
1600
0
            }
1601
0
            else
1602
0
            {
1603
0
                if(ps_dec->u1_separate_parse)
1604
0
                {
1605
0
                    ps_cur_mb_info = ps_dec->ps_nmb_info;
1606
0
                }
1607
0
                else
1608
0
                {
1609
0
                    ps_cur_mb_info = ps_dec->ps_nmb_info
1610
0
                            + ps_dec->u4_num_mbs_prev_nmb - 1;
1611
0
                }
1612
0
            }
1613
0
1614
0
            ps_dec->u2_mby = ps_cur_mb_info->u2_mby;
1615
0
            ps_dec->u2_mbx = ps_cur_mb_info->u2_mbx;
1616
0
1617
0
            ps_dec->u1_mb_ngbr_availablity =
1618
0
                    ps_cur_mb_info->u1_mb_ngbr_availablity;
1619
0
1620
0
            if(u1_num_mbs)
1621
0
            {
1622
0
                // Going back 1 mb
1623
0
                ps_dec->pv_parse_tu_coeff_data = ps_dec->pv_prev_mb_parse_tu_coeff_data;
1624
0
                ps_dec->u2_cur_mb_addr--;
1625
0
                ps_dec->i4_submb_ofst -= SUB_BLK_SIZE;
1626
0
1627
0
                // Parse/decode N-MB left unparsed
1628
0
                if (ps_dec->u1_pr_sl_type == P_SLICE
1629
0
                        || ps_dec->u1_pr_sl_type == B_SLICE)
1630
0
                {
1631
0
                    ps_dec->pf_mvpred_ref_tfr_nby2mb(ps_dec, u1_mb_idx,    u1_num_mbs);
1632
0
                    ps_dec->ps_part = ps_dec->ps_parse_part_params;
1633
0
                }
1634
0
1635
0
                u1_num_mbs_next = i2_pic_wdin_mbs - ps_dec->u2_mbx - 1;
1636
0
                u1_end_of_row = (!u1_num_mbs_next)
1637
0
                        && (!(ps_dec->ps_cur_slice->u1_mbaff_frame_flag && (u1_num_mbs & 0x01)));
1638
0
                u1_slice_end = 1;
1639
0
                u1_tfr_n_mb = 1;
1640
0
                ps_cur_mb_info->u1_end_of_slice = u1_slice_end;
1641
0
1642
0
                if(ps_dec->u1_separate_parse)
1643
0
                {
1644
0
                    ih264d_parse_tfr_nmb(ps_dec, u1_mb_idx, u1_num_mbs,
1645
0
                            u1_num_mbs_next, u1_tfr_n_mb, u1_end_of_row);
1646
0
                    ps_dec->ps_nmb_info += u1_num_mbs;
1647
0
                }
1648
0
                else
1649
0
                {
1650
0
                    ih264d_decode_recon_tfr_nmb(ps_dec, u1_mb_idx, u1_num_mbs,
1651
0
                            u1_num_mbs_next, u1_tfr_n_mb, u1_end_of_row);
1652
0
                }
1653
0
                ps_dec->u2_total_mbs_coded += u1_num_mbs;
1654
0
                ps_dec->u1_mb_idx = 0;
1655
0
                ps_dec->u4_num_mbs_cur_nmb = 0;
1656
0
            }
1657
0
1658
0
            if(ps_dec->u2_total_mbs_coded
1659
0
                    >= ps_dec->u2_frm_ht_in_mbs * ps_dec->u2_frm_wd_in_mbs)
1660
0
            {
1661
0
                ps_dec->u1_pic_decode_done = 1;
1662
0
                return 0;
1663
0
            }
1664
0
1665
0
            /* Inserting new slice only if the current slice has atleast 1 MB*/
1666
0
            if(ps_dec->ps_parse_cur_slice->u4_first_mb_in_slice <
1667
0
                    (UWORD32)(ps_dec->u2_total_mbs_coded >> ps_slice->u1_mbaff_frame_flag))
1668
0
            {
1669
0
                ps_dec->i2_prev_slice_mbx = ps_dec->u2_mbx;
1670
0
                ps_dec->i2_prev_slice_mby = ps_dec->u2_mby;
1671
0
                ps_dec->u2_cur_slice_num++;
1672
0
                ps_dec->ps_parse_cur_slice++;
1673
0
            }
1674
0
1675
0
        }
1676
0
        else
1677
0
        {
1678
0
            // Slice missing / header corrupted
1679
0
            ps_dec->ps_parse_cur_slice = ps_dec->ps_dec_slice_buf
1680
0
                                            + ps_dec->u2_cur_slice_num;
1681
0
        }
1682
0
    }
1683
0
1684
0
    /******************************************************/
1685
0
    /* Initializations to new slice                       */
1686
0
    /******************************************************/
1687
0
    {
1688
0
        WORD32 num_entries;
1689
0
        WORD32 size;
1690
0
        UWORD8 *pu1_buf;
1691
0
1692
0
        num_entries = MAX_FRAMES;
1693
0
        if((1 >= ps_dec->ps_cur_sps->u1_num_ref_frames) &&
1694
0
            (0 == ps_dec->i4_display_delay))
1695
0
        {
1696
0
            num_entries = 1;
1697
0
        }
1698
0
        num_entries = ((2 * num_entries) + 1);
1699
0
        num_entries *= 2;
1700
0
1701
0
        size = num_entries * sizeof(void *);
1702
0
        size += PAD_MAP_IDX_POC * sizeof(void *);
1703
0
1704
0
        pu1_buf = (UWORD8 *)ps_dec->pv_map_ref_idx_to_poc_buf;
1705
0
        pu1_buf += size * ps_dec->u2_cur_slice_num;
1706
0
        ps_dec->ps_parse_cur_slice->ppv_map_ref_idx_to_poc = (volatile void **)pu1_buf;
1707
0
    }
1708
0
    u1_mbaff = ps_slice->u1_mbaff_frame_flag;
1709
0
    ps_dec->ps_cur_slice->u2_first_mb_in_slice = ps_dec->u2_total_mbs_coded >> u1_mbaff;
1710
0
    ps_dec->ps_cur_slice->i1_slice_alpha_c0_offset = 0;
1711
0
    ps_dec->ps_cur_slice->i1_slice_beta_offset = 0;
1712
0
1713
0
    if(ps_dec->ps_cur_slice->u1_field_pic_flag)
1714
0
        ps_dec->u2_prv_frame_num = ps_dec->ps_cur_slice->u2_frame_num;
1715
0
1716
0
    ps_dec->ps_parse_cur_slice->u4_first_mb_in_slice = ps_dec->u2_total_mbs_coded >> u1_mbaff;
1717
0
    ps_dec->ps_parse_cur_slice->u2_log2Y_crwd =    ps_dec->ps_cur_slice->u2_log2Y_crwd;
1718
0
1719
0
1720
0
    if(ps_dec->u1_separate_parse)
1721
0
    {
1722
0
        ps_dec->ps_parse_cur_slice->pv_tu_coeff_data_start = ps_dec->pv_parse_tu_coeff_data;
1723
0
    }
1724
0
    else
1725
0
    {
1726
0
        ps_dec->pv_proc_tu_coeff_data = ps_dec->pv_parse_tu_coeff_data;
1727
0
    }
1728
0
1729
0
    /******************************************************/
1730
0
    /* Initializations specific to P slice                */
1731
0
    /******************************************************/
1732
0
    u1_inter_mb_type = P_MB;
1733
0
    u1_deblk_mb_type = D_INTER_MB;
1734
0
1735
0
    ps_dec->ps_cur_slice->u1_slice_type = P_SLICE;
1736
0
    ps_dec->ps_parse_cur_slice->slice_type = P_SLICE;
1737
0
    ps_dec->pf_mvpred_ref_tfr_nby2mb = ih264d_mv_pred_ref_tfr_nby2_pmb;
1738
0
    ps_dec->ps_part = ps_dec->ps_parse_part_params;
1739
0
    ps_dec->u2_mbx =
1740
0
                    (MOD(ps_dec->ps_cur_slice->u2_first_mb_in_slice - 1, ps_dec->u2_frm_wd_in_mbs));
1741
0
    ps_dec->u2_mby =
1742
0
                    (DIV(ps_dec->ps_cur_slice->u2_first_mb_in_slice - 1, ps_dec->u2_frm_wd_in_mbs));
1743
0
    ps_dec->u2_mby <<= u1_mbaff;
1744
0
1745
0
    /******************************************************/
1746
0
    /* Parsing / decoding the slice                       */
1747
0
    /******************************************************/
1748
0
    ps_dec->u1_slice_header_done = 2;
1749
0
    ps_dec->u1_qp = ps_slice->u1_slice_qp;
1750
0
    ih264d_update_qp(ps_dec, 0);
1751
0
    u1_mb_idx = ps_dec->u1_mb_idx;
1752
0
    ps_parse_mb_data = ps_dec->ps_parse_mb_data;
1753
0
    u1_num_mbs = u1_mb_idx;
1754
0
1755
0
    u1_slice_end = 0;
1756
0
    u1_tfr_n_mb = 0;
1757
0
    u1_decode_nmb = 0;
1758
0
    u1_num_mbsNby2 = 0;
1759
0
    i2_cur_mb_addr = ps_dec->u2_total_mbs_coded;
1760
0
    i2_mb_skip_run = num_mb_skip;
1761
0
1762
0
    while(!u1_slice_end)
1763
0
    {
1764
0
        UWORD8 u1_mb_type;
1765
0
1766
0
        if(i2_cur_mb_addr > ps_dec->ps_cur_sps->u2_max_mb_addr)
1767
0
            break;
1768
0
1769
0
        ps_cur_mb_info = ps_dec->ps_nmb_info + u1_num_mbs;
1770
0
        ps_dec->u4_num_mbs_cur_nmb = u1_num_mbs;
1771
0
1772
0
        ps_cur_mb_info->u1_Mux = 0;
1773
0
        ps_dec->u4_num_pmbair = (u1_num_mbs >> u1_mbaff);
1774
0
        ps_cur_deblk_mb = ps_dec->ps_deblk_mbn + u1_num_mbs;
1775
0
1776
0
        ps_cur_mb_info->u1_end_of_slice = 0;
1777
0
1778
0
        /* Storing Default partition info */
1779
0
        ps_parse_mb_data->u1_num_part = 1;
1780
0
        ps_parse_mb_data->u1_isI_mb = 0;
1781
0
1782
0
        /**************************************************************/
1783
0
        /* Get the required information for decoding of MB            */
1784
0
        /**************************************************************/
1785
0
        /* mb_x, mb_y, neighbor availablity, */
1786
0
        if (u1_mbaff)
1787
0
            ih264d_get_mb_info_cavlc_mbaff(ps_dec, i2_cur_mb_addr, ps_cur_mb_info, i2_mb_skip_run);
1788
0
        else
1789
0
            ih264d_get_mb_info_cavlc_nonmbaff(ps_dec, i2_cur_mb_addr, ps_cur_mb_info, i2_mb_skip_run);
1790
0
1791
0
        /* Set the deblocking parameters for this MB */
1792
0
        if(ps_dec->u4_app_disable_deblk_frm == 0)
1793
0
        {
1794
0
            ih264d_set_deblocking_parameters(ps_cur_deblk_mb, ps_slice,
1795
0
                                             ps_dec->u1_mb_ngbr_availablity,
1796
0
                                             ps_dec->u1_cur_mb_fld_dec_flag);
1797
0
        }
1798
0
1799
0
        /* Set appropriate flags in ps_cur_mb_info and ps_dec */
1800
0
        ps_dec->i1_prev_mb_qp_delta = 0;
1801
0
        ps_dec->u1_sub_mb_num = 0;
1802
0
        ps_cur_mb_info->u1_mb_type = MB_SKIP;
1803
0
        ps_cur_mb_info->u1_mb_mc_mode = PRED_16x16;
1804
0
        ps_cur_mb_info->u1_cbp = 0;
1805
0
1806
0
        /* Storing Skip partition info */
1807
0
        ps_part_info = ps_dec->ps_part;
1808
0
        ps_part_info->u1_is_direct = PART_DIRECT_16x16;
1809
0
        ps_part_info->u1_sub_mb_num = 0;
1810
0
        ps_dec->ps_part++;
1811
0
1812
0
        /* Update Nnzs */
1813
0
        ih264d_update_nnz_for_skipmb(ps_dec, ps_cur_mb_info, CAVLC);
1814
0
1815
0
        ps_cur_mb_info->ps_curmb->u1_mb_type = u1_inter_mb_type;
1816
0
        ps_cur_deblk_mb->u1_mb_type |= u1_deblk_mb_type;
1817
0
1818
0
        i2_mb_skip_run--;
1819
0
1820
0
        ps_cur_deblk_mb->u1_mb_qp = ps_dec->u1_qp;
1821
0
1822
0
        if (u1_mbaff)
1823
0
        {
1824
0
            ih264d_update_mbaff_left_nnz(ps_dec, ps_cur_mb_info);
1825
0
        }
1826
0
1827
0
        /**************************************************************/
1828
0
        /* Get next Macroblock address                                */
1829
0
        /**************************************************************/
1830
0
        i2_cur_mb_addr++;
1831
0
1832
0
        u1_num_mbs++;
1833
0
        u1_num_mbsNby2++;
1834
0
        ps_parse_mb_data++;
1835
0
1836
0
        /****************************************************************/
1837
0
        /* Check for End Of Row and other flags that determine when to  */
1838
0
        /* do DMA setup for N/2-Mb, Decode for N-Mb, and Transfer for   */
1839
0
        /* N-Mb                                                         */
1840
0
        /****************************************************************/
1841
0
        u1_num_mbs_next = i2_pic_wdin_mbs - ps_dec->u2_mbx - 1;
1842
0
        u1_end_of_row = (!u1_num_mbs_next) && (!(u1_mbaff && (u1_num_mbs & 0x01)));
1843
0
        u1_slice_end = !i2_mb_skip_run;
1844
0
        u1_tfr_n_mb = (u1_num_mbs == ps_dec->u1_recon_mb_grp) || u1_end_of_row
1845
0
                        || u1_slice_end;
1846
0
        u1_decode_nmb = u1_tfr_n_mb || u1_slice_end;
1847
0
        ps_cur_mb_info->u1_end_of_slice = u1_slice_end;
1848
0
1849
0
        if(u1_decode_nmb)
1850
0
        {
1851
0
            ps_dec->pf_mvpred_ref_tfr_nby2mb(ps_dec, u1_mb_idx, u1_num_mbs);
1852
0
            u1_num_mbsNby2 = 0;
1853
0
1854
0
            ps_parse_mb_data = ps_dec->ps_parse_mb_data;
1855
0
            ps_dec->ps_part = ps_dec->ps_parse_part_params;
1856
0
1857
0
            if(ps_dec->u1_separate_parse)
1858
0
            {
1859
0
                ih264d_parse_tfr_nmb(ps_dec, u1_mb_idx, u1_num_mbs,
1860
0
                                     u1_num_mbs_next, u1_tfr_n_mb, u1_end_of_row);
1861
0
                ps_dec->ps_nmb_info +=  u1_num_mbs;
1862
0
            }
1863
0
            else
1864
0
            {
1865
0
                ih264d_decode_recon_tfr_nmb(ps_dec, u1_mb_idx, u1_num_mbs, u1_num_mbs_next,
1866
0
                                            u1_tfr_n_mb, u1_end_of_row);
1867
0
            }
1868
0
            ps_dec->u2_total_mbs_coded += u1_num_mbs;
1869
0
            if(u1_tfr_n_mb)
1870
0
                u1_num_mbs = 0;
1871
0
            u1_mb_idx = u1_num_mbs;
1872
0
            ps_dec->u1_mb_idx = u1_num_mbs;
1873
0
        }
1874
0
    }
1875
0
1876
0
    ps_dec->u4_num_mbs_cur_nmb = 0;
1877
0
    ps_dec->ps_cur_slice->u4_mbs_in_slice = i2_cur_mb_addr
1878
0
                        - ps_dec->ps_parse_cur_slice->u4_first_mb_in_slice;
1879
0
1880
0
    H264_DEC_DEBUG_PRINT("Mbs in slice: %d\n", ps_dec->ps_cur_slice->u4_mbs_in_slice);
1881
0
1882
0
1883
0
    /* incremented here only if first slice is inserted */
1884
0
    if(ps_dec->u4_first_slice_in_pic != 0)
1885
0
    {
1886
0
        ps_dec->ps_parse_cur_slice++;
1887
0
        ps_dec->u2_cur_slice_num++;
1888
0
    }
1889
0
1890
0
    ps_dec->i2_prev_slice_mbx = ps_dec->u2_mbx;
1891
0
    ps_dec->i2_prev_slice_mby = ps_dec->u2_mby;
1892
0
1893
0
    if(ps_dec->u2_total_mbs_coded
1894
0
            >= ps_dec->u2_frm_ht_in_mbs * ps_dec->u2_frm_wd_in_mbs)
1895
0
    {
1896
0
        ps_dec->u1_pic_decode_done = 1;
1897
0
    }
1898
0
1899
0
    return 0;
1900
0
1901
0
}
1902
1903
/*!
1904
 **************************************************************************
1905
 * \if Function name : ih264d_decode_pslice \endif
1906
 *
1907
 * \brief
1908
 *    Decodes a P Slice
1909
 *
1910
 *
1911
 * \return
1912
 *    0 on Success and Error code otherwise
1913
 **************************************************************************
1914
 */
1915
WORD32 ih264d_parse_pslice(dec_struct_t *ps_dec, UWORD16 u2_first_mb_in_slice)
1916
0
{
1917
0
    dec_pic_params_t * ps_pps = ps_dec->ps_cur_pps;
1918
0
    dec_slice_params_t * ps_cur_slice = ps_dec->ps_cur_slice;
1919
0
    dec_bit_stream_t *ps_bitstrm = ps_dec->ps_bitstrm;
1920
0
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
1921
0
    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
1922
0
    UWORD8 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag; //ps_dec->ps_cur_sps->u1_mb_aff_flag;
1923
0
    UWORD8 u1_field_pic_flag = ps_cur_slice->u1_field_pic_flag;
1924
0
1925
0
    UWORD32 u4_temp;
1926
0
    WORD32 i_temp;
1927
0
    WORD32 ret;
1928
0
1929
0
    /*--------------------------------------------------------------------*/
1930
0
    /* Read remaining contents of the slice header                        */
1931
0
    /*--------------------------------------------------------------------*/
1932
0
    {
1933
0
        WORD8 *pi1_buf;
1934
0
        WORD16 *pi2_mv = ps_dec->s_default_mv_pred.i2_mv;
1935
0
        WORD32 *pi4_mv = (WORD32*)pi2_mv;
1936
0
        WORD16 *pi16_refFrame;
1937
0
1938
0
        pi1_buf = ps_dec->s_default_mv_pred.i1_ref_frame;
1939
0
        pi16_refFrame = (WORD16*)pi1_buf;
1940
0
        *pi4_mv = 0;
1941
0
        *(pi4_mv + 1) = 0;
1942
0
        *pi16_refFrame = OUT_OF_RANGE_REF;
1943
0
        ps_dec->s_default_mv_pred.u1_col_ref_pic_idx = (UWORD8)-1;
1944
0
        ps_dec->s_default_mv_pred.u1_pic_type = (UWORD8)-1;
1945
0
    }
1946
0
1947
0
    ps_cur_slice->u1_num_ref_idx_active_override_flag = ih264d_get_bit_h264(
1948
0
                    ps_bitstrm);
1949
0
1950
0
    COPYTHECONTEXT("SH: num_ref_idx_override_flag",
1951
0
                    ps_cur_slice->u1_num_ref_idx_active_override_flag);
1952
0
1953
0
    u4_temp = ps_dec->ps_cur_pps->u1_num_ref_idx_lx_active[0];
1954
0
    if(ps_cur_slice->u1_num_ref_idx_active_override_flag)
1955
0
    {
1956
0
        u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf) + 1;
1957
0
    }
1958
0
1959
0
    {
1960
0
1961
0
1962
0
1963
0
        UWORD8 u1_max_ref_idx = MAX_FRAMES << u1_field_pic_flag;
1964
0
        if(u4_temp > u1_max_ref_idx || u4_temp < 1)
1965
0
        {
1966
0
            return ERROR_NUM_REF;
1967
0
        }
1968
0
        ps_cur_slice->u1_num_ref_idx_lx_active[0] = u4_temp;
1969
0
        COPYTHECONTEXT("SH: num_ref_idx_l0_active_minus1",
1970
0
                        ps_cur_slice->u1_num_ref_idx_lx_active[0] - 1);
1971
0
1972
0
    }
1973
0
1974
0
    {
1975
0
        UWORD8 uc_refIdxReFlagL0 = ih264d_get_bit_h264(ps_bitstrm);
1976
0
        COPYTHECONTEXT("SH: ref_pic_list_reordering_flag_l0",uc_refIdxReFlagL0);
1977
0
1978
0
        ih264d_init_ref_idx_lx_p(ps_dec);
1979
0
        /* Store the value for future slices in the same picture */
1980
0
        ps_dec->u1_num_ref_idx_lx_active_prev =
1981
0
                        ps_cur_slice->u1_num_ref_idx_lx_active[0];
1982
0
1983
0
        /* Modified temporarily */
1984
0
        if(uc_refIdxReFlagL0)
1985
0
        {
1986
0
            WORD8 ret;
1987
0
            ps_dec->ps_ref_pic_buf_lx[0] = ps_dec->ps_dpb_mgr->ps_mod_dpb[0];
1988
0
            ret = ih264d_ref_idx_reordering(ps_dec, 0);
1989
0
            if(ret == -1)
1990
0
                return ERROR_REFIDX_ORDER_T;
1991
0
            ps_dec->ps_ref_pic_buf_lx[0] = ps_dec->ps_dpb_mgr->ps_mod_dpb[0];
1992
0
        }
1993
0
        else
1994
0
            ps_dec->ps_ref_pic_buf_lx[0] =
1995
0
                            ps_dec->ps_dpb_mgr->ps_init_dpb[0];
1996
0
    }
1997
0
    /* Create refIdx to POC mapping */
1998
0
    {
1999
0
        void **pui_map_ref_idx_to_poc_lx0, **pui_map_ref_idx_to_poc_lx1;
2000
0
        WORD8 idx;
2001
0
        struct pic_buffer_t *ps_pic;
2002
0
2003
0
        pui_map_ref_idx_to_poc_lx0 = ps_dec->ppv_map_ref_idx_to_poc + FRM_LIST_L0;
2004
0
        pui_map_ref_idx_to_poc_lx0[0] = 0; //For ref_idx = -1
2005
0
        pui_map_ref_idx_to_poc_lx0++;
2006
0
        for(idx = 0; idx < ps_cur_slice->u1_num_ref_idx_lx_active[0]; idx++)
2007
0
        {
2008
0
            ps_pic = ps_dec->ps_ref_pic_buf_lx[0][idx];
2009
0
            pui_map_ref_idx_to_poc_lx0[idx] = (ps_pic->pu1_buf1);
2010
0
        }
2011
0
2012
0
        /* Bug Fix Deblocking */
2013
0
        pui_map_ref_idx_to_poc_lx1 = ps_dec->ppv_map_ref_idx_to_poc + FRM_LIST_L1;
2014
0
        pui_map_ref_idx_to_poc_lx1[0] = 0;
2015
0
2016
0
        if(u1_mbaff)
2017
0
        {
2018
0
            void **ppv_map_ref_idx_to_poc_lx_t, **ppv_map_ref_idx_to_poc_lx_b;
2019
0
            void **ppv_map_ref_idx_to_poc_lx_t1, **ppv_map_ref_idx_to_poc_lx_b1;
2020
0
            ppv_map_ref_idx_to_poc_lx_t = ps_dec->ppv_map_ref_idx_to_poc
2021
0
                            + TOP_LIST_FLD_L0;
2022
0
            ppv_map_ref_idx_to_poc_lx_b = ps_dec->ppv_map_ref_idx_to_poc
2023
0
                            + BOT_LIST_FLD_L0;
2024
0
2025
0
            ppv_map_ref_idx_to_poc_lx_t[0] = 0; //  For ref_idx = -1
2026
0
            ppv_map_ref_idx_to_poc_lx_t++;
2027
0
            ppv_map_ref_idx_to_poc_lx_b[0] = 0; // For ref_idx = -1
2028
0
            ppv_map_ref_idx_to_poc_lx_b++;
2029
0
2030
0
            idx = 0;
2031
0
            for(idx = 0; idx < ps_cur_slice->u1_num_ref_idx_lx_active[0]; idx++)
2032
0
            {
2033
0
                ps_pic = ps_dec->ps_ref_pic_buf_lx[0][idx];
2034
0
                ppv_map_ref_idx_to_poc_lx_t[0] = (ps_pic->pu1_buf1);
2035
0
                ppv_map_ref_idx_to_poc_lx_b[1] = (ps_pic->pu1_buf1);
2036
0
2037
0
                ppv_map_ref_idx_to_poc_lx_b[0] = (ps_pic->pu1_buf1) + 1;
2038
0
                ppv_map_ref_idx_to_poc_lx_t[1] = (ps_pic->pu1_buf1) + 1;
2039
0
2040
0
                ppv_map_ref_idx_to_poc_lx_t += 2;
2041
0
                ppv_map_ref_idx_to_poc_lx_b += 2;
2042
0
            }
2043
0
            ppv_map_ref_idx_to_poc_lx_t1 = ps_dec->ppv_map_ref_idx_to_poc
2044
0
                            + TOP_LIST_FLD_L1;
2045
0
            ppv_map_ref_idx_to_poc_lx_t1[0] = 0;
2046
0
            ppv_map_ref_idx_to_poc_lx_b1 = ps_dec->ppv_map_ref_idx_to_poc
2047
0
                            + BOT_LIST_FLD_L1;
2048
0
            ppv_map_ref_idx_to_poc_lx_b1[0] = 0;
2049
0
2050
0
        }
2051
0
2052
0
        if(ps_dec->u4_num_cores >= 3)
2053
0
        {
2054
0
            WORD32 num_entries;
2055
0
            WORD32 size;
2056
0
2057
0
            num_entries = MAX_FRAMES;
2058
0
            if((1 >= ps_dec->ps_cur_sps->u1_num_ref_frames) &&
2059
0
                (0 == ps_dec->i4_display_delay))
2060
0
            {
2061
0
                num_entries = 1;
2062
0
            }
2063
0
            num_entries = ((2 * num_entries) + 1);
2064
0
            num_entries *= 2;
2065
0
2066
0
            size = num_entries * sizeof(void *);
2067
0
            size += PAD_MAP_IDX_POC * sizeof(void *);
2068
0
2069
0
            memcpy((void *)ps_dec->ps_parse_cur_slice->ppv_map_ref_idx_to_poc,
2070
0
                   ps_dec->ppv_map_ref_idx_to_poc,
2071
0
                   size);
2072
0
        }
2073
0
2074
0
2075
0
    }
2076
0
    if(ps_pps->u1_wted_pred_flag)
2077
0
    {
2078
0
        ret = ih264d_parse_pred_weight_table(ps_cur_slice, ps_bitstrm);
2079
0
        if(ret != OK)
2080
0
            return ret;
2081
0
        ih264d_form_pred_weight_matrix(ps_dec);
2082
0
        ps_dec->pu4_wt_ofsts = ps_dec->pu4_wts_ofsts_mat;
2083
0
    }
2084
0
    else
2085
0
    {
2086
0
        ps_dec->ps_cur_slice->u2_log2Y_crwd = 0;
2087
0
        ps_dec->pu4_wt_ofsts = ps_dec->pu4_wts_ofsts_mat;
2088
0
    }
2089
0
2090
0
    ps_dec->ps_parse_cur_slice->u2_log2Y_crwd =
2091
0
                    ps_dec->ps_cur_slice->u2_log2Y_crwd;
2092
0
2093
0
    if(u1_mbaff && (u1_field_pic_flag == 0))
2094
0
    {
2095
0
        ih264d_convert_frm_mbaff_list(ps_dec);
2096
0
    }
2097
0
2098
0
    /* G050 */
2099
0
    if(ps_cur_slice->u1_nal_ref_idc != 0)
2100
0
    {
2101
0
        if(!ps_dec->ps_dpb_cmds->u1_dpb_commands_read)
2102
0
        {
2103
0
            i_temp = ih264d_read_mmco_commands(ps_dec);
2104
0
            if (i_temp < 0)
2105
0
            {
2106
0
                return ERROR_DBP_MANAGER_T;
2107
0
            }
2108
0
            ps_dec->u4_bitoffset = i_temp;
2109
0
        }
2110
0
        else
2111
0
            ps_bitstrm->u4_ofst += ps_dec->u4_bitoffset;
2112
0
2113
0
    }
2114
0
    /* G050 */
2115
0
2116
0
    if(ps_pps->u1_entropy_coding_mode == CABAC)
2117
0
    {
2118
0
        u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
2119
0
2120
0
        if(u4_temp > MAX_CABAC_INIT_IDC)
2121
0
        {
2122
0
            return ERROR_INV_SLICE_HDR_T;
2123
0
        }
2124
0
        ps_cur_slice->u1_cabac_init_idc = u4_temp;
2125
0
        COPYTHECONTEXT("SH: cabac_init_idc",ps_cur_slice->u1_cabac_init_idc);
2126
0
    }
2127
0
2128
0
    /* Read slice_qp_delta */
2129
0
    i_temp = ps_pps->u1_pic_init_qp
2130
0
                    + ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
2131
0
    if((i_temp < 0) || (i_temp > 51))
2132
0
    {
2133
0
        return ERROR_INV_RANGE_QP_T;
2134
0
    }
2135
0
    ps_cur_slice->u1_slice_qp = i_temp;
2136
0
    COPYTHECONTEXT("SH: slice_qp_delta",
2137
0
                    (WORD8)(ps_cur_slice->u1_slice_qp - ps_pps->u1_pic_init_qp));
2138
0
2139
0
    if(ps_pps->u1_deblocking_filter_parameters_present_flag == 1)
2140
0
    {
2141
0
        u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
2142
0
        if(u4_temp > SLICE_BOUNDARY_DBLK_DISABLED)
2143
0
        {
2144
0
            return ERROR_INV_SLICE_HDR_T;
2145
0
        }
2146
0
2147
0
        COPYTHECONTEXT("SH: disable_deblocking_filter_idc", u4_temp);
2148
0
        ps_cur_slice->u1_disable_dblk_filter_idc = u4_temp;
2149
0
        if(u4_temp != 1)
2150
0
        {
2151
0
            i_temp = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf)
2152
0
                            << 1;
2153
0
            if((MIN_DBLK_FIL_OFF > i_temp) || (i_temp > MAX_DBLK_FIL_OFF))
2154
0
            {
2155
0
                return ERROR_INV_SLICE_HDR_T;
2156
0
            }
2157
0
            ps_cur_slice->i1_slice_alpha_c0_offset = i_temp;
2158
0
            COPYTHECONTEXT("SH: slice_alpha_c0_offset_div2",
2159
0
                            ps_cur_slice->i1_slice_alpha_c0_offset >> 1);
2160
0
2161
0
            i_temp = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf)
2162
0
                            << 1;
2163
0
            if((MIN_DBLK_FIL_OFF > i_temp) || (i_temp > MAX_DBLK_FIL_OFF))
2164
0
            {
2165
0
                return ERROR_INV_SLICE_HDR_T;
2166
0
            }
2167
0
            ps_cur_slice->i1_slice_beta_offset = i_temp;
2168
0
            COPYTHECONTEXT("SH: slice_beta_offset_div2",
2169
0
                            ps_cur_slice->i1_slice_beta_offset >> 1);
2170
0
        }
2171
0
        else
2172
0
        {
2173
0
            ps_cur_slice->i1_slice_alpha_c0_offset = 0;
2174
0
            ps_cur_slice->i1_slice_beta_offset = 0;
2175
0
        }
2176
0
    }
2177
0
    else
2178
0
    {
2179
0
        ps_cur_slice->u1_disable_dblk_filter_idc = 0;
2180
0
        ps_cur_slice->i1_slice_alpha_c0_offset = 0;
2181
0
        ps_cur_slice->i1_slice_beta_offset = 0;
2182
0
    }
2183
0
2184
0
    ps_dec->u1_slice_header_done = 2;
2185
0
2186
0
    if(ps_pps->u1_entropy_coding_mode)
2187
0
    {
2188
0
        SWITCHOFFTRACE; SWITCHONTRACECABAC;
2189
0
        ps_dec->pf_parse_inter_slice = ih264d_parse_inter_slice_data_cabac;
2190
0
        ps_dec->pf_parse_inter_mb = ih264d_parse_pmb_cabac;
2191
0
        ih264d_init_cabac_contexts(P_SLICE, ps_dec);
2192
0
2193
0
        if(ps_dec->ps_cur_slice->u1_mbaff_frame_flag)
2194
0
            ps_dec->pf_get_mb_info = ih264d_get_mb_info_cabac_mbaff;
2195
0
        else
2196
0
            ps_dec->pf_get_mb_info = ih264d_get_mb_info_cabac_nonmbaff;
2197
0
    }
2198
0
    else
2199
0
    {
2200
0
        SWITCHONTRACE; SWITCHOFFTRACECABAC;
2201
0
        ps_dec->pf_parse_inter_slice = ih264d_parse_inter_slice_data_cavlc;
2202
0
        ps_dec->pf_parse_inter_mb = ih264d_parse_pmb_cavlc;
2203
0
        if(ps_dec->ps_cur_slice->u1_mbaff_frame_flag)
2204
0
        {
2205
0
            ps_dec->pf_get_mb_info = ih264d_get_mb_info_cavlc_mbaff;
2206
0
        }
2207
0
        else
2208
0
            ps_dec->pf_get_mb_info = ih264d_get_mb_info_cavlc_nonmbaff;
2209
0
    }
2210
0
2211
0
    ps_dec->u1_B = 0;
2212
0
    ps_dec->pf_mvpred_ref_tfr_nby2mb = ih264d_mv_pred_ref_tfr_nby2_pmb;
2213
0
    ret = ps_dec->pf_parse_inter_slice(ps_dec, ps_cur_slice, u2_first_mb_in_slice);
2214
0
    if(ret != OK)
2215
0
        return ret;
2216
0
//    ps_dec->curr_slice_in_error = 0 ;
2217
0
    return OK;
2218
0
}
/proc/self/cwd/external/libavc/decoder/ih264d_parse_slice.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/*!
21
 **************************************************************************
22
 * \file ih264d_parse_slice.c
23
 *
24
 * \brief
25
 *    Contains routines that decodes a slice NAL unit
26
 *
27
 * \date
28
 *    19/12/2002
29
 *
30
 * \author  AI
31
 **************************************************************************
32
 */
33
#include <string.h>
34
#include "ih264_typedefs.h"
35
#include "ih264_macros.h"
36
#include "ih264_platform_macros.h"
37
#include "ithread.h"
38
#include "ih264d_structs.h"
39
#include "ih264d_debug.h"
40
#include "ih264d_bitstrm.h"
41
#include "ih264d_parse_mb_header.h"
42
#include "ih264d_process_bslice.h"
43
#include "ih264d_process_pslice.h"
44
#include "ih264d_parse_cavlc.h"
45
#include "ih264d_utils.h"
46
#include "ih264d_deblocking.h"
47
#include "ih264d_defs.h"
48
#include "ih264d_error_handler.h"
49
#include "ih264d_tables.h"
50
#include "ih264d_defs.h"
51
#include "ih264d_mem_request.h"
52
#include "ih264d_parse_islice.h"
53
#include "ih264d_parse_slice.h"
54
#include "ih264d_mvpred.h"
55
#include "ih264d_mb_utils.h"
56
57
#include "ih264d_defs.h"
58
#include "ih264d_quant_scaling.h"
59
60
#include "ih264d_inter_pred.h"
61
62
#include "ih264d_sei.h"
63
#include "ih264d.h"
64
#include "ih264_error.h"
65
#include "ih264_disp_mgr.h"
66
#include "ih264_buf_mgr.h"
67
68
#include "ih264d_thread_parse_decode.h"
69
#include "ih264d_thread_compute_bs.h"
70
#include "ih264d_dpb_manager.h"
71
#include <assert.h>
72
#include "ih264d_parse_islice.h"
73
#define RET_LAST_SKIP  0x80000000
74
75
WORD32 check_app_out_buf_size(dec_struct_t *ps_dec);
76
/*!
77
 **************************************************************************
78
 * \if Function name : ih264d_form_pred_weight_matrix \endif
79
 *
80
 * \brief
81
 *    Forms pred weight matrix.
82
 *
83
 * \return
84
 *    None
85
 *
86
 **************************************************************************
87
 */
88
89
void ih264d_form_pred_weight_matrix(dec_struct_t *ps_dec)
90
0
{
91
0
    dec_slice_params_t *ps_cur_slice;
92
0
    UWORD8 uc_num_ref_idx_l0_active, uc_num_ref_idx_l1_active;
93
0
    UWORD8 i, j;
94
0
    UWORD32 *pu4_mat_iwt_ofst;
95
0
    UWORD16 i2_idx;
96
0
    UWORD32 *pui32_weight_offset_l0, *pui32_weight_offset_l1;
97
0
    UWORD32 u4_temp;
98
0
99
0
    ps_cur_slice = ps_dec->ps_cur_slice;
100
0
    uc_num_ref_idx_l0_active = ps_cur_slice->u1_num_ref_idx_lx_active[0];
101
0
    uc_num_ref_idx_l1_active = ps_cur_slice->u1_num_ref_idx_lx_active[1];
102
0
103
0
    pu4_mat_iwt_ofst = ps_dec->pu4_wts_ofsts_mat;
104
0
105
0
    if(ps_cur_slice->u1_slice_type == B_SLICE)
106
0
    {
107
0
        for(i = 0; i < uc_num_ref_idx_l0_active; i++)
108
0
        {
109
0
            pui32_weight_offset_l0 = ps_cur_slice->u4_wt_ofst_lx[0][i];
110
0
            for(j = 0; j < uc_num_ref_idx_l1_active; j++)
111
0
            {
112
0
                pui32_weight_offset_l1 = ps_cur_slice->u4_wt_ofst_lx[1][j];
113
0
                i2_idx = i * uc_num_ref_idx_l0_active + j;
114
0
                i2_idx = X3(i2_idx);
115
0
                /*        u4_temp = (pui32_weight_offset_l0[0] | (pui32_weight_offset_l1[0] << 16));
116
0
                 pu4_mat_iwt_ofst[0] = u4_temp;
117
0
                 u4_temp = (pui32_weight_offset_l0[1] | (pui32_weight_offset_l1[1] << 16));
118
0
                 pu4_mat_iwt_ofst[1] = u4_temp;
119
0
                 u4_temp = (pui32_weight_offset_l0[2] | (pui32_weight_offset_l1[2] << 16));
120
0
                 pu4_mat_iwt_ofst[2] = u4_temp;
121
0
                 pu4_mat_iwt_ofst += 3;*/
122
0
                pu4_mat_iwt_ofst[0] = pui32_weight_offset_l0[0];
123
0
                pu4_mat_iwt_ofst[1] = pui32_weight_offset_l1[0];
124
0
                pu4_mat_iwt_ofst[2] = pui32_weight_offset_l0[1];
125
0
                pu4_mat_iwt_ofst[3] = pui32_weight_offset_l1[1];
126
0
                pu4_mat_iwt_ofst[4] = pui32_weight_offset_l0[2];
127
0
                pu4_mat_iwt_ofst[5] = pui32_weight_offset_l1[2];
128
0
                pu4_mat_iwt_ofst += 6;
129
0
            }
130
0
        }
131
0
    }
132
0
    else
133
0
    {
134
0
        for(i = 0; i < uc_num_ref_idx_l0_active; i++)
135
0
        {
136
0
            pui32_weight_offset_l0 = ps_cur_slice->u4_wt_ofst_lx[0][i];
137
0
            i2_idx = X3(i);
138
0
            u4_temp = (UWORD32)pui32_weight_offset_l0[0];
139
0
            pu4_mat_iwt_ofst[0] = u4_temp;
140
0
            u4_temp = (UWORD32)pui32_weight_offset_l0[1];
141
0
            pu4_mat_iwt_ofst[2] = u4_temp;
142
0
            u4_temp = (UWORD32)pui32_weight_offset_l0[2];
143
0
            pu4_mat_iwt_ofst[4] = u4_temp;
144
0
            pu4_mat_iwt_ofst += 6;
145
0
        }
146
0
    }
147
0
}
148
149
150
/*!
151
 **************************************************************************
152
 * \if Function name :  init_firstSliceParam \endif
153
 *
154
 * \brief
155
 *    Initialize the Parameter required for all the slices for a picture
156
 *
157
 * \return           : Nothing
158
 *
159
 **************************************************************************
160
 */
161
162
WORD32 ih264d_start_of_pic(dec_struct_t *ps_dec,
163
                         WORD32 i4_poc,
164
                         pocstruct_t *ps_temp_poc,
165
                         UWORD16 u2_frame_num,
166
                         dec_pic_params_t *ps_pps)
167
11
{
168
11
    pocstruct_t *ps_prev_poc = &ps_dec->s_cur_pic_poc;
169
11
    pocstruct_t *ps_cur_poc = ps_temp_poc;
170
11
171
11
    pic_buffer_t *pic_buf;
172
11
173
11
    ivd_video_decode_op_t * ps_dec_output =
174
11
                    (ivd_video_decode_op_t *)ps_dec->pv_dec_out;
175
11
    dec_slice_params_t *ps_cur_slice = ps_dec->ps_cur_slice;
176
11
    dec_seq_params_t *ps_seq = ps_pps->ps_sps;
177
11
    UWORD8 u1_bottom_field_flag = ps_cur_slice->u1_bottom_field_flag;
178
11
    UWORD8 u1_field_pic_flag = ps_cur_slice->u1_field_pic_flag;
179
11
    /* high profile related declarations */
180
11
    high_profile_tools_t s_high_profile;
181
11
    WORD32 ret;
182
11
183
11
    H264_MUTEX_LOCK(&ps_dec->process_disp_mutex);
184
11
185
11
    /* check output buffer size given by the application */
186
11
    if(check_app_out_buf_size(ps_dec) != IV_SUCCESS)
187
0
        return IVD_DISP_FRM_ZERO_OP_BUF_SIZE;
188
11
189
11
    ps_prev_poc->i4_pic_order_cnt_lsb = ps_cur_poc->i4_pic_order_cnt_lsb;
190
11
    ps_prev_poc->i4_pic_order_cnt_msb = ps_cur_poc->i4_pic_order_cnt_msb;
191
11
    ps_prev_poc->i4_delta_pic_order_cnt_bottom =
192
11
                    ps_cur_poc->i4_delta_pic_order_cnt_bottom;
193
11
    ps_prev_poc->i4_delta_pic_order_cnt[0] =
194
11
                    ps_cur_poc->i4_delta_pic_order_cnt[0];
195
11
    ps_prev_poc->i4_delta_pic_order_cnt[1] =
196
11
                    ps_cur_poc->i4_delta_pic_order_cnt[1];
197
11
    ps_prev_poc->u1_bot_field = ps_dec->ps_cur_slice->u1_bottom_field_flag;
198
11
    ps_prev_poc->i4_prev_frame_num_ofst = ps_cur_poc->i4_prev_frame_num_ofst;
199
11
    ps_prev_poc->u2_frame_num = u2_frame_num;
200
11
    ps_dec->i1_prev_mb_qp_delta = 0;
201
11
    ps_dec->i1_next_ctxt_idx = 0;
202
11
203
11
204
11
    ps_dec->u4_nmb_deblk = 0;
205
11
    if(ps_dec->u4_num_cores == 1)
206
0
       ps_dec->u4_nmb_deblk = 1;
207
11
208
11
209
11
210
11
    if(ps_seq->u1_mb_aff_flag == 1)
211
0
    {
212
0
        ps_dec->u4_nmb_deblk = 0;
213
0
        if(ps_dec->u4_num_cores > 2)
214
0
            ps_dec->u4_num_cores = 2;
215
0
    }
216
11
217
11
        ps_dec->u4_use_intrapred_line_copy = 0;
218
11
219
11
220
11
221
11
    if (ps_seq->u1_mb_aff_flag == 0)
222
11
    {
223
11
        ps_dec->u4_use_intrapred_line_copy = 1;
224
11
    }
225
11
226
11
    ps_dec->u4_app_disable_deblk_frm = 0;
227
11
    /* If degrade is enabled, set the degrade flags appropriately */
228
11
    if(ps_dec->i4_degrade_type && ps_dec->i4_degrade_pics)
229
0
    {
230
0
        WORD32 degrade_pic;
231
0
        ps_dec->i4_degrade_pic_cnt++;
232
0
        degrade_pic = 0;
233
0
234
0
        /* If degrade is to be done in all frames, then do not check further */
235
0
        switch(ps_dec->i4_degrade_pics)
236
0
        {
237
0
            case 4:
238
0
            {
239
0
                degrade_pic = 1;
240
0
                break;
241
0
            }
242
0
            case 3:
243
0
            {
244
0
                if(ps_cur_slice->u1_slice_type != I_SLICE)
245
0
                    degrade_pic = 1;
246
0
247
0
                break;
248
0
            }
249
0
            case 2:
250
0
            {
251
0
252
0
                /* If pic count hits non-degrade interval or it is an islice, then do not degrade */
253
0
                if((ps_cur_slice->u1_slice_type != I_SLICE)
254
0
                                && (ps_dec->i4_degrade_pic_cnt
255
0
                                                != ps_dec->i4_nondegrade_interval))
256
0
                    degrade_pic = 1;
257
0
258
0
                break;
259
0
            }
260
0
            case 1:
261
0
            {
262
0
                /* Check if the current picture is non-ref */
263
0
                if(0 == ps_cur_slice->u1_nal_ref_idc)
264
0
                {
265
0
                    degrade_pic = 1;
266
0
                }
267
0
                break;
268
0
            }
269
0
270
0
        }
271
0
        if(degrade_pic)
272
0
        {
273
0
            if(ps_dec->i4_degrade_type & 0x2)
274
0
                ps_dec->u4_app_disable_deblk_frm = 1;
275
0
276
0
            /* MC degrading is done only for non-ref pictures */
277
0
            if(0 == ps_cur_slice->u1_nal_ref_idc)
278
0
            {
279
0
                if(ps_dec->i4_degrade_type & 0x4)
280
0
                    ps_dec->i4_mv_frac_mask = 0;
281
0
282
0
                if(ps_dec->i4_degrade_type & 0x8)
283
0
                    ps_dec->i4_mv_frac_mask = 0;
284
0
            }
285
0
        }
286
0
        else
287
0
            ps_dec->i4_degrade_pic_cnt = 0;
288
0
    }
289
11
290
11
    {
291
11
        dec_err_status_t * ps_err = ps_dec->ps_dec_err_status;
292
11
        if((ps_cur_slice->u1_slice_type == I_SLICE)
293
11
                        || (ps_cur_slice->u1_slice_type == SI_SLICE))
294
11
            ps_err->u1_cur_pic_type = PIC_TYPE_I;
295
11
        else
296
11
            ps_err->u1_cur_pic_type = PIC_TYPE_UNKNOWN;
297
11
298
11
        if(ps_err->u1_pic_aud_i == PIC_TYPE_I)
299
11
        {
300
0
            ps_err->u1_cur_pic_type = PIC_TYPE_I;
301
0
            ps_err->u1_pic_aud_i = PIC_TYPE_UNKNOWN;
302
0
        }
303
11
304
11
        if(ps_cur_slice->u1_nal_unit_type == IDR_SLICE_NAL)
305
11
        {
306
11
            if(ps_err->u1_err_flag)
307
0
                ih264d_reset_ref_bufs(ps_dec->ps_dpb_mgr);
308
11
            ps_err->u1_err_flag = ACCEPT_ALL_PICS;
309
11
        }
310
11
    }
311
11
312
11
    if(ps_dec->u1_init_dec_flag && ps_dec->s_prev_seq_params.u1_eoseq_pending)
313
0
    {
314
0
        /* Reset the decoder picture buffers */
315
0
        WORD32 j;
316
0
        for(j = 0; j < MAX_DISP_BUFS_NEW; j++)
317
0
        {
318
0
319
0
            ih264_buf_mgr_release((buf_mgr_t *)ps_dec->pv_pic_buf_mgr,
320
0
                                  j,
321
0
                                  BUF_MGR_REF);
322
0
            ih264_buf_mgr_release((buf_mgr_t *)ps_dec->pv_mv_buf_mgr,
323
0
                                  ps_dec->au1_pic_buf_id_mv_buf_id_map[j],
324
0
                                  BUF_MGR_REF);
325
0
            ih264_buf_mgr_release((buf_mgr_t *)ps_dec->pv_pic_buf_mgr,
326
0
                                  j,
327
0
                                  BUF_MGR_IO);
328
0
        }
329
0
330
0
        /* reset the decoder structure parameters related to buffer handling */
331
0
        ps_dec->u1_second_field = 0;
332
0
        ps_dec->i4_cur_display_seq = 0;
333
0
334
0
        /********************************************************************/
335
0
        /* indicate in the decoder output i4_status that some frames are being */
336
0
        /* dropped, so that it resets timestamp and wait for a new sequence */
337
0
        /********************************************************************/
338
0
339
0
        ps_dec->s_prev_seq_params.u1_eoseq_pending = 0;
340
0
    }
341
11
    ret = ih264d_init_pic(ps_dec, u2_frame_num, i4_poc, ps_pps);
342
11
    if(ret != OK)
343
11
        return ret;
344
11
345
11
    ps_dec->pv_parse_tu_coeff_data = ps_dec->pv_pic_tu_coeff_data;
346
11
    ps_dec->pv_proc_tu_coeff_data  = ps_dec->pv_pic_tu_coeff_data;
347
11
    ps_dec->ps_nmb_info = ps_dec->ps_frm_mb_info;
348
11
    if(ps_dec->u1_separate_parse)
349
11
    {
350
11
        UWORD16 pic_wd;
351
11
        UWORD16 pic_ht;
352
11
        UWORD32 num_mbs;
353
11
354
11
        pic_wd = ps_dec->u2_pic_wd;
355
11
        pic_ht = ps_dec->u2_pic_ht;
356
11
        num_mbs = (pic_wd * pic_ht) >> 8;
357
11
358
11
        if(ps_dec->pu1_dec_mb_map)
359
11
        {
360
11
            memset((void *)ps_dec->pu1_dec_mb_map, 0, num_mbs);
361
11
        }
362
11
363
11
        if(ps_dec->pu1_recon_mb_map)
364
11
        {
365
11
366
11
            memset((void *)ps_dec->pu1_recon_mb_map, 0, num_mbs);
367
11
        }
368
11
369
11
        if(ps_dec->pu2_slice_num_map)
370
11
        {
371
11
            memset((void *)ps_dec->pu2_slice_num_map, 0,
372
11
                   (num_mbs * sizeof(UWORD16)));
373
11
        }
374
11
375
11
    }
376
11
377
11
    ps_dec->ps_parse_cur_slice = &(ps_dec->ps_dec_slice_buf[0]);
378
11
    ps_dec->ps_decode_cur_slice = &(ps_dec->ps_dec_slice_buf[0]);
379
11
    ps_dec->ps_computebs_cur_slice = &(ps_dec->ps_dec_slice_buf[0]);
380
11
    ps_dec->u2_cur_slice_num = 0;
381
11
382
11
    /* Initialize all the HP toolsets to zero */
383
11
    ps_dec->s_high_profile.u1_scaling_present = 0;
384
11
    ps_dec->s_high_profile.u1_transform8x8_present = 0;
385
11
386
11
    /* Get Next Free Picture */
387
11
    if(1 == ps_dec->u4_share_disp_buf)
388
0
    {
389
0
        UWORD32 i;
390
0
        /* Free any buffer that is in the queue to be freed */
391
0
        for(i = 0; i < MAX_DISP_BUFS_NEW; i++)
392
0
        {
393
0
            if(0 == ps_dec->u4_disp_buf_to_be_freed[i])
394
0
                continue;
395
0
            ih264_buf_mgr_release((buf_mgr_t *)ps_dec->pv_pic_buf_mgr, i,
396
0
            BUF_MGR_IO);
397
0
            ps_dec->u4_disp_buf_to_be_freed[i] = 0;
398
0
            ps_dec->u4_disp_buf_mapping[i] = 0;
399
0
400
0
        }
401
0
    }
402
11
    if(!(u1_field_pic_flag && 0 != ps_dec->u1_top_bottom_decoded)) //ps_dec->u1_second_field))
403
11
    {
404
11
        pic_buffer_t *ps_cur_pic;
405
11
        WORD32 cur_pic_buf_id, cur_mv_buf_id;
406
11
        col_mv_buf_t *ps_col_mv;
407
11
        while(1)
408
11
        {
409
11
            ps_cur_pic = (pic_buffer_t *)ih264_buf_mgr_get_next_free(
410
11
                            (buf_mgr_t *)ps_dec->pv_pic_buf_mgr,
411
11
                            &cur_pic_buf_id);
412
11
            if(ps_cur_pic == NULL)
413
11
            {
414
0
                ps_dec->i4_error_code = ERROR_UNAVAIL_PICBUF_T;
415
0
                return ERROR_UNAVAIL_PICBUF_T;
416
0
            }
417
11
            if(0 == ps_dec->u4_disp_buf_mapping[cur_pic_buf_id])
418
11
            {
419
11
                break;
420
11
            }
421
11
422
11
        }
423
11
        ps_col_mv = (col_mv_buf_t *)ih264_buf_mgr_get_next_free((buf_mgr_t *)ps_dec->pv_mv_buf_mgr,
424
11
                                                               &cur_mv_buf_id);
425
11
        if(ps_col_mv == NULL)
426
11
        {
427
0
            ps_dec->i4_error_code = ERROR_UNAVAIL_MVBUF_T;
428
0
            return ERROR_UNAVAIL_MVBUF_T;
429
0
        }
430
11
431
11
        ps_dec->ps_cur_pic = ps_cur_pic;
432
11
        ps_dec->u1_pic_buf_id = cur_pic_buf_id;
433
11
        ps_cur_pic->u4_ts = ps_dec->u4_ts;
434
11
435
11
436
11
        ps_cur_pic->u1_mv_buf_id = cur_mv_buf_id;
437
11
        ps_dec->au1_pic_buf_id_mv_buf_id_map[cur_pic_buf_id] = cur_mv_buf_id;
438
11
439
11
        ps_cur_pic->pu1_col_zero_flag = (UWORD8 *)ps_col_mv->pv_col_zero_flag;
440
11
        ps_cur_pic->ps_mv = (mv_pred_t *)ps_col_mv->pv_mv;
441
11
        ps_dec->au1_pic_buf_ref_flag[cur_pic_buf_id] = 0;
442
11
443
11
        {
444
11
            /*make first entry of list0 and list1 point to cur pic,
445
11
             *so that if first slice is in error, ref pic struct will have valid entries*/
446
11
            ps_dec->ps_ref_pic_buf_lx[0] = ps_dec->ps_dpb_mgr->ps_init_dpb[0];
447
11
            ps_dec->ps_ref_pic_buf_lx[1] = ps_dec->ps_dpb_mgr->ps_init_dpb[1];
448
11
            *(ps_dec->ps_dpb_mgr->ps_init_dpb[0][0]) = *ps_cur_pic;
449
11
            /* Initialize for field reference as well */
450
11
            *(ps_dec->ps_dpb_mgr->ps_init_dpb[0][MAX_REF_BUFS]) = *ps_cur_pic;
451
11
452
11
            *(ps_dec->ps_dpb_mgr->ps_mod_dpb[0][0]) = *ps_cur_pic;
453
11
            /* Initialize for field reference as well */
454
11
            *(ps_dec->ps_dpb_mgr->ps_mod_dpb[0][MAX_REF_BUFS]) = *ps_cur_pic;
455
11
            *(ps_dec->ps_dpb_mgr->ps_init_dpb[1][0]) = *ps_cur_pic;
456
11
            /* Initialize for field reference as well */
457
11
            *(ps_dec->ps_dpb_mgr->ps_init_dpb[1][MAX_REF_BUFS]) = *ps_cur_pic;
458
11
            *(ps_dec->ps_dpb_mgr->ps_mod_dpb[1][0]) = *ps_cur_pic;
459
11
            /* Initialize for field reference as well */
460
11
            *(ps_dec->ps_dpb_mgr->ps_mod_dpb[1][MAX_REF_BUFS]) = *ps_cur_pic;
461
11
        }
462
11
463
11
        if(!ps_dec->ps_cur_pic)
464
0
        {
465
0
            WORD32 j;
466
0
            H264_DEC_DEBUG_PRINT("------- Display Buffers Reset --------\n");
467
0
            for(j = 0; j < MAX_DISP_BUFS_NEW; j++)
468
0
            {
469
0
470
0
                ih264_buf_mgr_release((buf_mgr_t *)ps_dec->pv_pic_buf_mgr,
471
0
                                      j,
472
0
                                      BUF_MGR_REF);
473
0
                ih264_buf_mgr_release((buf_mgr_t *)ps_dec->pv_mv_buf_mgr,
474
0
                                      ps_dec->au1_pic_buf_id_mv_buf_id_map[j],
475
0
                                      BUF_MGR_REF);
476
0
                ih264_buf_mgr_release((buf_mgr_t *)ps_dec->pv_pic_buf_mgr,
477
0
                                      j,
478
0
                                      BUF_MGR_IO);
479
0
            }
480
0
481
0
            ps_dec->i4_cur_display_seq = 0;
482
0
            ps_dec->i4_prev_max_display_seq = 0;
483
0
            ps_dec->i4_max_poc = 0;
484
0
485
0
            ps_cur_pic = (pic_buffer_t *)ih264_buf_mgr_get_next_free(
486
0
                            (buf_mgr_t *)ps_dec->pv_pic_buf_mgr,
487
0
                            &cur_pic_buf_id);
488
0
            if(ps_cur_pic == NULL)
489
0
            {
490
0
                ps_dec->i4_error_code = ERROR_UNAVAIL_PICBUF_T;
491
0
                return ERROR_UNAVAIL_PICBUF_T;
492
0
            }
493
0
494
0
            ps_col_mv = (col_mv_buf_t *)ih264_buf_mgr_get_next_free((buf_mgr_t *)ps_dec->pv_mv_buf_mgr,
495
0
                                                                   &cur_mv_buf_id);
496
0
            if(ps_col_mv == NULL)
497
0
            {
498
0
                ps_dec->i4_error_code = ERROR_UNAVAIL_MVBUF_T;
499
0
                return ERROR_UNAVAIL_MVBUF_T;
500
0
            }
501
0
502
0
            ps_dec->ps_cur_pic = ps_cur_pic;
503
0
            ps_dec->u1_pic_buf_id = cur_pic_buf_id;
504
0
            ps_cur_pic->u4_ts = ps_dec->u4_ts;
505
0
            ps_dec->apv_buf_id_pic_buf_map[cur_pic_buf_id] = (void *)ps_cur_pic;
506
0
507
0
            ps_cur_pic->u1_mv_buf_id = cur_mv_buf_id;
508
0
            ps_dec->au1_pic_buf_id_mv_buf_id_map[cur_pic_buf_id] = cur_mv_buf_id;
509
0
510
0
            ps_cur_pic->pu1_col_zero_flag = (UWORD8 *)ps_col_mv->pv_col_zero_flag;
511
0
            ps_cur_pic->ps_mv = (mv_pred_t *)ps_col_mv->pv_mv;
512
0
            ps_dec->au1_pic_buf_ref_flag[cur_pic_buf_id] = 0;
513
0
514
0
        }
515
11
516
11
        ps_dec->ps_cur_pic->u1_picturetype = u1_field_pic_flag;
517
11
        ps_dec->ps_cur_pic->u4_pack_slc_typ = SKIP_NONE;
518
11
        H264_DEC_DEBUG_PRINT("got a buffer\n");
519
11
    }
520
0
    else
521
0
    {
522
0
        H264_DEC_DEBUG_PRINT("did not get a buffer\n");
523
0
    }
524
11
525
11
    ps_dec->u4_pic_buf_got = 1;
526
11
527
11
    ps_dec->ps_cur_pic->i4_poc = i4_poc;
528
11
    ps_dec->ps_cur_pic->i4_frame_num = u2_frame_num;
529
11
    ps_dec->ps_cur_pic->i4_pic_num = u2_frame_num;
530
11
    ps_dec->ps_cur_pic->i4_top_field_order_cnt = ps_pps->i4_top_field_order_cnt;
531
11
    ps_dec->ps_cur_pic->i4_bottom_field_order_cnt =
532
11
                    ps_pps->i4_bottom_field_order_cnt;
533
11
    ps_dec->ps_cur_pic->i4_avg_poc = ps_pps->i4_avg_poc;
534
11
    ps_dec->ps_cur_pic->u4_time_stamp = ps_dec->u4_pts;
535
11
536
11
    ps_dec->s_cur_pic = *(ps_dec->ps_cur_pic);
537
11
    if(u1_field_pic_flag && u1_bottom_field_flag)
538
0
    {
539
0
        WORD32 i4_temp_poc;
540
0
        WORD32 i4_top_field_order_poc, i4_bot_field_order_poc;
541
0
        /* Point to odd lines, since it's bottom field */
542
0
        ps_dec->s_cur_pic.pu1_buf1 += ps_dec->s_cur_pic.u2_frm_wd_y;
543
0
        ps_dec->s_cur_pic.pu1_buf2 += ps_dec->s_cur_pic.u2_frm_wd_uv;
544
0
        ps_dec->s_cur_pic.pu1_buf3 += ps_dec->s_cur_pic.u2_frm_wd_uv;
545
0
        ps_dec->s_cur_pic.ps_mv +=
546
0
                        ((ps_dec->u2_pic_ht * ps_dec->u2_pic_wd) >> 5);
547
0
        ps_dec->s_cur_pic.pu1_col_zero_flag += ((ps_dec->u2_pic_ht
548
0
                        * ps_dec->u2_pic_wd) >> 5);
549
0
        ps_dec->ps_cur_pic->u1_picturetype |= BOT_FLD;
550
0
        i4_top_field_order_poc = ps_dec->ps_cur_pic->i4_top_field_order_cnt;
551
0
        i4_bot_field_order_poc = ps_dec->ps_cur_pic->i4_bottom_field_order_cnt;
552
0
        i4_temp_poc = MIN(i4_top_field_order_poc,
553
0
                                 i4_bot_field_order_poc);
554
0
        ps_dec->ps_cur_pic->i4_avg_poc = i4_temp_poc;
555
0
    }
556
11
557
11
    ps_cur_slice->u1_mbaff_frame_flag = ps_seq->u1_mb_aff_flag
558
11
                    && (!u1_field_pic_flag);
559
11
560
11
    ps_dec->ps_cur_pic->u1_picturetype |= (ps_cur_slice->u1_mbaff_frame_flag
561
11
                    << 2);
562
11
563
11
    ps_dec->ps_cur_mb_row = ps_dec->ps_nbr_mb_row; //[0];
564
11
    //Increment by 2 ,so that left mb (mbaff decrements by 2)  will always be valid
565
11
    ps_dec->ps_cur_mb_row += 2;
566
11
    ps_dec->ps_top_mb_row = ps_dec->ps_nbr_mb_row;
567
11
    ps_dec->ps_top_mb_row += ((ps_dec->u2_frm_wd_in_mbs + 2) << (1 - ps_dec->ps_cur_sps->u1_frame_mbs_only_flag));
568
11
    //Increment by 2 ,so that left mb (mbaff decrements by 2)  will always be valid
569
11
    ps_dec->ps_top_mb_row += 2;
570
11
571
11
    /* CHANGED CODE */
572
11
    ps_dec->ps_mv_cur = ps_dec->s_cur_pic.ps_mv;
573
11
    ps_dec->ps_mv_top = ps_dec->ps_mv_top_p[0];
574
11
    /* CHANGED CODE */
575
11
    ps_dec->u1_mv_top_p = 0;
576
11
    ps_dec->u1_mb_idx = 0;
577
11
    /* CHANGED CODE */
578
11
    ps_dec->ps_mv_left = ps_dec->s_cur_pic.ps_mv;
579
11
    ps_dec->u2_total_mbs_coded = 0;
580
11
    ps_dec->i4_submb_ofst = -(SUB_BLK_SIZE);
581
11
    ps_dec->u4_pred_info_idx = 0;
582
11
    ps_dec->u4_pred_info_pkd_idx = 0;
583
11
    ps_dec->u4_dma_buf_idx = 0;
584
11
    ps_dec->ps_mv = ps_dec->s_cur_pic.ps_mv;
585
11
    ps_dec->ps_mv_bank_cur = ps_dec->s_cur_pic.ps_mv;
586
11
    ps_dec->pu1_col_zero_flag = ps_dec->s_cur_pic.pu1_col_zero_flag;
587
11
    ps_dec->ps_part = ps_dec->ps_parse_part_params;
588
11
    ps_dec->i2_prev_slice_mbx = -1;
589
11
    ps_dec->i2_prev_slice_mby = 0;
590
11
    ps_dec->u2_mv_2mb[0] = 0;
591
11
    ps_dec->u2_mv_2mb[1] = 0;
592
11
    ps_dec->u1_last_pic_not_decoded = 0;
593
11
594
11
    ps_dec->u2_cur_slice_num_dec_thread = 0;
595
11
    ps_dec->u2_cur_slice_num_bs = 0;
596
11
    ps_dec->u4_intra_pred_line_ofst = 0;
597
11
    ps_dec->pu1_cur_y_intra_pred_line = ps_dec->pu1_y_intra_pred_line;
598
11
    ps_dec->pu1_cur_u_intra_pred_line = ps_dec->pu1_u_intra_pred_line;
599
11
    ps_dec->pu1_cur_v_intra_pred_line = ps_dec->pu1_v_intra_pred_line;
600
11
601
11
    ps_dec->pu1_cur_y_intra_pred_line_base = ps_dec->pu1_y_intra_pred_line;
602
11
    ps_dec->pu1_cur_u_intra_pred_line_base = ps_dec->pu1_u_intra_pred_line;
603
11
    ps_dec->pu1_cur_v_intra_pred_line_base = ps_dec->pu1_v_intra_pred_line;
604
11
605
11
606
11
607
11
608
11
609
11
    ps_dec->pu1_prev_y_intra_pred_line = ps_dec->pu1_y_intra_pred_line
610
11
                    + (ps_dec->u2_frm_wd_in_mbs * MB_SIZE);
611
11
612
11
    ps_dec->pu1_prev_u_intra_pred_line = ps_dec->pu1_u_intra_pred_line
613
11
                    + ps_dec->u2_frm_wd_in_mbs * BLK8x8SIZE * YUV420SP_FACTOR;
614
11
    ps_dec->pu1_prev_v_intra_pred_line = ps_dec->pu1_v_intra_pred_line
615
11
                    + ps_dec->u2_frm_wd_in_mbs * BLK8x8SIZE;
616
11
617
11
    ps_dec->ps_deblk_mbn = ps_dec->ps_deblk_pic;
618
11
    /* Initialize The Function Pointer Depending Upon the Entropy and MbAff Flag */
619
11
    {
620
11
        if(ps_cur_slice->u1_mbaff_frame_flag)
621
0
        {
622
0
            ps_dec->pf_compute_bs = ih264d_compute_bs_mbaff;
623
0
            ps_dec->pf_mvpred = ih264d_mvpred_mbaff;
624
0
        }
625
11
        else
626
11
        {
627
11
            ps_dec->pf_compute_bs = ih264d_compute_bs_non_mbaff;
628
11
            ps_dec->u1_cur_mb_fld_dec_flag = ps_cur_slice->u1_field_pic_flag;
629
11
        }
630
11
    }
631
11
    /* Set up the Parameter for DMA transfer */
632
11
    {
633
11
        UWORD8 u1_field_pic_flag = ps_dec->ps_cur_slice->u1_field_pic_flag;
634
11
635
11
        UWORD8 u1_mbaff = ps_cur_slice->u1_mbaff_frame_flag;
636
11
637
11
        UWORD8 uc_lastmbs = (((ps_dec->u2_pic_wd) >> 4)
638
11
                        % (ps_dec->u1_recon_mb_grp >> u1_mbaff));
639
11
        UWORD16 ui16_lastmbs_widthY =
640
11
                        (uc_lastmbs ? (uc_lastmbs << 4) : ((ps_dec->u1_recon_mb_grp
641
11
                                        >> u1_mbaff) << 4));
642
11
        UWORD16 ui16_lastmbs_widthUV =
643
11
                        uc_lastmbs ? (uc_lastmbs << 3) : ((ps_dec->u1_recon_mb_grp
644
11
                                        >> u1_mbaff) << 3);
645
11
646
11
        ps_dec->s_tran_addrecon.pu1_dest_y = ps_dec->s_cur_pic.pu1_buf1;
647
11
        ps_dec->s_tran_addrecon.pu1_dest_u = ps_dec->s_cur_pic.pu1_buf2;
648
11
        ps_dec->s_tran_addrecon.pu1_dest_v = ps_dec->s_cur_pic.pu1_buf3;
649
11
650
11
        ps_dec->s_tran_addrecon.u2_frm_wd_y = ps_dec->u2_frm_wd_y
651
11
                        << u1_field_pic_flag;
652
11
        ps_dec->s_tran_addrecon.u2_frm_wd_uv = ps_dec->u2_frm_wd_uv
653
11
                        << u1_field_pic_flag;
654
11
655
11
        if(u1_field_pic_flag)
656
0
        {
657
0
            ui16_lastmbs_widthY += ps_dec->u2_frm_wd_y;
658
0
            ui16_lastmbs_widthUV += ps_dec->u2_frm_wd_uv;
659
0
        }
660
11
661
11
        /* Normal Increment of Pointer */
662
11
        ps_dec->s_tran_addrecon.u4_inc_y[0] = ((ps_dec->u1_recon_mb_grp << 4)
663
11
                        >> u1_mbaff);
664
11
        ps_dec->s_tran_addrecon.u4_inc_uv[0] = ((ps_dec->u1_recon_mb_grp << 4)
665
11
                        >> u1_mbaff);
666
11
667
11
        /* End of Row Increment */
668
11
        ps_dec->s_tran_addrecon.u4_inc_y[1] = (ui16_lastmbs_widthY
669
11
                        + (PAD_LEN_Y_H << 1)
670
11
                        + ps_dec->s_tran_addrecon.u2_frm_wd_y
671
11
                                        * ((15 << u1_mbaff) + u1_mbaff));
672
11
        ps_dec->s_tran_addrecon.u4_inc_uv[1] = (ui16_lastmbs_widthUV
673
11
                        + (PAD_LEN_UV_H << 2)
674
11
                        + ps_dec->s_tran_addrecon.u2_frm_wd_uv
675
11
                                        * ((15 << u1_mbaff) + u1_mbaff));
676
11
677
11
        /* Assign picture numbers to each frame/field  */
678
11
        /* only once per picture.                      */
679
11
        ih264d_assign_pic_num(ps_dec);
680
11
        ps_dec->s_tran_addrecon.u2_mv_top_left_inc = (ps_dec->u1_recon_mb_grp
681
11
                        << 2) - 1 - (u1_mbaff << 2);
682
11
        ps_dec->s_tran_addrecon.u2_mv_left_inc = ((ps_dec->u1_recon_mb_grp
683
11
                        >> u1_mbaff) - 1) << (4 + u1_mbaff);
684
11
    }
685
11
    /**********************************************************************/
686
11
    /* High profile related initialization at pictrue level               */
687
11
    /**********************************************************************/
688
11
    if(ps_seq->u1_profile_idc == HIGH_PROFILE_IDC)
689
11
    {
690
0
        if((ps_seq->i4_seq_scaling_matrix_present_flag)
691
0
                        || (ps_pps->i4_pic_scaling_matrix_present_flag))
692
0
        {
693
0
            ih264d_form_scaling_matrix_picture(ps_seq, ps_pps, ps_dec);
694
0
            ps_dec->s_high_profile.u1_scaling_present = 1;
695
0
        }
696
0
        else
697
0
        {
698
0
            ih264d_form_default_scaling_matrix(ps_dec);
699
0
        }
700
0
701
0
        if(ps_pps->i4_transform_8x8_mode_flag)
702
0
        {
703
0
            ps_dec->s_high_profile.u1_transform8x8_present = 1;
704
0
        }
705
0
    }
706
11
    else
707
11
    {
708
11
        ih264d_form_default_scaling_matrix(ps_dec);
709
11
    }
710
11
711
11
    /* required while reading the transform_size_8x8 u4_flag */
712
11
    ps_dec->s_high_profile.u1_direct_8x8_inference_flag =
713
11
                    ps_seq->u1_direct_8x8_inference_flag;
714
11
    ps_dec->s_high_profile.s_cavlc_ctxt = ps_dec->s_cavlc_ctxt;
715
11
716
11
    ps_dec->i1_recon_in_thread3_flag = 1;
717
11
    ps_dec->ps_frame_buf_ip_recon = &ps_dec->s_tran_addrecon;
718
11
    if(ps_dec->u1_separate_parse)
719
11
    {
720
11
        memcpy(&ps_dec->s_tran_addrecon_parse, &ps_dec->s_tran_addrecon,
721
11
               sizeof(tfr_ctxt_t));
722
11
        if(ps_dec->u4_num_cores >= 3 && ps_dec->i1_recon_in_thread3_flag)
723
11
        {
724
11
            memcpy(&ps_dec->s_tran_iprecon, &ps_dec->s_tran_addrecon,
725
11
                   sizeof(tfr_ctxt_t));
726
11
            ps_dec->ps_frame_buf_ip_recon = &ps_dec->s_tran_iprecon;
727
11
        }
728
11
    }
729
11
730
11
731
11
    ih264d_init_deblk_tfr_ctxt(ps_dec,&(ps_dec->s_pad_mgr), &(ps_dec->s_tran_addrecon),
732
11
                               ps_dec->u2_frm_wd_in_mbs, 0);
733
11
734
11
    ps_dec->ps_cur_deblk_mb = ps_dec->ps_deblk_pic;
735
11
    ps_dec->u4_cur_deblk_mb_num = 0;
736
11
737
11
    ps_dec->u4_deblk_mb_x = 0;
738
11
    ps_dec->u4_deblk_mb_y = 0;
739
11
    ps_dec->pu4_wt_ofsts = ps_dec->pu4_wts_ofsts_mat;
740
11
741
11
    ps_dec->u4_first_slice_in_pic = 0;
742
11
    H264_MUTEX_UNLOCK(&ps_dec->process_disp_mutex);
743
11
    return OK;
744
11
}
745
746
/*!
747
 **************************************************************************
748
 * \if Function name :  ih264d_deblock_display \endif
749
 *
750
 * \brief            :  The function callls the deblocking routine and manages
751
 :  the Recon buffers and displays .
752
 * \return           :  Nothing
753
 *
754
 **************************************************************************
755
 */
756
WORD32 ih264d_end_of_pic_dispbuf_mgr(dec_struct_t * ps_dec)
757
11
{
758
11
    dec_slice_params_t *ps_cur_slice = ps_dec->ps_cur_slice;
759
11
    UWORD8 u1_num_of_users = 0;
760
11
    WORD32 ret;
761
11
762
11
    H264_MUTEX_LOCK(&ps_dec->process_disp_mutex);
763
11
    if(1)
764
11
    {
765
11
766
11
        {
767
11
            ih264d_delete_nonref_nondisplay_pics(ps_dec->ps_dpb_mgr);
768
11
            if(ps_cur_slice->u1_mmco_equalto5
769
11
                            || (ps_cur_slice->u1_nal_unit_type == IDR_SLICE_NAL))
770
11
            {
771
11
                ps_dec->ps_cur_pic->i4_poc = 0;
772
11
                if(ps_dec->u2_total_mbs_coded
773
11
                                == (ps_dec->ps_cur_sps->u2_max_mb_addr + 1))
774
11
                    ih264d_reset_ref_bufs(ps_dec->ps_dpb_mgr);
775
11
                ih264d_release_display_bufs(ps_dec);
776
11
            }
777
11
            if(IVD_DECODE_FRAME_OUT != ps_dec->e_frm_out_mode)
778
11
            {
779
11
                ret = ih264d_assign_display_seq(ps_dec);
780
11
                if(ret != OK)
781
11
                    return ret;
782
11
            }
783
11
        }
784
11
785
11
        if(ps_cur_slice->u1_nal_ref_idc)
786
11
        {
787
11
            /* Mark pic buf as needed for reference */
788
11
            ih264_buf_mgr_set_status((buf_mgr_t *)ps_dec->pv_pic_buf_mgr,
789
11
                                     ps_dec->u1_pic_buf_id,
790
11
                                     BUF_MGR_REF);
791
11
            /* Mark mv buf as needed for reference */
792
11
            ih264_buf_mgr_set_status((buf_mgr_t *)ps_dec->pv_mv_buf_mgr,
793
11
                                     ps_dec->au1_pic_buf_id_mv_buf_id_map[ps_dec->u1_pic_buf_id],
794
11
                                     BUF_MGR_REF);
795
11
            ps_dec->au1_pic_buf_ref_flag[ps_dec->u1_pic_buf_id] = 1;
796
11
        }
797
11
798
11
        /* 420 consumer */
799
11
        /* Increment the number of users by 1 for display based upon */
800
11
        /*the SEEK KEY FRAME control sent to decoder                 */
801
11
        if(((0 == ps_dec->u1_last_pic_not_decoded)
802
11
                        && (0
803
11
                                        == (ps_dec->ps_cur_pic->u4_pack_slc_typ
804
11
                                                        & ps_dec->u4_skip_frm_mask)))
805
11
                        || (ps_cur_slice->u1_nal_unit_type == IDR_SLICE_NAL))
806
11
        {
807
11
            /* Mark pic buf as needed for display */
808
11
            ih264_buf_mgr_set_status((buf_mgr_t *)ps_dec->pv_pic_buf_mgr,
809
11
                                     ps_dec->u1_pic_buf_id,
810
11
                                     BUF_MGR_IO);
811
11
812
11
        }
813
11
814
11
        if(!ps_cur_slice->u1_field_pic_flag
815
11
                        || ((TOP_FIELD_ONLY | BOT_FIELD_ONLY)
816
0
                                        != ps_dec->u1_top_bottom_decoded))
817
11
        {
818
11
            pic_buffer_t *ps_cur_pic = ps_dec->ps_cur_pic;
819
11
            ps_cur_pic->u2_disp_width = ps_dec->u2_disp_width;
820
11
            ps_cur_pic->u2_disp_height = ps_dec->u2_disp_height >> 1;
821
11
822
11
            ps_cur_pic->u2_crop_offset_y = ps_dec->u2_crop_offset_y;
823
11
            ps_cur_pic->u2_crop_offset_uv = ps_dec->u2_crop_offset_uv;
824
11
            ps_cur_pic->u1_pic_type = 0;
825
11
826
11
            ret = ih264d_insert_pic_in_display_list(
827
11
                            ps_dec->ps_dpb_mgr,
828
11
                            ps_dec->u1_pic_buf_id,
829
11
                            ps_dec->i4_prev_max_display_seq
830
11
                                            + ps_dec->ps_cur_pic->i4_poc,
831
11
                            ps_dec->ps_cur_pic->i4_frame_num);
832
11
            if(ret != OK)
833
11
                return ret;
834
11
835
11
            {
836
11
                ivd_video_decode_op_t * ps_dec_output =
837
11
                                (ivd_video_decode_op_t *)ps_dec->pv_dec_out;
838
11
839
11
                ps_dec_output->u4_frame_decoded_flag = 1;
840
11
            }
841
11
            if(ps_dec->au1_pic_buf_ref_flag[ps_dec->u1_pic_buf_id] == 0)
842
0
            {
843
0
                ih264_buf_mgr_release((buf_mgr_t *)ps_dec->pv_mv_buf_mgr,
844
0
                                      ps_dec->au1_pic_buf_id_mv_buf_id_map[ps_dec->u1_pic_buf_id],
845
0
                                      BUF_MGR_REF);
846
0
                ps_dec->au1_pic_buf_ref_flag[ps_dec->u1_pic_buf_id] = 0;
847
0
848
0
            }
849
11
        }
850
0
        else
851
0
        {
852
0
            H264_DEC_DEBUG_PRINT("pic not inserted display %d %d\n",
853
0
                                 ps_cur_slice->u1_field_pic_flag,
854
0
                                 ps_dec->u1_second_field);
855
0
        }
856
11
857
11
        if(!ps_cur_slice->u1_field_pic_flag
858
11
                        || ((TOP_FIELD_ONLY | BOT_FIELD_ONLY)
859
0
                                        == ps_dec->u1_top_bottom_decoded))
860
11
        {
861
11
            if(IVD_DECODE_FRAME_OUT == ps_dec->e_frm_out_mode)
862
0
            {
863
0
                ret = ih264d_assign_display_seq(ps_dec);
864
0
                if(ret != OK)
865
0
                    return ret;
866
11
            }
867
11
        }
868
11
    }
869
11
870
11
    H264_MUTEX_UNLOCK(&ps_dec->process_disp_mutex);
871
11
872
11
    return OK;
873
11
}
874
875
void ih264d_err_pic_dispbuf_mgr(dec_struct_t *ps_dec)
876
0
{
877
0
    dec_slice_params_t *ps_cur_slice = ps_dec->ps_cur_slice;
878
0
    ivd_video_decode_op_t * ps_dec_output =
879
0
                    (ivd_video_decode_op_t *)ps_dec->pv_dec_out;
880
0
881
0
    ih264_buf_mgr_release((buf_mgr_t *)ps_dec->pv_pic_buf_mgr,
882
0
                          ps_dec->u1_pic_buf_id,
883
0
                          BUF_MGR_REF);
884
0
    ih264_buf_mgr_release((buf_mgr_t *)ps_dec->pv_mv_buf_mgr,
885
0
                          ps_dec->au1_pic_buf_id_mv_buf_id_map[ps_dec->u1_pic_buf_id],
886
0
                          BUF_MGR_REF);
887
0
    ih264_buf_mgr_release((buf_mgr_t *)ps_dec->pv_pic_buf_mgr,
888
0
                          ps_dec->u1_pic_buf_id,
889
0
                          BUF_MGR_IO);
890
0
}
891
892
void ih264d_deblock_picture(void *ptr)
893
11
{
894
11
    dec_struct_t *ps_dec = (dec_struct_t *)ptr;
895
11
896
11
    {
897
11
        /*Deblock picture only if all the mb's in the frame have been decoded*/
898
11
        if(ps_dec->u1_pic_decode_done == 1)
899
11
        {
900
11
            if(ps_dec->ps_cur_slice->u1_mbaff_frame_flag
901
11
                            || ps_dec->ps_cur_slice->u1_field_pic_flag)
902
0
            {
903
0
                ps_dec->p_DeblockPicture[ps_dec->ps_cur_slice->u1_mbaff_frame_flag](
904
0
                                ps_dec);
905
0
            }
906
11
            else
907
11
908
11
            {
909
11
910
11
                ih264d_deblock_picture_progressive(ps_dec);
911
11
            }
912
11
913
11
        }
914
11
    }
915
11
916
11
}
917
918
/*!
919
 **************************************************************************
920
 * \if Function name :  ih264d_deblock_display \endif
921
 *
922
 * \brief            :  The function callls the deblocking routine and manages
923
 :  the Recon buffers and displays .
924
 * \return           :  Nothing
925
 *
926
 **************************************************************************
927
 */
928
WORD32 ih264d_deblock_display(dec_struct_t *ps_dec)
929
11
{
930
11
    WORD32 ret;
931
11
    /* Call deblocking */
932
11
    ih264d_deblock_picture(ps_dec);
933
11
934
11
    ret = ih264d_end_of_pic_dispbuf_mgr(ps_dec);
935
11
    if(ret != OK)
936
11
        return ret;
937
11
938
11
    return OK;
939
11
}
940
941
/*
942
 *!
943
 **************************************************************************
944
 * \if Function name : EndofPoc \endif
945
 *
946
 * \brief
947
 *    EndofPoc Processing
948
 *
949
 * \return
950
 *    0 on Success and Error code otherwise
951
 **************************************************************************
952
 */
953
954
WORD32 ih264d_end_of_pic(dec_struct_t *ps_dec)
955
11
{
956
11
    dec_slice_params_t *ps_cur_slice = ps_dec->ps_cur_slice;
957
11
    WORD32 ret;
958
11
959
11
    {
960
11
        dec_err_status_t * ps_err = ps_dec->ps_dec_err_status;
961
11
        if(ps_err->u1_err_flag & REJECT_CUR_PIC)
962
11
        {
963
0
            ih264d_err_pic_dispbuf_mgr(ps_dec);
964
0
            return ERROR_NEW_FRAME_EXPECTED;
965
0
        }
966
11
    }
967
11
968
11
    H264_MUTEX_LOCK(&ps_dec->process_disp_mutex);
969
11
    ret = ih264d_end_of_pic_processing(ps_dec);
970
11
    if(ret != OK)
971
11
        return ret;
972
11
    /*--------------------------------------------------------------------*/
973
11
    /* ih264d_decode_pic_order_cnt - calculate the Pic Order Cnt                    */
974
11
    /* Needed to detect end of picture                                    */
975
11
    /*--------------------------------------------------------------------*/
976
11
977
11
    H264_MUTEX_UNLOCK(&ps_dec->process_disp_mutex);
978
11
979
11
    return OK;
980
11
}
981
982
/*!
983
 **************************************************************************
984
 * \if Function name : DecodeSlice \endif
985
 *
986
 * \brief
987
 *    Parses a slice
988
 *
989
 * \return
990
 *    0 on Success and Error code otherwise
991
 **************************************************************************
992
 */
993
994
WORD32 ih264d_parse_decode_slice(UWORD8 u1_is_idr_slice,
995
                                 UWORD8 u1_nal_ref_idc,
996
                                 dec_struct_t *ps_dec /* Decoder parameters */
997
                                 )
998
11
{
999
11
    dec_bit_stream_t * ps_bitstrm = ps_dec->ps_bitstrm;
1000
11
    dec_pic_params_t *ps_pps;
1001
11
    dec_seq_params_t *ps_seq;
1002
11
    dec_slice_params_t *ps_cur_slice = ps_dec->ps_cur_slice;
1003
11
    pocstruct_t s_tmp_poc;
1004
11
    WORD32 i_delta_poc[2];
1005
11
    WORD32 i4_poc = 0;
1006
11
    UWORD16 u2_first_mb_in_slice, u2_frame_num;
1007
11
    UWORD8 u1_field_pic_flag, u1_redundant_pic_cnt = 0, u1_slice_type;
1008
11
    UWORD32 u4_idr_pic_id = 0;
1009
11
    UWORD8 u1_bottom_field_flag, u1_pic_order_cnt_type;
1010
11
1011
11
    UWORD8 u1_nal_unit_type;
1012
11
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
1013
11
    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
1014
11
    WORD8 i1_is_end_of_poc;
1015
11
1016
11
    WORD32 ret, end_of_frame;
1017
11
    WORD32 prev_slice_err, num_mb_skipped;
1018
11
    UWORD8 u1_mbaff;
1019
11
    pocstruct_t *ps_cur_poc;
1020
11
1021
11
    UWORD32 u4_temp;
1022
11
    WORD32 i_temp;
1023
11
    UWORD32 u4_call_end_of_pic = 0;
1024
11
1025
11
    /* read FirstMbInSlice  and slice type*/
1026
11
    ps_dec->ps_dpb_cmds->u1_dpb_commands_read_slc = 0;
1027
11
    u2_first_mb_in_slice = ih264d_uev(pu4_bitstrm_ofst,
1028
11
                                     pu4_bitstrm_buf);
1029
11
    if(u2_first_mb_in_slice
1030
11
                    > (ps_dec->u2_frm_ht_in_mbs * ps_dec->u2_frm_wd_in_mbs))
1031
0
    {
1032
0
1033
0
        return ERROR_CORRUPTED_SLICE;
1034
0
    }
1035
11
1036
11
    /*we currently don not support ASO*/
1037
11
    if(((u2_first_mb_in_slice << ps_cur_slice->u1_mbaff_frame_flag)
1038
11
                    <= ps_dec->u2_cur_mb_addr) && (ps_dec->u4_first_slice_in_pic == 0))
1039
0
    {
1040
0
        return ERROR_CORRUPTED_SLICE;
1041
0
    }
1042
11
1043
11
    COPYTHECONTEXT("SH: first_mb_in_slice",u2_first_mb_in_slice);
1044
11
1045
11
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1046
11
1047
11
    if(u4_temp > 9)
1048
0
        return ERROR_INV_SLC_TYPE_T;
1049
11
1050
11
    u1_slice_type = u4_temp;
1051
11
    COPYTHECONTEXT("SH: slice_type",(u1_slice_type));
1052
11
    /* Find Out the Slice Type is 5 to 9 or not then Set the Flag   */
1053
11
    /* u1_sl_typ_5_9 = 1 .Which tells that all the slices in the Pic*/
1054
11
    /* will be of same type of current                            */
1055
11
    if(u1_slice_type > 4)
1056
11
    {
1057
11
        u1_slice_type -= 5;
1058
11
    }
1059
11
1060
11
    {
1061
11
        UWORD32 skip;
1062
11
1063
11
        if((ps_dec->i4_app_skip_mode == IVD_SKIP_PB)
1064
11
                        || (ps_dec->i4_dec_skip_mode == IVD_SKIP_PB))
1065
0
        {
1066
0
            UWORD32 u4_bit_stream_offset = 0;
1067
0
1068
0
            if(ps_dec->u1_nal_unit_type == IDR_SLICE_NAL)
1069
0
            {
1070
0
                skip = 0;
1071
0
1072
0
                ps_dec->i4_dec_skip_mode = IVD_SKIP_NONE;
1073
0
            }
1074
0
            else if((I_SLICE == u1_slice_type)
1075
0
                            && (1 >= ps_dec->ps_cur_sps->u1_num_ref_frames))
1076
0
            {
1077
0
                skip = 0;
1078
0
1079
0
                ps_dec->i4_dec_skip_mode = IVD_SKIP_NONE;
1080
0
            }
1081
0
            else
1082
0
            {
1083
0
                skip = 1;
1084
0
            }
1085
0
1086
0
            /* If one frame worth of data is already skipped, do not skip the next one */
1087
0
            if((0 == u2_first_mb_in_slice) && (1 == ps_dec->u4_prev_nal_skipped))
1088
0
            {
1089
0
                skip = 0;
1090
0
            }
1091
0
1092
0
            if(skip)
1093
0
            {
1094
0
                ps_dec->u4_prev_nal_skipped = 1;
1095
0
                ps_dec->i4_dec_skip_mode = IVD_SKIP_PB;
1096
0
                return 0;
1097
0
            }
1098
0
            else
1099
0
            {
1100
0
                /* If the previous NAL was skipped, then
1101
0
                 do not process that buffer in this call.
1102
0
                 Return to app and process it in the next call.
1103
0
                 This is necessary to handle cases where I/IDR is not complete in
1104
0
                 the current buffer and application intends to fill the remaining part of the bitstream
1105
0
                 later. This ensures we process only frame worth of data in every call */
1106
0
                if(1 == ps_dec->u4_prev_nal_skipped)
1107
0
                {
1108
0
                    ps_dec->u4_return_to_app = 1;
1109
0
                    return 0;
1110
0
                }
1111
11
            }
1112
0
        }
1113
11
1114
11
    }
1115
11
1116
11
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1117
11
    if(u4_temp & MASK_ERR_PIC_SET_ID)
1118
11
        return ERROR_INV_SLICE_HDR_T;
1119
11
    /* discard slice if pic param is invalid */
1120
11
    COPYTHECONTEXT("SH: pic_parameter_set_id", u4_temp);
1121
11
    ps_pps = &ps_dec->ps_pps[u4_temp];
1122
11
    if(FALSE == ps_pps->u1_is_valid)
1123
0
    {
1124
0
        return ERROR_INV_SLICE_HDR_T;
1125
0
    }
1126
11
    ps_seq = ps_pps->ps_sps;
1127
11
    if(!ps_seq)
1128
0
        return ERROR_INV_SLICE_HDR_T;
1129
11
    if(FALSE == ps_seq->u1_is_valid)
1130
0
        return ERROR_INV_SLICE_HDR_T;
1131
11
1132
11
    /* Get the frame num */
1133
11
    u2_frame_num = ih264d_get_bits_h264(ps_bitstrm,
1134
11
                                         ps_seq->u1_bits_in_frm_num);
1135
11
//    H264_DEC_DEBUG_PRINT("FRAME %d First MB in slice: %d\n", u2_frame_num, u2_first_mb_in_slice);
1136
11
1137
11
    COPYTHECONTEXT("SH: frame_num", u2_frame_num);
1138
11
//    H264_DEC_DEBUG_PRINT("Second field: %d frame num: %d prv_frame_num: %d \n", ps_dec->u1_second_field, u2_frame_num, ps_dec->u2_prv_frame_num);
1139
11
    if(!ps_dec->u1_first_slice_in_stream && ps_dec->u4_first_slice_in_pic)
1140
10
    {
1141
10
        pocstruct_t *ps_prev_poc = &ps_dec->s_prev_pic_poc;
1142
10
        pocstruct_t *ps_cur_poc = &ps_dec->s_cur_pic_poc;
1143
10
1144
10
        ps_dec->u2_mbx = 0xffff;
1145
10
        ps_dec->u2_mby = 0;
1146
10
1147
10
        if((0 == u1_is_idr_slice) && ps_cur_slice->u1_nal_ref_idc)
1148
0
            ps_dec->u2_prev_ref_frame_num = ps_cur_slice->u2_frame_num;
1149
10
1150
10
        if(u1_is_idr_slice || ps_cur_slice->u1_mmco_equalto5)
1151
10
            ps_dec->u2_prev_ref_frame_num = 0;
1152
10
1153
10
        if(ps_dec->ps_cur_sps->u1_gaps_in_frame_num_value_allowed_flag)
1154
0
        {
1155
0
            ih264d_decode_gaps_in_frame_num(ps_dec, u2_frame_num);
1156
0
        }
1157
10
1158
10
        ps_prev_poc->i4_prev_frame_num_ofst = ps_cur_poc->i4_prev_frame_num_ofst;
1159
10
        ps_prev_poc->u2_frame_num = ps_cur_poc->u2_frame_num;
1160
10
        ps_prev_poc->u1_mmco_equalto5 = ps_cur_slice->u1_mmco_equalto5;
1161
10
        if(ps_cur_slice->u1_nal_ref_idc)
1162
10
        {
1163
10
            ps_prev_poc->i4_pic_order_cnt_lsb = ps_cur_poc->i4_pic_order_cnt_lsb;
1164
10
            ps_prev_poc->i4_pic_order_cnt_msb = ps_cur_poc->i4_pic_order_cnt_msb;
1165
10
            ps_prev_poc->i4_delta_pic_order_cnt_bottom =
1166
10
                            ps_cur_poc->i4_delta_pic_order_cnt_bottom;
1167
10
            ps_prev_poc->i4_delta_pic_order_cnt[0] =
1168
10
                            ps_cur_poc->i4_delta_pic_order_cnt[0];
1169
10
            ps_prev_poc->i4_delta_pic_order_cnt[1] =
1170
10
                            ps_cur_poc->i4_delta_pic_order_cnt[1];
1171
10
            ps_prev_poc->u1_bot_field = ps_cur_poc->u1_bot_field;
1172
10
        }
1173
10
1174
10
        ps_dec->u2_total_mbs_coded = 0;
1175
10
    }
1176
11
    /* Get the field related flags  */
1177
11
    if(!ps_seq->u1_frame_mbs_only_flag)
1178
0
    {
1179
0
1180
0
        u1_field_pic_flag = ih264d_get_bit_h264(ps_bitstrm);
1181
0
        COPYTHECONTEXT("SH: field_pic_flag", u1_field_pic_flag);
1182
0
        u1_bottom_field_flag = 0;
1183
0
1184
0
        if(u1_field_pic_flag)
1185
0
        {
1186
0
            ps_dec->pu1_inv_scan = (UWORD8 *)gau1_ih264d_inv_scan_fld;
1187
0
            u1_bottom_field_flag = ih264d_get_bit_h264(ps_bitstrm);
1188
0
            COPYTHECONTEXT("SH: bottom_field_flag", u1_bottom_field_flag);
1189
0
1190
0
        }
1191
0
        else
1192
0
        {
1193
0
            ps_dec->pu1_inv_scan = (UWORD8 *)gau1_ih264d_inv_scan;
1194
0
        }
1195
0
    }
1196
11
    else
1197
11
    {
1198
11
        u1_field_pic_flag = 0;
1199
11
        u1_bottom_field_flag = 0;
1200
11
1201
11
        ps_dec->pu1_inv_scan = (UWORD8 *)gau1_ih264d_inv_scan;
1202
11
    }
1203
11
1204
11
    u1_nal_unit_type = SLICE_NAL;
1205
11
    if(u1_is_idr_slice)
1206
11
    {
1207
11
        u1_nal_unit_type = IDR_SLICE_NAL;
1208
11
        u4_idr_pic_id = ih264d_uev(pu4_bitstrm_ofst,
1209
11
                                   pu4_bitstrm_buf);
1210
11
        if(u4_idr_pic_id > 65535)
1211
0
            return ERROR_INV_SLICE_HDR_T;
1212
11
        COPYTHECONTEXT("SH:  ", u4_idr_pic_id);
1213
11
    }
1214
11
1215
11
    /* read delta pic order count information*/
1216
11
    i_delta_poc[0] = i_delta_poc[1] = 0;
1217
11
    s_tmp_poc.i4_pic_order_cnt_lsb = 0;
1218
11
    s_tmp_poc.i4_delta_pic_order_cnt_bottom = 0;
1219
11
    u1_pic_order_cnt_type = ps_seq->u1_pic_order_cnt_type;
1220
11
    if(u1_pic_order_cnt_type == 0)
1221
11
    {
1222
11
        i_temp = ih264d_get_bits_h264(
1223
11
                        ps_bitstrm,
1224
11
                        ps_seq->u1_log2_max_pic_order_cnt_lsb_minus);
1225
11
        if(i_temp < 0 || i_temp >= ps_seq->i4_max_pic_order_cntLsb)
1226
0
            return ERROR_INV_SLICE_HDR_T;
1227
11
        s_tmp_poc.i4_pic_order_cnt_lsb = i_temp;
1228
11
        COPYTHECONTEXT("SH: pic_order_cnt_lsb", s_tmp_poc.i4_pic_order_cnt_lsb);
1229
11
1230
11
        if((ps_pps->u1_pic_order_present_flag == 1) && (!u1_field_pic_flag))
1231
0
        {
1232
0
            s_tmp_poc.i4_delta_pic_order_cnt_bottom = ih264d_sev(
1233
0
                            pu4_bitstrm_ofst, pu4_bitstrm_buf);
1234
0
            //if(s_tmp_poc.i4_delta_pic_order_cnt_bottom > ps_seq->i4_max_pic_order_cntLsb)
1235
0
            COPYTHECONTEXT("SH: delta_pic_order_cnt_bottom",
1236
0
                            s_tmp_poc.i4_delta_pic_order_cnt_bottom);
1237
0
        }
1238
11
    }
1239
11
1240
11
    s_tmp_poc.i4_delta_pic_order_cnt[0] = 0;
1241
11
    s_tmp_poc.i4_delta_pic_order_cnt[1] = 0;
1242
11
    if(u1_pic_order_cnt_type == 1
1243
11
                    && (!ps_seq->u1_delta_pic_order_always_zero_flag))
1244
0
    {
1245
0
        s_tmp_poc.i4_delta_pic_order_cnt[0] = ih264d_sev(pu4_bitstrm_ofst,
1246
0
                                                         pu4_bitstrm_buf);
1247
0
        COPYTHECONTEXT("SH: delta_pic_order_cnt[0]",
1248
0
                        s_tmp_poc.i4_delta_pic_order_cnt[0]);
1249
0
1250
0
        if(ps_pps->u1_pic_order_present_flag && !u1_field_pic_flag)
1251
0
        {
1252
0
            s_tmp_poc.i4_delta_pic_order_cnt[1] = ih264d_sev(
1253
0
                            pu4_bitstrm_ofst, pu4_bitstrm_buf);
1254
0
            COPYTHECONTEXT("SH: delta_pic_order_cnt[1]",
1255
0
                            s_tmp_poc.i4_delta_pic_order_cnt[1]);
1256
0
        }
1257
0
    }
1258
11
1259
11
    if(ps_pps->u1_redundant_pic_cnt_present_flag)
1260
0
    {
1261
0
        u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1262
0
        if(u4_temp > MAX_REDUNDANT_PIC_CNT)
1263
0
            return ERROR_INV_SLICE_HDR_T;
1264
0
        u1_redundant_pic_cnt = u4_temp;
1265
0
        COPYTHECONTEXT("SH: redundant_pic_cnt", u1_redundant_pic_cnt);
1266
0
    }
1267
11
1268
11
    /*--------------------------------------------------------------------*/
1269
11
    /* Check if the slice is part of new picture                          */
1270
11
    /*--------------------------------------------------------------------*/
1271
11
    /* First slice of a picture is always considered as part of new picture */
1272
11
    i1_is_end_of_poc = 1;
1273
11
    ps_dec->ps_dec_err_status->u1_err_flag &= MASK_REJECT_CUR_PIC;
1274
11
1275
11
    if(ps_dec->u4_first_slice_in_pic == 0)
1276
0
    {
1277
0
        i1_is_end_of_poc = ih264d_is_end_of_pic(u2_frame_num, u1_nal_ref_idc,
1278
0
                                            &s_tmp_poc, &ps_dec->s_cur_pic_poc,
1279
0
                                            ps_cur_slice, u1_pic_order_cnt_type,
1280
0
                                            u1_nal_unit_type, u4_idr_pic_id,
1281
0
                                            u1_field_pic_flag,
1282
0
                                            u1_bottom_field_flag);
1283
0
        if(i1_is_end_of_poc)
1284
0
        {
1285
0
            ps_dec->u1_first_slice_in_stream = 0;
1286
0
            return ERROR_INCOMPLETE_FRAME;
1287
0
        }
1288
11
1289
11
    }
1290
11
1291
11
    /*--------------------------------------------------------------------*/
1292
11
    /* Check for error in slice and parse the missing/corrupted MB's      */
1293
11
    /* as skip-MB's in an inserted P-slice                                */
1294
11
    /*--------------------------------------------------------------------*/
1295
11
    u1_mbaff = ps_seq->u1_mb_aff_flag && (!u1_field_pic_flag);
1296
11
    prev_slice_err = 0;
1297
11
1298
11
    if(i1_is_end_of_poc || ps_dec->u1_first_slice_in_stream)
1299
11
    {
1300
11
        if(u2_frame_num != ps_dec->u2_prv_frame_num
1301
11
               && ps_dec->u1_top_bottom_decoded != 0
1302
11
                   && ps_dec->u1_top_bottom_decoded
1303
0
                       != (TOP_FIELD_ONLY | BOT_FIELD_ONLY))
1304
0
        {
1305
0
            ps_dec->u1_dangling_field = 1;
1306
0
            if(ps_dec->u4_first_slice_in_pic)
1307
0
            {
1308
0
                // first slice - dangling field
1309
0
                prev_slice_err = 1;
1310
0
            }
1311
0
            else
1312
0
            {
1313
0
                // last slice - dangling field
1314
0
                prev_slice_err = 2;
1315
0
            }
1316
0
1317
0
            if(ps_dec->u1_top_bottom_decoded ==TOP_FIELD_ONLY)
1318
0
                ps_cur_slice->u1_bottom_field_flag = 1;
1319
0
            else
1320
0
                ps_cur_slice->u1_bottom_field_flag = 0;
1321
0
1322
0
            num_mb_skipped = (ps_dec->u2_frm_ht_in_mbs * ps_dec->u2_frm_wd_in_mbs)
1323
0
                    - ps_dec->u2_total_mbs_coded;
1324
0
            ps_cur_poc = &ps_dec->s_cur_pic_poc;
1325
0
1326
0
            u1_is_idr_slice = ps_cur_slice->u1_nal_unit_type == IDR_SLICE_NAL;
1327
0
        }
1328
11
        else if(ps_dec->u4_first_slice_in_pic)
1329
11
        {
1330
11
            if(u2_first_mb_in_slice > 0)
1331
0
            {
1332
0
                // first slice - missing/header corruption
1333
0
                prev_slice_err = 1;
1334
0
                num_mb_skipped = u2_first_mb_in_slice << u1_mbaff;
1335
0
                ps_cur_poc = &s_tmp_poc;
1336
0
1337
0
                // initializing slice parameters
1338
0
                ps_cur_slice->u4_idr_pic_id = u4_idr_pic_id;
1339
0
                ps_cur_slice->u1_field_pic_flag = u1_field_pic_flag;
1340
0
                ps_cur_slice->u1_bottom_field_flag = u1_bottom_field_flag;
1341
0
                ps_cur_slice->i4_pic_order_cnt_lsb =
1342
0
                        s_tmp_poc.i4_pic_order_cnt_lsb;
1343
0
                ps_cur_slice->u1_nal_unit_type = u1_nal_unit_type;
1344
0
                ps_cur_slice->u1_redundant_pic_cnt = u1_redundant_pic_cnt;
1345
0
                ps_cur_slice->u1_nal_ref_idc = u1_nal_ref_idc;
1346
0
                ps_cur_slice->u1_pic_order_cnt_type = u1_pic_order_cnt_type;
1347
0
                ps_cur_slice->u1_mbaff_frame_flag = ps_seq->u1_mb_aff_flag
1348
0
                        && (!u1_field_pic_flag);
1349
0
            }
1350
11
        }
1351
0
        else
1352
0
        {
1353
0
            /* since i1_is_end_of_poc is set ,means new frame num is encountered. so conceal the current frame
1354
0
             * completely */
1355
0
            prev_slice_err = 2;
1356
0
            num_mb_skipped = (ps_dec->u2_frm_ht_in_mbs
1357
0
                            * ps_dec->u2_frm_wd_in_mbs)
1358
0
                            - ps_dec->u2_total_mbs_coded;
1359
0
            ps_cur_poc = &s_tmp_poc;
1360
0
        }
1361
11
    }
1362
0
    else
1363
0
    {
1364
0
        if((u2_first_mb_in_slice << u1_mbaff) > ps_dec->u2_total_mbs_coded)
1365
0
        {
1366
0
            // previous slice - missing/corruption
1367
0
            prev_slice_err = 2;
1368
0
            num_mb_skipped = (u2_first_mb_in_slice << u1_mbaff)
1369
0
                    - ps_dec->u2_total_mbs_coded;
1370
0
            ps_cur_poc = &s_tmp_poc;
1371
0
        }
1372
0
        else if((u2_first_mb_in_slice << u1_mbaff) < ps_dec->u2_total_mbs_coded)
1373
0
        {
1374
0
            return ERROR_CORRUPTED_SLICE;
1375
0
        }
1376
11
    }
1377
11
1378
11
    if(prev_slice_err)
1379
0
    {
1380
0
        ret = ih264d_mark_err_slice_skip(ps_dec, num_mb_skipped, u1_is_idr_slice, u2_frame_num, ps_cur_poc, prev_slice_err);
1381
0
1382
0
        if(ps_dec->u1_dangling_field == 1)
1383
0
        {
1384
0
            ps_dec->u1_second_field = 1 - ps_dec->u1_second_field;
1385
0
            ps_dec->u1_first_slice_in_stream = 0;
1386
0
            ps_dec->u1_top_bottom_decoded = TOP_FIELD_ONLY | BOT_FIELD_ONLY;
1387
0
            return ERROR_DANGLING_FIELD_IN_PIC;
1388
0
        }
1389
0
1390
0
        if(prev_slice_err == 2)
1391
0
        {
1392
0
            ps_dec->u1_first_slice_in_stream = 0;
1393
0
            return ERROR_INCOMPLETE_FRAME;
1394
0
        }
1395
0
1396
0
        if(ps_dec->u2_total_mbs_coded
1397
0
                >= ps_dec->u2_frm_ht_in_mbs * ps_dec->u2_frm_wd_in_mbs)
1398
0
        {
1399
0
            /* return if all MBs in frame are parsed*/
1400
0
            ps_dec->u1_first_slice_in_stream = 0;
1401
0
            return ERROR_IN_LAST_SLICE_OF_PIC;
1402
0
        }
1403
0
1404
0
        if(ps_dec->ps_dec_err_status->u1_err_flag & REJECT_CUR_PIC)
1405
0
        {
1406
0
            ih264d_err_pic_dispbuf_mgr(ps_dec);
1407
0
            return ERROR_NEW_FRAME_EXPECTED;
1408
0
        }
1409
0
1410
0
        if(ret != OK)
1411
0
            return ret;
1412
0
1413
0
        i1_is_end_of_poc = 0;
1414
0
    }
1415
11
1416
11
    if (ps_dec->u4_first_slice_in_pic == 0)
1417
0
    {
1418
0
        ps_dec->ps_parse_cur_slice++;
1419
0
        ps_dec->u2_cur_slice_num++;
1420
0
    }
1421
11
1422
11
    // in the case of single core increment ps_decode_cur_slice
1423
11
    if((ps_dec->u1_separate_parse == 0) && (ps_dec->u4_first_slice_in_pic == 0))
1424
0
    {
1425
0
        ps_dec->ps_decode_cur_slice++;
1426
0
    }
1427
11
    ps_dec->u1_slice_header_done = 0;
1428
11
1429
11
1430
11
    if(u1_field_pic_flag)
1431
0
    {
1432
0
        ps_dec->u2_prv_frame_num = u2_frame_num;
1433
0
    }
1434
11
1435
11
    if(ps_cur_slice->u1_mmco_equalto5)
1436
0
    {
1437
0
        WORD32 i4_temp_poc;
1438
0
        WORD32 i4_top_field_order_poc, i4_bot_field_order_poc;
1439
0
1440
0
        if(!ps_cur_slice->u1_field_pic_flag) // or a complementary field pair
1441
0
        {
1442
0
            i4_top_field_order_poc = ps_dec->ps_cur_pic->i4_top_field_order_cnt;
1443
0
            i4_bot_field_order_poc =
1444
0
                            ps_dec->ps_cur_pic->i4_bottom_field_order_cnt;
1445
0
            i4_temp_poc = MIN(i4_top_field_order_poc,
1446
0
                                     i4_bot_field_order_poc);
1447
0
        }
1448
0
        else if(!ps_cur_slice->u1_bottom_field_flag)
1449
0
            i4_temp_poc = ps_dec->ps_cur_pic->i4_top_field_order_cnt;
1450
0
        else
1451
0
            i4_temp_poc = ps_dec->ps_cur_pic->i4_bottom_field_order_cnt;
1452
0
1453
0
        ps_dec->ps_cur_pic->i4_top_field_order_cnt = i4_temp_poc
1454
0
                        - ps_dec->ps_cur_pic->i4_top_field_order_cnt;
1455
0
        ps_dec->ps_cur_pic->i4_bottom_field_order_cnt = i4_temp_poc
1456
0
                        - ps_dec->ps_cur_pic->i4_bottom_field_order_cnt;
1457
0
        ps_dec->ps_cur_pic->i4_poc = i4_temp_poc;
1458
0
        ps_dec->ps_cur_pic->i4_avg_poc = i4_temp_poc;
1459
0
    }
1460
11
    if(ps_dec->u4_first_slice_in_pic)
1461
11
    {
1462
11
        ret = ih264d_decode_pic_order_cnt(u1_is_idr_slice, u2_frame_num,
1463
11
                                          &ps_dec->s_prev_pic_poc,
1464
11
                                          &s_tmp_poc, ps_cur_slice, ps_pps,
1465
11
                                          u1_nal_ref_idc,
1466
11
                                          u1_bottom_field_flag,
1467
11
                                          u1_field_pic_flag, &i4_poc);
1468
11
        if(ret != OK)
1469
11
            return ret;
1470
11
        /* Display seq no calculations */
1471
11
        if(i4_poc >= ps_dec->i4_max_poc)
1472
11
            ps_dec->i4_max_poc = i4_poc;
1473
11
        /* IDR Picture or POC wrap around */
1474
11
        if(i4_poc == 0)
1475
11
        {
1476
11
            ps_dec->i4_prev_max_display_seq = ps_dec->i4_prev_max_display_seq
1477
11
                            + ps_dec->i4_max_poc
1478
11
                            + ps_dec->u1_max_dec_frame_buffering + 1;
1479
11
            ps_dec->i4_max_poc = 0;
1480
11
        }
1481
11
    }
1482
11
1483
11
    /*--------------------------------------------------------------------*/
1484
11
    /* Copy the values read from the bitstream to the slice header and then*/
1485
11
    /* If the slice is first slice in picture, then do Start of Picture   */
1486
11
    /* processing.                                                        */
1487
11
    /*--------------------------------------------------------------------*/
1488
11
    ps_cur_slice->i4_delta_pic_order_cnt[0] = i_delta_poc[0];
1489
11
    ps_cur_slice->i4_delta_pic_order_cnt[1] = i_delta_poc[1];
1490
11
    ps_cur_slice->u4_idr_pic_id = u4_idr_pic_id;
1491
11
    ps_cur_slice->u2_first_mb_in_slice = u2_first_mb_in_slice;
1492
11
    ps_cur_slice->u1_field_pic_flag = u1_field_pic_flag;
1493
11
    ps_cur_slice->u1_bottom_field_flag = u1_bottom_field_flag;
1494
11
    ps_cur_slice->u1_slice_type = u1_slice_type;
1495
11
    ps_cur_slice->i4_pic_order_cnt_lsb = s_tmp_poc.i4_pic_order_cnt_lsb;
1496
11
1497
11
    ps_cur_slice->u1_nal_unit_type = u1_nal_unit_type;
1498
11
    ps_cur_slice->u1_redundant_pic_cnt = u1_redundant_pic_cnt;
1499
11
    ps_cur_slice->u1_nal_ref_idc = u1_nal_ref_idc;
1500
11
    ps_cur_slice->u1_pic_order_cnt_type = u1_pic_order_cnt_type;
1501
11
1502
11
    if(ps_seq->u1_frame_mbs_only_flag)
1503
11
        ps_cur_slice->u1_direct_8x8_inference_flag =
1504
11
                        ps_seq->u1_direct_8x8_inference_flag;
1505
0
    else
1506
0
        ps_cur_slice->u1_direct_8x8_inference_flag = 1;
1507
11
1508
11
    if(u1_slice_type == B_SLICE)
1509
11
    {
1510
0
        ps_cur_slice->u1_direct_spatial_mv_pred_flag = ih264d_get_bit_h264(
1511
0
                        ps_bitstrm);
1512
0
        COPYTHECONTEXT("SH: direct_spatial_mv_pred_flag",
1513
0
                        ps_cur_slice->u1_direct_spatial_mv_pred_flag);
1514
0
1515
0
        if(ps_cur_slice->u1_direct_spatial_mv_pred_flag)
1516
0
            ps_cur_slice->pf_decodeDirect = ih264d_decode_spatial_direct;
1517
0
        else
1518
0
            ps_cur_slice->pf_decodeDirect = ih264d_decode_temporal_direct;
1519
0
        if(!((ps_pps->ps_sps->u1_mb_aff_flag) && (!u1_field_pic_flag)))
1520
0
            ps_dec->pf_mvpred = ih264d_mvpred_nonmbaffB;
1521
0
    }
1522
11
    else
1523
11
    {
1524
11
        if(!((ps_pps->ps_sps->u1_mb_aff_flag) && (!u1_field_pic_flag)))
1525
11
            ps_dec->pf_mvpred = ih264d_mvpred_nonmbaff;
1526
11
    }
1527
11
1528
11
    if(ps_dec->u4_first_slice_in_pic)
1529
11
    {
1530
11
        if(u2_first_mb_in_slice == 0)
1531
11
        {
1532
11
            ret = ih264d_start_of_pic(ps_dec, i4_poc, &s_tmp_poc, u2_frame_num, ps_pps);
1533
11
            if(ret != OK)
1534
11
                return ret;
1535
11
        }
1536
11
1537
11
        ps_dec->u4_output_present = 0;
1538
11
1539
11
        {
1540
11
            ih264d_get_next_display_field(ps_dec,
1541
11
                                          ps_dec->ps_out_buffer,
1542
11
                                          &(ps_dec->s_disp_op));
1543
11
            /* If error code is non-zero then there is no buffer available for display,
1544
11
             hence avoid format conversion */
1545
11
1546
11
            if(0 != ps_dec->s_disp_op.u4_error_code)
1547
2
            {
1548
2
                ps_dec->u4_fmt_conv_cur_row = ps_dec->s_disp_frame_info.u4_y_ht;
1549
2
            }
1550
9
            else
1551
9
                ps_dec->u4_output_present = 1;
1552
11
        }
1553
11
        if(ps_dec->u1_separate_parse == 1)
1554
11
        {
1555
11
            if(ps_dec->u4_dec_thread_created == 0)
1556
11
            {
1557
11
                ithread_create(ps_dec->pv_dec_thread_handle, NULL,
1558
11
                               (void *)ih264d_decode_picture_thread,
1559
11
                               (void *)ps_dec);
1560
11
1561
11
                ps_dec->u4_dec_thread_created = 1;
1562
11
            }
1563
11
1564
11
            if((ps_dec->u4_num_cores == 3) &&
1565
11
                            ((ps_dec->u4_app_disable_deblk_frm == 0) || ps_dec->i1_recon_in_thread3_flag)
1566
11
                            && (ps_dec->u4_bs_deblk_thread_created == 0))
1567
11
            {
1568
11
                ps_dec->u4_start_recon_deblk = 0;
1569
11
                ithread_create(ps_dec->pv_bs_deblk_thread_handle, NULL,
1570
11
                               (void *)ih264d_recon_deblk_thread,
1571
11
                               (void *)ps_dec);
1572
11
                ps_dec->u4_bs_deblk_thread_created = 1;
1573
11
            }
1574
11
        }
1575
11
1576
11
    }
1577
11
1578
11
    /* INITIALIZATION of fn ptrs for MC and formMbPartInfo functions */
1579
11
    {
1580
11
        UWORD8 uc_nofield_nombaff;
1581
11
1582
11
1583
11
1584
11
        uc_nofield_nombaff = ((ps_dec->ps_cur_slice->u1_field_pic_flag == 0)
1585
11
                        && (ps_dec->ps_cur_slice->u1_mbaff_frame_flag == 0)
1586
11
                        && (u1_slice_type != B_SLICE)
1587
11
                        && (ps_dec->ps_cur_pps->u1_wted_pred_flag == 0));
1588
11
1589
11
        /* Initialise MC and formMbPartInfo fn ptrs one time based on profile_idc */
1590
11
1591
11
        if(uc_nofield_nombaff)
1592
11
        {
1593
11
            ps_dec->p_form_mb_part_info = ih264d_form_mb_part_info_bp;
1594
11
            ps_dec->p_motion_compensate = ih264d_motion_compensate_bp;
1595
11
        }
1596
0
        else
1597
0
        {
1598
0
            ps_dec->p_form_mb_part_info = ih264d_form_mb_part_info_mp;
1599
0
            ps_dec->p_motion_compensate = ih264d_motion_compensate_mp;
1600
0
        }
1601
11
1602
11
1603
11
    }
1604
11
1605
11
    /*
1606
11
     * Decide whether to decode the current picture or not
1607
11
     */
1608
11
    {
1609
11
        dec_err_status_t * ps_err = ps_dec->ps_dec_err_status;
1610
11
        if(ps_err->u4_frm_sei_sync == u2_frame_num)
1611
0
        {
1612
0
            ps_err->u1_err_flag = ACCEPT_ALL_PICS;
1613
0
            ps_err->u4_frm_sei_sync = SYNC_FRM_DEFAULT;
1614
0
        }
1615
11
        ps_err->u4_cur_frm = u2_frame_num;
1616
11
    }
1617
11
1618
11
    /* Decision for decoding if the picture is to be skipped */
1619
11
    {
1620
11
        WORD32 i4_skip_b_pic, i4_skip_p_pic;
1621
11
1622
11
        i4_skip_b_pic = (ps_dec->u4_skip_frm_mask & B_SLC_BIT)
1623
11
                        && (B_SLICE == u1_slice_type) && (0 == u1_nal_ref_idc);
1624
11
1625
11
        i4_skip_p_pic = (ps_dec->u4_skip_frm_mask & P_SLC_BIT)
1626
11
                        && (P_SLICE == u1_slice_type) && (0 == u1_nal_ref_idc);
1627
11
1628
11
        /**************************************************************/
1629
11
        /* Skip the B picture if skip mask is set for B picture and   */
1630
11
        /* Current B picture is a non reference B picture or there is */
1631
11
        /* no user for reference B picture                            */
1632
11
        /**************************************************************/
1633
11
        if(i4_skip_b_pic)
1634
0
        {
1635
0
            ps_dec->ps_cur_pic->u4_pack_slc_typ |= B_SLC_BIT;
1636
0
            /* Don't decode the picture in SKIP-B mode if that picture is B */
1637
0
            /* and also it is not to be used as a reference picture         */
1638
0
            ps_dec->u1_last_pic_not_decoded = 1;
1639
0
1640
0
            return OK;
1641
0
        }
1642
11
        /**************************************************************/
1643
11
        /* Skip the P picture if skip mask is set for P picture and   */
1644
11
        /* Current P picture is a non reference P picture or there is */
1645
11
        /* no user for reference P picture                            */
1646
11
        /**************************************************************/
1647
11
        if(i4_skip_p_pic)
1648
0
        {
1649
0
            ps_dec->ps_cur_pic->u4_pack_slc_typ |= P_SLC_BIT;
1650
0
            /* Don't decode the picture in SKIP-P mode if that picture is P */
1651
0
            /* and also it is not to be used as a reference picture         */
1652
0
            ps_dec->u1_last_pic_not_decoded = 1;
1653
0
1654
0
            return OK;
1655
0
        }
1656
11
    }
1657
11
1658
11
    {
1659
11
        UWORD16 u2_mb_x, u2_mb_y;
1660
11
1661
11
        ps_dec->i4_submb_ofst = ((u2_first_mb_in_slice
1662
11
                        << ps_cur_slice->u1_mbaff_frame_flag) * SUB_BLK_SIZE)
1663
11
                        - SUB_BLK_SIZE;
1664
11
        if(u2_first_mb_in_slice)
1665
0
        {
1666
0
            UWORD8 u1_mb_aff;
1667
0
            UWORD8 u1_field_pic;
1668
0
            UWORD16 u2_frm_wd_in_mbs;
1669
0
            u2_frm_wd_in_mbs = ps_seq->u2_frm_wd_in_mbs;
1670
0
            u1_mb_aff = ps_cur_slice->u1_mbaff_frame_flag;
1671
0
            u1_field_pic = ps_cur_slice->u1_field_pic_flag;
1672
0
1673
0
            {
1674
0
                UWORD32 x_offset;
1675
0
                UWORD32 y_offset;
1676
0
                UWORD32 u4_frame_stride;
1677
0
                tfr_ctxt_t *ps_trns_addr; // = &ps_dec->s_tran_addrecon_parse;
1678
0
1679
0
                if(ps_dec->u1_separate_parse)
1680
0
                {
1681
0
                    ps_trns_addr = &ps_dec->s_tran_addrecon_parse;
1682
0
                }
1683
0
                else
1684
0
                {
1685
0
                    ps_trns_addr = &ps_dec->s_tran_addrecon;
1686
0
                }
1687
0
                u2_mb_x = MOD(u2_first_mb_in_slice, u2_frm_wd_in_mbs);
1688
0
                u2_mb_y = DIV(u2_first_mb_in_slice, u2_frm_wd_in_mbs);
1689
0
1690
0
                u2_mb_y <<= u1_mb_aff;
1691
0
1692
0
                if((u2_mb_x > u2_frm_wd_in_mbs - 1)
1693
0
                                || (u2_mb_y > ps_dec->u2_frm_ht_in_mbs - 1))
1694
0
                {
1695
0
                    return ERROR_CORRUPTED_SLICE;
1696
0
                }
1697
0
1698
0
                u4_frame_stride = ps_dec->u2_frm_wd_y << u1_field_pic;
1699
0
                x_offset = u2_mb_x << 4;
1700
0
                y_offset = (u2_mb_y * u4_frame_stride) << 4;
1701
0
1702
0
                ps_trns_addr->pu1_dest_y = ps_dec->s_cur_pic.pu1_buf1 + x_offset
1703
0
                                + y_offset;
1704
0
1705
0
                u4_frame_stride = ps_dec->u2_frm_wd_uv << u1_field_pic;
1706
0
                x_offset >>= 1;
1707
0
                y_offset = (u2_mb_y * u4_frame_stride) << 3;
1708
0
1709
0
                x_offset *= YUV420SP_FACTOR;
1710
0
1711
0
                ps_trns_addr->pu1_dest_u = ps_dec->s_cur_pic.pu1_buf2 + x_offset
1712
0
                                + y_offset;
1713
0
                ps_trns_addr->pu1_dest_v = ps_dec->s_cur_pic.pu1_buf3 + x_offset
1714
0
                                + y_offset;
1715
0
1716
0
                ps_trns_addr->pu1_mb_y = ps_trns_addr->pu1_dest_y;
1717
0
                ps_trns_addr->pu1_mb_u = ps_trns_addr->pu1_dest_u;
1718
0
                ps_trns_addr->pu1_mb_v = ps_trns_addr->pu1_dest_v;
1719
0
1720
0
1721
0
                // assign the deblock structure pointers to start of slice
1722
0
                if(ps_dec->u1_separate_parse == 1)
1723
0
                {
1724
0
                    ps_dec->ps_deblk_mbn = ps_dec->ps_deblk_pic
1725
0
                                    + (u2_first_mb_in_slice << u1_mb_aff);
1726
0
                }
1727
0
                else
1728
0
                {
1729
0
                        ps_dec->ps_deblk_mbn = ps_dec->ps_deblk_pic
1730
0
                                        + (u2_first_mb_in_slice << u1_mb_aff);
1731
0
                }
1732
0
1733
0
                ps_dec->u2_cur_mb_addr = (u2_first_mb_in_slice << u1_mb_aff);
1734
0
1735
0
                ps_dec->ps_mv_cur = ps_dec->s_cur_pic.ps_mv
1736
0
                                + ((u2_first_mb_in_slice << u1_mb_aff) << 4);
1737
0
            }
1738
0
        }
1739
11
        else
1740
11
        {
1741
11
            tfr_ctxt_t *ps_trns_addr;
1742
11
1743
11
            if(ps_dec->u1_separate_parse)
1744
11
            {
1745
11
                ps_trns_addr = &ps_dec->s_tran_addrecon_parse;
1746
11
            }
1747
0
            else
1748
0
            {
1749
0
                ps_trns_addr = &ps_dec->s_tran_addrecon;
1750
0
            }
1751
11
1752
11
            u2_mb_x = 0xffff;
1753
11
            u2_mb_y = 0;
1754
11
            // assign the deblock structure pointers to start of slice
1755
11
            ps_dec->u2_cur_mb_addr = 0;
1756
11
            ps_dec->ps_deblk_mbn = ps_dec->ps_deblk_pic;
1757
11
            ps_dec->ps_mv_cur = ps_dec->s_cur_pic.ps_mv;
1758
11
            ps_trns_addr->pu1_dest_y = ps_dec->s_cur_pic.pu1_buf1;
1759
11
            ps_trns_addr->pu1_dest_u = ps_dec->s_cur_pic.pu1_buf2;
1760
11
            ps_trns_addr->pu1_dest_v = ps_dec->s_cur_pic.pu1_buf3;
1761
11
1762
11
            ps_trns_addr->pu1_mb_y = ps_trns_addr->pu1_dest_y;
1763
11
            ps_trns_addr->pu1_mb_u = ps_trns_addr->pu1_dest_u;
1764
11
            ps_trns_addr->pu1_mb_v = ps_trns_addr->pu1_dest_v;
1765
11
1766
11
        }
1767
11
1768
11
        ps_dec->ps_part = ps_dec->ps_parse_part_params;
1769
11
1770
11
        ps_dec->u2_mbx =
1771
11
                        (MOD(u2_first_mb_in_slice - 1, ps_seq->u2_frm_wd_in_mbs));
1772
11
        ps_dec->u2_mby =
1773
11
                        (DIV(u2_first_mb_in_slice - 1, ps_seq->u2_frm_wd_in_mbs));
1774
11
        ps_dec->u2_mby <<= ps_cur_slice->u1_mbaff_frame_flag;
1775
11
        ps_dec->i2_prev_slice_mbx = ps_dec->u2_mbx;
1776
11
        ps_dec->i2_prev_slice_mby = ps_dec->u2_mby;
1777
11
    }
1778
11
1779
11
    /* RBSP stop bit is used for CABAC decoding*/
1780
11
    ps_bitstrm->u4_max_ofst += ps_dec->ps_cur_pps->u1_entropy_coding_mode;
1781
11
1782
11
    ps_dec->u1_B = (u1_slice_type == B_SLICE);
1783
11
    ps_dec->u4_next_mb_skip = 0;
1784
11
1785
11
    ps_dec->ps_parse_cur_slice->u4_first_mb_in_slice =
1786
11
                    ps_dec->ps_cur_slice->u2_first_mb_in_slice;
1787
11
    ps_dec->ps_parse_cur_slice->slice_type =
1788
11
                    ps_dec->ps_cur_slice->u1_slice_type;
1789
11
1790
11
1791
11
    ps_dec->u4_start_recon_deblk = 1;
1792
11
    {
1793
11
        WORD32 num_entries;
1794
11
        WORD32 size;
1795
11
        UWORD8 *pu1_buf;
1796
11
1797
11
        num_entries = MAX_FRAMES;
1798
11
        if((1 >= ps_dec->ps_cur_sps->u1_num_ref_frames) &&
1799
11
            (0 == ps_dec->i4_display_delay))
1800
0
        {
1801
0
            num_entries = 1;
1802
0
        }
1803
11
        num_entries = ((2 * num_entries) + 1);
1804
11
        num_entries *= 2;
1805
11
1806
11
1807
11
        size = num_entries * sizeof(void *);
1808
11
        size += PAD_MAP_IDX_POC * sizeof(void *);
1809
11
1810
11
        pu1_buf = (UWORD8 *)ps_dec->pv_map_ref_idx_to_poc_buf;
1811
11
        pu1_buf += size * ps_dec->u2_cur_slice_num;
1812
11
        ps_dec->ps_parse_cur_slice->ppv_map_ref_idx_to_poc = ( void *)pu1_buf;
1813
11
    }
1814
11
1815
11
    if(ps_dec->u1_separate_parse)
1816
11
    {
1817
11
        ps_dec->ps_parse_cur_slice->pv_tu_coeff_data_start = ps_dec->pv_parse_tu_coeff_data;
1818
11
    }
1819
0
    else
1820
0
    {
1821
0
        ps_dec->pv_proc_tu_coeff_data = ps_dec->pv_parse_tu_coeff_data;
1822
0
    }
1823
11
1824
11
    if(u1_slice_type == I_SLICE)
1825
11
    {
1826
11
        ps_dec->ps_cur_pic->u4_pack_slc_typ |= I_SLC_BIT;
1827
11
1828
11
        ret = ih264d_parse_islice(ps_dec, u2_first_mb_in_slice);
1829
11
        ps_dec->u1_pr_sl_type = u1_slice_type;
1830
11
        if(ps_dec->i4_pic_type != B_SLICE && ps_dec->i4_pic_type != P_SLICE)
1831
11
            ps_dec->i4_pic_type = I_SLICE;
1832
11
1833
11
    }
1834
0
    else if(u1_slice_type == P_SLICE)
1835
0
    {
1836
0
        ps_dec->ps_cur_pic->u4_pack_slc_typ |= P_SLC_BIT;
1837
0
        ret = ih264d_parse_pslice(ps_dec, u2_first_mb_in_slice);
1838
0
        ps_dec->u1_pr_sl_type = u1_slice_type;
1839
0
        if(ps_dec->i4_pic_type != B_SLICE)
1840
0
            ps_dec->i4_pic_type = P_SLICE;
1841
0
    }
1842
0
    else if(u1_slice_type == B_SLICE)
1843
0
    {
1844
0
        ps_dec->ps_cur_pic->u4_pack_slc_typ |= B_SLC_BIT;
1845
0
        ret = ih264d_parse_bslice(ps_dec, u2_first_mb_in_slice);
1846
0
        ps_dec->u1_pr_sl_type = u1_slice_type;
1847
0
        ps_dec->i4_pic_type = B_SLICE;
1848
0
    }
1849
0
    else
1850
0
        return ERROR_INV_SLC_TYPE_T;
1851
11
1852
11
    if(ps_dec->u1_slice_header_done)
1853
11
    {
1854
11
        /* set to zero to indicate a valid slice has been decoded */
1855
11
        ps_dec->u1_first_slice_in_stream = 0;
1856
11
    }
1857
11
1858
11
    if(ret != OK)
1859
11
        return ret;
1860
11
1861
11
    if(u1_nal_ref_idc != 0)
1862
11
    {
1863
11
        if(!ps_dec->ps_dpb_cmds->u1_dpb_commands_read)
1864
11
        {
1865
11
            memcpy((void *)ps_dec->ps_dpb_cmds, (void *)(&(ps_dec->s_dpb_cmds_scratch)),
1866
11
                   sizeof(dpb_commands_t));
1867
11
        }
1868
11
    }
1869
11
1870
11
    /* storing last Mb X and MbY of the slice */
1871
11
    ps_dec->i2_prev_slice_mbx = ps_dec->u2_mbx;
1872
11
    ps_dec->i2_prev_slice_mby = ps_dec->u2_mby;
1873
11
1874
11
    /* End of Picture detection */
1875
11
1876
11
    if(ps_dec->u2_total_mbs_coded >= (ps_seq->u2_max_mb_addr + 1))
1877
11
    {
1878
11
        ps_dec->u1_pic_decode_done = 1;
1879
11
1880
11
    }
1881
11
1882
11
    {
1883
11
        dec_err_status_t * ps_err = ps_dec->ps_dec_err_status;
1884
11
        if((ps_err->u1_err_flag & REJECT_PB_PICS)
1885
11
                        && (ps_err->u1_cur_pic_type == PIC_TYPE_I))
1886
0
        {
1887
0
            ps_err->u1_err_flag = ACCEPT_ALL_PICS;
1888
0
        }
1889
11
    }
1890
11
1891
11
    PRINT_BIN_BIT_RATIO(ps_dec)
1892
11
1893
11
    return ret;
1894
11
}
1895
/proc/self/cwd/external/libavc/decoder/ih264d_process_bslice.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/*!
21
 **************************************************************************
22
 * \file ih264d_process_bslice.c
23
 *
24
 * \brief
25
 *    Contains routines that decode B slice type
26
 *
27
 * Detailed_description
28
 *
29
 * \date
30
 *    21/12/2002
31
 *
32
 * \author  NS
33
 **************************************************************************
34
 */
35
#include "ih264_typedefs.h"
36
#include "ih264_macros.h"
37
#include "ih264_platform_macros.h"
38
39
#include <string.h>
40
#include "ih264d_structs.h"
41
#include "ih264d_bitstrm.h"
42
#include "ih264d_parse_cavlc.h"
43
#include "ih264d_mb_utils.h"
44
#include "ih264d_mvpred.h"
45
#include "ih264d_inter_pred.h"
46
#include "ih264d_process_pslice.h"
47
#include "ih264d_error_handler.h"
48
#include "ih264d_tables.h"
49
#include "ih264d_parse_slice.h"
50
#include "ih264d_process_pslice.h"
51
#include "ih264d_process_bslice.h"
52
#include "ih264d_tables.h"
53
#include "ih264d_parse_islice.h"
54
#include "ih264d_mvpred.h"
55
56
void ih264d_init_cabac_contexts(UWORD8 u1_slice_type, dec_struct_t * ps_dec);
57
//UWORD32 g_hits = 0;
58
//UWORD32 g_miss = 0;
59
/*!
60
 **************************************************************************
61
 * \if Function name : ih264d_decode_spatial_direct \endif
62
 *
63
 * \brief
64
 *    Decodes spatial direct mode.
65
 *
66
 * \return
67
 *    None.
68
 *    Arunoday T
69
 **************************************************************************
70
 */
71
WORD32 ih264d_decode_spatial_direct(dec_struct_t * ps_dec,
72
                                    UWORD8 u1_wd_x,
73
                                    dec_mb_info_t * ps_cur_mb_info,
74
                                    UWORD8 u1_mb_num)
75
0
{
76
0
    mv_pred_t s_mv_pred, *ps_mv;
77
0
    UWORD8 u1_col_zero_flag, u1_sub_mb_num, u1_direct_zero_pred_flag = 0;
78
0
    UWORD8 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
79
0
    mv_pred_t *ps_mv_ntop_start;
80
0
    mv_pred_t *ps_mv_nmb_start = ps_dec->ps_mv_cur + (u1_mb_num << 4);
81
0
    UWORD8 partition_size, sub_partition, u1_mb_partw, u1_mb_parth;
82
0
    UWORD8 i;
83
0
    WORD8 i1_pred, i1_ref_frame0, i1_ref_frame1;
84
0
    struct pic_buffer_t *ps_ref_frame = NULL, *ps_col_pic, *ps_pic_buff0 = NULL,
85
0
                    *ps_pic_buff1 = NULL;
86
0
87
0
    UWORD8 u1_zero_pred_cond_f, u1_zero_pred_cond_b;
88
0
    WORD16 i2_def_mv[2], i2_spat_pred_mv[4], *pi2_final_mv0, *pi2_final_mv1;
89
0
    UWORD16 ui2_mask_fwd = 0, ui2_mask_bwd = 0, u2_mask = 0;
90
0
    UWORD32 *pui32_weight_ofsts = NULL;
91
0
    directmv_t s_mvdirect;
92
0
    UWORD8 u1_colz;
93
0
    UWORD8 u1_final_ref_idx = 0;
94
0
    const UWORD8 *pu1_mb_parth = (const UWORD8 *)gau1_ih264d_mb_parth;
95
0
    const UWORD8 *pu1_mb_partw = (const UWORD8 *)gau1_ih264d_mb_partw;
96
0
    const UWORD16 sub_mask_table[] =
97
0
        { 0x33, 0x3, 0x11, 0x1 };
98
0
    const UWORD16 mask_table[] =
99
0
        { 0xffff, /*16x16 NA */
100
0
          0xff, /* 16x8*/
101
0
          0x3333, /* 8x16*/
102
0
          0x33 };/* 8x8*/
103
0
    mv_pred_t s_temp_mv_pred;
104
0
    WORD32 ret = 0;
105
0
106
0
    /* CHANGED CODE */
107
0
    ps_mv_ntop_start = ps_dec->ps_mv_cur + (u1_mb_num << 4)
108
0
                    - (ps_dec->u2_frm_wd_in_mbs << (4 + u1_mbaff)) + 12;
109
0
110
0
    /* assign default values for MotionVector as zero */
111
0
    i2_def_mv[0] = 0;
112
0
    i2_def_mv[1] = 0;
113
0
114
0
    u1_direct_zero_pred_flag = ps_dec->pf_mvpred(ps_dec, ps_cur_mb_info, ps_mv_nmb_start,
115
0
                                              ps_mv_ntop_start, &s_mv_pred, 0, 4,
116
0
                                              0, 1, B_DIRECT_SPATIAL);
117
0
118
0
    i2_spat_pred_mv[0] = s_mv_pred.i2_mv[0];
119
0
    i2_spat_pred_mv[1] = s_mv_pred.i2_mv[1];
120
0
    i2_spat_pred_mv[2] = s_mv_pred.i2_mv[2];
121
0
    i2_spat_pred_mv[3] = s_mv_pred.i2_mv[3];
122
0
123
0
    i1_ref_frame0 = s_mv_pred.i1_ref_frame[0];
124
0
    i1_ref_frame1 = s_mv_pred.i1_ref_frame[1];
125
0
126
0
    i1_ref_frame0 = (i1_ref_frame0 < 0) ? -1 : i1_ref_frame0;
127
0
    i1_ref_frame1 = (i1_ref_frame1 < 0) ? -1 : i1_ref_frame1;
128
0
129
0
    i1_pred = 0;
130
0
131
0
    {
132
0
        WORD8 u1_ref_idx, u1_ref_idx1;
133
0
        UWORD32 uc_Idx, uc_Idx1;
134
0
        UWORD8 u1_scale_ref = (ps_dec->ps_cur_slice->u1_mbaff_frame_flag
135
0
                        && ps_cur_mb_info->u1_mb_field_decodingflag);
136
0
        u1_final_ref_idx = i1_ref_frame0;
137
0
        if(i1_ref_frame0 >= 0)
138
0
        {
139
0
            /* convert RefIdx if it is MbAff */
140
0
            u1_ref_idx = i1_ref_frame0;
141
0
            u1_ref_idx1 = i1_ref_frame0;
142
0
            if(u1_scale_ref)
143
0
            {
144
0
                u1_ref_idx1 = u1_ref_idx >> 1;
145
0
                if((u1_ref_idx & 0x01) != (1 - ps_cur_mb_info->u1_topmb))
146
0
                    u1_ref_idx1 += MAX_REF_BUFS;
147
0
            }
148
0
            /* If i1_ref_frame0 < 0 then refIdxCol is obtained from ps_pic_buff1 */
149
0
            ps_pic_buff0 = ps_dec->ps_ref_pic_buf_lx[0][u1_ref_idx1];
150
0
            ps_ref_frame = ps_pic_buff0;
151
0
            i1_pred = PRED_L0;
152
0
        }
153
0
154
0
        if(i1_ref_frame1 >= 0)
155
0
        {
156
0
            /* convert RefIdx if it is MbAff */
157
0
            u1_ref_idx = i1_ref_frame1;
158
0
            u1_ref_idx1 = i1_ref_frame1;
159
0
            if(u1_scale_ref)
160
0
            {
161
0
                u1_ref_idx1 = u1_ref_idx >> 1;
162
0
                if((u1_ref_idx & 0x01) != (1 - ps_cur_mb_info->u1_topmb))
163
0
                    u1_ref_idx1 += MAX_REF_BUFS;
164
0
            }
165
0
            ps_pic_buff1 = ps_dec->ps_ref_pic_buf_lx[1][u1_ref_idx1];
166
0
            i1_pred = i1_pred | PRED_L1;
167
0
        }
168
0
        if(i1_ref_frame0 < 0)
169
0
        {
170
0
            ps_ref_frame = ps_pic_buff1;
171
0
            u1_final_ref_idx = i1_ref_frame1;
172
0
        }
173
0
174
0
        u1_zero_pred_cond_f = (u1_direct_zero_pred_flag) || (i1_ref_frame0 < 0);
175
0
        u1_zero_pred_cond_b = (u1_direct_zero_pred_flag) || (i1_ref_frame1 < 0);
176
0
177
0
        if(ps_dec->ps_cur_pps->u1_wted_bipred_idc)
178
0
        {
179
0
            uc_Idx = ((i1_ref_frame0 < 1) ? 0 : i1_ref_frame0)
180
0
                            * ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[1];
181
0
            if(u1_scale_ref)
182
0
                uc_Idx >>= 1;
183
0
            uc_Idx1 = (i1_ref_frame1 < 0) ? 0 : i1_ref_frame1;
184
0
            uc_Idx += (u1_scale_ref) ? (uc_Idx1 >> 1) : uc_Idx1;
185
0
            pui32_weight_ofsts =
186
0
                            (UWORD32*)&ps_dec->pu4_wt_ofsts[2 * X3(uc_Idx)];
187
0
188
0
            if(i1_ref_frame0 < 0)
189
0
                pui32_weight_ofsts += 1;
190
0
191
0
            if(u1_scale_ref && (ps_dec->ps_cur_pps->u1_wted_bipred_idc == 2))
192
0
            {
193
0
                WORD16 i2_ref_idx;
194
0
                i2_ref_idx = MAX(i1_ref_frame0, 0);
195
0
                i2_ref_idx *= (ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[1]
196
0
                                << 1);
197
0
                i2_ref_idx += MAX(i1_ref_frame1, 0);
198
0
                if(!ps_cur_mb_info->u1_topmb)
199
0
                    i2_ref_idx +=
200
0
                                    (ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[0]
201
0
                                                    << 1)
202
0
                                                    * (ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[1]
203
0
                                                                    << 1);
204
0
                pui32_weight_ofsts = (UWORD32*)&ps_dec->pu4_mbaff_wt_mat[2
205
0
                                * X3(i2_ref_idx)];
206
0
            }
207
0
        }
208
0
    }
209
0
210
0
    s_temp_mv_pred.i1_ref_frame[0] = i1_ref_frame0;
211
0
    s_temp_mv_pred.i1_ref_frame[1] = i1_ref_frame1;
212
0
    s_temp_mv_pred.u1_col_ref_pic_idx = ps_ref_frame->u1_mv_buf_id;
213
0
    s_temp_mv_pred.u1_pic_type = ps_ref_frame->u1_pic_type;
214
0
215
0
    /**********************************************************************/
216
0
    /* Call the function which gets the number of partitions and          */
217
0
    /* partition info of colocated Mb                                     */
218
0
    /**********************************************************************/
219
0
220
0
    ps_dec->pf_parse_mvdirect(ps_dec, ps_dec->ps_col_pic, &s_mvdirect, u1_wd_x,
221
0
                           ps_dec->i4_submb_ofst, ps_cur_mb_info);
222
0
    ps_col_pic = ps_dec->ps_col_pic;
223
0
    if((s_mvdirect.u1_col_zeroflag_change == 0) || u1_direct_zero_pred_flag)
224
0
    {
225
0
        WORD16 i2_mv_x, i2_mv_y, i2_mvX1, i2_mvY1;
226
0
        /* Most probable case */
227
0
        u1_col_zero_flag = *(ps_col_pic->pu1_col_zero_flag
228
0
                        + s_mvdirect.i4_mv_indices[0]);
229
0
        u1_col_zero_flag = u1_col_zero_flag & 0x01;
230
0
231
0
        if(u1_zero_pred_cond_f || ((i1_ref_frame0 == 0) && (u1_col_zero_flag == 1)))
232
0
        {
233
0
            i2_mv_x = 0;
234
0
            i2_mv_y = 0;
235
0
        }
236
0
        else
237
0
        {
238
0
            i2_mv_x = i2_spat_pred_mv[0];
239
0
            i2_mv_y = i2_spat_pred_mv[1];
240
0
241
0
        }
242
0
243
0
        if(u1_zero_pred_cond_b || ((i1_ref_frame1 == 0) && (u1_col_zero_flag == 1)))
244
0
        {
245
0
            i2_mvX1 = 0;
246
0
            i2_mvY1 = 0;
247
0
        }
248
0
        else
249
0
        {
250
0
            i2_mvX1 = i2_spat_pred_mv[2];
251
0
            i2_mvY1 = i2_spat_pred_mv[3];
252
0
        }
253
0
254
0
        u1_sub_mb_num = ps_dec->u1_sub_mb_num;
255
0
        u1_mb_partw = (u1_wd_x >> 2);
256
0
257
0
258
0
        if(i1_ref_frame0 >= 0)
259
0
        {
260
0
            {
261
0
               pred_info_pkd_t *ps_pred_pkd;
262
0
               WORD16 i2_mv[2];
263
0
               WORD8 i1_ref_idx= 0;
264
0
265
0
               i2_mv[0] = i2_mv_x;
266
0
               i2_mv[1] = i2_mv_y;
267
0
268
0
               ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx;
269
0
            ih264d_fill_pred_info(i2_mv,u1_mb_partw,u1_mb_partw,u1_sub_mb_num,i1_pred,
270
0
                            ps_pred_pkd,ps_pic_buff0->u1_pic_buf_id,i1_ref_idx,pui32_weight_ofsts,
271
0
                            ps_pic_buff0->u1_pic_type);
272
0
            ps_dec->u4_pred_info_pkd_idx++;
273
0
            ps_cur_mb_info->u1_num_pred_parts++;
274
0
275
0
276
0
            }
277
0
278
0
        }
279
0
280
0
        if(i1_ref_frame1 >= 0)
281
0
        {
282
0
            {
283
0
                pred_info_pkd_t *ps_pred_pkd;
284
0
               WORD16 i2_mv[2];
285
0
               WORD8 i1_ref_idx= 0;
286
0
287
0
               i2_mv[0] = i2_mvX1;
288
0
               i2_mv[1] = i2_mvY1;
289
0
290
0
               ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx;
291
0
            ih264d_fill_pred_info(i2_mv,u1_mb_partw,u1_mb_partw,u1_sub_mb_num,i1_pred,
292
0
                            ps_pred_pkd,ps_pic_buff1->u1_pic_buf_id,i1_ref_idx,pui32_weight_ofsts,
293
0
                            ps_pic_buff1->u1_pic_type);
294
0
            ps_dec->u4_pred_info_pkd_idx++;
295
0
            ps_cur_mb_info->u1_num_pred_parts++;
296
0
297
0
298
0
            }
299
0
        }
300
0
301
0
302
0
        /* Replication optimisation */
303
0
        s_temp_mv_pred.i2_mv[0] = i2_mv_x;
304
0
        s_temp_mv_pred.i2_mv[1] = i2_mv_y;
305
0
        s_temp_mv_pred.i2_mv[2] = i2_mvX1;
306
0
        s_temp_mv_pred.i2_mv[3] = i2_mvY1;
307
0
308
0
        /* Calculating colocated zero information */
309
0
        {
310
0
            /*************************************/
311
0
            /* If(bit2 and bit3 set)             */
312
0
            /* then                              */
313
0
            /*  (bit0 and bit1) => submmbmode    */
314
0
            /*  (bit2 and bit3) => mbmode        */
315
0
            /* else                              */
316
0
            /*  (bit0 and bit1) => mbmode        */
317
0
            /*************************************/
318
0
            /*UWORD8 u1_packed_mb_sub_mb_mode = sub_partition ?
319
0
             (s_mvdirect.i1_partitionsize[0]) : ((s_mvdirect.i1_partitionsize[0]) << 2);*/
320
0
            UWORD8 u1_packed_mb_sub_mb_mode = (u1_mb_partw == 2) ? 0x03 : 0;
321
0
322
0
            if(i1_ref_frame0 < 0)
323
0
            {
324
0
                i2_mv_x = i2_mvX1;
325
0
                i2_mv_y = i2_mvY1;
326
0
            }
327
0
328
0
            /* Change from left shift 4 to 6 - Varun */
329
0
            u1_colz = (ps_cur_mb_info->u1_mb_field_decodingflag << 1)
330
0
                            | ((u1_final_ref_idx == 0) && (ABS(i2_mv_x) <= 1)
331
0
                                            && (ABS(i2_mv_y) <= 1));
332
0
            u1_colz |= (u1_packed_mb_sub_mb_mode << 6);
333
0
        }
334
0
        ps_mv = ps_mv_nmb_start + u1_sub_mb_num;
335
0
        ih264d_rep_mv_colz(ps_dec, &s_temp_mv_pred, ps_mv, u1_sub_mb_num, u1_colz,
336
0
                           u1_mb_partw, u1_mb_partw);
337
0
        if(u1_wd_x == MB_SIZE)
338
0
            ps_dec->u1_currB_type = 0;
339
0
340
0
341
0
342
0
        return OK;
343
0
    }
344
0
    /***************************************************************************/
345
0
    /* If present MB is 16x16 and the partition of colocated Mb is >= PRED_8x8 */
346
0
    /* i.e 8x8 or less than 8x8 partitions then set up DMA for (0,0) and       */
347
0
    /* spatially predicted motion vector and do the multiplexing after         */
348
0
    /* motion compensation                                                     */
349
0
    /***************************************************************************/
350
0
351
0
352
0
    if((u1_wd_x == MB_SIZE) && (s_mvdirect.i1_num_partitions > 2))
353
0
    {
354
0
        ps_cur_mb_info->u1_Mux = 1;
355
0
        if(i1_ref_frame0 >= 0)
356
0
        {
357
0
358
0
            {
359
0
                pred_info_pkd_t *ps_pred_pkd;
360
0
               WORD8 i1_ref_idx= 0;
361
0
362
0
               ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx;
363
0
            ih264d_fill_pred_info(&(i2_spat_pred_mv[0]),4,4,0,i1_pred,
364
0
                            ps_pred_pkd,ps_pic_buff0->u1_pic_buf_id,i1_ref_idx,pui32_weight_ofsts,
365
0
                            ps_pic_buff0->u1_pic_type);
366
0
            ps_dec->u4_pred_info_pkd_idx++;
367
0
            ps_cur_mb_info->u1_num_pred_parts++;
368
0
369
0
370
0
            }
371
0
372
0
            /******    (0,0) Motion vectors DMA     *****/
373
0
            {
374
0
                pred_info_pkd_t *ps_pred_pkd;
375
0
               WORD16 i2_mv[2];
376
0
               WORD8 i1_ref_idx= 0;
377
0
378
0
               i2_mv[0] = 0;
379
0
               i2_mv[1] = 0;
380
0
381
0
               ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx;
382
0
            ih264d_fill_pred_info(i2_mv,4,4,0,i1_pred,
383
0
                            ps_pred_pkd,ps_pic_buff0->u1_pic_buf_id,i1_ref_idx,pui32_weight_ofsts,
384
0
                            ps_pic_buff0->u1_pic_type);
385
0
            ps_dec->u4_pred_info_pkd_idx++;
386
0
            ps_cur_mb_info->u1_num_pred_parts++;
387
0
388
0
389
0
            }
390
0
        }
391
0
        if(i1_ref_frame1 >= 0)
392
0
        {
393
0
            {
394
0
                pred_info_pkd_t *ps_pred_pkd;
395
0
               WORD16 i2_mv[2];
396
0
               WORD8 i1_ref_idx= 0;
397
0
398
0
               ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx;
399
0
            ih264d_fill_pred_info(&(i2_spat_pred_mv[2]),4,4,0,i1_pred,
400
0
                            ps_pred_pkd,ps_pic_buff1->u1_pic_buf_id,i1_ref_idx,pui32_weight_ofsts,
401
0
                            ps_pic_buff1->u1_pic_type);
402
0
            ps_dec->u4_pred_info_pkd_idx++;
403
0
            ps_cur_mb_info->u1_num_pred_parts++;
404
0
405
0
406
0
            }
407
0
408
0
            /******    (0,0) Motion vectors DMA     *****/
409
0
410
0
            {
411
0
                pred_info_pkd_t *ps_pred_pkd;
412
0
               WORD16 i2_mv[2];
413
0
               WORD8 i1_ref_idx= 0;
414
0
415
0
               i2_mv[0] = 0;
416
0
               i2_mv[1] = 0;
417
0
418
0
               ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx;
419
0
            ih264d_fill_pred_info(i2_mv,4,4,0,i1_pred,
420
0
                            ps_pred_pkd,ps_pic_buff1->u1_pic_buf_id,i1_ref_idx,pui32_weight_ofsts,
421
0
                            ps_pic_buff1->u1_pic_type);
422
0
            ps_dec->u4_pred_info_pkd_idx++;
423
0
            ps_cur_mb_info->u1_num_pred_parts++;
424
0
425
0
426
0
            }
427
0
        }
428
0
    }
429
0
430
0
    /*u1_col = *(ps_col_pic->pu1_col_zero_flag + s_mvdirect.i4_mv_indices[0]);
431
0
     u1_col &= 1;
432
0
     u1_init = 0;*/
433
0
434
0
    for(i = 0; i < s_mvdirect.i1_num_partitions; i++)
435
0
    {
436
0
        partition_size = s_mvdirect.i1_partitionsize[i];
437
0
        u1_sub_mb_num = s_mvdirect.i1_submb_num[i];
438
0
439
0
        sub_partition = partition_size >> 2;
440
0
        partition_size &= 0x3;
441
0
        u1_mb_partw = pu1_mb_partw[partition_size];
442
0
        u1_mb_parth = pu1_mb_parth[partition_size];
443
0
        u2_mask = mask_table[partition_size];
444
0
        if(sub_partition != 0)
445
0
        {
446
0
            u1_mb_partw >>= 1;
447
0
            u1_mb_parth >>= 1;
448
0
            u2_mask = sub_mask_table[partition_size];
449
0
        }
450
0
451
0
        u1_col_zero_flag = *(ps_col_pic->pu1_col_zero_flag
452
0
                        + s_mvdirect.i4_mv_indices[i]);
453
0
        u1_col_zero_flag = u1_col_zero_flag & 0x01;
454
0
455
0
        /*if(u1_col != u1_col_zero_flag)
456
0
         u1_init = 1;*/
457
0
458
0
        if(u1_zero_pred_cond_f || ((i1_ref_frame0 == 0) && (u1_col_zero_flag == 1)))
459
0
        {
460
0
            pi2_final_mv0 = &i2_def_mv[0];
461
0
            ui2_mask_fwd |= (u2_mask << u1_sub_mb_num);
462
0
        }
463
0
        else
464
0
            pi2_final_mv0 = &i2_spat_pred_mv[0];
465
0
466
0
        if(u1_zero_pred_cond_b || ((i1_ref_frame1 == 0) && (u1_col_zero_flag == 1)))
467
0
        {
468
0
            pi2_final_mv1 = &i2_def_mv[0];
469
0
            ui2_mask_bwd |= (u2_mask << u1_sub_mb_num);
470
0
        }
471
0
        else
472
0
            pi2_final_mv1 = &i2_spat_pred_mv[2];
473
0
474
0
        if(ps_cur_mb_info->u1_Mux != 1)
475
0
        {
476
0
            /*u1_sub_mb_x = u1_sub_mb_num & 0x03;
477
0
             uc_sub_mb_y = (u1_sub_mb_num >> 2);*/
478
0
            if(i1_ref_frame0 >= 0)
479
0
            {
480
0
481
0
                {
482
0
                    pred_info_pkd_t *ps_pred_pkd;
483
0
                   WORD8 i1_ref_idx= 0;
484
0
485
0
                   ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx;
486
0
                ih264d_fill_pred_info(pi2_final_mv0,u1_mb_partw,u1_mb_parth,u1_sub_mb_num,i1_pred,
487
0
                                ps_pred_pkd,ps_pic_buff0->u1_pic_buf_id,i1_ref_idx,pui32_weight_ofsts,
488
0
                                ps_pic_buff0->u1_pic_type);
489
0
                ps_dec->u4_pred_info_pkd_idx++;
490
0
                ps_cur_mb_info->u1_num_pred_parts++;
491
0
492
0
493
0
                }
494
0
495
0
            }
496
0
497
0
            if(i1_ref_frame1 >= 0)
498
0
            {
499
0
                {
500
0
                    pred_info_pkd_t *ps_pred_pkd;
501
0
                   WORD8 i1_ref_idx= 0;
502
0
503
0
                   ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx;
504
0
                ih264d_fill_pred_info(pi2_final_mv1,u1_mb_partw,u1_mb_parth,u1_sub_mb_num,i1_pred,
505
0
                                ps_pred_pkd,ps_pic_buff1->u1_pic_buf_id,i1_ref_idx,pui32_weight_ofsts,
506
0
                                ps_pic_buff1->u1_pic_type);
507
0
                ps_dec->u4_pred_info_pkd_idx++;
508
0
                ps_cur_mb_info->u1_num_pred_parts++;
509
0
510
0
511
0
                }
512
0
            }
513
0
        }
514
0
515
0
        /* Replication optimisation */
516
0
        s_temp_mv_pred.i2_mv[0] = pi2_final_mv0[0];
517
0
        s_temp_mv_pred.i2_mv[1] = pi2_final_mv0[1];
518
0
        s_temp_mv_pred.i2_mv[2] = pi2_final_mv1[0];
519
0
        s_temp_mv_pred.i2_mv[3] = pi2_final_mv1[1];
520
0
521
0
        /* Calculating colocated zero information */
522
0
        {
523
0
            WORD16 i2_mv_x = 0, i2_mv_y = 0;
524
0
            /*************************************/
525
0
            /* If(bit2 and bit3 set)             */
526
0
            /* then                              */
527
0
            /*  (bit0 and bit1) => submmbmode    */
528
0
            /*  (bit2 and bit3) => mbmode        */
529
0
            /* else                              */
530
0
            /*  (bit0 and bit1) => mbmode        */
531
0
            /*************************************/
532
0
            UWORD8 u1_packed_mb_sub_mb_mode =
533
0
                            sub_partition ? (s_mvdirect.i1_partitionsize[i]) : ((s_mvdirect.i1_partitionsize[i])
534
0
                                                            << 2);
535
0
536
0
            if(i1_ref_frame0 >= 0)
537
0
            {
538
0
                i2_mv_x = pi2_final_mv0[0];
539
0
                i2_mv_y = pi2_final_mv0[1];
540
0
            }
541
0
            else
542
0
            {
543
0
                i2_mv_x = pi2_final_mv1[0];
544
0
                i2_mv_y = pi2_final_mv1[1];
545
0
            }
546
0
547
0
            u1_colz = (ps_cur_mb_info->u1_mb_field_decodingflag << 1)
548
0
                            | ((u1_final_ref_idx == 0) && (ABS(i2_mv_x) <= 1)
549
0
                                            && (ABS(i2_mv_y) <= 1));
550
0
            u1_colz |= (u1_packed_mb_sub_mb_mode << 4);
551
0
        }
552
0
        ps_mv = ps_mv_nmb_start + u1_sub_mb_num;
553
0
        ih264d_rep_mv_colz(ps_dec, &s_temp_mv_pred, ps_mv, u1_sub_mb_num, u1_colz,
554
0
                           u1_mb_parth, u1_mb_partw);
555
0
    }
556
0
    i = 0;
557
0
    if(i1_ref_frame0 >= 0)
558
0
        ps_cur_mb_info->u2_mask[i++] = ui2_mask_fwd;
559
0
    if(i1_ref_frame1 >= 0)
560
0
        ps_cur_mb_info->u2_mask[i] = ui2_mask_bwd;
561
0
562
0
    /*if(u1_init)
563
0
     H264_DEC_DEBUG_PRINT("hit\n");
564
0
     else
565
0
     H264_DEC_DEBUG_PRINT("miss\n");*/
566
0
567
0
    return OK;
568
0
}
569
570
/*!
571
 **************************************************************************
572
 * \if Function name : ih264d_decode_temporal_direct \endif
573
 *
574
 * \brief
575
 *    Decodes temporal direct mode.
576
 *
577
 * \return
578
 *    None.
579
 *
580
 **************************************************************************
581
 */
582
WORD32 ih264d_decode_temporal_direct(dec_struct_t * ps_dec,
583
                                     UWORD8 u1_wd_x,
584
                                     dec_mb_info_t * ps_cur_mb_info,
585
                                     UWORD8 u1_mb_num)
586
0
{
587
0
    struct pic_buffer_t *ps_pic_buff0, *ps_pic_buff1, *ps_col_pic;
588
0
    mv_pred_t *ps_mv, s_temp_mv_pred;
589
0
    UWORD8 u1_sub_mb_num;
590
0
    UWORD8 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
591
0
    WORD16 i2_mv_x0, i2_mv_y0, i2_mv_x1, i2_mv_y1;
592
0
    UWORD8 u1_mb_partw, u1_mb_parth;
593
0
    UWORD8 i, partition_size, sub_partition;
594
0
    UWORD32 *pui32_weight_ofsts = NULL;
595
0
    directmv_t s_mvdirect;
596
0
    const UWORD8 *pu1_mb_parth = (const UWORD8 *)gau1_ih264d_mb_parth;
597
0
    const UWORD8 *pu1_mb_partw = (const UWORD8 *)gau1_ih264d_mb_partw;
598
0
    WORD8 c_refFrm0, c_refFrm1;
599
0
    UWORD8 u1_ref_idx0, u1_is_cur_mb_fld;
600
0
    UWORD32 pic0_poc, pic1_poc, cur_poc;
601
0
    WORD32 ret = 0;
602
0
603
0
    u1_is_cur_mb_fld = ps_cur_mb_info->u1_mb_field_decodingflag;
604
0
    ps_pic_buff1 = ps_dec->ps_ref_pic_buf_lx[1][0];
605
0
606
0
    /**********************************************************************/
607
0
    /* Call the function which gets the number of partitions and          */
608
0
    /* partition info of colocated Mb                                     */
609
0
    /**********************************************************************/
610
0
    ps_dec->pf_parse_mvdirect(ps_dec, ps_dec->ps_col_pic, &s_mvdirect, u1_wd_x,
611
0
                           ps_dec->i4_submb_ofst, ps_cur_mb_info);
612
0
    ps_col_pic = ps_dec->ps_col_pic;
613
0
614
0
    for(i = 0; i < s_mvdirect.i1_num_partitions; i++)
615
0
    {
616
0
        UWORD8 u1_colz;
617
0
        partition_size = s_mvdirect.i1_partitionsize[i];
618
0
        u1_sub_mb_num = s_mvdirect.i1_submb_num[i];
619
0
        ps_mv = ps_col_pic->ps_mv + s_mvdirect.i4_mv_indices[i];
620
0
621
0
        /* This should be removed to catch unitialized memory read */
622
0
        u1_ref_idx0 = 0;
623
0
624
0
        sub_partition = partition_size >> 2;
625
0
        partition_size &= 0x3;
626
0
        u1_mb_partw = pu1_mb_partw[partition_size];
627
0
        u1_mb_parth = pu1_mb_parth[partition_size];
628
0
        if(sub_partition != 0)
629
0
        {
630
0
            u1_mb_partw >>= 1;
631
0
            u1_mb_parth >>= 1;
632
0
        }
633
0
        c_refFrm0 = ps_mv->i1_ref_frame[0];
634
0
        c_refFrm1 = ps_mv->i1_ref_frame[1];
635
0
636
0
        if((c_refFrm0 == -1) && (c_refFrm1 == -1))
637
0
        {
638
0
            u1_ref_idx0 = 0;
639
0
            ps_pic_buff0 = ps_dec->ps_ref_pic_buf_lx[0][0];
640
0
            if(u1_mbaff && u1_is_cur_mb_fld)
641
0
            {
642
0
                if(ps_cur_mb_info->u1_topmb)
643
0
                {
644
0
                    pic0_poc = ps_pic_buff0->i4_top_field_order_cnt;
645
0
                    pic1_poc = ps_pic_buff1->i4_top_field_order_cnt;
646
0
                    cur_poc = ps_dec->ps_cur_pic->i4_top_field_order_cnt;
647
0
                }
648
0
                else
649
0
                {
650
0
                    pic1_poc = ps_pic_buff1->i4_bottom_field_order_cnt;
651
0
                    cur_poc = ps_dec->ps_cur_pic->i4_bottom_field_order_cnt;
652
0
                    ps_pic_buff1 = ps_dec->ps_ref_pic_buf_lx[1][MAX_REF_BUFS];
653
0
                    pic0_poc = ps_pic_buff0->i4_bottom_field_order_cnt;
654
0
                    ps_pic_buff0 = ps_dec->ps_ref_pic_buf_lx[0][MAX_REF_BUFS];
655
0
                }
656
0
            }
657
0
            else
658
0
            {
659
0
                pic0_poc = ps_pic_buff0->i4_avg_poc;
660
0
                pic1_poc = ps_pic_buff1->i4_avg_poc;
661
0
                cur_poc = ps_dec->ps_cur_pic->i4_poc;
662
0
            }
663
0
        }
664
0
        else
665
0
        {
666
0
            UWORD8 uc_i, u1_num_frw_ref_pics;
667
0
            UWORD8 buf_id, u1_pic_type;
668
0
            buf_id = ps_mv->u1_col_ref_pic_idx;
669
0
            u1_pic_type = ps_mv->u1_pic_type;
670
0
            if(ps_dec->ps_cur_slice->u1_field_pic_flag)
671
0
            {
672
0
                if(s_mvdirect.u1_vert_mv_scale == FRM_TO_FLD)
673
0
                {
674
0
                    u1_pic_type = TOP_FLD;
675
0
                    if(ps_dec->ps_cur_slice->u1_bottom_field_flag)
676
0
                        u1_pic_type = BOT_FLD;
677
0
                }
678
0
            }
679
0
            u1_num_frw_ref_pics =
680
0
                            ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[0];
681
0
682
0
            for(uc_i = 0; uc_i < u1_num_frw_ref_pics; uc_i++)
683
0
            {
684
0
                if(ps_dec->ps_cur_slice->u1_field_pic_flag)
685
0
                {
686
0
                    if(ps_dec->ps_ref_pic_buf_lx[0][uc_i]->u1_mv_buf_id == buf_id)
687
0
                    {
688
0
                        if(ps_dec->ps_ref_pic_buf_lx[0][uc_i]->u1_pic_type
689
0
                                        == u1_pic_type)
690
0
                        {
691
0
                            u1_ref_idx0 = uc_i;
692
0
                            break;
693
0
                        }
694
0
                    }
695
0
                }
696
0
                else
697
0
                {
698
0
                    if(ps_dec->ps_ref_pic_buf_lx[0][uc_i]->u1_mv_buf_id == buf_id)
699
0
                    {
700
0
                        u1_ref_idx0 = uc_i;
701
0
                        break;
702
0
                    }
703
0
                }
704
0
            }
705
0
706
0
            ps_pic_buff0 = ps_dec->ps_ref_pic_buf_lx[0][u1_ref_idx0];
707
0
            ps_pic_buff1 = ps_dec->ps_ref_pic_buf_lx[1][0];
708
0
709
0
            if(u1_mbaff && u1_is_cur_mb_fld)
710
0
            {
711
0
                pic0_poc = ps_pic_buff0->i4_top_field_order_cnt;
712
0
                u1_ref_idx0 <<= 1;
713
0
                if(s_mvdirect.u1_vert_mv_scale == ONE_TO_ONE)
714
0
                {
715
0
                    if(u1_pic_type == BOT_FLD)
716
0
                    {
717
0
                        pic0_poc = ps_pic_buff0->i4_bottom_field_order_cnt;
718
0
                        ps_pic_buff0 = ps_dec->ps_ref_pic_buf_lx[0][(u1_ref_idx0
719
0
                                        >> 1) + MAX_REF_BUFS];
720
0
                        if(ps_cur_mb_info->u1_topmb)
721
0
                            u1_ref_idx0++;
722
0
                    }
723
0
                    else
724
0
                    {
725
0
                        if(1 - ps_cur_mb_info->u1_topmb)
726
0
                            u1_ref_idx0++;
727
0
                    }
728
0
                }
729
0
                if(s_mvdirect.u1_vert_mv_scale == FRM_TO_FLD)
730
0
                {
731
0
                    if(1 - ps_cur_mb_info->u1_topmb)
732
0
                    {
733
0
                        pic0_poc = ps_pic_buff0->i4_bottom_field_order_cnt;
734
0
                        ps_pic_buff0 = ps_dec->ps_ref_pic_buf_lx[0][(u1_ref_idx0
735
0
                                        >> 1) + MAX_REF_BUFS];
736
0
                    }
737
0
                }
738
0
                if(ps_cur_mb_info->u1_topmb)
739
0
                {
740
0
                    pic1_poc = ps_pic_buff1->i4_top_field_order_cnt;
741
0
                    cur_poc = ps_dec->ps_cur_pic->i4_top_field_order_cnt;
742
0
                }
743
0
                else
744
0
                {
745
0
                    pic1_poc = ps_pic_buff1->i4_bottom_field_order_cnt;
746
0
                    cur_poc = ps_dec->ps_cur_pic->i4_bottom_field_order_cnt;
747
0
                    ps_pic_buff1 = ps_dec->ps_ref_pic_buf_lx[1][MAX_REF_BUFS];
748
0
                }
749
0
            }
750
0
            else
751
0
            {
752
0
                pic0_poc = ps_pic_buff0->i4_avg_poc;
753
0
                pic1_poc = ps_pic_buff1->i4_avg_poc;
754
0
                cur_poc = ps_dec->ps_cur_pic->i4_poc;
755
0
            }
756
0
        }
757
0
        {
758
0
            WORD16 i16_td;
759
0
760
0
            if(c_refFrm0 >= 0)
761
0
            {
762
0
                i2_mv_x0 = ps_mv->i2_mv[0];
763
0
                i2_mv_y0 = ps_mv->i2_mv[1];
764
0
            }
765
0
            else if(c_refFrm1 >= 0)
766
0
            {
767
0
                i2_mv_x0 = ps_mv->i2_mv[2];
768
0
                i2_mv_y0 = ps_mv->i2_mv[3];
769
0
            }
770
0
            else
771
0
            {
772
0
                i2_mv_x0 = 0;
773
0
                i2_mv_y0 = 0;
774
0
            }
775
0
            /* If FRM_TO_FLD or FLD_TO_FRM scale the "y" component of the colocated Mv*/
776
0
            if(s_mvdirect.u1_vert_mv_scale == FRM_TO_FLD)
777
0
            {
778
0
                i2_mv_y0 /= 2;
779
0
            }
780
0
            else if(s_mvdirect.u1_vert_mv_scale == FLD_TO_FRM)
781
0
            {
782
0
                i2_mv_y0 *= 2;
783
0
            }
784
0
785
0
            i16_td = pic1_poc - pic0_poc;
786
0
            if((ps_pic_buff0->u1_is_short == 0) || (i16_td == 0))
787
0
            {
788
0
                i2_mv_x1 = 0;
789
0
                i2_mv_y1 = 0;
790
0
            }
791
0
            else
792
0
            {
793
0
                WORD16 i16_tb, i16_tx, i2_dist_scale_factor, i16_temp;
794
0
795
0
                i16_td = CLIP3(-128, 127, i16_td);
796
0
                i16_tb = cur_poc - pic0_poc;
797
0
                i16_tb = CLIP3(-128, 127, i16_tb);
798
0
799
0
                i16_tx = (16384 + ABS(SIGN_POW2_DIV(i16_td, 1))) / i16_td;
800
0
                i2_dist_scale_factor = CLIP3(-1024, 1023,
801
0
                                            (((i16_tb * i16_tx) + 32) >> 6));
802
0
                i16_temp = (i2_mv_x0 * i2_dist_scale_factor + 128) >> 8;
803
0
                i2_mv_x1 = i16_temp - i2_mv_x0;
804
0
                i2_mv_x0 = i16_temp;
805
0
806
0
                i16_temp = (i2_mv_y0 * i2_dist_scale_factor + 128) >> 8;
807
0
                i2_mv_y1 = i16_temp - i2_mv_y0;
808
0
                i2_mv_y0 = i16_temp;
809
0
            }
810
0
            {
811
0
                mv_pred_t *ps_mv;
812
0
813
0
                /*u1_sub_mb_x = u1_sub_mb_num & 0x03;
814
0
                 uc_sub_mb_y = u1_sub_mb_num >> 2;*/
815
0
                if(ps_dec->ps_cur_pps->u1_wted_bipred_idc)
816
0
                {
817
0
                    UWORD8 u1_idx =
818
0
                                    u1_ref_idx0
819
0
                                                    * ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[1];
820
0
                    UWORD8 u1_scale_ref = u1_mbaff && u1_is_cur_mb_fld;
821
0
                    if(u1_scale_ref)
822
0
                        u1_idx >>= 1;
823
0
                    pui32_weight_ofsts = (UWORD32*)&ps_dec->pu4_wt_ofsts[2
824
0
                                    * X3(u1_idx)];
825
0
                    if(u1_scale_ref
826
0
                                    && (ps_dec->ps_cur_pps->u1_wted_bipred_idc
827
0
                                                    == 2))
828
0
                    {
829
0
                        WORD16 i2_ref_idx;
830
0
                        i2_ref_idx = u1_ref_idx0;
831
0
                        i2_ref_idx *=
832
0
                                        (ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[1]
833
0
                                                        << 1);
834
0
                        if(!ps_cur_mb_info->u1_topmb)
835
0
                            i2_ref_idx +=
836
0
                                            (ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[0]
837
0
                                                            << 1)
838
0
                                                            * (ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[1]
839
0
                                                                            << 1);
840
0
                        pui32_weight_ofsts =
841
0
                                        (UWORD32*)&ps_dec->pu4_mbaff_wt_mat[2
842
0
                                                        * X3(i2_ref_idx)];
843
0
                    }
844
0
                }
845
0
                {
846
0
                    pred_info_pkd_t *ps_pred_pkd;
847
0
                   WORD16 i2_mv[2];
848
0
                   WORD8 i1_ref_idx= 0;
849
0
850
0
                   i2_mv[0] = i2_mv_x0;
851
0
                   i2_mv[1] = i2_mv_y0;
852
0
853
0
                   ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx;
854
0
                ih264d_fill_pred_info(i2_mv,u1_mb_partw,u1_mb_parth,u1_sub_mb_num,PRED_L0 | PRED_L1,
855
0
                                ps_pred_pkd,ps_pic_buff0->u1_pic_buf_id,i1_ref_idx,pui32_weight_ofsts,
856
0
                                ps_pic_buff0->u1_pic_type);
857
0
                ps_dec->u4_pred_info_pkd_idx++;
858
0
                ps_cur_mb_info->u1_num_pred_parts++;
859
0
860
0
861
0
                }
862
0
                {
863
0
                   pred_info_pkd_t *ps_pred_pkd;
864
0
                   WORD16 i2_mv[2];
865
0
                   WORD8 i1_ref_idx= 0;
866
0
867
0
                   i2_mv[0] = i2_mv_x1;
868
0
                   i2_mv[1] = i2_mv_y1;
869
0
870
0
                   ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx;
871
0
                ih264d_fill_pred_info(i2_mv,u1_mb_partw,u1_mb_parth,u1_sub_mb_num,PRED_L0 | PRED_L1,
872
0
                                ps_pred_pkd,ps_pic_buff1->u1_pic_buf_id,i1_ref_idx,pui32_weight_ofsts,
873
0
                                ps_pic_buff1->u1_pic_type);
874
0
                ps_dec->u4_pred_info_pkd_idx++;
875
0
                ps_cur_mb_info->u1_num_pred_parts++;
876
0
877
0
878
0
                }
879
0
880
0
                /* Replication optimisation */
881
0
                s_temp_mv_pred.i2_mv[0] = i2_mv_x0;
882
0
                s_temp_mv_pred.i2_mv[1] = i2_mv_y0;
883
0
                s_temp_mv_pred.i2_mv[2] = i2_mv_x1;
884
0
                s_temp_mv_pred.i2_mv[3] = i2_mv_y1;
885
0
                s_temp_mv_pred.i1_ref_frame[0] = u1_ref_idx0;
886
0
                s_temp_mv_pred.i1_ref_frame[1] = 0;
887
0
                s_temp_mv_pred.u1_col_ref_pic_idx = ps_pic_buff0->u1_mv_buf_id;
888
0
                s_temp_mv_pred.u1_pic_type = ps_pic_buff0->u1_pic_type;
889
0
                ps_mv = ps_dec->ps_mv_cur + (u1_mb_num << 4) + u1_sub_mb_num;
890
0
891
0
                {
892
0
                    WORD16 i2_mv_x = 0, i2_mv_y = 0;
893
0
                    UWORD8 u1_packed_mb_sub_mb_mode =
894
0
                                    sub_partition ? (s_mvdirect.i1_partitionsize[i]) : ((s_mvdirect.i1_partitionsize[i])
895
0
                                                                    << 2);
896
0
897
0
                    if(c_refFrm0 >= 0)
898
0
                    {
899
0
                        i2_mv_x = i2_mv_x0;
900
0
                        i2_mv_y = i2_mv_y0;
901
0
                    }
902
0
                    else
903
0
                    {
904
0
                        i2_mv_x = i2_mv_x1;
905
0
                        i2_mv_y = i2_mv_y1;
906
0
                    }
907
0
908
0
                    u1_colz =
909
0
                                    (ps_cur_mb_info->u1_mb_field_decodingflag << 1)
910
0
                                                    | ((u1_ref_idx0 == 0)
911
0
                                                                    && (ABS(i2_mv_x)
912
0
                                                                                    <= 1)
913
0
                                                                    && (ABS(i2_mv_y)
914
0
                                                                                    <= 1));
915
0
                    u1_colz |= (u1_packed_mb_sub_mb_mode << 4);
916
0
                }
917
0
                ih264d_rep_mv_colz(ps_dec, &s_temp_mv_pred, ps_mv, u1_sub_mb_num,
918
0
                                   u1_colz, u1_mb_parth, u1_mb_partw);
919
0
            }
920
0
        }
921
0
    }
922
0
    /* return value set to UWORD8 to make it homogeneous  */
923
0
    /* with decodespatialdirect                           */
924
0
    return OK;
925
0
}
926
927
void ih264d_convert_frm_to_fld_list(struct pic_buffer_t *ps_ref_pic_buf_lx,
928
                                    UWORD8 *pu1_L0,
929
                                    dec_struct_t *ps_dec,
930
                                    UWORD8 u1_num_short_term_bufs)
931
0
{
932
0
    UWORD8 uc_count = *pu1_L0, i, uc_l1, uc_lx, j;
933
0
    struct pic_buffer_t *ps_ref_lx[2], *ps_ref_pic_lx;
934
0
    UWORD8 u1_bottom_field_flag;
935
0
    dec_slice_params_t *ps_cur_slice;
936
0
    UWORD8 u1_ref[2], u1_fld[2], u1_same_fld, u1_op_fld;
937
0
    UWORD32 ui_half_num_of_sub_mbs;
938
0
939
0
    uc_l1 = 0;
940
0
    uc_lx = 0;
941
0
    ps_cur_slice = ps_dec->ps_cur_slice;
942
0
    ps_ref_pic_lx = ps_ref_pic_buf_lx - MAX_REF_BUFS;
943
0
    ps_ref_lx[0] = ps_ref_pic_buf_lx;
944
0
    ps_ref_lx[1] = ps_ref_pic_buf_lx;
945
0
    u1_bottom_field_flag = ps_cur_slice->u1_bottom_field_flag;
946
0
    ui_half_num_of_sub_mbs = ((ps_dec->u2_pic_ht * ps_dec->u2_pic_wd) >> 5);
947
0
    if(u1_bottom_field_flag)
948
0
    {
949
0
        u1_ref[0] = BOT_REF;
950
0
        u1_ref[1] = TOP_REF;
951
0
        u1_fld[0] = BOT_FLD;
952
0
        u1_fld[1] = TOP_FLD;
953
0
        u1_same_fld = BOT_FLD;
954
0
        u1_op_fld = TOP_FLD;
955
0
    }
956
0
    else
957
0
    {
958
0
        u1_ref[0] = TOP_REF;
959
0
        u1_ref[1] = BOT_REF;
960
0
        u1_fld[0] = TOP_FLD;
961
0
        u1_fld[1] = BOT_FLD;
962
0
        u1_same_fld = TOP_FLD;
963
0
        u1_op_fld = BOT_FLD;
964
0
    }
965
0
966
0
    /* Create the field list starting with all the short term     */
967
0
    /* frames followed by all the long term frames. No long term  */
968
0
    /* reference field should have a list idx less than a short   */
969
0
    /* term reference field during initiailization.               */
970
0
971
0
    for(j = 0; j < 2; j++)
972
0
    {
973
0
        i = ((j == 0) ? 0 : u1_num_short_term_bufs);
974
0
        uc_count = ((j == 0) ? u1_num_short_term_bufs : *pu1_L0);
975
0
        for(; i < uc_count; i++, ps_ref_lx[0]++)
976
0
        {
977
0
            /* Search field of same parity in Frame list */
978
0
            if((ps_ref_lx[0]->u1_pic_type & u1_ref[0])) // || ((ps_ref_lx[0]->u1_picturetype & 0x3) == 0))
979
0
            {
980
0
                /* Insert PIC of same parity in RefPicList */
981
0
                ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_lx, ps_ref_lx[0]);
982
0
                ps_ref_pic_lx->i4_pic_num = (ps_ref_pic_lx->i4_pic_num * 2 + 1);
983
0
                ps_ref_pic_lx->u1_long_term_pic_num =
984
0
                                (ps_ref_pic_lx->u1_long_term_frm_idx * 2 + 1);
985
0
                ps_ref_pic_lx->u1_pic_type = u1_same_fld;
986
0
                if(u1_fld[0] & BOT_FLD)
987
0
                {
988
0
                    ps_ref_pic_lx->u1_pic_type = BOT_FLD;
989
0
                    ps_ref_pic_lx->pu1_buf1 += ps_ref_pic_lx->u2_frm_wd_y;
990
0
                    ps_ref_pic_lx->pu1_buf2 += ps_ref_pic_lx->u2_frm_wd_uv;
991
0
                    ps_ref_pic_lx->pu1_buf3 += ps_ref_pic_lx->u2_frm_wd_uv;
992
0
                    if(ps_ref_pic_lx->u1_picturetype & 0x3)
993
0
                    {
994
0
                        ps_ref_pic_lx->pu1_col_zero_flag += ui_half_num_of_sub_mbs;
995
0
                        ps_ref_pic_lx->ps_mv += ui_half_num_of_sub_mbs;
996
0
                    }
997
0
                    ps_ref_pic_lx->i4_poc =
998
0
                                    ps_ref_pic_lx->i4_bottom_field_order_cnt;
999
0
                    ps_ref_pic_lx->i4_avg_poc =
1000
0
                                    ps_ref_pic_lx->i4_bottom_field_order_cnt;
1001
0
                }
1002
0
                else
1003
0
                {
1004
0
                    ps_ref_pic_lx->u1_pic_type = TOP_FLD;
1005
0
                    ps_ref_pic_lx->i4_poc = ps_ref_pic_lx->i4_top_field_order_cnt;
1006
0
                    ps_ref_pic_lx->i4_avg_poc =
1007
0
                                    ps_ref_pic_lx->i4_top_field_order_cnt;
1008
0
                }
1009
0
1010
0
                ps_ref_pic_lx++;
1011
0
                uc_lx++;
1012
0
                /* Find field of opposite parity */
1013
0
                if(uc_l1 < uc_count && ps_ref_lx[1])
1014
0
                {
1015
0
                    while(!(ps_ref_lx[1]->u1_pic_type & u1_ref[1]))
1016
0
                    {
1017
0
                        ps_ref_lx[1]++;
1018
0
                        uc_l1++;
1019
0
                        if(uc_l1 >= uc_count)
1020
0
                            ps_ref_lx[1] = 0;
1021
0
                        if(!ps_ref_lx[1])
1022
0
                            break;
1023
0
                    }
1024
0
1025
0
                    if(ps_ref_lx[1])
1026
0
                    {
1027
0
                        uc_l1++;
1028
0
                        ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_lx,
1029
0
                                                           ps_ref_lx[1]);
1030
0
                        ps_ref_pic_lx->u1_pic_type = u1_op_fld;
1031
0
                        ps_ref_pic_lx->i4_pic_num = (ps_ref_pic_lx->i4_pic_num * 2);
1032
0
                        ps_ref_pic_lx->u1_long_term_pic_num =
1033
0
                                        (ps_ref_pic_lx->u1_long_term_frm_idx * 2);
1034
0
                        if(u1_fld[1] & BOT_FLD)
1035
0
                        {
1036
0
                            ps_ref_pic_lx->u1_pic_type = BOT_FLD;
1037
0
                            ps_ref_pic_lx->pu1_buf1 += ps_ref_pic_lx->u2_frm_wd_y;
1038
0
                            ps_ref_pic_lx->pu1_buf2 += ps_ref_pic_lx->u2_frm_wd_uv;
1039
0
                            ps_ref_pic_lx->pu1_buf3 += ps_ref_pic_lx->u2_frm_wd_uv;
1040
0
                            if(ps_ref_pic_lx->u1_picturetype & 0x3)
1041
0
                            {
1042
0
                                ps_ref_pic_lx->pu1_col_zero_flag +=
1043
0
                                                ui_half_num_of_sub_mbs;
1044
0
                                ps_ref_pic_lx->ps_mv += ui_half_num_of_sub_mbs;
1045
0
                            }
1046
0
                            ps_ref_pic_lx->i4_poc =
1047
0
                                            ps_ref_pic_lx->i4_bottom_field_order_cnt;
1048
0
                            ps_ref_pic_lx->i4_avg_poc =
1049
0
                                            ps_ref_pic_lx->i4_bottom_field_order_cnt;
1050
0
                        }
1051
0
                        else
1052
0
                        {
1053
0
                            ps_ref_pic_lx->u1_pic_type = TOP_FLD;
1054
0
                            ps_ref_pic_lx->i4_poc =
1055
0
                                            ps_ref_pic_lx->i4_top_field_order_cnt;
1056
0
                            ps_ref_pic_lx->i4_avg_poc =
1057
0
                                            ps_ref_pic_lx->i4_top_field_order_cnt;
1058
0
                        }
1059
0
                        ps_ref_pic_lx++;
1060
0
                        uc_lx++;
1061
0
                        ps_ref_lx[1]++;
1062
0
                    }
1063
0
                }
1064
0
            }
1065
0
        }
1066
0
1067
0
        /* Same parity fields are over, now insert left over opposite parity fields */
1068
0
        /** Added  if(ps_ref_lx[1]) for error checks */
1069
0
        if(ps_ref_lx[1])
1070
0
        {
1071
0
            for(; uc_l1 < uc_count; uc_l1++)
1072
0
            {
1073
0
                if(ps_ref_lx[1]->u1_pic_type & u1_ref[1])
1074
0
                {
1075
0
                    /* Insert PIC of opposite parity in RefPicList */
1076
0
                    ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_lx,
1077
0
                                                       ps_ref_lx[1]);
1078
0
                    ps_ref_pic_lx->u1_pic_type = u1_op_fld;
1079
0
                    ps_ref_pic_lx->i4_pic_num = (ps_ref_pic_lx->i4_pic_num * 2);
1080
0
                    ps_ref_pic_lx->u1_long_term_pic_num =
1081
0
                                    (ps_ref_pic_lx->u1_long_term_frm_idx * 2);
1082
0
                    if(u1_op_fld == BOT_FLD)
1083
0
                    {
1084
0
                        ps_ref_pic_lx->u1_pic_type = BOT_FLD;
1085
0
                        ps_ref_pic_lx->pu1_buf1 += ps_ref_pic_lx->u2_frm_wd_y;
1086
0
                        ps_ref_pic_lx->pu1_buf2 += ps_ref_pic_lx->u2_frm_wd_uv;
1087
0
                        ps_ref_pic_lx->pu1_buf3 += ps_ref_pic_lx->u2_frm_wd_uv;
1088
0
                        if(ps_ref_pic_lx->u1_picturetype & 0x3)
1089
0
                        {
1090
0
                            ps_ref_pic_lx->pu1_col_zero_flag +=
1091
0
                                            ui_half_num_of_sub_mbs;
1092
0
                            ps_ref_pic_lx->ps_mv += ui_half_num_of_sub_mbs;
1093
0
                        }
1094
0
                        ps_ref_pic_lx->i4_poc =
1095
0
                                        ps_ref_pic_lx->i4_bottom_field_order_cnt;
1096
0
                        ps_ref_pic_lx->i4_avg_poc =
1097
0
                                        ps_ref_pic_lx->i4_bottom_field_order_cnt;
1098
0
                    }
1099
0
                    else
1100
0
                    {
1101
0
                        ps_ref_pic_lx->i4_poc =
1102
0
                                        ps_ref_pic_lx->i4_top_field_order_cnt;
1103
0
                        ps_ref_pic_lx->i4_avg_poc =
1104
0
                                        ps_ref_pic_lx->i4_top_field_order_cnt;
1105
0
                    }
1106
0
                    ps_ref_pic_lx++;
1107
0
                    uc_lx++;
1108
0
                    ps_ref_lx[1]++;
1109
0
                }
1110
0
            }
1111
0
        }
1112
0
    }
1113
0
    *pu1_L0 = uc_lx;
1114
0
}
1115
1116
void ih264d_convert_frm_mbaff_list(dec_struct_t *ps_dec)
1117
0
{
1118
0
    struct pic_buffer_t **ps_ref_pic_lx;
1119
0
    UWORD8 u1_max_ref_idx, idx;
1120
0
    UWORD16 u2_frm_wd_y, u2_frm_wd_uv;
1121
0
    struct pic_buffer_t **ps_ref_pic_buf_lx;
1122
0
    UWORD32 u4_half_num_of_sub_mbs = ((ps_dec->u2_pic_ht * ps_dec->u2_pic_wd) >> 5);
1123
0
1124
0
    ps_ref_pic_buf_lx = ps_dec->ps_ref_pic_buf_lx[0];
1125
0
    ps_ref_pic_lx = ps_dec->ps_ref_pic_buf_lx[0];
1126
0
    u1_max_ref_idx = ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[0];
1127
0
    for(idx = 0; idx < u1_max_ref_idx; idx++)
1128
0
    {
1129
0
        ps_ref_pic_lx[idx]->u1_pic_type = TOP_FLD;
1130
0
        ps_ref_pic_lx[idx]->i4_poc = ps_ref_pic_lx[idx]->i4_top_field_order_cnt;
1131
0
1132
0
    }
1133
0
    u2_frm_wd_y = ps_dec->u2_frm_wd_y;
1134
0
    u2_frm_wd_uv = ps_dec->u2_frm_wd_uv;
1135
0
1136
0
    for(idx = 0; idx < u1_max_ref_idx; idx++)
1137
0
    {
1138
0
        *ps_ref_pic_lx[idx + MAX_REF_BUFS] = *ps_ref_pic_buf_lx[idx];
1139
0
        ps_ref_pic_lx[idx + MAX_REF_BUFS]->pu1_buf1 =
1140
0
                        ps_ref_pic_buf_lx[idx]->pu1_buf1 + u2_frm_wd_y;
1141
0
        ps_ref_pic_lx[idx + MAX_REF_BUFS]->pu1_buf2 =
1142
0
                        ps_ref_pic_buf_lx[idx]->pu1_buf2 + u2_frm_wd_uv;
1143
0
        ps_ref_pic_lx[idx + MAX_REF_BUFS]->pu1_buf3 =
1144
0
                        ps_ref_pic_buf_lx[idx]->pu1_buf3 + u2_frm_wd_uv;
1145
0
1146
0
        ps_ref_pic_lx[idx + MAX_REF_BUFS]->u1_pic_type = BOT_FLD;
1147
0
        ps_ref_pic_lx[idx + MAX_REF_BUFS]->i4_poc =
1148
0
                        ps_ref_pic_buf_lx[idx]->i4_bottom_field_order_cnt;
1149
0
        if(ps_ref_pic_buf_lx[idx]->u1_picturetype & 0x3)
1150
0
        {
1151
0
            ps_ref_pic_lx[idx + MAX_REF_BUFS]->pu1_col_zero_flag =
1152
0
                            ps_ref_pic_buf_lx[idx]->pu1_col_zero_flag
1153
0
                                            + u4_half_num_of_sub_mbs;
1154
0
            ps_ref_pic_lx[idx + MAX_REF_BUFS]->ps_mv =
1155
0
                            ps_ref_pic_buf_lx[idx]->ps_mv + u4_half_num_of_sub_mbs;
1156
0
        }
1157
0
    }
1158
0
1159
0
    if(ps_dec->u1_B)
1160
0
    {
1161
0
        ps_ref_pic_buf_lx = ps_dec->ps_ref_pic_buf_lx[1];
1162
0
        ps_ref_pic_lx = ps_dec->ps_ref_pic_buf_lx[1];
1163
0
        u1_max_ref_idx = ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[1];
1164
0
        for(idx = 0; idx < u1_max_ref_idx; idx++)
1165
0
        {
1166
0
            ps_ref_pic_lx[idx]->u1_pic_type = TOP_FLD;
1167
0
            ps_ref_pic_lx[idx]->i4_poc = ps_ref_pic_lx[idx]->i4_top_field_order_cnt;
1168
0
1169
0
        }
1170
0
1171
0
        for(idx = 0; idx < u1_max_ref_idx; idx++)
1172
0
        {
1173
0
            *ps_ref_pic_lx[idx + MAX_REF_BUFS] = *ps_ref_pic_buf_lx[idx];
1174
0
            ps_ref_pic_lx[idx + MAX_REF_BUFS]->pu1_buf1 =
1175
0
                            ps_ref_pic_buf_lx[idx]->pu1_buf1 + u2_frm_wd_y;
1176
0
            ps_ref_pic_lx[idx + MAX_REF_BUFS]->pu1_buf2 =
1177
0
                            ps_ref_pic_buf_lx[idx]->pu1_buf2 + u2_frm_wd_uv;
1178
0
            ps_ref_pic_lx[idx + MAX_REF_BUFS]->pu1_buf3 =
1179
0
                            ps_ref_pic_buf_lx[idx]->pu1_buf3 + u2_frm_wd_uv;
1180
0
            ps_ref_pic_lx[idx + MAX_REF_BUFS]->u1_pic_type = BOT_FLD;
1181
0
            ps_ref_pic_lx[idx + MAX_REF_BUFS]->i4_poc =
1182
0
                            ps_ref_pic_buf_lx[idx]->i4_bottom_field_order_cnt;
1183
0
1184
0
            if(ps_ref_pic_buf_lx[idx]->u1_picturetype & 0x3)
1185
0
            {
1186
0
                ps_ref_pic_lx[idx + MAX_REF_BUFS]->pu1_col_zero_flag =
1187
0
                                ps_ref_pic_buf_lx[idx]->pu1_col_zero_flag
1188
0
                                                + u4_half_num_of_sub_mbs;
1189
0
                ps_ref_pic_lx[idx + MAX_REF_BUFS]->ps_mv =
1190
0
                                ps_ref_pic_buf_lx[idx]->ps_mv
1191
0
                                                + u4_half_num_of_sub_mbs;
1192
0
            }
1193
0
        }
1194
0
    }
1195
0
}
1196
/*!
1197
 **************************************************************************
1198
 * \if Function name : ih264d_init_ref_idx_lx_b \endif
1199
 *
1200
 * \brief
1201
 *    Initializes forward and backward refernce lists for B slice decoding.
1202
 *
1203
 *
1204
 * \return
1205
 *    0 on Success and Error code otherwise
1206
 **************************************************************************
1207
 */
1208
void ih264d_init_ref_idx_lx_b(dec_struct_t *ps_dec)
1209
0
{
1210
0
    struct pic_buffer_t *ps_ref_pic_buf_lx;
1211
0
    dpb_manager_t *ps_dpb_mgr;
1212
0
    struct dpb_info_t *ps_next_dpb;
1213
0
    WORD32 i_cur_poc, i_max_st_poc, i_min_st_poc, i_ref_poc, i_temp_poc;
1214
0
    WORD8 i;
1215
0
    UWORD8 u1_max_lt_index, u1_min_lt_index;
1216
0
    UWORD32 u4_lt_index;
1217
0
    UWORD8 u1_field_pic_flag;
1218
0
    dec_slice_params_t *ps_cur_slice;
1219
0
    UWORD8 u1_L0, u1_L1;
1220
0
    UWORD8 u1_num_short_term_bufs;
1221
0
    UWORD8 u1_max_ref_idx_l0, u1_max_ref_idx_l1;
1222
0
1223
0
    ps_cur_slice = ps_dec->ps_cur_slice;
1224
0
    u1_field_pic_flag = ps_cur_slice->u1_field_pic_flag;
1225
0
    u1_max_ref_idx_l0 = ps_cur_slice->u1_num_ref_idx_lx_active[0]
1226
0
                    << u1_field_pic_flag;
1227
0
    u1_max_ref_idx_l1 = ps_cur_slice->u1_num_ref_idx_lx_active[1]
1228
0
                    << u1_field_pic_flag;
1229
0
1230
0
    ps_dpb_mgr = ps_dec->ps_dpb_mgr;
1231
0
    /* Get the current POC */
1232
0
    i_cur_poc = ps_dec->ps_cur_pic->i4_poc;
1233
0
1234
0
    /* Get MaxStPOC,MinStPOC,MaxLt,MinLt */
1235
0
    i_max_st_poc = i_cur_poc;
1236
0
    i_min_st_poc = i_cur_poc;
1237
0
    u1_max_lt_index = MAX_REF_BUFS + 1;
1238
0
    u1_min_lt_index = MAX_REF_BUFS + 1;
1239
0
    /* Start from ST head */
1240
0
    ps_next_dpb = ps_dpb_mgr->ps_dpb_st_head;
1241
0
    for(i = 0; i < ps_dpb_mgr->u1_num_st_ref_bufs; i++)
1242
0
    {
1243
0
        i_ref_poc = ps_next_dpb->ps_pic_buf->i4_poc;
1244
0
        if(i_ref_poc < i_cur_poc)
1245
0
        {
1246
0
            /* RefPic Buf POC is before Current POC in display order */
1247
0
            i_min_st_poc = MIN(i_min_st_poc, i_ref_poc);
1248
0
        }
1249
0
        else
1250
0
        {
1251
0
            /* RefPic Buf POC is after Current POC in display order */
1252
0
            i_max_st_poc = MAX(i_max_st_poc, i_ref_poc);
1253
0
        }
1254
0
1255
0
        /* Chase the next link */
1256
0
        ps_next_dpb = ps_next_dpb->ps_prev_short;
1257
0
    }
1258
0
1259
0
    /* Start from LT head */
1260
0
    ps_next_dpb = ps_dpb_mgr->ps_dpb_ht_head;
1261
0
    if(ps_next_dpb)
1262
0
    {
1263
0
        u1_max_lt_index = ps_next_dpb->u1_lt_idx;
1264
0
        u1_min_lt_index = ps_next_dpb->u1_lt_idx;
1265
0
    }
1266
0
    for(i = 0; i < ps_dpb_mgr->u1_num_lt_ref_bufs; i++)
1267
0
    {
1268
0
        u4_lt_index = ps_next_dpb->u1_lt_idx;
1269
0
        u1_max_lt_index = (UWORD8)(MAX(u1_max_lt_index, u4_lt_index));
1270
0
        u1_min_lt_index = (UWORD8)(MIN(u1_min_lt_index, u4_lt_index));
1271
0
1272
0
        /* Chase the next link */
1273
0
        ps_next_dpb = ps_next_dpb->ps_prev_long;
1274
0
    }
1275
0
1276
0
    /* 1. Initialize refIdxL0 */
1277
0
    u1_L0 = 0;
1278
0
    if(u1_field_pic_flag)
1279
0
    {
1280
0
        ps_ref_pic_buf_lx = ps_dpb_mgr->ps_init_dpb[0][0];
1281
0
        ps_ref_pic_buf_lx += MAX_REF_BUFS;
1282
0
        i_temp_poc = i_cur_poc;
1283
0
    }
1284
0
    else
1285
0
    {
1286
0
        ps_ref_pic_buf_lx = ps_dpb_mgr->ps_init_dpb[0][0];
1287
0
        i_temp_poc = i_cur_poc - 1;
1288
0
    }
1289
0
    /* Arrange all short term buffers in output order as given by POC */
1290
0
    /* 1.1 Arrange POC's less than CurrPOC in the descending POC order starting
1291
0
     from (CurrPOC - 1)*/
1292
0
    for(; i_temp_poc >= i_min_st_poc; i_temp_poc--)
1293
0
    {
1294
0
        /* Start from ST head */
1295
0
        ps_next_dpb = ps_dpb_mgr->ps_dpb_st_head;
1296
0
        for(i = 0; i < ps_dpb_mgr->u1_num_st_ref_bufs; i++)
1297
0
        {
1298
0
            if((WORD32)ps_next_dpb->ps_pic_buf->i4_poc == i_temp_poc)
1299
0
            {
1300
0
                /* Copy info in pic buffer */
1301
0
                ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx,
1302
0
                                                   ps_next_dpb->ps_pic_buf);
1303
0
                ps_ref_pic_buf_lx++;
1304
0
                u1_L0++;
1305
0
                break;
1306
0
            }
1307
0
            ps_next_dpb = ps_next_dpb->ps_prev_short;
1308
0
        }
1309
0
    }
1310
0
1311
0
    {
1312
0
        /* 1.2. Arrange POC's more than CurrPOC in the ascending POC order starting
1313
0
         from (CurrPOC + 1)*/
1314
0
        for(i_temp_poc = i_cur_poc + 1; i_temp_poc <= i_max_st_poc; i_temp_poc++)
1315
0
        {
1316
0
            /* Start from ST head */
1317
0
            ps_next_dpb = ps_dpb_mgr->ps_dpb_st_head;
1318
0
            for(i = 0; i < ps_dpb_mgr->u1_num_st_ref_bufs; i++)
1319
0
            {
1320
0
                if((WORD32)ps_next_dpb->ps_pic_buf->i4_poc == i_temp_poc)
1321
0
                {
1322
0
                    ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx,
1323
0
                                                       ps_next_dpb->ps_pic_buf);
1324
0
                    ps_ref_pic_buf_lx++;
1325
0
                    u1_L0++;
1326
0
                    break;
1327
0
                }
1328
0
                ps_next_dpb = ps_next_dpb->ps_prev_short;
1329
0
            }
1330
0
        }
1331
0
    }
1332
0
1333
0
    /* 1.3 Arrange all Long term buffers in ascending order, in LongtermIndex */
1334
0
    /* Start from ST head */
1335
0
1336
0
    u1_num_short_term_bufs = u1_L0;
1337
0
    for(u4_lt_index = u1_min_lt_index; u4_lt_index <= u1_max_lt_index; u4_lt_index++)
1338
0
    {
1339
0
        ps_next_dpb = ps_dpb_mgr->ps_dpb_ht_head;
1340
0
        for(i = 0; i < ps_dpb_mgr->u1_num_lt_ref_bufs; i++)
1341
0
        {
1342
0
            if(ps_next_dpb->u1_lt_idx == u4_lt_index)
1343
0
            {
1344
0
                ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx,
1345
0
                                                   ps_next_dpb->ps_pic_buf);
1346
0
                ps_ref_pic_buf_lx->u1_long_term_pic_num =
1347
0
                                ps_ref_pic_buf_lx->u1_long_term_frm_idx;
1348
0
1349
0
                ps_ref_pic_buf_lx++;
1350
0
                u1_L0++;
1351
0
                break;
1352
0
            }
1353
0
            ps_next_dpb = ps_next_dpb->ps_prev_long;
1354
0
        }
1355
0
    }
1356
0
1357
0
    if(u1_field_pic_flag)
1358
0
    {
1359
0
        /* Initialize the rest of the entries in the */
1360
0
        /* reference list to handle of errors        */
1361
0
        {
1362
0
            UWORD8 u1_i;
1363
0
            pic_buffer_t *ps_ref_pic;
1364
0
1365
0
            ps_ref_pic = ps_dpb_mgr->ps_init_dpb[0][0] + MAX_REF_BUFS;
1366
0
1367
0
            if(NULL == ps_ref_pic->pu1_buf1)
1368
0
            {
1369
0
                ps_ref_pic = ps_dec->ps_cur_pic;
1370
0
            }
1371
0
            for(u1_i = u1_L0; u1_i < u1_max_ref_idx_l0; u1_i++)
1372
0
            {
1373
0
                *ps_ref_pic_buf_lx = *ps_ref_pic;
1374
0
                ps_ref_pic_buf_lx++;
1375
0
            }
1376
0
        }
1377
0
        ih264d_convert_frm_to_fld_list(
1378
0
                        ps_dpb_mgr->ps_init_dpb[0][0] + MAX_REF_BUFS, &u1_L0,
1379
0
                        ps_dec, u1_num_short_term_bufs);
1380
0
1381
0
        ps_ref_pic_buf_lx = ps_dpb_mgr->ps_init_dpb[0][0] + u1_L0;
1382
0
    }
1383
0
1384
0
    ps_dec->ps_cur_slice->u1_initial_list_size[0] = u1_L0;
1385
0
1386
0
    /* Initialize the rest of the entries in the */
1387
0
    /* reference list to handle of errors        */
1388
0
    {
1389
0
        UWORD8 u1_i;
1390
0
        pic_buffer_t *ps_ref_pic;
1391
0
1392
0
        ps_ref_pic = ps_dpb_mgr->ps_init_dpb[0][0];
1393
0
1394
0
        if(NULL == ps_ref_pic->pu1_buf1)
1395
0
        {
1396
0
            ps_ref_pic = ps_dec->ps_cur_pic;
1397
0
        }
1398
0
        for(u1_i = u1_L0; u1_i < u1_max_ref_idx_l0; u1_i++)
1399
0
        {
1400
0
            *ps_ref_pic_buf_lx = *ps_ref_pic;
1401
0
            ps_ref_pic_buf_lx++;
1402
0
        }
1403
0
    }
1404
0
    {
1405
0
        /* 2. Initialize refIdxL1 */
1406
0
        u1_L1 = 0;
1407
0
        if(u1_field_pic_flag)
1408
0
        {
1409
0
            ps_ref_pic_buf_lx = ps_dpb_mgr->ps_init_dpb[1][0] + MAX_REF_BUFS;
1410
0
        }
1411
0
        else
1412
0
        {
1413
0
            ps_ref_pic_buf_lx = ps_dpb_mgr->ps_init_dpb[1][0];
1414
0
        }
1415
0
1416
0
        /* 2.1. Arrange POC's more than CurrPOC in the ascending POC order starting
1417
0
         from (CurrPOC + 1)*/
1418
0
        for(i_temp_poc = i_cur_poc + 1; i_temp_poc <= i_max_st_poc; i_temp_poc++)
1419
0
        {
1420
0
            /* Start from ST head */
1421
0
            ps_next_dpb = ps_dpb_mgr->ps_dpb_st_head;
1422
0
            for(i = 0; i < ps_dpb_mgr->u1_num_st_ref_bufs; i++)
1423
0
            {
1424
0
                if((WORD32)ps_next_dpb->ps_pic_buf->i4_poc == i_temp_poc)
1425
0
                {
1426
0
                    ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx,
1427
0
                                                       ps_next_dpb->ps_pic_buf);
1428
0
                    ps_ref_pic_buf_lx++;
1429
0
                    u1_L1++;
1430
0
                    break;
1431
0
                }
1432
0
                ps_next_dpb = ps_next_dpb->ps_prev_short;
1433
0
            }
1434
0
        }
1435
0
1436
0
        if(u1_field_pic_flag)
1437
0
        {
1438
0
            i_temp_poc = i_cur_poc;
1439
0
        }
1440
0
        else
1441
0
        {
1442
0
            i_temp_poc = i_cur_poc - 1;
1443
0
        }
1444
0
1445
0
        /* Arrange all short term buffers in output order as given by POC */
1446
0
        /* 2.2 Arrange POC's less than CurrPOC in the descending POC order starting
1447
0
         from (CurrPOC - 1)*/
1448
0
        for(; i_temp_poc >= i_min_st_poc; i_temp_poc--)
1449
0
        {
1450
0
            /* Start from ST head */
1451
0
            ps_next_dpb = ps_dpb_mgr->ps_dpb_st_head;
1452
0
            for(i = 0; i < ps_dpb_mgr->u1_num_st_ref_bufs; i++)
1453
0
            {
1454
0
                if((WORD32)ps_next_dpb->ps_pic_buf->i4_poc == i_temp_poc)
1455
0
                {
1456
0
                    ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx,
1457
0
                                                       ps_next_dpb->ps_pic_buf);
1458
0
                    ps_ref_pic_buf_lx++;
1459
0
                    u1_L1++;
1460
0
                    break;
1461
0
                }
1462
0
                ps_next_dpb = ps_next_dpb->ps_prev_short;
1463
0
            }
1464
0
        }
1465
0
1466
0
        /* 2.3 Arrange all Long term buffers in ascending order, in LongtermIndex */
1467
0
        /* Start from ST head */
1468
0
        u1_num_short_term_bufs = u1_L1;
1469
0
1470
0
        for(u4_lt_index = u1_min_lt_index; u4_lt_index <= u1_max_lt_index;
1471
0
                        u4_lt_index++)
1472
0
        {
1473
0
            ps_next_dpb = ps_dpb_mgr->ps_dpb_ht_head;
1474
0
            for(i = 0; i < ps_dpb_mgr->u1_num_lt_ref_bufs; i++)
1475
0
            {
1476
0
                if(ps_next_dpb->u1_lt_idx == u4_lt_index)
1477
0
                {
1478
0
                    ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx,
1479
0
                                                       ps_next_dpb->ps_pic_buf);
1480
0
                    ps_ref_pic_buf_lx->u1_long_term_pic_num =
1481
0
                                    ps_ref_pic_buf_lx->u1_long_term_frm_idx;
1482
0
                    ps_ref_pic_buf_lx++;
1483
0
                    u1_L1++;
1484
0
                    break;
1485
0
                }
1486
0
                ps_next_dpb = ps_next_dpb->ps_prev_long;
1487
0
            }
1488
0
        }
1489
0
1490
0
        if(u1_field_pic_flag)
1491
0
        {
1492
0
            /* Initialize the rest of the entries in the */
1493
0
            /* reference list to handle of errors        */
1494
0
            {
1495
0
                UWORD8 u1_i;
1496
0
                pic_buffer_t *ps_ref_pic;
1497
0
1498
0
                ps_ref_pic = ps_dpb_mgr->ps_init_dpb[0][0] + MAX_REF_BUFS;
1499
0
1500
0
                if(NULL == ps_ref_pic->pu1_buf1)
1501
0
                {
1502
0
                    ps_ref_pic = ps_dec->ps_cur_pic;
1503
0
                }
1504
0
                for(u1_i = u1_L1; u1_i < u1_max_ref_idx_l1; u1_i++)
1505
0
                {
1506
0
                    *ps_ref_pic_buf_lx = *ps_ref_pic;
1507
0
                    ps_ref_pic_buf_lx++;
1508
0
                }
1509
0
            }
1510
0
1511
0
            ih264d_convert_frm_to_fld_list(
1512
0
                            ps_dpb_mgr->ps_init_dpb[1][0] + MAX_REF_BUFS,
1513
0
                            &u1_L1, ps_dec, u1_num_short_term_bufs);
1514
0
            ps_ref_pic_buf_lx = ps_dpb_mgr->ps_init_dpb[1][0] + u1_L1;
1515
0
        }
1516
0
1517
0
        ps_dec->ps_cur_slice->u1_initial_list_size[1] = u1_L1;
1518
0
1519
0
        /* Initialize the rest of the entries in the */
1520
0
        /* reference list to handle of errors        */
1521
0
        {
1522
0
            UWORD8 u1_i;
1523
0
            pic_buffer_t *ps_ref_pic;
1524
0
1525
0
            ps_ref_pic = ps_dpb_mgr->ps_init_dpb[0][0];
1526
0
1527
0
            if(NULL == ps_ref_pic->pu1_buf1)
1528
0
            {
1529
0
                ps_ref_pic = ps_dec->ps_cur_pic;
1530
0
            }
1531
0
            for(u1_i = u1_L1; u1_i < u1_max_ref_idx_l1; u1_i++)
1532
0
            {
1533
0
                *ps_ref_pic_buf_lx = *ps_ref_pic;
1534
0
                ps_ref_pic_buf_lx++;
1535
0
            }
1536
0
        }
1537
0
1538
0
        /* If list0 and list 1 ebtries are same then swap the 0th and 1st entry */
1539
0
        /* of list 1                                                            */
1540
0
        {
1541
0
            struct pic_buffer_t *ps_ref_pic1_buf_l0, *ps_ref_pic1_buf_l1;
1542
0
            struct pic_buffer_t s_ref_pic1_buf_temp;
1543
0
1544
0
            ps_ref_pic1_buf_l0 = ps_dpb_mgr->ps_init_dpb[0][0];
1545
0
            ps_ref_pic1_buf_l1 = ps_dpb_mgr->ps_init_dpb[1][0];
1546
0
1547
0
            if((u1_L0 == u1_L1) && (u1_L0 > 1))
1548
0
            {
1549
0
                WORD32 i_index, i_swap;
1550
0
1551
0
                i_swap = 1;
1552
0
1553
0
                for(i_index = 0; i_index < u1_L0; i_index++)
1554
0
                {
1555
0
                    if((ps_ref_pic1_buf_l0[i_index]).pu1_buf1
1556
0
                                    != (ps_ref_pic1_buf_l1[i_index]).pu1_buf1)
1557
0
                    {
1558
0
                        i_swap = 0;
1559
0
                        break;
1560
0
                    }
1561
0
                }
1562
0
                if(1 == i_swap)
1563
0
                {
1564
0
                    memcpy(&s_ref_pic1_buf_temp, &ps_ref_pic1_buf_l1[1],
1565
0
                           sizeof(struct pic_buffer_t));
1566
0
                    memcpy(&ps_ref_pic1_buf_l1[1], &ps_ref_pic1_buf_l1[0],
1567
0
                           sizeof(struct pic_buffer_t));
1568
0
                    memcpy(&ps_ref_pic1_buf_l1[0], &s_ref_pic1_buf_temp,
1569
0
                           sizeof(struct pic_buffer_t));
1570
0
                }
1571
0
            }
1572
0
        }
1573
0
    }
1574
0
}
1575
1576
1577
1578
void ih264d_get_implicit_weights(dec_struct_t *ps_dec);
1579
1580
/*!
1581
 **************************************************************************
1582
 * \if Function name : ih264d_one_to_one \endif
1583
 *
1584
 * \brief
1585
 *    Initializes forward and backward refernce lists for B slice decoding.
1586
 *
1587
 *
1588
 * \return
1589
 *    0 on Success and Error code otherwise
1590
 **************************************************************************
1591
 */
1592
void ih264d_one_to_one(dec_struct_t *ps_dec,
1593
                       struct pic_buffer_t *ps_col_pic,
1594
                       directmv_t *ps_direct,
1595
                       UWORD8 u1_wd_x,
1596
                       WORD32 u2_sub_mb_ofst,
1597
                       dec_mb_info_t * ps_cur_mb_info)
1598
0
{
1599
0
    UWORD8 *pu1_col_zero_flag_start, u1_col_mb_pred_mode, u1_num_blks, u1_sub_mb_num;
1600
0
    UWORD8 u1_init_colzero_flag;
1601
0
    UNUSED(ps_cur_mb_info);
1602
0
    pu1_col_zero_flag_start = ps_col_pic->pu1_col_zero_flag + u2_sub_mb_ofst;
1603
0
    u1_col_mb_pred_mode = pu1_col_zero_flag_start[ps_dec->u1_sub_mb_num];
1604
0
    u1_init_colzero_flag = u1_col_mb_pred_mode & 1;
1605
0
    u1_col_mb_pred_mode >>= 6;
1606
0
    ps_direct->u1_vert_mv_scale = ONE_TO_ONE;
1607
0
    ps_direct->u1_col_zeroflag_change = 0;
1608
0
1609
0
    if(u1_wd_x == MB_SIZE)
1610
0
    {
1611
0
        ps_dec->u1_currB_type = (!!u1_col_mb_pred_mode);
1612
0
        if(u1_col_mb_pred_mode == PRED_16x16)
1613
0
        {
1614
0
            ps_direct->i1_num_partitions = 1;
1615
0
            ps_direct->i4_mv_indices[0] = u2_sub_mb_ofst;
1616
0
            ps_direct->i1_submb_num[0] = 0;
1617
0
            ps_direct->i1_partitionsize[0] = PRED_16x16;
1618
0
1619
0
            return;
1620
0
        }
1621
0
        else if(u1_col_mb_pred_mode < PRED_8x8)
1622
0
        {
1623
0
            ps_direct->i1_num_partitions = 2;
1624
0
            ps_direct->i4_mv_indices[0] = u2_sub_mb_ofst;
1625
0
            ps_direct->i1_submb_num[0] = 0;
1626
0
            ps_direct->i1_partitionsize[0] = u1_col_mb_pred_mode;
1627
0
            u1_sub_mb_num = (u1_col_mb_pred_mode == PRED_16x8) ? 8 : 2;
1628
0
            ps_direct->i1_submb_num[1] = u1_sub_mb_num;
1629
0
            ps_direct->i4_mv_indices[1] = u2_sub_mb_ofst
1630
0
                            + ps_direct->i1_submb_num[1];
1631
0
            ps_direct->i1_partitionsize[1] = u1_col_mb_pred_mode;
1632
0
            if((pu1_col_zero_flag_start[u1_sub_mb_num] & 1) != u1_init_colzero_flag)
1633
0
                ps_direct->u1_col_zeroflag_change = 1;
1634
0
            return;
1635
0
        }
1636
0
        else
1637
0
        {
1638
0
            u1_num_blks = 4;
1639
0
        }
1640
0
    }
1641
0
    else
1642
0
    {
1643
0
        u1_num_blks = 1;
1644
0
    }
1645
0
1646
0
    {
1647
0
        const UWORD8 *pu1_top_lt_mb_part_idx;
1648
0
        UWORD8 u1_col_sub_mb_pred_mode, uc_blk, u1_sub_blk, u1_submb_col = 0;
1649
0
        UWORD8 u1_num_sub_blks, uc_direct8x8inf, *pu1_col_zero_flag, u1_sub_mb_num;
1650
0
        const UWORD8 *pu1_num_sub_mb_part =
1651
0
                        (const UWORD8 *)gau1_ih264d_num_submb_part;
1652
0
        UWORD8 i1_num_partitions = 0, partition_size;
1653
0
        WORD32 mv_index;
1654
0
        const UWORD8 *pu1_top_lt_sub_mb_idx = gau1_ih264d_submb_indx_mod_sp_drct;
1655
0
1656
0
        u1_sub_mb_num = ps_dec->u1_sub_mb_num;
1657
0
        uc_direct8x8inf = ps_dec->ps_cur_slice->u1_direct_8x8_inference_flag;
1658
0
        pu1_top_lt_mb_part_idx = gau1_ih264d_top_left_mb_part_indx_mod
1659
0
                        + (PRED_8x8 << 1) + 1;
1660
0
1661
0
        for(uc_blk = 0; uc_blk < u1_num_blks; uc_blk++)
1662
0
        {
1663
0
            partition_size = PRED_8x8;
1664
0
            pu1_top_lt_sub_mb_idx = gau1_ih264d_submb_indx_mod_sp_drct;
1665
0
            if(uc_direct8x8inf == 1)
1666
0
            {
1667
0
                u1_submb_col = u1_sub_mb_num | (u1_sub_mb_num >> 1);
1668
0
                mv_index = u2_sub_mb_ofst + u1_submb_col;
1669
0
                u1_num_sub_blks = 1;
1670
0
            }
1671
0
            else
1672
0
            {
1673
0
                /* colMbPart is either 8x8, 8x4, 4x8, 4x4 */
1674
0
                pu1_col_zero_flag = pu1_col_zero_flag_start + u1_sub_mb_num;
1675
0
                u1_col_sub_mb_pred_mode = *pu1_col_zero_flag;
1676
0
                u1_col_sub_mb_pred_mode = (u1_col_sub_mb_pred_mode & 0x30) >> 4;
1677
0
                partition_size = (UWORD8)((u1_col_sub_mb_pred_mode)
1678
0
                                | (PRED_8x8 << 2));
1679
0
                mv_index = u2_sub_mb_ofst + u1_sub_mb_num;
1680
0
                pu1_top_lt_sub_mb_idx += (u1_col_sub_mb_pred_mode << 1);
1681
0
                u1_num_sub_blks = pu1_num_sub_mb_part[u1_col_sub_mb_pred_mode];
1682
0
1683
0
            }
1684
0
1685
0
            for(u1_sub_blk = 0; u1_sub_blk < u1_num_sub_blks;
1686
0
                            u1_sub_blk++, pu1_top_lt_sub_mb_idx++)
1687
0
            {
1688
0
                u1_sub_mb_num += *pu1_top_lt_sub_mb_idx;
1689
0
                mv_index += *pu1_top_lt_sub_mb_idx;
1690
0
                ps_direct->i4_mv_indices[i1_num_partitions] = mv_index;
1691
0
                ps_direct->i1_submb_num[i1_num_partitions] = u1_sub_mb_num;
1692
0
                ps_direct->i1_partitionsize[i1_num_partitions] = partition_size;
1693
0
                i1_num_partitions++;
1694
0
                if(!uc_direct8x8inf)
1695
0
                    u1_submb_col = u1_sub_mb_num;
1696
0
                if((pu1_col_zero_flag_start[u1_submb_col] & 1)
1697
0
                                != u1_init_colzero_flag)
1698
0
                    ps_direct->u1_col_zeroflag_change = 1;
1699
0
            }
1700
0
            u1_sub_mb_num = *pu1_top_lt_mb_part_idx++;
1701
0
        }
1702
0
        ps_direct->i1_num_partitions = i1_num_partitions;
1703
0
    }
1704
0
}
1705
/*!
1706
 **************************************************************************
1707
 * \if Function name : ih264d_mbaff_cross_pmbair \endif
1708
 *
1709
 * \brief
1710
 *    Initializes forward and backward refernce lists for B slice decoding.
1711
 *
1712
 *
1713
 * \return
1714
 *    0 on Success and Error code otherwise
1715
 **************************************************************************
1716
 */
1717
void ih264d_mbaff_cross_pmbair(dec_struct_t *ps_dec,
1718
                               struct pic_buffer_t *ps_col_pic,
1719
                               directmv_t *ps_direct,
1720
                               UWORD8 u1_wd_x,
1721
                               WORD32 u2_sub_mb_ofst,
1722
                               dec_mb_info_t * ps_cur_mb_info)
1723
0
{
1724
0
    UWORD8 *pu1_col_zero_flag_start, *pu1_col_zero_flag, u1_sub_mb_num,
1725
0
                    uc_sub_mb_num_col;
1726
0
    UWORD8 *pu1_col_zero_flag_right_half;
1727
0
    WORD32 i4_force_8X8;
1728
0
    UWORD8 u1_num_blks, u1_col_mb_pred_mode, uc_blk, u1_col_sub_mb_pred_mode,
1729
0
                    u1_col_sub_mb_pred_mode_rt;
1730
0
    UWORD8 i1_num_partitions = 0, partition_size;
1731
0
1732
0
    WORD32 mv_index;
1733
0
1734
0
    UWORD8 u1_num_sub_blks;
1735
0
    UWORD8 u1_is_cur_mb_fld, i;
1736
0
    UWORD8 u1_init_colzero_flag;
1737
0
1738
0
    u1_is_cur_mb_fld = ps_cur_mb_info->u1_mb_field_decodingflag;
1739
0
    u1_sub_mb_num = ps_dec->u1_sub_mb_num;
1740
0
    ps_direct->u1_col_zeroflag_change = 0;
1741
0
    /*pu1_col_zero_flag_start = ps_col_pic->pu1_col_zero_flag + u2_sub_mb_ofst;
1742
0
     u1_col_mb_pred_mode = pu1_col_zero_flag_start[u1_sub_mb_num];
1743
0
     u1_init_colzero_flag = u1_col_mb_pred_mode & 1;
1744
0
     u1_col_mb_pred_mode >>= 6; */
1745
0
    if(0 == u1_is_cur_mb_fld)
1746
0
    {
1747
0
        ps_direct->u1_vert_mv_scale = FLD_TO_FRM;
1748
0
        if(u1_wd_x == MB_SIZE)
1749
0
        {
1750
0
            pu1_col_zero_flag_start = ps_col_pic->pu1_col_zero_flag
1751
0
                            + u2_sub_mb_ofst;
1752
0
            u1_col_mb_pred_mode = pu1_col_zero_flag_start[0];
1753
0
            u1_init_colzero_flag = u1_col_mb_pred_mode & 1;
1754
0
            u1_col_mb_pred_mode >>= 6;
1755
0
1756
0
1757
0
            if(u1_col_mb_pred_mode & 0x2)
1758
0
            {
1759
0
                ps_dec->u1_currB_type = 1;
1760
0
                if(u1_col_mb_pred_mode == PRED_8x16)
1761
0
                {
1762
0
                    ps_direct->i1_num_partitions = 2;
1763
0
                    ps_direct->i4_mv_indices[0] = u2_sub_mb_ofst;
1764
0
                    ps_direct->i1_submb_num[0] = 0;
1765
0
                    ps_direct->i1_partitionsize[0] = PRED_8x16;
1766
0
                    ps_direct->i4_mv_indices[1] = u2_sub_mb_ofst + 2;
1767
0
                    ps_direct->i1_submb_num[1] = 2;
1768
0
                    ps_direct->i1_partitionsize[1] = PRED_8x16;
1769
0
                    if((pu1_col_zero_flag_start[2] & 1) != u1_init_colzero_flag)
1770
0
                        ps_direct->u1_col_zeroflag_change = 1;
1771
0
                }
1772
0
                else
1773
0
                {
1774
0
                    pu1_col_zero_flag = pu1_col_zero_flag_start + u1_sub_mb_num;
1775
0
                    u1_col_sub_mb_pred_mode = (*pu1_col_zero_flag & 0x10);/* 8x4 or 4x4 mode */
1776
0
1777
0
                    pu1_col_zero_flag_right_half = pu1_col_zero_flag_start
1778
0
                                    + u1_sub_mb_num + 2;
1779
0
                    u1_col_sub_mb_pred_mode_rt =
1780
0
                                    (*pu1_col_zero_flag_right_half & 0x10);/* 8x4 or 4x4 mode */
1781
0
1782
0
                    i4_force_8X8 = (u1_col_sub_mb_pred_mode)
1783
0
                                    || (u1_col_sub_mb_pred_mode_rt);
1784
0
                    if(i4_force_8X8)
1785
0
                    {
1786
0
                        u1_num_sub_blks = 2;
1787
0
                        partition_size = PRED_8x8;
1788
0
                    }
1789
0
                    else
1790
0
                    {
1791
0
                        partition_size = PRED_8x16;
1792
0
                        u1_num_sub_blks = 1;
1793
0
                    }
1794
0
1795
0
                    for(i = 0; i < 2; i++)
1796
0
                    {
1797
0
                        for(uc_blk = 0; uc_blk < u1_num_sub_blks; uc_blk++)
1798
0
                        {
1799
0
                            uc_sub_mb_num_col = u1_sub_mb_num | (u1_sub_mb_num >> 1);
1800
0
                            uc_sub_mb_num_col &= 0x7;
1801
0
                            mv_index = u2_sub_mb_ofst + uc_sub_mb_num_col;
1802
0
1803
0
                            ps_direct->i4_mv_indices[i1_num_partitions] =
1804
0
                                            mv_index;
1805
0
                            ps_direct->i1_submb_num[i1_num_partitions] =
1806
0
                                            u1_sub_mb_num;
1807
0
                            ps_direct->i1_partitionsize[i1_num_partitions] =
1808
0
                                            partition_size;
1809
0
                            i1_num_partitions++;
1810
0
                            if((pu1_col_zero_flag_start[uc_sub_mb_num_col] & 1)
1811
0
                                            != u1_init_colzero_flag)
1812
0
                                ps_direct->u1_col_zeroflag_change = 1;
1813
0
                            u1_sub_mb_num += 8;
1814
0
                        }
1815
0
                        u1_sub_mb_num = 2; /* move to second half of Cur MB */
1816
0
                    }
1817
0
                    ps_direct->i1_num_partitions = i1_num_partitions;
1818
0
                    return;
1819
0
                }
1820
0
            }
1821
0
            else
1822
0
            {
1823
0
                ps_direct->i1_num_partitions = 1;
1824
0
                ps_direct->i4_mv_indices[0] = u2_sub_mb_ofst;
1825
0
                ps_direct->i1_submb_num[0] = 0;
1826
0
                ps_direct->i1_partitionsize[0] = PRED_16x16;
1827
0
                ps_dec->u1_currB_type = 0;
1828
0
                return;
1829
0
            }
1830
0
        }
1831
0
        else
1832
0
        {
1833
0
            uc_sub_mb_num_col = u1_sub_mb_num | (u1_sub_mb_num >> 1);
1834
0
            uc_sub_mb_num_col &= 0x7;
1835
0
1836
0
            ps_direct->i4_mv_indices[0] = u2_sub_mb_ofst + uc_sub_mb_num_col;
1837
0
            ps_direct->i1_submb_num[0] = u1_sub_mb_num;
1838
0
            ps_direct->i1_partitionsize[0] = PRED_8x8;
1839
0
            ps_direct->i1_num_partitions = 1;
1840
0
        }
1841
0
    }
1842
0
    else
1843
0
    {
1844
0
        ps_direct->u1_vert_mv_scale = FRM_TO_FLD;
1845
0
        pu1_col_zero_flag_start = ps_col_pic->pu1_col_zero_flag + u2_sub_mb_ofst;
1846
0
        u1_init_colzero_flag = pu1_col_zero_flag_start[0] & 1;
1847
0
1848
0
        if(u1_wd_x == MB_SIZE)
1849
0
        {
1850
0
            UWORD8 u1_submb_col;
1851
0
            UWORD8 *puc_colZeroFlagStart_bot_mb, uc_colMbPredMode_bot_mb;
1852
0
1853
0
            pu1_col_zero_flag_start = ps_col_pic->pu1_col_zero_flag
1854
0
                            + u2_sub_mb_ofst;
1855
0
            u1_col_mb_pred_mode = pu1_col_zero_flag_start[u1_sub_mb_num] >> 6;
1856
0
1857
0
            puc_colZeroFlagStart_bot_mb = ps_col_pic->pu1_col_zero_flag
1858
0
                            + u2_sub_mb_ofst + 16;
1859
0
            uc_colMbPredMode_bot_mb = puc_colZeroFlagStart_bot_mb[8] >> 6;
1860
0
1861
0
            i4_force_8X8 = (u1_col_mb_pred_mode & 0x2)
1862
0
                            || (uc_colMbPredMode_bot_mb & 0x2);
1863
0
            if(i4_force_8X8)
1864
0
            {
1865
0
                u1_num_blks = 2;
1866
0
                partition_size = PRED_8x8;
1867
0
            }
1868
0
            else
1869
0
            {
1870
0
                u1_num_blks = 1;
1871
0
                partition_size = PRED_16x8;
1872
0
            }
1873
0
1874
0
            ps_dec->u1_currB_type = 1;
1875
0
            /*As this mb is derived from 2 Mbs min no of partitions = 2*/
1876
0
            for(i = 0; i < 2; i++)
1877
0
            {
1878
0
1879
0
                pu1_col_zero_flag_start = ps_col_pic->pu1_col_zero_flag
1880
0
                                + u2_sub_mb_ofst;
1881
0
                u1_col_mb_pred_mode = pu1_col_zero_flag_start[u1_sub_mb_num] >> 6;
1882
0
1883
0
                for(uc_blk = 0; uc_blk < u1_num_blks; uc_blk++)
1884
0
                {
1885
0
                    u1_submb_col = (u1_sub_mb_num & 0x7) ? 1 : 0;
1886
0
                    u1_submb_col += u1_sub_mb_num;
1887
0
                    mv_index = u2_sub_mb_ofst + u1_submb_col;
1888
0
1889
0
1890
0
                    ps_direct->i4_mv_indices[i1_num_partitions] = mv_index;
1891
0
                    ps_direct->i1_submb_num[i1_num_partitions] = u1_sub_mb_num;
1892
0
                    ps_direct->i1_partitionsize[i1_num_partitions] =
1893
0
                                    partition_size;
1894
0
                    i1_num_partitions++;
1895
0
                    if((pu1_col_zero_flag_start[u1_submb_col] & 1)
1896
0
                                    != u1_init_colzero_flag)
1897
0
                        ps_direct->u1_col_zeroflag_change = 1;
1898
0
                    u1_sub_mb_num += 2;
1899
0
                }
1900
0
                u1_sub_mb_num = 8; /* move to second half of Cur MB */
1901
0
                u2_sub_mb_ofst += 16;/* move to next Colocated MB */
1902
0
            }
1903
0
            ps_direct->i1_num_partitions = i1_num_partitions;
1904
0
            return;
1905
0
        }
1906
0
        else
1907
0
        {
1908
0
            uc_sub_mb_num_col = u1_sub_mb_num | (u1_sub_mb_num >> 1);
1909
0
            uc_sub_mb_num_col &= 0xb;
1910
0
            u2_sub_mb_ofst += (u1_sub_mb_num >> 3) ? 16 : 0;
1911
0
1912
0
            ps_direct->i4_mv_indices[0] = u2_sub_mb_ofst + uc_sub_mb_num_col;
1913
0
            ps_direct->i1_submb_num[0] = u1_sub_mb_num;
1914
0
            ps_direct->i1_partitionsize[0] = PRED_8x8;
1915
0
            ps_direct->i1_num_partitions = 1;
1916
0
            return;
1917
0
        }
1918
0
    }
1919
0
}
1920
/*!
1921
 **************************************************************************
1922
 * \if Function name : ih264d_cal_col_pic \endif
1923
 *
1924
 * \brief
1925
 *    Finds the colocated picture.
1926
 *
1927
 *
1928
 * \return
1929
 *    0 on Success and Error code otherwise
1930
 **************************************************************************
1931
 */
1932
WORD32 ih264d_cal_col_pic(dec_struct_t *ps_dec)
1933
0
{
1934
0
    struct pic_buffer_t* ps_col_pic = ps_dec->ps_col_pic;
1935
0
    UWORD8 uc_curpictype, uc_colpictype;
1936
0
    ps_col_pic = ps_dec->ps_ref_pic_buf_lx[1][0];
1937
0
    uc_curpictype = (ps_dec->ps_cur_pic->u1_picturetype & 0x7);
1938
0
    uc_colpictype = (ps_col_pic->u1_picturetype & 0x7);
1939
0
    if(uc_curpictype == FRM_PIC)
1940
0
    {
1941
0
        if(uc_colpictype == FRM_PIC)
1942
0
            ps_dec->pf_parse_mvdirect = ih264d_one_to_one;
1943
0
        else if(uc_colpictype == COMP_FLD_PAIR)
1944
0
        {
1945
0
            ps_dec->pf_parse_mvdirect = ih264d_fld_to_frm;
1946
0
            if(ps_col_pic->i4_top_field_order_cnt
1947
0
                            >= ps_col_pic->i4_bottom_field_order_cnt)
1948
0
            {
1949
0
                struct pic_buffer_t* ps_tempPic = ps_col_pic;
1950
0
                UWORD32 ui_half_num_of_sub_mbs = ((ps_dec->u2_pic_ht
1951
0
                                * ps_dec->u2_pic_wd) >> 5);
1952
0
                ps_col_pic = ps_dec->ps_ref_pic_buf_lx[1][MAX_REF_BUFS];
1953
0
                /* memcpy ps_tempPic to ps_col_pic */
1954
0
                *ps_col_pic = *ps_tempPic;
1955
0
                ps_col_pic->pu1_buf1 = ps_tempPic->pu1_buf1
1956
0
                                + ps_tempPic->u2_frm_wd_y;
1957
0
                ps_col_pic->pu1_buf2 = ps_tempPic->pu1_buf2
1958
0
                                + ps_tempPic->u2_frm_wd_uv;
1959
0
                ps_col_pic->pu1_buf3 = ps_tempPic->pu1_buf3
1960
0
                                + ps_tempPic->u2_frm_wd_uv;
1961
0
                ps_col_pic->pu1_col_zero_flag = ps_tempPic->pu1_col_zero_flag
1962
0
                                + ui_half_num_of_sub_mbs;
1963
0
                ps_col_pic->ps_mv = ps_tempPic->ps_mv + ui_half_num_of_sub_mbs;
1964
0
1965
0
1966
0
                ps_col_pic->u1_pic_type = 0;/*complementary reference field pair-refering as frame */
1967
0
1968
0
1969
0
1970
0
            }
1971
0
        }
1972
0
        else
1973
0
        {
1974
0
            UWORD32 i4_error_code;
1975
0
            i4_error_code = ERROR_DBP_MANAGER_T;
1976
0
//          i4_error_code |= 1<<IVD_CORRUPTEDDATA;
1977
0
            return i4_error_code;
1978
0
        }
1979
0
    }
1980
0
    else if(uc_curpictype == AFRM_PIC)
1981
0
    {
1982
0
        ps_dec->pf_parse_mvdirect = ih264d_fld_to_mbaff;
1983
0
    }
1984
0
    else /* must be a field*/
1985
0
    {
1986
0
        if(uc_colpictype == FRM_PIC)
1987
0
            ps_dec->pf_parse_mvdirect = ih264d_frm_to_fld;
1988
0
        else if(uc_colpictype == AFRM_PIC)
1989
0
            ps_dec->pf_parse_mvdirect = ih264d_mbaff_to_fld;
1990
0
        else
1991
0
            ps_dec->pf_parse_mvdirect = ih264d_one_to_one;
1992
0
    }
1993
0
    ps_dec->ps_col_pic = ps_col_pic;
1994
0
    return OK;
1995
0
}
1996
1997
/*!
1998
 **************************************************************************
1999
 * \if Function name : ih264d_frm_to_fld \endif
2000
 *
2001
 * \brief
2002
 *    Initializes forward and backward refernce lists for B slice decoding.
2003
 *
2004
 *
2005
 * \return
2006
 *    0 on Success and Error code otherwise
2007
 **************************************************************************
2008
 */
2009
void ih264d_frm_to_fld(dec_struct_t *ps_dec,
2010
                       struct pic_buffer_t *ps_col_pic,
2011
                       directmv_t *ps_direct,
2012
                       UWORD8 u1_wd_x,
2013
                       WORD32 u2_sub_mb_ofst,
2014
                       dec_mb_info_t * ps_cur_mb_info)
2015
0
{
2016
0
    UWORD8 *pu1_col_zero_flag_start, u1_sub_mb_num;
2017
0
    UWORD8 u1_num_blks, u1_col_mb_pred_mode, uc_blk;
2018
0
    UWORD8 i1_num_partitions = 0, partition_size, i;
2019
0
    WORD32 mv_index;
2020
0
    UWORD32 increment;
2021
0
    WORD32 i4_force_8X8;
2022
0
    UNUSED(ps_cur_mb_info);
2023
0
    ps_direct->u1_col_zeroflag_change = 1;
2024
0
    ps_direct->u1_vert_mv_scale = FRM_TO_FLD;
2025
0
    u1_sub_mb_num = ps_dec->u1_sub_mb_num;
2026
0
2027
0
    /* new calculation specific to this function */
2028
0
    if((ps_col_pic->u1_picturetype & 0x7) == FRM_PIC)
2029
0
    {
2030
0
        UWORD16 u2_frm_wd_in_mbs = ps_dec->u2_frm_wd_in_mbs;
2031
0
        increment = (u2_frm_wd_in_mbs << 4);
2032
0
        /*mbAddrCol = mbAddrCol1 */
2033
0
        u2_sub_mb_ofst = (ps_dec->u2_mbx
2034
0
                        + (2 * ps_dec->u2_mby * u2_frm_wd_in_mbs)) << 4;
2035
0
    }
2036
0
    else
2037
0
        increment = 16;
2038
0
2039
0
    if(u1_wd_x == MB_SIZE)
2040
0
    {
2041
0
        ps_dec->u1_currB_type = 1;
2042
0
2043
0
        {
2044
0
            UWORD8 *puc_colZeroFlagStart_bot_mb, uc_colMbPredMode_bot_mb;
2045
0
2046
0
            pu1_col_zero_flag_start = ps_col_pic->pu1_col_zero_flag
2047
0
                            + u2_sub_mb_ofst;
2048
0
            u1_col_mb_pred_mode = (*pu1_col_zero_flag_start >> 6);
2049
0
2050
0
            puc_colZeroFlagStart_bot_mb = ps_col_pic->pu1_col_zero_flag
2051
0
                            + u2_sub_mb_ofst + increment;
2052
0
            uc_colMbPredMode_bot_mb = (*puc_colZeroFlagStart_bot_mb >> 6);
2053
0
2054
0
            i4_force_8X8 = (u1_col_mb_pred_mode & 0x2)
2055
0
                            || (uc_colMbPredMode_bot_mb & 0x2);
2056
0
2057
0
            if(i4_force_8X8)
2058
0
            {
2059
0
                u1_num_blks = 2;
2060
0
                partition_size = PRED_8x8;
2061
0
            }
2062
0
            else
2063
0
            {
2064
0
                partition_size = PRED_16x8;
2065
0
                u1_num_blks = 1;
2066
0
            }
2067
0
        }
2068
0
2069
0
        /*As this mb is derived from 2 Mbs, min no of partitions = 2*/
2070
0
        for(i = 0; i < 2; i++)
2071
0
        {
2072
0
            for(uc_blk = 0; uc_blk < u1_num_blks; uc_blk++)
2073
0
            {
2074
0
                mv_index = u2_sub_mb_ofst + u1_sub_mb_num;
2075
0
                mv_index += (u1_sub_mb_num & 0x7) ? 1 : 0;
2076
0
2077
0
                ps_direct->i4_mv_indices[i1_num_partitions] = mv_index;
2078
0
                ps_direct->i1_submb_num[i1_num_partitions] = u1_sub_mb_num;
2079
0
                ps_direct->i1_partitionsize[i1_num_partitions] = partition_size;
2080
0
                i1_num_partitions++;
2081
0
2082
0
                u1_sub_mb_num += 2;
2083
0
            }
2084
0
            u1_sub_mb_num = 8; /* move to second half of Cur MB */
2085
0
            u2_sub_mb_ofst += increment;/* move to next Colocated MB */
2086
0
        }
2087
0
        ps_direct->i1_num_partitions = i1_num_partitions;
2088
0
        return;
2089
0
    }
2090
0
    else
2091
0
    {
2092
0
        UWORD8 u1_sub_mb_num_col;
2093
0
        u1_sub_mb_num_col = u1_sub_mb_num | (u1_sub_mb_num >> 1);
2094
0
        u1_sub_mb_num_col &= 0xb;
2095
0
        u2_sub_mb_ofst += (u1_sub_mb_num >> 3) ? increment : 0;
2096
0
2097
0
        ps_direct->i4_mv_indices[0] = u2_sub_mb_ofst + u1_sub_mb_num_col;
2098
0
        ps_direct->i1_submb_num[0] = u1_sub_mb_num;
2099
0
        ps_direct->i1_partitionsize[0] = PRED_8x8;
2100
0
        ps_direct->i1_num_partitions = 1;
2101
0
        return;
2102
0
    }
2103
0
}
2104
/*!
2105
 **************************************************************************
2106
 * \if Function name : ih264d_fld_to_frm \endif
2107
 *
2108
 * \brief
2109
 *    Initializes forward and backward refernce lists for B slice decoding.
2110
 *
2111
 *
2112
 * \return
2113
 *    0 on Success and Error code otherwise
2114
 **************************************************************************
2115
 */
2116
void ih264d_fld_to_frm(dec_struct_t *ps_dec,
2117
                       struct pic_buffer_t *ps_col_pic,
2118
                       directmv_t *ps_direct,
2119
                       UWORD8 u1_wd_x,
2120
                       WORD32 u2_sub_mb_ofst,
2121
                       dec_mb_info_t * ps_cur_mb_info)
2122
0
{
2123
0
    UWORD8 *pu1_col_zero_flag_start, *pu1_col_zero_flag,
2124
0
                    *pu1_col_zero_flag_right_half, u1_sub_mb_num, uc_sub_mb_num_col;
2125
0
    UWORD8 u1_col_mb_pred_mode, uc_blk;
2126
0
    WORD32 i4_force_8X8;
2127
0
2128
0
    UNUSED(ps_cur_mb_info);
2129
0
    ps_direct->u1_vert_mv_scale = FLD_TO_FRM;
2130
0
    ps_direct->u1_col_zeroflag_change = 1;
2131
0
    /* new calculation specific to this function for u2_sub_mb_ofst*/
2132
0
    u2_sub_mb_ofst = (ps_dec->u2_mbx
2133
0
                    + ((ps_dec->u2_mby >> 1) * ps_dec->u2_frm_wd_in_mbs)) << 4;
2134
0
    u2_sub_mb_ofst += ((ps_dec->u2_mby & 1) << 3);
2135
0
2136
0
    if(u1_wd_x == MB_SIZE)
2137
0
    {
2138
0
        pu1_col_zero_flag_start = ps_col_pic->pu1_col_zero_flag + u2_sub_mb_ofst;
2139
0
        u1_col_mb_pred_mode = (*pu1_col_zero_flag_start >> 6);
2140
0
        ps_dec->u1_currB_type = (!!u1_col_mb_pred_mode);
2141
0
2142
0
        if(u1_col_mb_pred_mode & 0x2)
2143
0
        {
2144
0
            if(u1_col_mb_pred_mode == PRED_8x16)
2145
0
            {
2146
0
                ps_direct->i1_num_partitions = 2;
2147
0
                ps_direct->i4_mv_indices[0] = u2_sub_mb_ofst;
2148
0
                ps_direct->i1_submb_num[0] = 0;
2149
0
                ps_direct->i1_partitionsize[0] = PRED_8x16;
2150
0
                ps_direct->i4_mv_indices[1] = u2_sub_mb_ofst + 2;
2151
0
                ps_direct->i1_submb_num[1] = 2;
2152
0
                ps_direct->i1_partitionsize[1] = PRED_8x16;
2153
0
            }
2154
0
            else
2155
0
            {
2156
0
                UWORD8 i1_num_partitions = 0, partition_size;
2157
0
                UWORD32 mv_index;
2158
0
                UWORD8 u1_num_sub_blks, i, u1_col_sub_mb_pred_mode,
2159
0
                                u1_col_sub_mb_pred_mode_rt;
2160
0
2161
0
                u1_sub_mb_num = ps_dec->u1_sub_mb_num;
2162
0
2163
0
                pu1_col_zero_flag = pu1_col_zero_flag_start + u1_sub_mb_num;
2164
0
                u1_col_sub_mb_pred_mode = (*pu1_col_zero_flag & 0x10);/* 8x4 or 4x4 mode */
2165
0
2166
0
                pu1_col_zero_flag_right_half = pu1_col_zero_flag_start + u1_sub_mb_num
2167
0
                                + 2;
2168
0
                u1_col_sub_mb_pred_mode_rt = (*pu1_col_zero_flag_right_half
2169
0
                                & 0x10);/* 8x4 or 4x4 mode */
2170
0
2171
0
                i4_force_8X8 = (u1_col_sub_mb_pred_mode)
2172
0
                                || (u1_col_sub_mb_pred_mode_rt);
2173
0
                if(i4_force_8X8)
2174
0
                {
2175
0
                    u1_num_sub_blks = 2;
2176
0
                    partition_size = PRED_8x8;
2177
0
                }
2178
0
                else
2179
0
                {
2180
0
                    partition_size = PRED_8x16;
2181
0
                    u1_num_sub_blks = 1;
2182
0
                }
2183
0
2184
0
                for(i = 0; i < 2; i++)
2185
0
                {
2186
0
                    for(uc_blk = 0; uc_blk < u1_num_sub_blks; uc_blk++)
2187
0
                    {
2188
0
                        uc_sub_mb_num_col = u1_sub_mb_num | (u1_sub_mb_num >> 1);
2189
0
                        uc_sub_mb_num_col &= 0x7;
2190
0
                        mv_index = u2_sub_mb_ofst + uc_sub_mb_num_col;
2191
0
2192
0
                        ps_direct->i4_mv_indices[i1_num_partitions] = mv_index;
2193
0
                        ps_direct->i1_submb_num[i1_num_partitions] =
2194
0
                                        u1_sub_mb_num;
2195
0
                        ps_direct->i1_partitionsize[i1_num_partitions] =
2196
0
                                        partition_size;
2197
0
                        i1_num_partitions++;
2198
0
                        u1_sub_mb_num += 8;
2199
0
                    }
2200
0
2201
0
                    u1_sub_mb_num = 2; /* move to second half of Cur MB */
2202
0
2203
0
                }
2204
0
                ps_direct->i1_num_partitions = i1_num_partitions;
2205
0
                return;
2206
0
            }
2207
0
        }
2208
0
        else
2209
0
        {
2210
0
            ps_direct->i1_num_partitions = 1;
2211
0
            ps_direct->i4_mv_indices[0] = u2_sub_mb_ofst;
2212
0
            ps_direct->i1_submb_num[0] = 0;
2213
0
            ps_direct->i1_partitionsize[0] = PRED_16x16;
2214
0
            return;
2215
0
        }
2216
0
    }
2217
0
    else
2218
0
    {
2219
0
        u1_sub_mb_num = ps_dec->u1_sub_mb_num;
2220
0
        uc_sub_mb_num_col = u1_sub_mb_num | (u1_sub_mb_num >> 1);
2221
0
        uc_sub_mb_num_col &= 0x7;
2222
0
2223
0
        ps_direct->i4_mv_indices[0] = u2_sub_mb_ofst + uc_sub_mb_num_col;
2224
0
        ps_direct->i1_submb_num[0] = u1_sub_mb_num;
2225
0
        ps_direct->i1_partitionsize[0] = PRED_8x8;
2226
0
        ps_direct->i1_num_partitions = 1;
2227
0
    }
2228
0
}
2229
/*!
2230
 **************************************************************************
2231
 * \if Function name : ih264d_one_to_one \endif
2232
 *
2233
 * \brief
2234
 *    Initializes forward and backward refernce lists for B slice decoding.
2235
 *
2236
 *
2237
 * \return
2238
 *    0 on Success and Error code otherwise
2239
 **************************************************************************
2240
 */
2241
void ih264d_mbaff_to_fld(dec_struct_t *ps_dec,
2242
                         struct pic_buffer_t *ps_col_pic,
2243
                         directmv_t *ps_direct,
2244
                         UWORD8 u1_wd_x,
2245
                         WORD32 u2_sub_mb_ofst,
2246
                         dec_mb_info_t * ps_cur_mb_info)
2247
0
{
2248
0
    UWORD8* pu1_col_zero_flag, u1_iscol_mb_fld;
2249
0
    u2_sub_mb_ofst <<= 1;
2250
0
    pu1_col_zero_flag = ps_col_pic->pu1_col_zero_flag + u2_sub_mb_ofst;
2251
0
    u1_iscol_mb_fld = (*pu1_col_zero_flag & 0x2) >> 1;
2252
0
    if(u1_iscol_mb_fld)
2253
0
    {
2254
0
        u2_sub_mb_ofst += (ps_dec->ps_cur_slice->u1_bottom_field_flag << 4);
2255
0
        ih264d_one_to_one(ps_dec, ps_col_pic, ps_direct, u1_wd_x,
2256
0
                          u2_sub_mb_ofst, ps_cur_mb_info);
2257
0
    }
2258
0
    else
2259
0
        ih264d_frm_to_fld(ps_dec, ps_col_pic, ps_direct, u1_wd_x,
2260
0
                          u2_sub_mb_ofst, ps_cur_mb_info);
2261
0
}
2262
/*!
2263
 **************************************************************************
2264
 * \if Function name : ih264d_one_to_one \endif
2265
 *
2266
 * \brief
2267
 *    Initializes forward and backward refernce lists for B slice decoding.
2268
 *
2269
 *
2270
 * \return
2271
 *    0 on Success and Error code otherwise
2272
 **************************************************************************
2273
 */
2274
void ih264d_fld_to_mbaff(dec_struct_t *ps_dec,
2275
                         struct pic_buffer_t *ps_col_pic,
2276
                         directmv_t *ps_direct,
2277
                         UWORD8 u1_wd_x,
2278
                         WORD32 u2_sub_mb_ofst,
2279
                         dec_mb_info_t * ps_cur_mb_info)
2280
0
{
2281
0
    if((ps_col_pic->u1_picturetype & 0x7) == COMP_FLD_PAIR)
2282
0
    {
2283
0
        /* first calculate the colocated picture which varies with Mb */
2284
0
        UWORD8 u1_is_cur_mb_fld;
2285
0
        u1_is_cur_mb_fld = ps_cur_mb_info->u1_mb_field_decodingflag;
2286
0
        u2_sub_mb_ofst = (u2_sub_mb_ofst & 0xffe0); /* mbaddrCol5 = curmbaddr/2;*/
2287
0
        u2_sub_mb_ofst >>= 1;
2288
0
2289
0
        ps_col_pic = ps_dec->ps_ref_pic_buf_lx[1][0];
2290
0
        if(u1_is_cur_mb_fld)
2291
0
        {
2292
0
            if(1 - ps_cur_mb_info->u1_topmb)
2293
0
                ps_col_pic = ps_dec->ps_ref_pic_buf_lx[1][MAX_REF_BUFS];
2294
0
2295
0
            ih264d_one_to_one(ps_dec, ps_col_pic, ps_direct, u1_wd_x,
2296
0
                              u2_sub_mb_ofst, ps_cur_mb_info);
2297
0
        }
2298
0
        else
2299
0
        {
2300
0
2301
0
            if(ABS(ps_col_pic->i4_top_field_order_cnt
2302
0
                            - ps_dec->ps_cur_pic->i4_poc) >=
2303
0
                            ABS(ps_dec->ps_cur_pic->i4_poc - ps_col_pic->i4_bottom_field_order_cnt))
2304
0
            {
2305
0
                ps_col_pic = ps_dec->ps_ref_pic_buf_lx[1][MAX_REF_BUFS];
2306
0
            }
2307
0
2308
0
            if(ps_cur_mb_info->u1_topmb == 0)
2309
0
                u2_sub_mb_ofst += 8;
2310
0
            ih264d_mbaff_cross_pmbair(ps_dec, ps_col_pic, ps_direct, u1_wd_x,
2311
0
                                      u2_sub_mb_ofst, ps_cur_mb_info);
2312
0
        }
2313
0
        ps_dec->ps_col_pic = ps_col_pic;
2314
0
    }
2315
0
    else
2316
0
    {
2317
0
        UWORD8* pu1_col_zero_flag = ps_col_pic->pu1_col_zero_flag
2318
0
                        + u2_sub_mb_ofst;
2319
0
        UWORD8 temp, u1_is_cur_mb_fld, u1_iscol_mb_fld;
2320
0
2321
0
        u1_iscol_mb_fld = (*pu1_col_zero_flag & 0x2) >> 1;
2322
0
        u1_is_cur_mb_fld = ps_cur_mb_info->u1_mb_field_decodingflag;
2323
0
        temp = (u1_iscol_mb_fld ^ u1_is_cur_mb_fld);
2324
0
2325
0
        if(temp == 0)
2326
0
            ih264d_one_to_one(ps_dec, ps_col_pic, ps_direct, u1_wd_x,
2327
0
                              u2_sub_mb_ofst, ps_cur_mb_info);
2328
0
        else
2329
0
        {
2330
0
            u2_sub_mb_ofst &= 0xffef;
2331
0
            if(u1_is_cur_mb_fld == 0)
2332
0
            {
2333
0
                if(ABS(ps_col_pic->i4_top_field_order_cnt
2334
0
                                - ps_dec->ps_cur_pic->i4_poc) >=
2335
0
                                ABS(ps_dec->ps_cur_pic->i4_poc - ps_col_pic->i4_bottom_field_order_cnt))
2336
0
                {
2337
0
                    u2_sub_mb_ofst += 0x10;
2338
0
                }
2339
0
                if(ps_cur_mb_info->u1_topmb == 0)
2340
0
                    u2_sub_mb_ofst += 8;
2341
0
            }
2342
0
            ih264d_mbaff_cross_pmbair(ps_dec, ps_col_pic, ps_direct, u1_wd_x,
2343
0
                                      u2_sub_mb_ofst, ps_cur_mb_info);
2344
0
        }
2345
0
    }
2346
0
}
2347
/proc/self/cwd/external/libavc/decoder/ih264d_process_intra_mb.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/*!
21
 **************************************************************************
22
 * \file ih264d_process_intra_mb.c
23
 *
24
 * \brief
25
 *    Contains routines that decode a I slice type
26
 *
27
 * Detailed_description
28
 *
29
 * \date
30
 *    07/07/2003
31
 *
32
 * \author  NS
33
 **************************************************************************
34
 */
35
36
#include <string.h>
37
#include "ih264d_bitstrm.h"
38
#include "ih264d_defs.h"
39
#include "ih264d_debug.h"
40
#include "ih264d_tables.h"
41
#include "ih264d_structs.h"
42
#include "ih264d_defs.h"
43
#include "ih264d_parse_cavlc.h"
44
#include "ih264d_mb_utils.h"
45
#include "ih264d_parse_slice.h"
46
#include "ih264d_process_intra_mb.h"
47
#include "ih264d_error_handler.h"
48
#include "ih264d_quant_scaling.h"
49
#include "ih264d_tables.h"
50
51
/*!
52
 **************************************************************************
53
 * \if Function name : ih264d_itrans_recon_luma_dc \endif
54
 *
55
 * \brief
56
 *    This function does InvTransform, scaling and reconstruction of Luma DC.
57
 *
58
 * \return
59
 *    0 on Success and Error code otherwise
60
 **************************************************************************
61
 */
62
void ih264d_itrans_recon_luma_dc(dec_struct_t *ps_dec,
63
                                 WORD16* pi2_src,
64
                                 WORD16* pi2_coeff_block,
65
                                 const UWORD16 *pu2_weigh_mat)
66
0
{
67
0
    WORD32 i;
68
0
    WORD16 pi2_out[16];
69
0
    WORD32 pi4_tmp[16];
70
0
    WORD16 *pi2_out_ptr = &pi2_out[0];
71
0
    PROFILE_DISABLE_IQ_IT_RECON_RETURN()
72
0
    ps_dec->pf_ihadamard_scaling_4x4(pi2_src, pi2_out,
73
0
                                     ps_dec->pu2_quant_scale_y, pu2_weigh_mat,
74
0
                                     ps_dec->u1_qp_y_div6, pi4_tmp);
75
0
    for(i = 0; i < 4; i++)
76
0
    {
77
0
        pi2_coeff_block[0] = pi2_out_ptr[0];
78
0
        pi2_coeff_block[4 * 16] = pi2_out_ptr[4];
79
0
        pi2_coeff_block[8 * 16] = pi2_out_ptr[8];
80
0
        pi2_coeff_block[12 * 16] = pi2_out_ptr[12];
81
0
82
0
        pi2_out_ptr++; /* Point to next column */
83
0
        pi2_coeff_block += 16;
84
0
    }
85
0
}
86
/*!
87
 **************************************************************************
88
 * \if Function name : ih264d_read_intra_pred_modes \endif
89
 *
90
 * \brief
91
 *    Reads the intra pred mode related values of I4x4 MB from bitstream.
92
 *
93
 *    This function will read the prev intra pred mode flags and
94
 *    stores it in pu1_prev_intra4x4_pred_mode_flag. If the u4_flag
95
 *    indicates that most probable mode is not intra pred mode, then
96
 *    the rem_intra4x4_pred_mode is read and stored in
97
 *    pu1_rem_intra4x4_pred_mode array.
98
 *
99
 *
100
 * \return
101
 *    0 on success and Error code otherwise
102
 *
103
 **************************************************************************
104
 */
105
WORD32 ih264d_read_intra_pred_modes(dec_struct_t * ps_dec,
106
                                    UWORD8 * pu1_prev_intra4x4_pred_mode_flag,
107
                                    UWORD8 * pu1_rem_intra4x4_pred_mode,
108
                                    UWORD32 u4_trans_form8x8)
109
2.54k
{
110
2.54k
    WORD32 i4x4_luma_blk_idx = 0, i8x8_luma_blk_idx = 0;
111
2.54k
112
2.54k
    dec_bit_stream_t * ps_bitstrm = ps_dec->ps_bitstrm;
113
2.54k
114
2.54k
    if(!u4_trans_form8x8)
115
2.54k
    {
116
43.1k
        for(i4x4_luma_blk_idx = 0; i4x4_luma_blk_idx < 16; ++i4x4_luma_blk_idx)
117
40.6k
        {
118
40.6k
            UWORD32 u4_temp;
119
40.6k
            SWITCHOFFTRACE;
120
40.6k
121
40.6k
            GETBIT(u4_temp, ps_bitstrm->u4_ofst, ps_bitstrm->pu4_buffer);
122
40.6k
            *pu1_prev_intra4x4_pred_mode_flag = (UWORD8)u4_temp;
123
40.6k
            if(!(*pu1_prev_intra4x4_pred_mode_flag))
124
8.86k
            {
125
8.86k
                GETBITS(u4_temp, ps_bitstrm->u4_ofst, ps_bitstrm->pu4_buffer, 3);
126
8.86k
127
8.86k
                *(pu1_rem_intra4x4_pred_mode) = (UWORD8)u4_temp;
128
8.86k
            }
129
40.6k
130
40.6k
            pu1_prev_intra4x4_pred_mode_flag++;
131
40.6k
            pu1_rem_intra4x4_pred_mode++;
132
40.6k
        }
133
2.54k
    }
134
0
    else
135
0
    {
136
0
        /**********************************************************************/
137
0
        /* prev_intra4x4_pred_modes to be interpreted as                      */
138
0
        /* prev_intra8x8_pred_modes in case of transform 8x8                  */
139
0
        /**********************************************************************/
140
0
        for(i8x8_luma_blk_idx = 0; i8x8_luma_blk_idx < 4; i8x8_luma_blk_idx++)
141
0
        {
142
0
            UWORD32 u4_temp;
143
0
            GETBIT(u4_temp, ps_bitstrm->u4_ofst, ps_bitstrm->pu4_buffer);
144
0
            *pu1_prev_intra4x4_pred_mode_flag = (UWORD8)u4_temp;
145
0
            if(!(*pu1_prev_intra4x4_pred_mode_flag))
146
0
            {
147
0
                GETBITS(u4_temp, ps_bitstrm->u4_ofst, ps_bitstrm->pu4_buffer, 3);
148
0
149
0
                (*pu1_rem_intra4x4_pred_mode) = (UWORD8)u4_temp;
150
0
            }
151
0
            pu1_prev_intra4x4_pred_mode_flag++;
152
0
            pu1_rem_intra4x4_pred_mode++;
153
0
        }
154
0
    }
155
2.54k
    return (0);
156
2.54k
}
157
WORD32 ih264d_unpack_coeff4x4_4x4blk(dec_struct_t * ps_dec,
158
                                   WORD16 *pi2_out_coeff_data,
159
                                   UWORD8 *pu1_inv_scan)
160
24.0k
{
161
24.0k
    tu_sblk4x4_coeff_data_t *ps_tu_4x4 = (tu_sblk4x4_coeff_data_t *)ps_dec->pv_proc_tu_coeff_data;
162
24.0k
    UWORD16 u2_sig_coeff_map = ps_tu_4x4->u2_sig_coeff_map;
163
24.0k
    WORD32 idx = 0;
164
24.0k
    WORD16 *pi2_coeff_data = &ps_tu_4x4->ai2_level[0];
165
24.0k
    WORD32 dc_only_flag = 0;
166
24.0k
    WORD32 num_coeff = 0;
167
24.0k
168
24.0k
    PROFILE_DISABLE_UNPACK_LUMA()
169
236k
    while(u2_sig_coeff_map)
170
212k
    {
171
212k
        idx = CLZ(u2_sig_coeff_map);
172
212k
173
212k
        idx = 31 - idx;
174
212k
        RESET_BIT(u2_sig_coeff_map,idx);
175
212k
176
212k
        idx = pu1_inv_scan[idx];
177
212k
        pi2_out_coeff_data[idx] = *pi2_coeff_data++;
178
212k
        num_coeff++;
179
212k
    }
180
24.0k
181
24.0k
    if((num_coeff == 1) && (idx == 0))
182
66
    {
183
66
        dc_only_flag = 1;
184
66
    }
185
24.0k
186
24.0k
    {
187
24.0k
        WORD32 offset;
188
24.0k
        offset = (UWORD8 *)pi2_coeff_data - (UWORD8 *)ps_tu_4x4;
189
24.0k
        offset = ALIGN4(offset);
190
24.0k
        ps_dec->pv_proc_tu_coeff_data = (void *)((UWORD8 *)ps_dec->pv_proc_tu_coeff_data + offset);
191
24.0k
    }
192
24.0k
193
24.0k
    return dc_only_flag;
194
24.0k
}
195
196
UWORD32 ih264d_unpack_coeff4x4_8x8blk(dec_struct_t * ps_dec,
197
                                   dec_mb_info_t * ps_cur_mb_info,
198
                                   UWORD16 ui2_luma_csbp,
199
                                   WORD16 *pi2_out_coeff_data)
200
10.4k
{
201
10.4k
    UWORD8 *pu1_inv_scan;
202
10.4k
    UWORD8 u1_mb_field_decoding_flag = ps_cur_mb_info->u1_mb_field_decodingflag;
203
10.4k
    UWORD8 u1_field_coding_flag = ps_cur_mb_info->ps_curmb->u1_mb_fld;
204
10.4k
    UWORD32 u4_luma_dc_only_csbp = 0;
205
10.4k
    WORD32 dc_only_flag = 0;
206
10.4k
207
10.4k
    PROFILE_DISABLE_UNPACK_LUMA()
208
10.4k
    if(u1_field_coding_flag || u1_mb_field_decoding_flag)
209
0
    {
210
0
        pu1_inv_scan = (UWORD8 *)gau1_ih264d_inv_scan_fld;
211
0
    }
212
10.4k
    else
213
10.4k
    {
214
10.4k
        pu1_inv_scan = (UWORD8 *)gau1_ih264d_inv_scan;
215
10.4k
    }
216
10.4k
217
10.4k
    // sub 0
218
10.4k
    if(ui2_luma_csbp & 0x1)
219
3.85k
    {
220
3.85k
        memset(pi2_out_coeff_data,0,16*sizeof(WORD16));
221
3.85k
        dc_only_flag = ih264d_unpack_coeff4x4_4x4blk(ps_dec,
222
3.85k
                                      pi2_out_coeff_data,
223
3.85k
                                      pu1_inv_scan);
224
3.85k
225
3.85k
        INSERT_BIT(u4_luma_dc_only_csbp, 0, dc_only_flag);
226
3.85k
    }
227
10.4k
228
10.4k
    pi2_out_coeff_data += 16;
229
10.4k
    // sub 1
230
10.4k
    if(ui2_luma_csbp & 0x2)
231
3.83k
    {
232
3.83k
        memset(pi2_out_coeff_data,0,16*sizeof(WORD16));
233
3.83k
        dc_only_flag = ih264d_unpack_coeff4x4_4x4blk(ps_dec,
234
3.83k
                                      pi2_out_coeff_data,
235
3.83k
                                      pu1_inv_scan);
236
3.83k
        INSERT_BIT(u4_luma_dc_only_csbp, 1, dc_only_flag);
237
3.83k
    }
238
10.4k
239
10.4k
    pi2_out_coeff_data += 16 + 32;
240
10.4k
    // sub 2
241
10.4k
    if(ui2_luma_csbp & 0x10)
242
3.75k
    {
243
3.75k
        memset(pi2_out_coeff_data,0,16*sizeof(WORD16));
244
3.75k
        dc_only_flag = ih264d_unpack_coeff4x4_4x4blk(ps_dec,
245
3.75k
                                      pi2_out_coeff_data,
246
3.75k
                                      pu1_inv_scan);
247
3.75k
        INSERT_BIT(u4_luma_dc_only_csbp, 4, dc_only_flag);
248
3.75k
    }
249
10.4k
250
10.4k
    pi2_out_coeff_data += 16;
251
10.4k
    // sub 3
252
10.4k
    if(ui2_luma_csbp & 0x20)
253
3.69k
    {
254
3.69k
        memset(pi2_out_coeff_data,0,16*sizeof(WORD16));
255
3.69k
        dc_only_flag = ih264d_unpack_coeff4x4_4x4blk(ps_dec,
256
3.69k
                                      pi2_out_coeff_data,
257
3.69k
                                      pu1_inv_scan);
258
3.69k
        INSERT_BIT(u4_luma_dc_only_csbp, 5, dc_only_flag);
259
3.69k
    }
260
10.4k
    return u4_luma_dc_only_csbp;
261
10.4k
}
262
WORD32 ih264d_unpack_coeff8x8_8x8blk_cavlc(dec_struct_t * ps_dec,
263
                                            dec_mb_info_t * ps_cur_mb_info,
264
                                            UWORD16 ui2_luma_csbp,
265
                                            WORD16 *pi2_out_coeff_data)
266
0
{
267
0
    UWORD8 *pu1_inv_scan;
268
0
    UWORD8 u1_mb_field_decoding_flag = ps_cur_mb_info->u1_mb_field_decodingflag;
269
0
    UWORD8 u1_field_coding_flag = ps_cur_mb_info->ps_curmb->u1_mb_fld;
270
0
    WORD32 dc_only_flag = 0;
271
0
272
0
    PROFILE_DISABLE_UNPACK_LUMA()
273
0
    if(ui2_luma_csbp & 0x33)
274
0
    {
275
0
        memset(pi2_out_coeff_data,0,64*sizeof(WORD16));
276
0
    }
277
0
278
0
    if(!u1_mb_field_decoding_flag)
279
0
    {
280
0
        pu1_inv_scan =
281
0
                        (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[0];
282
0
    }
283
0
    else
284
0
    {
285
0
        pu1_inv_scan =
286
0
                        (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[0];
287
0
    }
288
0
    // sub 0
289
0
    if(ui2_luma_csbp & 0x1)
290
0
    {
291
0
        dc_only_flag = ih264d_unpack_coeff4x4_4x4blk(ps_dec,
292
0
                                      pi2_out_coeff_data,
293
0
                                      pu1_inv_scan);
294
0
    }
295
0
296
0
    if(!u1_mb_field_decoding_flag)
297
0
    {
298
0
        pu1_inv_scan =
299
0
                        (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[1];
300
0
    }
301
0
    else
302
0
    {
303
0
        pu1_inv_scan =
304
0
                        (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[1];
305
0
    }
306
0
    // sub 1
307
0
    if(ui2_luma_csbp & 0x2)
308
0
    {
309
0
        dc_only_flag = 0;
310
0
        ih264d_unpack_coeff4x4_4x4blk(ps_dec,
311
0
                                      pi2_out_coeff_data,
312
0
                                      pu1_inv_scan);
313
0
    }
314
0
315
0
    if(!u1_mb_field_decoding_flag)
316
0
    {
317
0
        pu1_inv_scan =
318
0
                        (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[2];
319
0
    }
320
0
    else
321
0
    {
322
0
        pu1_inv_scan =
323
0
                        (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[2];
324
0
    }
325
0
    // sub 2
326
0
    if(ui2_luma_csbp & 0x10)
327
0
    {
328
0
        dc_only_flag = 0;
329
0
        ih264d_unpack_coeff4x4_4x4blk(ps_dec,
330
0
                                      pi2_out_coeff_data,
331
0
                                      pu1_inv_scan);
332
0
    }
333
0
334
0
    if(!u1_mb_field_decoding_flag)
335
0
    {
336
0
        pu1_inv_scan =
337
0
                        (UWORD8*)gau1_ih264d_inv_scan_prog8x8_cavlc[3];
338
0
    }
339
0
    else
340
0
    {
341
0
        pu1_inv_scan =
342
0
                        (UWORD8*)gau1_ih264d_inv_scan_int8x8_cavlc[3];
343
0
    }
344
0
    // sub 3
345
0
    if(ui2_luma_csbp & 0x20)
346
0
    {
347
0
        dc_only_flag = 0;
348
0
        ih264d_unpack_coeff4x4_4x4blk(ps_dec,
349
0
                                      pi2_out_coeff_data,
350
0
                                      pu1_inv_scan);
351
0
    }
352
0
    return dc_only_flag;
353
0
}
354
void ih264d_unpack_coeff4x4_8x8blk_chroma(dec_struct_t * ps_dec,
355
                                          dec_mb_info_t * ps_cur_mb_info,
356
                                          UWORD16 ui2_chroma_csbp,
357
                                          WORD16 *pi2_out_coeff_data)
358
4.37k
{
359
4.37k
    UWORD8 *pu1_inv_scan;
360
4.37k
    UWORD8 u1_mb_field_decoding_flag = ps_cur_mb_info->u1_mb_field_decodingflag;
361
4.37k
    UWORD8 u1_field_coding_flag = ps_cur_mb_info->ps_curmb->u1_mb_fld;
362
4.37k
363
4.37k
    PROFILE_DISABLE_UNPACK_CHROMA()
364
4.37k
    if(u1_field_coding_flag || u1_mb_field_decoding_flag)
365
0
    {
366
0
        pu1_inv_scan = (UWORD8 *)gau1_ih264d_inv_scan_fld;
367
0
    }
368
4.37k
    else
369
4.37k
    {
370
4.37k
        pu1_inv_scan = (UWORD8 *)gau1_ih264d_inv_scan;
371
4.37k
    }
372
4.37k
373
4.37k
    if(ui2_chroma_csbp & 0x1)
374
2.16k
    {
375
2.16k
        memset(pi2_out_coeff_data,0,16*sizeof(WORD16));
376
2.16k
        ih264d_unpack_coeff4x4_4x4blk(ps_dec,
377
2.16k
                                      pi2_out_coeff_data,
378
2.16k
                                      pu1_inv_scan);
379
2.16k
    }
380
4.37k
    pi2_out_coeff_data += 16;
381
4.37k
    if(ui2_chroma_csbp & 0x2)
382
2.20k
    {
383
2.20k
        memset(pi2_out_coeff_data,0,16*sizeof(WORD16));
384
2.20k
        ih264d_unpack_coeff4x4_4x4blk(ps_dec,
385
2.20k
                                      pi2_out_coeff_data,
386
2.20k
                                      pu1_inv_scan);
387
2.20k
    }
388
4.37k
389
4.37k
    pi2_out_coeff_data += 16;
390
4.37k
    if(ui2_chroma_csbp & 0x4)
391
2.23k
    {
392
2.23k
        memset(pi2_out_coeff_data,0,16*sizeof(WORD16));
393
2.23k
        ih264d_unpack_coeff4x4_4x4blk(ps_dec,
394
2.23k
                                      pi2_out_coeff_data,
395
2.23k
                                      pu1_inv_scan);
396
2.23k
    }
397
4.37k
398
4.37k
    pi2_out_coeff_data += 16;
399
4.37k
    if(ui2_chroma_csbp & 0x8)
400
2.28k
    {
401
2.28k
        memset(pi2_out_coeff_data,0,16*sizeof(WORD16));
402
2.28k
        ih264d_unpack_coeff4x4_4x4blk(ps_dec,
403
2.28k
                                      pi2_out_coeff_data,
404
2.28k
                                      pu1_inv_scan);
405
2.28k
    }
406
4.37k
}
407
UWORD32 ih264d_unpack_luma_coeff4x4_mb(dec_struct_t * ps_dec,
408
                                    dec_mb_info_t * ps_cur_mb_info,
409
                                    UWORD8 intra_flag)
410
5.06k
{
411
5.06k
    UWORD8 u1_mb_type = ps_cur_mb_info->u1_mb_type;
412
5.06k
    UWORD16 ui2_luma_csbp = ps_cur_mb_info->u2_luma_csbp;
413
5.06k
    UWORD8 *pu1_inv_scan = ps_dec->pu1_inv_scan;
414
5.06k
    WORD16 *pi2_coeff_data = ps_dec->pi2_coeff_data;
415
5.06k
416
5.06k
    PROFILE_DISABLE_UNPACK_LUMA()
417
5.06k
    if(!ps_cur_mb_info->u1_tran_form8x8)
418
5.06k
    {
419
5.06k
        UWORD32 u4_luma_dc_only_csbp = 0;
420
5.06k
        UWORD32 u4_temp = 0;
421
5.06k
        WORD16* pi2_dc_val = NULL;
422
5.06k
        /*
423
5.06k
         * Reserve the pointer to dc vals. The dc vals will be copied
424
5.06k
         * after unpacking of ac vals since memset to 0 inside.
425
5.06k
         */
426
5.06k
        if(intra_flag && (u1_mb_type != I_4x4_MB))
427
2.51k
        {
428
2.51k
            if(CHECKBIT(ps_cur_mb_info->u1_yuv_dc_block_flag,0))
429
2.51k
            {
430
0
                pi2_dc_val = (WORD16 *)ps_dec->pv_proc_tu_coeff_data;
431
0
432
0
                ps_dec->pv_proc_tu_coeff_data = (void *)(pi2_dc_val + 16);
433
0
            }
434
2.51k
        }
435
5.06k
436
5.06k
        if(ui2_luma_csbp)
437
2.61k
        {
438
2.61k
            pi2_coeff_data = ps_dec->pi2_coeff_data;
439
2.61k
            u4_temp = ih264d_unpack_coeff4x4_8x8blk(ps_dec,
440
2.61k
                                          ps_cur_mb_info,
441
2.61k
                                          ui2_luma_csbp,
442
2.61k
                                          pi2_coeff_data);
443
2.61k
            u4_luma_dc_only_csbp = u4_temp;
444
2.61k
445
2.61k
            pi2_coeff_data += 32;
446
2.61k
447
2.61k
            ui2_luma_csbp = ui2_luma_csbp >> 2;
448
2.61k
            u4_temp = ih264d_unpack_coeff4x4_8x8blk(ps_dec,
449
2.61k
                                          ps_cur_mb_info,
450
2.61k
                                          ui2_luma_csbp,
451
2.61k
                                          pi2_coeff_data);
452
2.61k
453
2.61k
            u4_luma_dc_only_csbp |= (u4_temp << 2);
454
2.61k
455
2.61k
            pi2_coeff_data += 32 + 64;
456
2.61k
457
2.61k
            ui2_luma_csbp = ui2_luma_csbp >> 6;
458
2.61k
            u4_temp = ih264d_unpack_coeff4x4_8x8blk(ps_dec,
459
2.61k
                                          ps_cur_mb_info,
460
2.61k
                                          ui2_luma_csbp,
461
2.61k
                                          pi2_coeff_data);
462
2.61k
463
2.61k
            u4_luma_dc_only_csbp |= (u4_temp << 8);
464
2.61k
465
2.61k
            pi2_coeff_data += 32;
466
2.61k
467
2.61k
            ui2_luma_csbp = ui2_luma_csbp >> 2;
468
2.61k
            u4_temp = ih264d_unpack_coeff4x4_8x8blk(ps_dec,
469
2.61k
                                          ps_cur_mb_info,
470
2.61k
                                          ui2_luma_csbp,
471
2.61k
                                          pi2_coeff_data);
472
2.61k
            u4_luma_dc_only_csbp |= (u4_temp << 10);
473
2.61k
        }
474
5.06k
475
5.06k
        if(pi2_dc_val != NULL)
476
5.06k
        {
477
0
            WORD32 i;
478
0
            pi2_coeff_data = ps_dec->pi2_coeff_data;
479
0
            for(i = 0; i < 4; i++)
480
0
            {
481
0
                pi2_coeff_data[0] = pi2_dc_val[0];
482
0
                pi2_coeff_data[4 * 16] = pi2_dc_val[4];
483
0
                pi2_coeff_data[8 * 16] = pi2_dc_val[8];
484
0
                pi2_coeff_data[12 * 16] = pi2_dc_val[12];
485
0
486
0
                pi2_dc_val++; /* Point to next column */
487
0
                pi2_coeff_data += 16;
488
0
            }
489
0
            u4_luma_dc_only_csbp = ps_cur_mb_info->u2_luma_csbp ^ 0xFFFF;
490
0
        }
491
5.06k
        return u4_luma_dc_only_csbp;
492
5.06k
    }
493
0
    else
494
0
    {
495
0
        UWORD32 u4_luma_dc_only_cbp = 0;
496
0
        WORD32 dc_only_flag;
497
0
        if(ui2_luma_csbp)
498
0
        {
499
0
            pi2_coeff_data = ps_dec->pi2_coeff_data;
500
0
            dc_only_flag = ih264d_unpack_coeff8x8_8x8blk_cavlc(ps_dec,
501
0
                                          ps_cur_mb_info,
502
0
                                          ui2_luma_csbp,
503
0
                                          pi2_coeff_data);
504
0
            INSERT_BIT(u4_luma_dc_only_cbp, 0, dc_only_flag);
505
0
506
0
            pi2_coeff_data += 64;
507
0
508
0
            ui2_luma_csbp = ui2_luma_csbp >> 2;
509
0
            dc_only_flag = ih264d_unpack_coeff8x8_8x8blk_cavlc(ps_dec,
510
0
                                          ps_cur_mb_info,
511
0
                                          ui2_luma_csbp,
512
0
                                          pi2_coeff_data);
513
0
514
0
            INSERT_BIT(u4_luma_dc_only_cbp, 1, dc_only_flag);
515
0
516
0
            pi2_coeff_data += 64;
517
0
518
0
            ui2_luma_csbp = ui2_luma_csbp >> 6;
519
0
            dc_only_flag = ih264d_unpack_coeff8x8_8x8blk_cavlc(ps_dec,
520
0
                                          ps_cur_mb_info,
521
0
                                          ui2_luma_csbp,
522
0
                                          pi2_coeff_data);
523
0
524
0
            INSERT_BIT(u4_luma_dc_only_cbp, 2, dc_only_flag);
525
0
526
0
            pi2_coeff_data += 64;
527
0
            ui2_luma_csbp = ui2_luma_csbp >> 2;
528
0
            dc_only_flag = ih264d_unpack_coeff8x8_8x8blk_cavlc(ps_dec,
529
0
                                          ps_cur_mb_info,
530
0
                                          ui2_luma_csbp,
531
0
                                          pi2_coeff_data);
532
0
            INSERT_BIT(u4_luma_dc_only_cbp, 3, dc_only_flag);
533
0
        }
534
0
        return u4_luma_dc_only_cbp;
535
0
    }
536
5.06k
537
5.06k
}
538
539
void ih264d_unpack_chroma_coeff4x4_mb(dec_struct_t * ps_dec,
540
                                      dec_mb_info_t * ps_cur_mb_info)
541
5.06k
{
542
5.06k
    UWORD8 u1_mb_type = ps_cur_mb_info->u1_mb_type;
543
5.06k
    UWORD16 ui2_chroma_csbp = ps_cur_mb_info->u2_chroma_csbp;
544
5.06k
    UWORD8 *pu1_inv_scan = ps_dec->pu1_inv_scan;
545
5.06k
    WORD16 *pi2_coeff_data = ps_dec->pi2_coeff_data;
546
5.06k
    WORD32 i;
547
5.06k
    WORD16 *pi2_dc_val_u = NULL;
548
5.06k
    WORD16 *pi2_dc_val_v = NULL;
549
5.06k
550
5.06k
    PROFILE_DISABLE_UNPACK_CHROMA()
551
5.06k
    if((ps_cur_mb_info->u1_cbp >> 4) == CBPC_ALLZERO)
552
5.06k
        return;
553
2.18k
554
2.18k
    /*
555
2.18k
     * Reserve the pointers to dc vals. The dc vals will be copied
556
2.18k
     * after unpacking of ac vals since memset to 0 inside.
557
2.18k
     */
558
2.18k
    if(CHECKBIT(ps_cur_mb_info->u1_yuv_dc_block_flag,1))
559
2.18k
    {
560
1.78k
        pi2_dc_val_u = (WORD16 *)ps_dec->pv_proc_tu_coeff_data;
561
1.78k
562
1.78k
        ps_dec->pv_proc_tu_coeff_data = (void *)(pi2_dc_val_u + 4);
563
1.78k
    }
564
2.18k
    if(CHECKBIT(ps_cur_mb_info->u1_yuv_dc_block_flag,2))
565
2.18k
    {
566
1.52k
        pi2_dc_val_v = (WORD16 *)ps_dec->pv_proc_tu_coeff_data;
567
1.52k
568
1.52k
        ps_dec->pv_proc_tu_coeff_data = (void *)(pi2_dc_val_v + 4);
569
1.52k
    }
570
2.18k
571
2.18k
    if((ps_cur_mb_info->u1_cbp >> 4) == CBPC_NONZERO)
572
2.18k
    {
573
2.18k
        pi2_coeff_data = ps_dec->pi2_coeff_data;
574
2.18k
        ih264d_unpack_coeff4x4_8x8blk_chroma(ps_dec,
575
2.18k
                                             ps_cur_mb_info,
576
2.18k
                                             ui2_chroma_csbp,
577
2.18k
                                             pi2_coeff_data);
578
2.18k
579
2.18k
        pi2_coeff_data += 64;
580
2.18k
        ui2_chroma_csbp = ui2_chroma_csbp >> 4;
581
2.18k
        ih264d_unpack_coeff4x4_8x8blk_chroma(ps_dec,
582
2.18k
                                             ps_cur_mb_info,
583
2.18k
                                             ui2_chroma_csbp,
584
2.18k
                                             pi2_coeff_data);
585
2.18k
586
2.18k
    }
587
2.18k
588
2.18k
    pi2_coeff_data = ps_dec->pi2_coeff_data;
589
2.18k
    if(pi2_dc_val_u != NULL)
590
2.18k
    {
591
1.78k
        pi2_coeff_data[0] = *pi2_dc_val_u++;
592
1.78k
        pi2_coeff_data[1 * 16] = *pi2_dc_val_u++;
593
1.78k
        pi2_coeff_data[2 * 16] = *pi2_dc_val_u++;
594
1.78k
        pi2_coeff_data[3 * 16] = *pi2_dc_val_u++;
595
1.78k
    }
596
407
    else
597
407
    {
598
407
        pi2_coeff_data[0] = 0;
599
407
        pi2_coeff_data[1 * 16] = 0;
600
407
        pi2_coeff_data[2 * 16] = 0;
601
407
        pi2_coeff_data[3 * 16] = 0;
602
407
    }
603
2.18k
    pi2_coeff_data += 64;
604
2.18k
    if(pi2_dc_val_v != NULL)
605
2.18k
    {
606
1.52k
        pi2_coeff_data[0] = *pi2_dc_val_v++;
607
1.52k
        pi2_coeff_data[1 * 16] = *pi2_dc_val_v++;
608
1.52k
        pi2_coeff_data[2 * 16] = *pi2_dc_val_v++;
609
1.52k
        pi2_coeff_data[3 * 16] = *pi2_dc_val_v++;
610
1.52k
    }
611
660
    else
612
660
    {
613
660
        pi2_coeff_data[0] = 0;
614
660
        pi2_coeff_data[1 * 16] = 0;
615
660
        pi2_coeff_data[2 * 16] = 0;
616
660
        pi2_coeff_data[3 * 16] = 0;
617
660
    }
618
2.18k
}
619
UWORD32 ih264d_unpack_luma_coeff8x8_mb(dec_struct_t * ps_dec,
620
                                    dec_mb_info_t * ps_cur_mb_info)
621
0
{
622
0
    WORD32 blk_8x8_cnt;
623
0
    WORD16 *pi2_out_coeff_data = ps_dec->pi2_coeff_data;
624
0
    UWORD8 u1_field_coding_flag = ps_cur_mb_info->ps_curmb->u1_mb_fld;
625
0
    UWORD8 *pu1_inv_scan;
626
0
    UWORD32 u4_luma_dc_only_cbp = 0;
627
0
628
0
    PROFILE_DISABLE_UNPACK_LUMA()
629
0
    if(!u1_field_coding_flag)
630
0
    {
631
0
        /*******************************************************************/
632
0
        /* initializing inverse scan  matrices                             */
633
0
        /*******************************************************************/
634
0
        pu1_inv_scan = (UWORD8 *)gau1_ih264d_inv_scan_prog8x8_cabac;
635
0
    }
636
0
    else
637
0
    {
638
0
        /*******************************************************************/
639
0
        /* initializing inverse scan  matrices                             */
640
0
        /*******************************************************************/
641
0
        pu1_inv_scan = (UWORD8 *)gau1_ih264d_inv_scan_int8x8_cabac;
642
0
    }
643
0
644
0
    for(blk_8x8_cnt = 0; blk_8x8_cnt < 4; blk_8x8_cnt++)
645
0
    {
646
0
        if(CHECKBIT(ps_cur_mb_info->u1_cbp, blk_8x8_cnt))
647
0
        {
648
0
            tu_blk8x8_coeff_data_t *ps_tu_8x8 = (tu_blk8x8_coeff_data_t *)ps_dec->pv_proc_tu_coeff_data;
649
0
            UWORD32 u4_sig_coeff_map;
650
0
            WORD32 idx = 0;
651
0
            WORD16 *pi2_coeff_data = &ps_tu_8x8->ai2_level[0];
652
0
            WORD32 num_coeff = 0;
653
0
654
0
            /* memset 64 coefficient to zero */
655
0
            memset(pi2_out_coeff_data,0,64*sizeof(WORD16));
656
0
657
0
            u4_sig_coeff_map = ps_tu_8x8->au4_sig_coeff_map[1];
658
0
659
0
            while(u4_sig_coeff_map)
660
0
            {
661
0
                idx = CLZ(u4_sig_coeff_map);
662
0
663
0
                idx = 31 - idx;
664
0
                RESET_BIT(u4_sig_coeff_map,idx);
665
0
666
0
                idx = pu1_inv_scan[idx + 32];
667
0
                pi2_out_coeff_data[idx] = *pi2_coeff_data++;
668
0
                num_coeff++;
669
0
            }
670
0
671
0
            u4_sig_coeff_map = ps_tu_8x8->au4_sig_coeff_map[0];
672
0
            while(u4_sig_coeff_map)
673
0
            {
674
0
                idx = CLZ(u4_sig_coeff_map);
675
0
676
0
                idx = 31 - idx;
677
0
                RESET_BIT(u4_sig_coeff_map,idx);
678
0
679
0
                idx = pu1_inv_scan[idx];
680
0
                pi2_out_coeff_data[idx] = *pi2_coeff_data++;
681
0
                num_coeff++;
682
0
            }
683
0
684
0
            if((num_coeff == 1) && (idx == 0))
685
0
            {
686
0
                SET_BIT(u4_luma_dc_only_cbp,blk_8x8_cnt);
687
0
            }
688
0
689
0
690
0
            {
691
0
                WORD32 offset;
692
0
                offset = (UWORD8 *)pi2_coeff_data - (UWORD8 *)ps_tu_8x8;
693
0
                offset = ALIGN4(offset);
694
0
                ps_dec->pv_proc_tu_coeff_data = (void *)((UWORD8 *)ps_dec->pv_proc_tu_coeff_data + offset);
695
0
            }
696
0
        }
697
0
        pi2_out_coeff_data += 64;
698
0
    }
699
0
700
0
    return u4_luma_dc_only_cbp;
701
0
}
702
/*!
703
 **************************************************************************
704
 * \if Function name : ih264d_process_intra_mb \endif
705
 *
706
 * \brief
707
 *    This function decodes an I MB. Intraprediction is carried out followed
708
 *    by InvTramsform. Both IntraPrediction and Reconstrucion are carried out
709
 *    row buffer itself.
710
 *
711
 *
712
 * \return
713
 *    0 on Success and Error code otherwise
714
 **************************************************************************
715
 */
716
WORD32 ih264d_process_intra_mb(dec_struct_t * ps_dec,
717
                               dec_mb_info_t * ps_cur_mb_info,
718
                               UWORD8 u1_mb_num)
719
5.06k
{
720
5.06k
    UWORD8 u1_mb_type = ps_cur_mb_info->u1_mb_type;
721
5.06k
    UWORD8 uc_temp = ps_cur_mb_info->u1_mb_ngbr_availablity;
722
5.06k
    UWORD8 u1_top_available = BOOLEAN(uc_temp & TOP_MB_AVAILABLE_MASK);
723
5.06k
    UWORD8 u1_left_available = BOOLEAN(uc_temp & LEFT_MB_AVAILABLE_MASK);
724
5.06k
    UWORD8 u1_use_top_right_mb = BOOLEAN(uc_temp & TOP_RIGHT_MB_AVAILABLE_MASK);
725
5.06k
    UWORD8 u1_use_top_left_mb = BOOLEAN(uc_temp & TOP_LEFT_MB_AVAILABLE_MASK);
726
5.06k
    UWORD8 uc_useTopMB = u1_top_available;
727
5.06k
    UWORD16 u2_use_left_mb = u1_left_available;
728
5.06k
    UWORD16 u2_use_left_mb_pack;
729
5.06k
    UWORD8 *pu1_luma_pred_buffer;
730
5.06k
    /* CHANGED CODE */
731
5.06k
    UWORD8 *pu1_luma_rec_buffer;
732
5.06k
    UWORD8 *puc_top;
733
5.06k
734
5.06k
    mb_neigbour_params_t *ps_left_mb;
735
5.06k
    mb_neigbour_params_t *ps_top_mb;
736
5.06k
    mb_neigbour_params_t *ps_top_right_mb;
737
5.06k
    mb_neigbour_params_t *ps_curmb;
738
5.06k
739
5.06k
    UWORD16 u2_mbx = ps_cur_mb_info->u2_mbx;
740
5.06k
    UWORD32 ui_pred_width, ui_rec_width;
741
5.06k
    WORD16 *pi2_y_coeff;
742
5.06k
    UWORD8 u1_mbaff, u1_topmb, u1_mb_field_decoding_flag;
743
5.06k
    UWORD32 u4_num_pmbair;
744
5.06k
    UWORD16 ui2_luma_csbp = ps_cur_mb_info->u2_luma_csbp;
745
5.06k
    UWORD8 *pu1_yleft, *pu1_ytop_left;
746
5.06k
    /* Chroma variables*/
747
5.06k
    UWORD8 *pu1_top_u;
748
5.06k
    UWORD8 *pu1_uleft;
749
5.06k
    UWORD8 *pu1_u_top_left;
750
5.06k
    /* CHANGED CODE */
751
5.06k
    UWORD8 *pu1_mb_cb_rei1_buffer, *pu1_mb_cr_rei1_buffer;
752
5.06k
    UWORD32 u4_recwidth_cr;
753
5.06k
    /* CHANGED CODE */
754
5.06k
    tfr_ctxt_t *ps_frame_buf = ps_dec->ps_frame_buf_ip_recon;
755
5.06k
    UWORD32 u4_luma_dc_only_csbp = 0;
756
5.06k
    UWORD32 u4_luma_dc_only_cbp = 0;
757
5.06k
758
5.06k
    UWORD8 *pu1_prev_intra4x4_pred_mode_data = (UWORD8 *)ps_dec->pv_proc_tu_coeff_data;                 //Pointer to keep track of intra4x4_pred_mode data in pv_proc_tu_coeff_data buffer
759
5.06k
    u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
760
5.06k
    u1_topmb = ps_cur_mb_info->u1_topmb;
761
5.06k
    u4_num_pmbair = (u1_mb_num >> u1_mbaff);
762
5.06k
763
5.06k
764
5.06k
    /*--------------------------------------------------------------------*/
765
5.06k
    /* Find the current MB's mb params                                    */
766
5.06k
    /*--------------------------------------------------------------------*/
767
5.06k
    u1_mb_field_decoding_flag = ps_cur_mb_info->u1_mb_field_decodingflag;
768
5.06k
769
5.06k
    ps_curmb = ps_cur_mb_info->ps_curmb;
770
5.06k
    ps_top_mb = ps_cur_mb_info->ps_top_mb;
771
5.06k
    ps_left_mb = ps_cur_mb_info->ps_left_mb;
772
5.06k
    ps_top_right_mb = ps_cur_mb_info->ps_top_right_mb;
773
5.06k
774
5.06k
    /*--------------------------------------------------------------------*/
775
5.06k
    /* Check whether neighbouring MB is Inter MB and                      */
776
5.06k
    /* constrained intra pred is 1.                                       */
777
5.06k
    /*--------------------------------------------------------------------*/
778
5.06k
    u2_use_left_mb_pack = (u2_use_left_mb << 8) + u2_use_left_mb;
779
5.06k
780
5.06k
    if(ps_dec->ps_cur_pps->u1_constrained_intra_pred_flag)
781
0
    {
782
0
        UWORD8 u1_left = (UWORD8)u2_use_left_mb;
783
0
784
0
        uc_useTopMB = uc_useTopMB
785
0
                        && ((ps_top_mb->u1_mb_type != P_MB)
786
0
                                        && (ps_top_mb->u1_mb_type != B_MB));
787
0
        u2_use_left_mb = u2_use_left_mb
788
0
                        && ((ps_left_mb->u1_mb_type != P_MB)
789
0
                                        && (ps_left_mb->u1_mb_type != B_MB));
790
0
791
0
        u2_use_left_mb_pack = (u2_use_left_mb << 8) + u2_use_left_mb;
792
0
        if(u1_mbaff)
793
0
        {
794
0
            if(u1_mb_field_decoding_flag ^ ps_left_mb->u1_mb_fld)
795
0
            {
796
0
                u1_left = u1_left
797
0
                                && (((ps_left_mb + 1)->u1_mb_type != P_MB)
798
0
                                                && ((ps_left_mb + 1)->u1_mb_type
799
0
                                                                != B_MB));
800
0
                u2_use_left_mb = u2_use_left_mb && u1_left;
801
0
                if(u1_mb_field_decoding_flag)
802
0
                    u2_use_left_mb_pack = (u1_left << 8)
803
0
                                    + (u2_use_left_mb_pack & 0xff);
804
0
                else
805
0
                    u2_use_left_mb_pack = (u2_use_left_mb << 8)
806
0
                                    + (u2_use_left_mb);
807
0
            }
808
0
        }
809
0
        u1_use_top_right_mb =
810
0
                        u1_use_top_right_mb
811
0
                                        && ((ps_top_right_mb->u1_mb_type != P_MB)
812
0
                                                        && (ps_top_right_mb->u1_mb_type
813
0
                                                                        != B_MB));
814
0
815
0
        u1_use_top_left_mb =
816
0
                        u1_use_top_left_mb
817
0
                                        && ((ps_cur_mb_info->u1_topleft_mbtype != P_MB)
818
0
                                                        && (ps_cur_mb_info->u1_topleft_mbtype
819
0
                                                                        != B_MB));
820
0
    }
821
5.06k
822
5.06k
    /*********************Common pointer calculations *************************/
823
5.06k
    /* CHANGED CODE */
824
5.06k
    pu1_luma_pred_buffer = ps_dec->pu1_y;
825
5.06k
    pu1_luma_rec_buffer = ps_frame_buf->pu1_dest_y + (u4_num_pmbair << 4);
826
5.06k
    pu1_mb_cb_rei1_buffer = ps_frame_buf->pu1_dest_u
827
5.06k
                    + (u4_num_pmbair << 3) * YUV420SP_FACTOR;
828
5.06k
    pu1_mb_cr_rei1_buffer = ps_frame_buf->pu1_dest_v + (u4_num_pmbair << 3);
829
5.06k
    ui_pred_width = MB_SIZE;
830
5.06k
    ui_rec_width = ps_dec->u2_frm_wd_y << u1_mb_field_decoding_flag;
831
5.06k
    u4_recwidth_cr = ps_dec->u2_frm_wd_uv << u1_mb_field_decoding_flag;
832
5.06k
    /************* Current and top luma pointer *****************/
833
5.06k
834
5.06k
    if(u1_mbaff)
835
0
    {
836
0
        if(u1_topmb == 0)
837
0
        {
838
0
            pu1_luma_rec_buffer += (
839
0
                            u1_mb_field_decoding_flag ?
840
0
                                            (ui_rec_width >> 1) :
841
0
                                            (ui_rec_width << 4));
842
0
            pu1_mb_cb_rei1_buffer += (
843
0
                            u1_mb_field_decoding_flag ?
844
0
                                            (u4_recwidth_cr >> 1) :
845
0
                                            (u4_recwidth_cr << 3));
846
0
            pu1_mb_cr_rei1_buffer += (
847
0
                            u1_mb_field_decoding_flag ?
848
0
                                            (u4_recwidth_cr >> 1) :
849
0
                                            (u4_recwidth_cr << 3));
850
0
        }
851
0
    }
852
5.06k
853
5.06k
    /* CHANGED CODE */
854
5.06k
    if(ps_dec->u4_use_intrapred_line_copy == 1)
855
5.06k
    {
856
5.06k
        puc_top = ps_dec->pu1_prev_y_intra_pred_line + (ps_cur_mb_info->u2_mbx << 4);
857
5.06k
        pu1_top_u = ps_dec->pu1_prev_u_intra_pred_line
858
5.06k
                        + (ps_cur_mb_info->u2_mbx << 3) * YUV420SP_FACTOR;
859
5.06k
    }
860
0
    else
861
0
    {
862
0
        puc_top = pu1_luma_rec_buffer - ui_rec_width;
863
0
        pu1_top_u = pu1_mb_cb_rei1_buffer - u4_recwidth_cr;
864
0
    }
865
5.06k
    /* CHANGED CODE */
866
5.06k
867
5.06k
    /************* Left pointer *****************/
868
5.06k
    pu1_yleft = pu1_luma_rec_buffer - 1;
869
5.06k
    pu1_uleft = pu1_mb_cb_rei1_buffer - 1 * YUV420SP_FACTOR;
870
5.06k
871
5.06k
    /**************Top Left pointer calculation**********/
872
5.06k
    pu1_ytop_left = puc_top - 1;
873
5.06k
    pu1_u_top_left = pu1_top_u - 1 * YUV420SP_FACTOR;
874
5.06k
875
5.06k
    /* CHANGED CODE */
876
5.06k
    PROFILE_DISABLE_INTRA_PRED()
877
5.06k
    {
878
5.06k
        pu1_prev_intra4x4_pred_mode_data = (UWORD8 *)ps_dec->pv_proc_tu_coeff_data;
879
5.06k
        if(u1_mb_type == I_4x4_MB && ps_cur_mb_info->u1_tran_form8x8 == 0)
880
2.54k
        {
881
2.54k
            ps_dec->pv_proc_tu_coeff_data = (void *)((UWORD8 *)ps_dec->pv_proc_tu_coeff_data + 32);
882
2.54k
883
2.54k
        }
884
2.51k
        else if (u1_mb_type == I_4x4_MB && ps_cur_mb_info->u1_tran_form8x8 == 1)
885
0
        {
886
0
            ps_dec->pv_proc_tu_coeff_data = (void *)((UWORD8 *)ps_dec->pv_proc_tu_coeff_data + 8);
887
0
        }
888
5.06k
    }
889
5.06k
    if(!ps_cur_mb_info->u1_tran_form8x8)
890
5.06k
    {
891
5.06k
        u4_luma_dc_only_csbp = ih264d_unpack_luma_coeff4x4_mb(ps_dec,
892
5.06k
                                       ps_cur_mb_info,
893
5.06k
                                       1);
894
5.06k
    }
895
0
    else
896
0
    {
897
0
        if(!ps_dec->ps_cur_pps->u1_entropy_coding_mode)
898
0
        {
899
0
            u4_luma_dc_only_cbp = ih264d_unpack_luma_coeff4x4_mb(ps_dec,
900
0
                                           ps_cur_mb_info,
901
0
                                           1);
902
0
        }
903
0
        else
904
0
        {
905
0
            u4_luma_dc_only_cbp = ih264d_unpack_luma_coeff8x8_mb(ps_dec,
906
0
                                           ps_cur_mb_info);
907
0
        }
908
0
    }
909
5.06k
910
5.06k
    pi2_y_coeff = ps_dec->pi2_coeff_data;
911
5.06k
912
5.06k
    if(u1_mb_type != I_4x4_MB)
913
5.06k
    {
914
2.51k
        UWORD8 u1_intrapred_mode = MB_TYPE_TO_INTRA_16x16_MODE(u1_mb_type);
915
2.51k
        /*--------------------------------------------------------------------*/
916
2.51k
        /* 16x16 IntraPrediction                                              */
917
2.51k
        /*--------------------------------------------------------------------*/
918
2.51k
        {
919
2.51k
            UWORD8 u1_packed_modes = (u1_top_available << 1)
920
2.51k
                            + u1_left_available;
921
2.51k
            UWORD8 u1_err_code =
922
2.51k
                            (u1_intrapred_mode & 1) ?
923
605
                                            u1_intrapred_mode :
924
2.51k
                                            (u1_intrapred_mode ^ 2);
925
2.51k
926
2.51k
            if((u1_err_code & u1_packed_modes) ^ u1_err_code)
927
0
            {
928
0
                u1_intrapred_mode = 0;
929
0
                ps_dec->i4_error_code = ERROR_INTRAPRED;
930
0
            }
931
2.51k
        }
932
2.51k
        {
933
2.51k
            /* Align the size to multiple of 8, so that SIMD functions
934
2.51k
               can read 64 bits at a time. Only 33 bytes are actaully used */
935
2.51k
            UWORD8 au1_ngbr_pels[40];
936
2.51k
            /* Get neighbour pixels */
937
2.51k
            /* left pels */
938
2.51k
            if(u2_use_left_mb)
939
2.42k
            {
940
2.42k
                WORD32 i;
941
41.1k
                for(i = 0; i < 16; i++)
942
38.7k
                    au1_ngbr_pels[16 - 1 - i] = pu1_yleft[i * ui_rec_width];
943
2.42k
            }
944
99
            else
945
99
            {
946
99
                memset(au1_ngbr_pels, 0, 16);
947
99
            }
948
2.51k
949
2.51k
            /* top left pels */
950
2.51k
            au1_ngbr_pels[16] = *pu1_ytop_left;
951
2.51k
952
2.51k
            /* top pels */
953
2.51k
            if(uc_useTopMB)
954
2.32k
            {
955
2.32k
                memcpy(au1_ngbr_pels + 16 + 1, puc_top, 16);
956
2.32k
            }
957
198
            else
958
198
            {
959
198
                memset(au1_ngbr_pels + 16 + 1, 0, 16);
960
198
            }
961
2.51k
            PROFILE_DISABLE_INTRA_PRED()
962
2.51k
            ps_dec->apf_intra_pred_luma_16x16[u1_intrapred_mode](
963
2.51k
                            au1_ngbr_pels, pu1_luma_rec_buffer, 1, ui_rec_width,
964
2.51k
                            ((uc_useTopMB << 2) | u2_use_left_mb));
965
2.51k
        }
966
2.51k
        {
967
2.51k
            UWORD32 i;
968
2.51k
            WORD16 ai2_tmp[16];
969
42.8k
            for(i = 0; i < 16; i++)
970
40.3k
            {
971
40.3k
                WORD16 *pi2_level = pi2_y_coeff + (i << 4);
972
40.3k
                UWORD8 *pu1_pred_sblk = pu1_luma_rec_buffer
973
40.3k
                                + ((i & 0x3) * BLK_SIZE)
974
40.3k
                                + (i >> 2) * (ui_rec_width << 2);
975
40.3k
                PROFILE_DISABLE_IQ_IT_RECON()
976
40.3k
                {
977
40.3k
                    if(CHECKBIT(ps_cur_mb_info->u2_luma_csbp, i))
978
40.3k
                    {
979
121
                        ps_dec->pf_iquant_itrans_recon_luma_4x4(
980
121
                                        pi2_level,
981
121
                                        pu1_pred_sblk,
982
121
                                        pu1_pred_sblk,
983
121
                                        ui_rec_width,
984
121
                                        ui_rec_width,
985
121
                                        gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qp_rem6],
986
121
                                        (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[0],
987
121
                                        ps_cur_mb_info->u1_qp_div6, ai2_tmp, 1,
988
121
                                        pi2_level);
989
121
                    }
990
40.1k
                    else if((CHECKBIT(u4_luma_dc_only_csbp, i)) && pi2_level[0] != 0)
991
0
                    {
992
0
                        ps_dec->pf_iquant_itrans_recon_luma_4x4_dc(
993
0
                                        pi2_level,
994
0
                                        pu1_pred_sblk,
995
0
                                        pu1_pred_sblk,
996
0
                                        ui_rec_width,
997
0
                                        ui_rec_width,
998
0
                                        gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qp_rem6],
999
0
                                        (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[0],
1000
0
                                        ps_cur_mb_info->u1_qp_div6, ai2_tmp, 1,
1001
0
                                        pi2_level);
1002
0
                    }
1003
40.3k
                }
1004
40.3k
            }
1005
2.51k
        }
1006
2.51k
    }
1007
2.54k
    else if(!ps_cur_mb_info->u1_tran_form8x8)
1008
2.54k
    {
1009
2.54k
        UWORD8 u1_is_left_sub_block, u1_is_top_sub_block = uc_useTopMB;
1010
2.54k
        UWORD8 u1_sub_blk_x, u1_sub_blk_y, u1_sub_mb_num;
1011
2.54k
        WORD8 i1_top_pred_mode;
1012
2.54k
        WORD8 i1_left_pred_mode;
1013
2.54k
        UWORD8 *pu1_top, *pu1_left, *pu1_top_left, *pu1_top_right;
1014
2.54k
        WORD8 *pi1_cur_pred_mode, *pi1_left_pred_mode, *pc_topPredMode;
1015
2.54k
        UWORD16 ui2_left_pred_buf_width = 0xffff;
1016
2.54k
        WORD8 i1_intra_pred;
1017
2.54k
        UWORD8 *pu1_prev_intra4x4_pred_mode_flag = pu1_prev_intra4x4_pred_mode_data;
1018
2.54k
        UWORD8 *pu1_rem_intra4x4_pred_mode = pu1_prev_intra4x4_pred_mode_data + 16;
1019
2.54k
        WORD16 *pi2_y_coeff1;
1020
2.54k
        UWORD8 u1_cur_sub_block;
1021
2.54k
        UWORD16 ui2_top_rt_mask;
1022
2.54k
1023
2.54k
        /*--------------------------------------------------------------------*/
1024
2.54k
        /* 4x4 IntraPrediction                                                */
1025
2.54k
        /*--------------------------------------------------------------------*/
1026
2.54k
        /* Calculation of Top Right subblock mask                             */
1027
2.54k
        /*                                                                    */
1028
2.54k
        /* (a) Set it to default mask                                         */
1029
2.54k
        /*     [It has 0 for sublocks which will never have top-right sub block] */
1030
2.54k
        /*                                                                    */
1031
2.54k
        /* (b) If top MB is not available                                     */
1032
2.54k
        /*      Clear the bits of the first row sub blocks                    */
1033
2.54k
        /*                                                                    */
1034
2.54k
        /* (c) Set/Clear bit for top-right sublock of MB                      */
1035
2.54k
        /*      [5 sub-block in decoding order] based on TOP RIGHT MB availablity */
1036
2.54k
        /*--------------------------------------------------------------------*/
1037
2.54k
1038
2.54k
        pu1_top = puc_top;
1039
2.54k
1040
2.54k
        ui2_top_rt_mask = (u1_use_top_right_mb << 3) | (0x5750);
1041
2.54k
        if(uc_useTopMB)
1042
2.48k
            ui2_top_rt_mask |= 0x7;
1043
2.54k
1044
2.54k
        /*Top Related initialisations*/
1045
2.54k
1046
2.54k
1047
2.54k
        pi1_cur_pred_mode = ps_cur_mb_info->ps_curmb->pi1_intrapredmodes;
1048
2.54k
        pc_topPredMode = ps_cur_mb_info->ps_top_mb->pi1_intrapredmodes;
1049
2.54k
        /*--------------------------------------
1050
2.54k
         if(u1_mbaff)
1051
2.54k
         {
1052
2.54k
1053
2.54k
         pi1_cur_pred_mode += (u2_mbx << 2);
1054
2.54k
         pc_topPredMode = pi1_cur_pred_mode + ps_cur_mb_info->i1_offset;
1055
2.54k
         pi1_cur_pred_mode += (u1_topmb) ? 0: 4;
1056
2.54k
         }*/
1057
2.54k
1058
2.54k
        if(u1_top_available)
1059
2.48k
        {
1060
2.48k
            if(ps_top_mb->u1_mb_type == I_4x4_MB)
1061
2.48k
                *(WORD32*)pi1_cur_pred_mode = *(WORD32*)pc_topPredMode;
1062
913
            else
1063
913
                *(WORD32*)pi1_cur_pred_mode =
1064
913
                                (uc_useTopMB) ? DC_DC_DC_DC : NOT_VALID;
1065
2.48k
        }
1066
55
        else
1067
55
            *(WORD32*)pi1_cur_pred_mode = NOT_VALID;
1068
2.54k
        /* CHANGED CODE */
1069
2.54k
1070
2.54k
        /* CHANGED CODE */
1071
2.54k
1072
2.54k
        /*Left Related initialisations*/
1073
2.54k
        pi1_left_pred_mode = ps_dec->pi1_left_pred_mode;
1074
2.54k
        if(!u1_mbaff)
1075
2.54k
        {
1076
2.54k
1077
2.54k
            if(u1_left_available)
1078
2.42k
            {
1079
2.42k
1080
2.42k
                if(ps_left_mb->u1_mb_type != I_4x4_MB)
1081
2.42k
                    *(WORD32*)pi1_left_pred_mode =
1082
704
                                    (u2_use_left_mb_pack) ?
1083
704
                                    DC_DC_DC_DC :
1084
704
                                                            NOT_VALID;
1085
2.42k
1086
2.42k
            }
1087
121
            else
1088
121
            {
1089
121
1090
121
                *(WORD32*)pi1_left_pred_mode = NOT_VALID;
1091
121
            }
1092
2.54k
1093
2.54k
        }
1094
0
        else
1095
0
        {
1096
0
            UWORD8 u1_curMbfld = ps_cur_mb_info->u1_mb_field_decodingflag;
1097
0
            UWORD8 u1_leftMbfld = ps_left_mb->u1_mb_fld;
1098
0
1099
0
            if(u1_curMbfld ^ u1_leftMbfld)
1100
0
            {
1101
0
1102
0
                if(u1_topmb
1103
0
                                | ((u1_topmb == 0)
1104
0
                                                && ((ps_curmb - 1)->u1_mb_type
1105
0
                                                                != I_4x4_MB)))
1106
0
                {
1107
0
                    if(u1_left_available)
1108
0
                    {
1109
0
                        if(ps_left_mb->u1_mb_type != I_4x4_MB)
1110
0
                        {
1111
0
                            if(CHECKBIT(u2_use_left_mb_pack,0) == 0)
1112
0
                                *(WORD32*)pi1_left_pred_mode = NOT_VALID;
1113
0
                            else
1114
0
                                *(WORD32*)pi1_left_pred_mode = DC_DC_DC_DC;
1115
0
                        }
1116
0
                    }
1117
0
                    else
1118
0
                        *(WORD32*)pi1_left_pred_mode = NOT_VALID;
1119
0
1120
0
                    if(u1_curMbfld)
1121
0
                    {
1122
0
                        if(u1_left_available)
1123
0
                        {
1124
0
                            if((ps_left_mb + 1)->u1_mb_type != I_4x4_MB)
1125
0
                            {
1126
0
                                if(u2_use_left_mb_pack >> 8)
1127
0
                                    *(WORD32*)(pi1_left_pred_mode + 4) =
1128
0
                                                    DC_DC_DC_DC;
1129
0
                                else
1130
0
                                    *(WORD32*)(pi1_left_pred_mode + 4) =
1131
0
                                                    NOT_VALID;
1132
0
                            }
1133
0
                        }
1134
0
                        else
1135
0
                            *(WORD32*)(pi1_left_pred_mode + 4) = NOT_VALID;
1136
0
                        pi1_left_pred_mode[1] = pi1_left_pred_mode[2];
1137
0
                        pi1_left_pred_mode[2] = pi1_left_pred_mode[4];
1138
0
                        pi1_left_pred_mode[3] = pi1_left_pred_mode[6];
1139
0
                        *(WORD32*)(pi1_left_pred_mode + 4) =
1140
0
                                        *(WORD32*)pi1_left_pred_mode;
1141
0
                    }
1142
0
                    else
1143
0
                    {
1144
0
1145
0
                        pi1_left_pred_mode[7] = pi1_left_pred_mode[3];
1146
0
                        pi1_left_pred_mode[6] = pi1_left_pred_mode[3];
1147
0
                        pi1_left_pred_mode[5] = pi1_left_pred_mode[2];
1148
0
                        pi1_left_pred_mode[4] = pi1_left_pred_mode[2];
1149
0
                        pi1_left_pred_mode[3] = pi1_left_pred_mode[1];
1150
0
                        pi1_left_pred_mode[2] = pi1_left_pred_mode[1];
1151
0
                        pi1_left_pred_mode[1] = pi1_left_pred_mode[0];
1152
0
                    }
1153
0
                }
1154
0
                pi1_left_pred_mode += (u1_topmb) ? 0 : 4;
1155
0
            }
1156
0
            else
1157
0
            {
1158
0
1159
0
                pi1_left_pred_mode += (u1_topmb) ? 0 : 4;
1160
0
                if(u1_left_available)
1161
0
                {
1162
0
1163
0
                    if(ps_left_mb->u1_mb_type != I_4x4_MB)
1164
0
                        *(WORD32*)pi1_left_pred_mode =
1165
0
                                        (u2_use_left_mb_pack) ?
1166
0
                                        DC_DC_DC_DC :
1167
0
                                                                NOT_VALID;
1168
0
                }
1169
0
                else
1170
0
                    *(WORD32*)pi1_left_pred_mode = NOT_VALID;
1171
0
            }
1172
0
        }
1173
2.54k
        /* One time pointer initialisations*/
1174
2.54k
        pi2_y_coeff1 = pi2_y_coeff;
1175
2.54k
        pu1_top_left = pu1_ytop_left;
1176
2.54k
1177
2.54k
        /* Scan the sub-blocks in Raster Scan Order */
1178
43.1k
        for(u1_sub_mb_num = 0; u1_sub_mb_num < 16; u1_sub_mb_num++)
1179
40.6k
        {
1180
40.6k
            /* Align the size to multiple of 8, so that SIMD functions
1181
40.6k
               can read 64 bits at a time. Only 13 bytes are actaully used */
1182
40.6k
            UWORD8 au1_ngbr_pels[16];
1183
40.6k
1184
40.6k
            u1_sub_blk_x = u1_sub_mb_num & 0x3;
1185
40.6k
            u1_sub_blk_y = u1_sub_mb_num >> 2;
1186
40.6k
            i1_top_pred_mode = pi1_cur_pred_mode[u1_sub_blk_x];
1187
40.6k
            i1_left_pred_mode = pi1_left_pred_mode[u1_sub_blk_y];
1188
40.6k
            u1_use_top_right_mb = (!!CHECKBIT(ui2_top_rt_mask, u1_sub_mb_num));
1189
40.6k
1190
40.6k
            /*********** left subblock availability**********/
1191
40.6k
            if(u1_sub_blk_x)
1192
30.4k
                u1_is_left_sub_block = 1;
1193
10.1k
            else
1194
10.1k
                u1_is_left_sub_block =
1195
10.1k
                                (u1_sub_blk_y < 2) ?
1196
5.08k
                                                (CHECKBIT(u2_use_left_mb_pack,
1197
5.08k
                                                          0)) :
1198
10.1k
                                                (u2_use_left_mb_pack >> 8);
1199
40.6k
1200
40.6k
            /* CHANGED CODE */
1201
40.6k
            if(u1_sub_blk_y)
1202
30.4k
                u1_is_top_sub_block = 1;
1203
40.6k
1204
40.6k
            /* CHANGED CODE */
1205
40.6k
            /***************** Top *********************/
1206
40.6k
            if(ps_dec->u4_use_intrapred_line_copy == 1)
1207
40.6k
            {
1208
40.6k
1209
40.6k
                if(u1_sub_blk_y)
1210
30.4k
                    pu1_top = pu1_luma_rec_buffer - ui_rec_width;
1211
10.1k
                else
1212
10.1k
                    pu1_top = puc_top + (u1_sub_blk_x << 2);
1213
40.6k
            }
1214
0
            else
1215
0
            {
1216
0
                pu1_top = pu1_luma_rec_buffer - ui_rec_width;
1217
0
            }
1218
40.6k
            /***************** Top Right *********************/
1219
40.6k
            pu1_top_right = pu1_top + 4;
1220
40.6k
            /***************** Top Left *********************/
1221
40.6k
            pu1_top_left = pu1_top - 1;
1222
40.6k
            /***************** Left *********************/
1223
40.6k
            pu1_left = pu1_luma_rec_buffer - 1;
1224
40.6k
            /* CHANGED CODE */
1225
40.6k
1226
40.6k
            /*---------------------------------------------------------------*/
1227
40.6k
            /* Calculation of Intra prediction mode                          */
1228
40.6k
            /*---------------------------------------------------------------*/
1229
40.6k
            i1_intra_pred = ((i1_left_pred_mode < 0) | (i1_top_pred_mode < 0)) ?
1230
40.6k
                            DC : MIN(i1_left_pred_mode, i1_top_pred_mode);
1231
40.6k
            {
1232
40.6k
                UWORD8 u1_packed_modes = (u1_is_top_sub_block << 1)
1233
40.6k
                                + u1_is_left_sub_block;
1234
40.6k
                UWORD8 *pu1_intra_err_codes =
1235
40.6k
                                (UWORD8 *)gau1_ih264d_intra_pred_err_code;
1236
40.6k
                UWORD8 uc_b2b0 = ((u1_sub_mb_num & 4) >> 1) | (u1_sub_mb_num & 1);
1237
40.6k
                UWORD8 uc_b3b1 = ((u1_sub_mb_num & 8) >> 2)
1238
40.6k
                                | ((u1_sub_mb_num & 2) >> 1);
1239
40.6k
1240
40.6k
                u1_cur_sub_block = (uc_b3b1 << 2) + uc_b2b0;
1241
40.6k
                PROFILE_DISABLE_INTRA_PRED()
1242
40.6k
                if(!pu1_prev_intra4x4_pred_mode_flag[u1_cur_sub_block])
1243
8.86k
                {
1244
8.86k
                    i1_intra_pred =
1245
8.86k
                                    pu1_rem_intra4x4_pred_mode[u1_cur_sub_block]
1246
8.86k
                                                    + (pu1_rem_intra4x4_pred_mode[u1_cur_sub_block]
1247
8.86k
                                                                    >= i1_intra_pred);
1248
8.86k
                }
1249
40.6k
                i1_intra_pred = CLIP3(0, 8, i1_intra_pred);
1250
40.6k
                {
1251
40.6k
                    UWORD8 u1_err_code = pu1_intra_err_codes[i1_intra_pred];
1252
40.6k
1253
40.6k
                    if((u1_err_code & u1_packed_modes) ^ u1_err_code)
1254
0
                     {
1255
0
                        i1_intra_pred = 0;
1256
0
                        ps_dec->i4_error_code = ERROR_INTRAPRED;
1257
0
                     }
1258
40.6k
1259
40.6k
                }
1260
40.6k
            }
1261
40.6k
            {
1262
40.6k
                /* Get neighbour pixels */
1263
40.6k
                /* left pels */
1264
40.6k
                if(u1_is_left_sub_block)
1265
40.1k
                {
1266
40.1k
                    WORD32 i;
1267
200k
                    for(i = 0; i < 4; i++)
1268
160k
                        au1_ngbr_pels[4 - 1 - i] = pu1_left[i * ui_rec_width];
1269
40.1k
                }
1270
484
                else
1271
484
                {
1272
484
                    memset(au1_ngbr_pels, 0, 4);
1273
484
                }
1274
40.6k
1275
40.6k
                /* top left pels */
1276
40.6k
                au1_ngbr_pels[4] = *pu1_top_left;
1277
40.6k
1278
40.6k
                /* top pels */
1279
40.6k
                if(u1_is_top_sub_block)
1280
40.4k
                {
1281
40.4k
                    memcpy(au1_ngbr_pels + 4 + 1, pu1_top, 4);
1282
40.4k
                }
1283
220
                else
1284
220
                {
1285
220
                    memset(au1_ngbr_pels + 4 + 1, 0, 4);
1286
220
                }
1287
40.6k
1288
40.6k
                /* top right pels */
1289
40.6k
                if(u1_use_top_right_mb)
1290
27.6k
                {
1291
27.6k
                    memcpy(au1_ngbr_pels + 4 * 2 + 1, pu1_top_right, 4);
1292
27.6k
                }
1293
12.9k
                else if(u1_is_top_sub_block)
1294
12.7k
                {
1295
12.7k
                    memset(au1_ngbr_pels + 4 * 2 + 1, au1_ngbr_pels[4 * 2], 4);
1296
12.7k
                }
1297
40.6k
            }
1298
40.6k
            PROFILE_DISABLE_INTRA_PRED()
1299
40.6k
            ps_dec->apf_intra_pred_luma_4x4[i1_intra_pred](
1300
40.6k
                            au1_ngbr_pels, pu1_luma_rec_buffer, 1,
1301
40.6k
                            ui_rec_width,
1302
40.6k
                            ((u1_is_top_sub_block << 2) | u1_is_left_sub_block));
1303
40.6k
1304
40.6k
            /* CHANGED CODE */
1305
40.6k
            if(CHECKBIT(ui2_luma_csbp, u1_sub_mb_num))
1306
40.6k
            {
1307
15.0k
                WORD16 ai2_tmp[16];
1308
15.0k
                PROFILE_DISABLE_IQ_IT_RECON()
1309
15.0k
                {
1310
15.0k
                    if(CHECKBIT(u4_luma_dc_only_csbp, u1_sub_mb_num))
1311
15.0k
                    {
1312
66
                        ps_dec->pf_iquant_itrans_recon_luma_4x4_dc(
1313
66
                                        pi2_y_coeff1,
1314
66
                                        pu1_luma_rec_buffer,
1315
66
                                        pu1_luma_rec_buffer,
1316
66
                                        ui_rec_width,
1317
66
                                        ui_rec_width,
1318
66
                                        gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qp_rem6],
1319
66
                                        (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[0],
1320
66
                                        ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0,
1321
66
                                        NULL);
1322
66
                    }
1323
14.9k
                    else
1324
14.9k
                    {
1325
14.9k
                        ps_dec->pf_iquant_itrans_recon_luma_4x4(
1326
14.9k
                                        pi2_y_coeff1,
1327
14.9k
                                        pu1_luma_rec_buffer,
1328
14.9k
                                        pu1_luma_rec_buffer,
1329
14.9k
                                        ui_rec_width,
1330
14.9k
                                        ui_rec_width,
1331
14.9k
                                        gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qp_rem6],
1332
14.9k
                                        (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[0],
1333
14.9k
                                        ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0,
1334
14.9k
                                        NULL);
1335
14.9k
                    }
1336
15.0k
                }
1337
15.0k
1338
15.0k
            }
1339
40.6k
1340
40.6k
            /*---------------------------------------------------------------*/
1341
40.6k
            /* Update sub block number                                       */
1342
40.6k
            /*---------------------------------------------------------------*/
1343
40.6k
            pi2_y_coeff1 += 16;
1344
40.6k
            pu1_luma_rec_buffer +=
1345
40.6k
                            (u1_sub_blk_x == 3) ? (ui_rec_width << 2) - 12 : 4;
1346
40.6k
            pu1_luma_pred_buffer +=
1347
40.6k
                            (u1_sub_blk_x == 3) ? (ui_pred_width << 2) - 12 : 4;
1348
40.6k
            /* CHANGED CODE */
1349
40.6k
            pi1_cur_pred_mode[u1_sub_blk_x] = i1_intra_pred;
1350
40.6k
            pi1_left_pred_mode[u1_sub_blk_y] = i1_intra_pred;
1351
40.6k
        }
1352
2.54k
    }
1353
0
    else if((u1_mb_type == I_4x4_MB) && (ps_cur_mb_info->u1_tran_form8x8 == 1))
1354
0
    {
1355
0
        UWORD8 u1_is_left_sub_block, u1_is_top_sub_block = uc_useTopMB;
1356
0
        UWORD8 u1_sub_blk_x, u1_sub_blk_y, u1_sub_mb_num;
1357
0
        WORD8 i1_top_pred_mode;
1358
0
        WORD8 i1_left_pred_mode;
1359
0
        UWORD8 *pu1_top, *pu1_left, *pu1_top_left;
1360
0
        WORD8 *pi1_cur_pred_mode, *pi1_left_pred_mode, *pc_topPredMode;
1361
0
        UWORD16 ui2_left_pred_buf_width = 0xffff;
1362
0
        WORD8 i1_intra_pred;
1363
0
        UWORD8 *pu1_prev_intra4x4_pred_mode_flag = pu1_prev_intra4x4_pred_mode_data;
1364
0
        UWORD8 *pu1_rem_intra4x4_pred_mode = pu1_prev_intra4x4_pred_mode_data + 4;
1365
0
        WORD16 *pi2_y_coeff1;
1366
0
        UWORD16 ui2_top_rt_mask;
1367
0
        UWORD32 u4_4x4_left_offset = 0;
1368
0
1369
0
        /*--------------------------------------------------------------------*/
1370
0
        /* 8x8 IntraPrediction                                                */
1371
0
        /*--------------------------------------------------------------------*/
1372
0
        /* Calculation of Top Right subblock mask                             */
1373
0
        /*                                                                    */
1374
0
        /* (a) Set it to default mask                                         */
1375
0
        /*  [It has 0 for sublocks which will never have top-right sub block] */
1376
0
        /*                                                                    */
1377
0
        /* (b) If top MB is not available                                     */
1378
0
        /*      Clear the bits of the first row sub blocks                    */
1379
0
        /*                                                                    */
1380
0
        /* (c) Set/Clear bit for top-right sublock of MB                      */
1381
0
        /*  [5 sub-block in decoding order] based on TOP RIGHT MB availablity */
1382
0
        /*                                                                    */
1383
0
        /* ui2_top_rt_mask: marks availibility of top right(neighbour)         */
1384
0
        /* in the 8x8 Block ordering                                          */
1385
0
        /*                                                                    */
1386
0
        /*      tr0   tr1                                                     */
1387
0
        /*   0    1   tr3                                                     */
1388
0
        /*   2    3                                                           */
1389
0
        /*                                                                    */
1390
0
        /*  Top rights for 0 is in top MB                                     */
1391
0
        /*  top right of 1 will be in top right MB                            */
1392
0
        /*  top right of 3 in right MB and hence not available                */
1393
0
        /*  This corresponds to ui2_top_rt_mask  having default value 0x4      */
1394
0
        /*--------------------------------------------------------------------*/
1395
0
1396
0
        ui2_top_rt_mask = (u1_use_top_right_mb << 1) | (0x4);
1397
0
1398
0
        if(uc_useTopMB)
1399
0
        {
1400
0
            ui2_top_rt_mask |= 0x1;
1401
0
        }
1402
0
1403
0
        /* Top Related initialisations */
1404
0
        pi1_cur_pred_mode = ps_cur_mb_info->ps_curmb->pi1_intrapredmodes;
1405
0
        pc_topPredMode = ps_cur_mb_info->ps_top_mb->pi1_intrapredmodes;
1406
0
        /*
1407
0
         if(u1_mbaff)
1408
0
         {
1409
0
         pi1_cur_pred_mode += (u2_mbx << 2);
1410
0
         pc_topPredMode = pi1_cur_pred_mode + ps_cur_mb_info->i1_offset;
1411
0
         pi1_cur_pred_mode += (u1_topmb) ? 0: 4;
1412
0
         }
1413
0
         */
1414
0
        if(u1_top_available)
1415
0
        {
1416
0
            if(ps_top_mb->u1_mb_type == I_4x4_MB)
1417
0
            {
1418
0
                *(WORD32*)pi1_cur_pred_mode = *(WORD32*)pc_topPredMode;
1419
0
            }
1420
0
            else
1421
0
            {
1422
0
                *(WORD32*)pi1_cur_pred_mode =
1423
0
                                (uc_useTopMB) ? DC_DC_DC_DC : NOT_VALID;
1424
0
            }
1425
0
        }
1426
0
        else
1427
0
        {
1428
0
            *(WORD32*)pi1_cur_pred_mode = NOT_VALID;
1429
0
        }
1430
0
1431
0
        pu1_top = puc_top - 8;
1432
0
1433
0
        /*Left Related initialisations*/
1434
0
        pi1_left_pred_mode = ps_dec->pi1_left_pred_mode;
1435
0
1436
0
        if(!u1_mbaff)
1437
0
        {
1438
0
            if(u1_left_available)
1439
0
            {
1440
0
                if(ps_left_mb->u1_mb_type != I_4x4_MB)
1441
0
                {
1442
0
                    *(WORD32*)pi1_left_pred_mode =
1443
0
                                    (u2_use_left_mb_pack) ?
1444
0
                                    DC_DC_DC_DC :
1445
0
                                                            NOT_VALID;
1446
0
                }
1447
0
            }
1448
0
            else
1449
0
            {
1450
0
                *(WORD32*)pi1_left_pred_mode = NOT_VALID;
1451
0
            }
1452
0
        }
1453
0
        else
1454
0
        {
1455
0
            UWORD8 u1_curMbfld = ps_cur_mb_info->u1_mb_field_decodingflag;
1456
0
1457
0
            UWORD8 u1_leftMbfld = ps_left_mb->u1_mb_fld;
1458
0
1459
0
            if((!u1_curMbfld) && (u1_leftMbfld))
1460
0
            {
1461
0
                u4_4x4_left_offset = 1;
1462
0
            }
1463
0
1464
0
            if(u1_curMbfld ^ u1_leftMbfld)
1465
0
            {
1466
0
1467
0
                if(u1_topmb
1468
0
                                | ((u1_topmb == 0)
1469
0
                                                && ((ps_curmb - 1)->u1_mb_type
1470
0
                                                                != I_4x4_MB)))
1471
0
1472
0
                {
1473
0
                    if(u1_left_available)
1474
0
                    {
1475
0
                        if(ps_left_mb->u1_mb_type != I_4x4_MB)
1476
0
                        {
1477
0
                            if(CHECKBIT(u2_use_left_mb_pack,0) == 0)
1478
0
                            {
1479
0
                                *(WORD32*)pi1_left_pred_mode = NOT_VALID;
1480
0
                            }
1481
0
                            else
1482
0
                            {
1483
0
                                *(WORD32*)pi1_left_pred_mode = DC_DC_DC_DC;
1484
0
                            }
1485
0
                        }
1486
0
                    }
1487
0
                    else
1488
0
                    {
1489
0
                        *(WORD32*)pi1_left_pred_mode = NOT_VALID;
1490
0
                    }
1491
0
1492
0
                    if(u1_curMbfld)
1493
0
                    {
1494
0
                        if(u1_left_available)
1495
0
                        {
1496
0
                            if((ps_left_mb + 1)->u1_mb_type != I_4x4_MB)
1497
0
                            {
1498
0
                                if(u2_use_left_mb_pack >> 8)
1499
0
                                {
1500
0
                                    *(WORD32*)(pi1_left_pred_mode + 4) =
1501
0
                                                    DC_DC_DC_DC;
1502
0
                                }
1503
0
                                else
1504
0
                                {
1505
0
                                    *(WORD32*)(pi1_left_pred_mode + 4) =
1506
0
                                                    NOT_VALID;
1507
0
                                }
1508
0
                            }
1509
0
                        }
1510
0
                        else
1511
0
                        {
1512
0
                            *(WORD32*)(pi1_left_pred_mode + 4) = NOT_VALID;
1513
0
                        }
1514
0
1515
0
                        pi1_left_pred_mode[1] = pi1_left_pred_mode[2];
1516
0
                        pi1_left_pred_mode[2] = pi1_left_pred_mode[4];
1517
0
                        pi1_left_pred_mode[3] = pi1_left_pred_mode[6];
1518
0
                        *(WORD32*)(pi1_left_pred_mode + 4) =
1519
0
                                        *(WORD32*)pi1_left_pred_mode;
1520
0
                    }
1521
0
                    else
1522
0
                    {
1523
0
                        pi1_left_pred_mode[7] = pi1_left_pred_mode[3];
1524
0
                        pi1_left_pred_mode[6] = pi1_left_pred_mode[3];
1525
0
                        pi1_left_pred_mode[5] = pi1_left_pred_mode[2];
1526
0
                        pi1_left_pred_mode[4] = pi1_left_pred_mode[2];
1527
0
                        pi1_left_pred_mode[3] = pi1_left_pred_mode[1];
1528
0
                        pi1_left_pred_mode[2] = pi1_left_pred_mode[1];
1529
0
                        pi1_left_pred_mode[1] = pi1_left_pred_mode[0];
1530
0
                    }
1531
0
                }
1532
0
                pi1_left_pred_mode += (u1_topmb) ? 0 : 4;
1533
0
            }
1534
0
            else
1535
0
            {
1536
0
                pi1_left_pred_mode += (u1_topmb) ? 0 : 4;
1537
0
1538
0
                if(u1_left_available)
1539
0
                {
1540
0
                    if(ps_left_mb->u1_mb_type != I_4x4_MB)
1541
0
                    {
1542
0
                        *(WORD32*)pi1_left_pred_mode =
1543
0
                                        (u2_use_left_mb_pack) ?
1544
0
                                        DC_DC_DC_DC :
1545
0
                                                                NOT_VALID;
1546
0
                    }
1547
0
                }
1548
0
                else
1549
0
                {
1550
0
                    *(WORD32*)pi1_left_pred_mode = NOT_VALID;
1551
0
                }
1552
0
            }
1553
0
        }
1554
0
1555
0
        /* One time pointer initialisations*/
1556
0
        pi2_y_coeff1 = pi2_y_coeff;
1557
0
1558
0
        if(u1_use_top_left_mb)
1559
0
        {
1560
0
            pu1_top_left = pu1_ytop_left;
1561
0
        }
1562
0
        else
1563
0
        {
1564
0
            pu1_top_left = NULL;
1565
0
        }
1566
0
1567
0
        /* Scan the sub-blocks in Raster Scan Order */
1568
0
        for(u1_sub_mb_num = 0; u1_sub_mb_num < 4; u1_sub_mb_num++)
1569
0
        {
1570
0
            u1_sub_blk_x = (u1_sub_mb_num & 0x1);
1571
0
            u1_sub_blk_y = (u1_sub_mb_num >> 1);
1572
0
            i1_top_pred_mode = pi1_cur_pred_mode[u1_sub_blk_x << 1];
1573
0
            i1_left_pred_mode = pi1_left_pred_mode[u1_sub_blk_y << 1];
1574
0
1575
0
            if(2 == u1_sub_mb_num)
1576
0
            {
1577
0
                i1_left_pred_mode = pi1_left_pred_mode[(u1_sub_blk_y << 1)
1578
0
                                + u4_4x4_left_offset];
1579
0
            }
1580
0
1581
0
            u1_use_top_right_mb = (!!CHECKBIT(ui2_top_rt_mask, u1_sub_mb_num));
1582
0
1583
0
            /*********** left subblock availability**********/
1584
0
            if(u1_sub_blk_x)
1585
0
            {
1586
0
                u1_is_left_sub_block = 1;
1587
0
            }
1588
0
            else
1589
0
            {
1590
0
                u1_is_left_sub_block =
1591
0
                                (u1_sub_blk_y < 1) ?
1592
0
                                                (CHECKBIT(u2_use_left_mb_pack,
1593
0
                                                          0)) :
1594
0
                                                (u2_use_left_mb_pack >> 8);
1595
0
            }
1596
0
1597
0
            /***************** Top *********************/
1598
0
            if(u1_sub_blk_y)
1599
0
            {
1600
0
                u1_is_top_sub_block = 1;
1601
0
                // sushant
1602
0
                pu1_top = /*pu1_luma_pred_buffer*/pu1_luma_rec_buffer - ui_rec_width;
1603
0
            }
1604
0
            else
1605
0
            {
1606
0
                pu1_top += 8;
1607
0
            }
1608
0
1609
0
            /***************** Left *********************/
1610
0
            if((u1_sub_blk_x) | (u4_num_pmbair != 0))
1611
0
            {
1612
0
                // sushant
1613
0
                pu1_left = /*pu1_luma_pred_buffer*/pu1_luma_rec_buffer - 1;
1614
0
                ui2_left_pred_buf_width = ui_rec_width;
1615
0
            }
1616
0
            else
1617
0
            {
1618
0
                pu1_left = pu1_yleft;
1619
0
                pu1_yleft += (ui_rec_width << 3);
1620
0
                ui2_left_pred_buf_width = ui_rec_width;
1621
0
            }
1622
0
1623
0
            /***************** Top Left *********************/
1624
0
            if(u1_sub_mb_num)
1625
0
            {
1626
0
                pu1_top_left = (u1_sub_blk_x) ?
1627
0
                                pu1_top - 1 : pu1_left - ui_rec_width;
1628
0
1629
0
                if((u1_sub_blk_x && (!u1_is_top_sub_block))
1630
0
                                || ((!u1_sub_blk_x) && (!u1_is_left_sub_block)))
1631
0
                {
1632
0
                    pu1_top_left = NULL;
1633
0
                }
1634
0
            }
1635
0
1636
0
            /*---------------------------------------------------------------*/
1637
0
            /* Calculation of Intra prediction mode                          */
1638
0
            /*---------------------------------------------------------------*/
1639
0
            i1_intra_pred = ((i1_left_pred_mode < 0) | (i1_top_pred_mode < 0)) ?
1640
0
                            DC : MIN(i1_left_pred_mode, i1_top_pred_mode);
1641
0
            {
1642
0
                UWORD8 u1_packed_modes = (u1_is_top_sub_block << 1)
1643
0
                                + u1_is_left_sub_block;
1644
0
                UWORD8 *pu1_intra_err_codes =
1645
0
                                (UWORD8 *)gau1_ih264d_intra_pred_err_code;
1646
0
1647
0
                /********************************************************************/
1648
0
                /* Same intra4x4_pred_mode array is filled with intra4x4_pred_mode  */
1649
0
                /* for a MB with 8x8 intrapredicition                               */
1650
0
                /********************************************************************/
1651
0
                PROFILE_DISABLE_INTRA_PRED()
1652
0
                if(!pu1_prev_intra4x4_pred_mode_flag[u1_sub_mb_num])
1653
0
                {
1654
0
                    i1_intra_pred = pu1_rem_intra4x4_pred_mode[u1_sub_mb_num]
1655
0
                                    + (pu1_rem_intra4x4_pred_mode[u1_sub_mb_num]
1656
0
                                                    >= i1_intra_pred);
1657
0
                }
1658
0
                i1_intra_pred = CLIP3(0, 8, i1_intra_pred);
1659
0
                {
1660
0
                    UWORD8 u1_err_code = pu1_intra_err_codes[i1_intra_pred];
1661
0
1662
0
                    if((u1_err_code & u1_packed_modes) ^ u1_err_code)
1663
0
                    {
1664
0
                        i1_intra_pred = 0;
1665
0
                        ps_dec->i4_error_code = ERROR_INTRAPRED;
1666
0
                    }
1667
0
                }
1668
0
            }
1669
0
1670
0
            {
1671
0
                /* Align the size to multiple of 8, so that SIMD functions
1672
0
                can read 64 bits at a time. Only 25 bytes are actaully used */
1673
0
                UWORD8 au1_ngbr_pels[32];
1674
0
                WORD32 ngbr_avail;
1675
0
                ngbr_avail = u1_is_left_sub_block << 0;
1676
0
                ngbr_avail |= u1_is_top_sub_block << 2;
1677
0
1678
0
                if(pu1_top_left)
1679
0
                    ngbr_avail |= 1 << 1;
1680
0
1681
0
                ngbr_avail |= u1_use_top_right_mb << 3;
1682
0
                PROFILE_DISABLE_INTRA_PRED()
1683
0
                {
1684
0
                    ps_dec->pf_intra_pred_ref_filtering(pu1_left, pu1_top_left,
1685
0
                                                        pu1_top, au1_ngbr_pels,
1686
0
                                                        ui2_left_pred_buf_width,
1687
0
                                                        ngbr_avail);
1688
0
1689
0
                    ps_dec->apf_intra_pred_luma_8x8[i1_intra_pred](
1690
0
                                    au1_ngbr_pels, pu1_luma_rec_buffer, 1,
1691
0
                                    ui_rec_width,
1692
0
                                    ((u1_is_top_sub_block << 2) | u1_is_left_sub_block));
1693
0
                }
1694
0
            }
1695
0
1696
0
            /* Inverse Transform and Reconstruction */
1697
0
            if(CHECKBIT(ps_cur_mb_info->u1_cbp, u1_sub_mb_num))
1698
0
            {
1699
0
                WORD16 *pi2_scale_matrix_ptr;
1700
0
                WORD16 ai2_tmp[64];
1701
0
1702
0
                pi2_scale_matrix_ptr =
1703
0
                                ps_dec->s_high_profile.i2_scalinglist8x8[0];
1704
0
                PROFILE_DISABLE_IQ_IT_RECON()
1705
0
                {
1706
0
                    if(CHECKBIT(u4_luma_dc_only_cbp, u1_sub_mb_num))
1707
0
                    {
1708
0
                        ps_dec->pf_iquant_itrans_recon_luma_8x8_dc(
1709
0
                                        pi2_y_coeff1,
1710
0
                                        pu1_luma_rec_buffer,
1711
0
                                        pu1_luma_rec_buffer,
1712
0
                                        ui_rec_width,
1713
0
                                        ui_rec_width,
1714
0
                                        gau1_ih264d_dequant8x8_cavlc[ps_cur_mb_info->u1_qp_rem6],
1715
0
                                        (UWORD16 *)pi2_scale_matrix_ptr,
1716
0
                                        ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0,
1717
0
                                        NULL);
1718
0
                    }
1719
0
                    else
1720
0
                    {
1721
0
                        ps_dec->pf_iquant_itrans_recon_luma_8x8(
1722
0
                                        pi2_y_coeff1,
1723
0
                                        pu1_luma_rec_buffer,
1724
0
                                        pu1_luma_rec_buffer,
1725
0
                                        ui_rec_width,
1726
0
                                        ui_rec_width,
1727
0
                                        gau1_ih264d_dequant8x8_cavlc[ps_cur_mb_info->u1_qp_rem6],
1728
0
                                        (UWORD16 *)pi2_scale_matrix_ptr,
1729
0
                                        ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0,
1730
0
                                        NULL);
1731
0
                    }
1732
0
                }
1733
0
1734
0
            }
1735
0
1736
0
            /*---------------------------------------------------------------*/
1737
0
            /* Update sub block number                                       */
1738
0
            /*---------------------------------------------------------------*/
1739
0
            pi2_y_coeff1 += 64;
1740
0
1741
0
            pu1_luma_rec_buffer +=
1742
0
                            (u1_sub_blk_x == 1) ?
1743
0
                                            (ui_rec_width << 3) - (8 * 1) : 8;
1744
0
1745
0
            /*---------------------------------------------------------------*/
1746
0
            /* Pred mode filled in terms of 4x4 block so replicated in 2     */
1747
0
            /* locations.                                                    */
1748
0
            /*---------------------------------------------------------------*/
1749
0
            pi1_cur_pred_mode[u1_sub_blk_x << 1] = i1_intra_pred;
1750
0
            pi1_cur_pred_mode[(u1_sub_blk_x << 1) + 1] = i1_intra_pred;
1751
0
            pi1_left_pred_mode[u1_sub_blk_y << 1] = i1_intra_pred;
1752
0
            pi1_left_pred_mode[(u1_sub_blk_y << 1) + 1] = i1_intra_pred;
1753
0
        }
1754
0
    }
1755
5.06k
    /* Decode Chroma Block */
1756
5.06k
    ih264d_unpack_chroma_coeff4x4_mb(ps_dec,
1757
5.06k
                                     ps_cur_mb_info);
1758
5.06k
    /*--------------------------------------------------------------------*/
1759
5.06k
    /* Chroma Blocks decoding                                             */
1760
5.06k
    /*--------------------------------------------------------------------*/
1761
5.06k
    {
1762
5.06k
        UWORD8 u1_intra_chrom_pred_mode;
1763
5.06k
        UWORD8 u1_chroma_cbp = (UWORD8)(ps_cur_mb_info->u1_cbp >> 4);
1764
5.06k
1765
5.06k
        /*--------------------------------------------------------------------*/
1766
5.06k
        /* Perform Chroma intra prediction                                    */
1767
5.06k
        /*--------------------------------------------------------------------*/
1768
5.06k
1769
5.06k
        u1_intra_chrom_pred_mode = CHROMA_TO_LUMA_INTRA_MODE(
1770
5.06k
                        ps_cur_mb_info->u1_chroma_pred_mode);
1771
5.06k
1772
5.06k
        {
1773
5.06k
            UWORD8 u1_packed_modes = (u1_top_available << 1)
1774
5.06k
                            + u1_left_available;
1775
5.06k
            UWORD8 u1_err_code =
1776
5.06k
                            (u1_intra_chrom_pred_mode & 1) ?
1777
1.11k
                                            u1_intra_chrom_pred_mode :
1778
5.06k
                                            (u1_intra_chrom_pred_mode ^ 2);
1779
5.06k
            if((u1_err_code & u1_packed_modes) ^ u1_err_code)
1780
0
            {
1781
0
                u1_intra_chrom_pred_mode = 0;
1782
0
                ps_dec->i4_error_code = ERROR_INTRAPRED;
1783
0
            }
1784
5.06k
        }
1785
5.06k
1786
5.06k
        /* CHANGED CODE */
1787
5.06k
        if(u1_chroma_cbp != CBPC_ALLZERO)
1788
5.06k
        {
1789
2.18k
            UWORD16 u2_chroma_csbp =
1790
2.18k
                            (u1_chroma_cbp == CBPC_ACZERO) ?
1791
2.18k
                                            0 : ps_cur_mb_info->u2_chroma_csbp;
1792
2.18k
            UWORD32 u4_scale_u;
1793
2.18k
            UWORD32 u4_scale_v;
1794
2.18k
1795
2.18k
            {
1796
2.18k
                UWORD16 au2_ngbr_pels[33];
1797
2.18k
                UWORD8 *pu1_ngbr_pels = (UWORD8 *)au2_ngbr_pels;
1798
2.18k
                UWORD16 *pu2_left_uv;
1799
2.18k
                UWORD16 *pu2_topleft_uv;
1800
2.18k
                WORD32 use_left1 = (u2_use_left_mb_pack & 0x0ff);
1801
2.18k
                WORD32 use_left2 = (u2_use_left_mb_pack & 0xff00) >> 8;
1802
2.18k
1803
2.18k
                pu2_left_uv = (UWORD16 *)pu1_uleft;
1804
2.18k
                pu2_topleft_uv = (UWORD16 *)pu1_u_top_left;
1805
2.18k
                /* Get neighbour pixels */
1806
2.18k
                /* left pels */
1807
2.18k
                if(u2_use_left_mb_pack)
1808
2.10k
                {
1809
2.10k
                    WORD32 i;
1810
2.10k
                    if(use_left1)
1811
2.10k
                    {
1812
10.5k
                        for(i = 0; i < 4; i++)
1813
8.40k
                            au2_ngbr_pels[8 - 1 - i] = pu2_left_uv[i
1814
8.40k
                                            * u4_recwidth_cr / YUV420SP_FACTOR];
1815
2.10k
                    }
1816
0
                    else
1817
0
                    {
1818
0
                        memset(au2_ngbr_pels + 4, 0, 4 * sizeof(UWORD16));
1819
0
                    }
1820
2.10k
1821
2.10k
                    if(use_left2)
1822
2.10k
                    {
1823
10.5k
                        for(i = 4; i < 8; i++)
1824
8.40k
                            au2_ngbr_pels[8 - 1 - i] = pu2_left_uv[i
1825
8.40k
                                            * u4_recwidth_cr / YUV420SP_FACTOR];
1826
2.10k
                    }
1827
0
                    else
1828
0
                    {
1829
0
                        memset(au2_ngbr_pels, 0, 4 * sizeof(UWORD16));
1830
0
                    }
1831
2.10k
                }
1832
88
                else
1833
88
                {
1834
88
                    memset(au2_ngbr_pels, 0, 8 * sizeof(UWORD16));
1835
88
                }
1836
2.18k
1837
2.18k
                /* top left pels */
1838
2.18k
                au2_ngbr_pels[8] = *pu2_topleft_uv;
1839
2.18k
1840
2.18k
                /* top pels */
1841
2.18k
                if(uc_useTopMB)
1842
2.13k
                {
1843
2.13k
                    memcpy(au2_ngbr_pels + 8 + 1, pu1_top_u,
1844
2.13k
                           8 * sizeof(UWORD16));
1845
2.13k
                }
1846
55
                else
1847
55
                {
1848
55
                    memset(au2_ngbr_pels + 8 + 1, 0, 8 * sizeof(UWORD16));
1849
55
                }
1850
2.18k
1851
2.18k
                PROFILE_DISABLE_INTRA_PRED()
1852
2.18k
                ps_dec->apf_intra_pred_chroma[u1_intra_chrom_pred_mode](
1853
2.18k
                                pu1_ngbr_pels,
1854
2.18k
                                pu1_mb_cb_rei1_buffer,
1855
2.18k
                                1,
1856
2.18k
                                u4_recwidth_cr,
1857
2.18k
                                ((uc_useTopMB << 2) | (use_left2 << 4)
1858
2.18k
                                                | use_left1));
1859
2.18k
            }
1860
2.18k
            u4_scale_u = ps_cur_mb_info->u1_qpc_div6;
1861
2.18k
            u4_scale_v = ps_cur_mb_info->u1_qpcr_div6;
1862
2.18k
            pi2_y_coeff = ps_dec->pi2_coeff_data;
1863
2.18k
1864
2.18k
            {
1865
2.18k
                UWORD32 i;
1866
2.18k
                WORD16 ai2_tmp[16];
1867
10.9k
                for(i = 0; i < 4; i++)
1868
8.75k
                {
1869
8.75k
                    WORD16 *pi2_level = pi2_y_coeff + (i << 4);
1870
8.75k
                    UWORD8 *pu1_pred_sblk = pu1_mb_cb_rei1_buffer
1871
8.75k
                                    + ((i & 0x1) * BLK_SIZE * YUV420SP_FACTOR)
1872
8.75k
                                    + (i >> 1) * (u4_recwidth_cr << 2);
1873
8.75k
                    PROFILE_DISABLE_IQ_IT_RECON()
1874
8.75k
                    {
1875
8.75k
                        if(CHECKBIT(u2_chroma_csbp, i))
1876
8.75k
                        {
1877
4.88k
                            ps_dec->pf_iquant_itrans_recon_chroma_4x4(
1878
4.88k
                                            pi2_level,
1879
4.88k
                                            pu1_pred_sblk,
1880
4.88k
                                            pu1_pred_sblk,
1881
4.88k
                                            u4_recwidth_cr,
1882
4.88k
                                            u4_recwidth_cr,
1883
4.88k
                                            gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpc_rem6],
1884
4.88k
                                            (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[1],
1885
4.88k
                                            u4_scale_u, ai2_tmp, pi2_level);
1886
4.88k
                        }
1887
3.87k
                        else if(pi2_level[0] != 0)
1888
517
                        {
1889
517
                            ps_dec->pf_iquant_itrans_recon_chroma_4x4_dc(
1890
517
                                            pi2_level,
1891
517
                                            pu1_pred_sblk,
1892
517
                                            pu1_pred_sblk,
1893
517
                                            u4_recwidth_cr,
1894
517
                                            u4_recwidth_cr,
1895
517
                                            gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpc_rem6],
1896
517
                                            (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[1],
1897
517
                                            u4_scale_u, ai2_tmp, pi2_level);
1898
517
                        }
1899
8.75k
                    }
1900
8.75k
1901
8.75k
                }
1902
2.18k
            }
1903
2.18k
1904
2.18k
            pi2_y_coeff += MB_CHROM_SIZE;
1905
2.18k
            u2_chroma_csbp = u2_chroma_csbp >> 4;
1906
2.18k
            {
1907
2.18k
                UWORD32 i;
1908
2.18k
                WORD16 ai2_tmp[16];
1909
10.9k
                for(i = 0; i < 4; i++)
1910
8.75k
                {
1911
8.75k
                    WORD16 *pi2_level = pi2_y_coeff + (i << 4);
1912
8.75k
                    UWORD8 *pu1_pred_sblk = pu1_mb_cb_rei1_buffer + 1
1913
8.75k
                                    + ((i & 0x1) * BLK_SIZE * YUV420SP_FACTOR)
1914
8.75k
                                    + (i >> 1) * (u4_recwidth_cr << 2);
1915
8.75k
                    PROFILE_DISABLE_IQ_IT_RECON()
1916
8.75k
                    {
1917
8.75k
                        if(CHECKBIT(u2_chroma_csbp, i))
1918
8.75k
                        {
1919
4.00k
                            ps_dec->pf_iquant_itrans_recon_chroma_4x4(
1920
4.00k
                                            pi2_level,
1921
4.00k
                                            pu1_pred_sblk,
1922
4.00k
                                            pu1_pred_sblk,
1923
4.00k
                                            u4_recwidth_cr,
1924
4.00k
                                            u4_recwidth_cr,
1925
4.00k
                                            gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpcr_rem6],
1926
4.00k
                                            (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[2],
1927
4.00k
                                            u4_scale_v, ai2_tmp, pi2_level);
1928
4.00k
                        }
1929
4.75k
                        else if(pi2_level[0] != 0)
1930
451
                        {
1931
451
                            ps_dec->pf_iquant_itrans_recon_chroma_4x4_dc(
1932
451
                                            pi2_level,
1933
451
                                            pu1_pred_sblk,
1934
451
                                            pu1_pred_sblk,
1935
451
                                            u4_recwidth_cr,
1936
451
                                            u4_recwidth_cr,
1937
451
                                            gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpcr_rem6],
1938
451
                                            (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[2],
1939
451
                                            u4_scale_v, ai2_tmp, pi2_level);
1940
451
                        }
1941
8.75k
                    }
1942
8.75k
                }
1943
2.18k
            }
1944
2.18k
1945
2.18k
        }
1946
2.87k
        else
1947
2.87k
        {
1948
2.87k
            /* If no inverse transform is needed, pass recon buffer pointer */
1949
2.87k
            /* to Intraprediction module instead of pred buffer pointer     */
1950
2.87k
            {
1951
2.87k
                UWORD16 au2_ngbr_pels[33];
1952
2.87k
                UWORD8 *pu1_ngbr_pels = (UWORD8 *)au2_ngbr_pels;
1953
2.87k
                UWORD16 *pu2_left_uv;
1954
2.87k
                UWORD16 *pu2_topleft_uv;
1955
2.87k
                WORD32 use_left1 = (u2_use_left_mb_pack & 0x0ff);
1956
2.87k
                WORD32 use_left2 = (u2_use_left_mb_pack & 0xff00) >> 8;
1957
2.87k
1958
2.87k
                pu2_topleft_uv = (UWORD16 *)pu1_u_top_left;
1959
2.87k
                pu2_left_uv = (UWORD16 *)pu1_uleft;
1960
2.87k
1961
2.87k
                /* Get neighbour pixels */
1962
2.87k
                /* left pels */
1963
2.87k
                if(u2_use_left_mb_pack)
1964
2.73k
                {
1965
2.73k
                    WORD32 i;
1966
2.73k
                    if(use_left1)
1967
2.73k
                    {
1968
13.6k
                        for(i = 0; i < 4; i++)
1969
10.9k
                            au2_ngbr_pels[8 - 1 - i] = pu2_left_uv[i
1970
10.9k
                                            * u4_recwidth_cr / YUV420SP_FACTOR];
1971
2.73k
                    }
1972
0
                    else
1973
0
                    {
1974
0
                        memset(au2_ngbr_pels + 4, 0, 4 * sizeof(UWORD16));
1975
0
                    }
1976
2.73k
1977
2.73k
                    if(use_left2)
1978
2.73k
                    {
1979
13.6k
                        for(i = 4; i < 8; i++)
1980
10.9k
                            au2_ngbr_pels[8 - 1 - i] = pu2_left_uv[i
1981
10.9k
                                            * u4_recwidth_cr / YUV420SP_FACTOR];
1982
2.73k
                    }
1983
0
                    else
1984
0
                    {
1985
0
                        memset(au2_ngbr_pels, 0, 4 * sizeof(UWORD16));
1986
0
                    }
1987
2.73k
1988
2.73k
                }
1989
132
                else
1990
132
                {
1991
132
                    memset(au2_ngbr_pels, 0, 8 * sizeof(UWORD16));
1992
132
                }
1993
2.87k
1994
2.87k
                /* top left pels */
1995
2.87k
                au2_ngbr_pels[8] = *pu2_topleft_uv;
1996
2.87k
1997
2.87k
                /* top pels */
1998
2.87k
                if(uc_useTopMB)
1999
2.67k
                {
2000
2.67k
                    memcpy(au2_ngbr_pels + 8 + 1, pu1_top_u,
2001
2.67k
                           8 * sizeof(UWORD16));
2002
2.67k
                }
2003
198
                else
2004
198
                {
2005
198
                    memset(au2_ngbr_pels + 8 + 1, 0, 8 * sizeof(UWORD16));
2006
198
                }
2007
2.87k
2008
2.87k
                PROFILE_DISABLE_INTRA_PRED()
2009
2.87k
                ps_dec->apf_intra_pred_chroma[u1_intra_chrom_pred_mode](
2010
2.87k
                                pu1_ngbr_pels,
2011
2.87k
                                pu1_mb_cb_rei1_buffer,
2012
2.87k
                                1,
2013
2.87k
                                u4_recwidth_cr,
2014
2.87k
                                ((uc_useTopMB << 2) | (use_left2 << 4)
2015
2.87k
                                                | use_left1));
2016
2.87k
            }
2017
2.87k
2018
2.87k
        }
2019
5.06k
2020
5.06k
    }
2021
5.06k
    return OK;
2022
5.06k
}
/proc/self/cwd/external/libavc/decoder/ih264d_process_intra_mb.h
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
21
/*!
22
 **************************************************************************
23
 * \file ih264d_process_intra_mb.h
24
 *
25
 * \brief
26
 *    Contains routines that decode a I slice type
27
 *
28
 * Detailed_description
29
 *
30
 * \date
31
 *    07/07/2003
32
 *
33
 * \author  NS
34
 **************************************************************************
35
 */
36
#ifndef _IH264D_PROCESS_INTRA_MB_H_
37
#define _IH264D_PROCESS_INTRA_MB_H_
38
39
#include "ih264_typedefs.h"
40
#include "ih264_macros.h"
41
#include "ih264_platform_macros.h"
42
#include "ih264d_structs.h"
43
44
5.06k
#define CHROMA_TO_LUMA_INTRA_MODE(x)   (x ^ ( (!(x & 0x01)) << 1))
45
2.51k
#define MB_TYPE_TO_INTRA_16x16_MODE(x) ((x - 1) & 0x03)
46
47
UWORD32 ih264d_unpack_luma_coeff4x4_mb(dec_struct_t * ps_dec,
48
                                    dec_mb_info_t * ps_cur_mb_info,
49
                                    UWORD8 intra_flag);
50
void ih264d_unpack_chroma_coeff4x4_mb(dec_struct_t * ps_dec,
51
                                      dec_mb_info_t * ps_cur_mb_info);
52
UWORD32 ih264d_unpack_luma_coeff8x8_mb(dec_struct_t * ps_dec,
53
                                    dec_mb_info_t * ps_cur_mb_info);
54
55
WORD32 ih264d_read_intra_pred_modes(dec_struct_t *ps_dec,
56
                                    UWORD8 *pu1_prev_intra4x4_pred_mode_flag,
57
                                    UWORD8 *pu1_rem_intra4x4_pred_mode,
58
                                    UWORD32 u4_trans_form8x8);
59
60
WORD32 ih264d_process_intra_mb(dec_struct_t * ps_dec,
61
                               dec_mb_info_t * ps_cur_mb_info,
62
                               UWORD8 u1_mb_num);
63
64
#endif  /* _IH264D_PROCESS_INTRA_MB_H_ */
65
/proc/self/cwd/external/libavc/decoder/ih264d_process_pslice.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/*!
21
 **************************************************************************
22
 * \file ih264d_process_pslice.c
23
 *
24
 * \brief
25
 *    Contains routines that decode a I slice type
26
 *
27
 * Detailed_description
28
 *
29
 * \date
30
 *    21/12/2002
31
 *
32
 * \author  NS
33
 **************************************************************************
34
 */
35
#include "ih264_typedefs.h"
36
#include "ih264_macros.h"
37
#include "ih264_platform_macros.h"
38
39
#include <string.h>
40
#include "ih264d_bitstrm.h"
41
#include "ih264d_defs.h"
42
#include "ih264d_debug.h"
43
#include "ih264d_structs.h"
44
#include "ih264d_defs.h"
45
#include "ih264d_parse_cavlc.h"
46
#include "ih264d_mb_utils.h"
47
#include "ih264d_deblocking.h"
48
#include "ih264d_dpb_manager.h"
49
#include "ih264d_mvpred.h"
50
#include "ih264d_inter_pred.h"
51
#include "ih264d_process_pslice.h"
52
#include "ih264d_error_handler.h"
53
#include "ih264d_cabac.h"
54
#include "ih264d_debug.h"
55
#include "ih264d_tables.h"
56
#include "ih264d_parse_slice.h"
57
#include "ih264d_utils.h"
58
#include "ih264d_parse_islice.h"
59
#include "ih264d_process_bslice.h"
60
#include "ih264d_process_intra_mb.h"
61
62
void ih264d_init_cabac_contexts(UWORD8 u1_slice_type, dec_struct_t * ps_dec);
63
64
void ih264d_insert_pic_in_ref_pic_listx(struct pic_buffer_t *ps_ref_pic_buf_lx,
65
                                        struct pic_buffer_t *ps_pic)
66
0
{
67
0
    *ps_ref_pic_buf_lx = *ps_pic;
68
0
}
69
70
WORD32 ih264d_mv_pred_ref_tfr_nby2_pmb(dec_struct_t * ps_dec,
71
                                     UWORD8 u1_mb_idx,
72
                                     UWORD8 u1_num_mbs)
73
0
{
74
0
    parse_pmbarams_t * ps_mb_part_info;
75
0
    parse_part_params_t * ps_part;
76
0
    mv_pred_t *ps_mv_nmb, *ps_mv_nmb_start, *ps_mv_ntop, *ps_mv_ntop_start;
77
0
    UWORD32 i, j;
78
0
    const UWORD32 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
79
0
    dec_mb_info_t * ps_cur_mb_info;
80
0
    WORD32 i2_mv_x, i2_mv_y;
81
0
    WORD32 ret;
82
0
83
0
    ps_dec->i4_submb_ofst -= (u1_num_mbs - u1_mb_idx) << 4;
84
0
    ps_mb_part_info = ps_dec->ps_parse_mb_data; // + u1_mb_idx;
85
0
    ps_part = ps_dec->ps_parse_part_params; // + u1_mb_idx;
86
0
87
0
    /* N/2 Mb MvPred and Transfer Setup Loop */
88
0
    for(i = u1_mb_idx; i < u1_num_mbs; i++, ps_mb_part_info++)
89
0
    {
90
0
        UWORD32 u1_colz;
91
0
        UWORD32 u1_field;
92
0
        mv_pred_t s_mvPred;
93
0
        mv_pred_t *ps_mv_pred = &s_mvPred;
94
0
95
0
96
0
97
0
        *ps_mv_pred = ps_dec->s_default_mv_pred;
98
0
99
0
        ps_dec->i4_submb_ofst += SUB_BLK_SIZE;
100
0
101
0
        /* Restore the slice scratch MbX and MbY context */
102
0
        ps_cur_mb_info = ps_dec->ps_nmb_info + i;
103
0
        u1_field = ps_cur_mb_info->u1_mb_field_decodingflag;
104
0
105
0
106
0
107
0
        ps_mv_nmb_start = ps_dec->ps_mv_cur + (i << 4);
108
0
        ps_dec->u2_mbx = ps_cur_mb_info->u2_mbx;
109
0
        ps_dec->u2_mby = ps_cur_mb_info->u2_mby;
110
0
        ps_dec->u2_mv_2mb[i & 0x1] = 0;
111
0
112
0
        /* Look for MV Prediction and Reference Transfer in Non-I Mbs */
113
0
        if(!ps_mb_part_info->u1_isI_mb)
114
0
        {
115
0
            UWORD32 u1_blk_no;
116
0
            WORD32 i1_ref_idx, i1_ref_idx1;
117
0
            UWORD32 u1_sub_mb_x, u1_sub_mb_y, u1_sub_mb_num;
118
0
            UWORD32 u1_num_part, u1_num_ref, u1_wd, u1_ht;
119
0
            UWORD32 *pu4_wt_offst, **ppu4_wt_ofst;
120
0
            UWORD32 u1_scale_ref, u4_bot_mb;
121
0
            WORD8 *pi1_ref_idx = ps_mb_part_info->i1_ref_idx[0];
122
0
            pic_buffer_t *ps_ref_frame, **pps_ref_frame;
123
0
            deblk_mb_t * ps_cur_deblk_mb = ps_dec->ps_deblk_mbn + i;
124
0
125
0
            /* MB Level initialisations */
126
0
            ps_dec->u4_num_pmbair = i >> u1_mbaff;
127
0
            ps_dec->u1_mb_idx_mv = i;
128
0
            ppu4_wt_ofst = ps_mb_part_info->pu4_wt_offst;
129
0
            pps_ref_frame = ps_dec->ps_ref_pic_buf_lx[0];
130
0
            /* CHANGED CODE */
131
0
            ps_mv_ntop_start = ps_mv_nmb_start
132
0
                            - (ps_dec->u2_frm_wd_in_mbs << (4 + u1_mbaff)) + 12;
133
0
134
0
            u1_num_part = ps_mb_part_info->u1_num_part;
135
0
            ps_cur_deblk_mb->u1_mb_type |= (u1_num_part > 1) << 1;
136
0
            ps_cur_mb_info->u4_pred_info_pkd_idx = ps_dec->u4_pred_info_pkd_idx;
137
0
            ps_cur_mb_info->u1_num_pred_parts = 0;
138
0
139
0
140
0
            /****************************************************/
141
0
            /* weighted u4_ofst pointer calculations, this loop  */
142
0
            /* runs maximum 4 times, even in direct cases       */
143
0
            /****************************************************/
144
0
            u1_scale_ref = u1_mbaff & u1_field;
145
0
146
0
            u4_bot_mb = 1 - ps_cur_mb_info->u1_topmb;
147
0
            if(ps_dec->ps_cur_pps->u1_wted_pred_flag)
148
0
            {
149
0
                u1_num_ref = MIN(u1_num_part, 4);
150
0
                for(u1_blk_no = 0; u1_blk_no < u1_num_ref; u1_blk_no++)
151
0
                {
152
0
                    i1_ref_idx = pi1_ref_idx[u1_blk_no];
153
0
                    if(u1_scale_ref)
154
0
                        i1_ref_idx >>= 1;
155
0
                    pu4_wt_offst = (UWORD32*)&ps_dec->pu4_wt_ofsts[2
156
0
                                    * X3(i1_ref_idx)];
157
0
                    ppu4_wt_ofst[u1_blk_no] = pu4_wt_offst;
158
0
                }
159
0
            }
160
0
            else
161
0
            {
162
0
                ppu4_wt_ofst[0] = NULL;
163
0
                ppu4_wt_ofst[1] = NULL;
164
0
                ppu4_wt_ofst[2] = NULL;
165
0
                ppu4_wt_ofst[3] = NULL;
166
0
            }
167
0
168
0
            /**************************************************/
169
0
            /* Loop on Partitions                             */
170
0
            /**************************************************/
171
0
            for(j = 0; j < u1_num_part; j++, ps_part++)
172
0
            {
173
0
174
0
                u1_sub_mb_num = ps_part->u1_sub_mb_num;
175
0
                ps_dec->u1_sub_mb_num = u1_sub_mb_num;
176
0
177
0
                if(PART_NOT_DIRECT != ps_part->u1_is_direct)
178
0
                {
179
0
                    /* Mb Skip Mode */
180
0
                    /* Setting the default and other members of MvPred Structure */
181
0
                    s_mvPred.i2_mv[2] = -1;
182
0
                    s_mvPred.i2_mv[3] = -1;
183
0
                    s_mvPred.i1_ref_frame[0] = 0;
184
0
                    i1_ref_idx = (u1_scale_ref && u4_bot_mb) ? MAX_REF_BUFS : 0;
185
0
                    ps_ref_frame = pps_ref_frame[i1_ref_idx];
186
0
                    s_mvPred.u1_col_ref_pic_idx = ps_ref_frame->u1_mv_buf_id;
187
0
                    s_mvPred.u1_pic_type = ps_ref_frame->u1_pic_type;
188
0
                    pu4_wt_offst = (UWORD32*)&ps_dec->pu4_wt_ofsts[0];
189
0
190
0
                    ps_dec->pf_mvpred(ps_dec, ps_cur_mb_info, ps_mv_nmb_start,
191
0
                                      ps_mv_ntop_start, &s_mvPred, 0, 4, 0, 1,
192
0
                                      MB_SKIP);
193
0
194
0
195
0
196
0
197
0
198
0
199
0
                    {
200
0
                        pred_info_pkd_t *ps_pred_pkd;
201
0
                        ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx;
202
0
                    ih264d_fill_pred_info (s_mvPred.i2_mv,4,4,0,PRED_L0,ps_pred_pkd,ps_ref_frame->u1_pic_buf_id,
203
0
                                           (i1_ref_idx >> u1_scale_ref),pu4_wt_offst,
204
0
                                           ps_ref_frame->u1_pic_type);
205
0
206
0
207
0
                    ps_dec->u4_pred_info_pkd_idx++;
208
0
                    ps_cur_mb_info->u1_num_pred_parts++;
209
0
                    }
210
0
211
0
212
0
213
0
                    /* Storing colocated zero information */
214
0
                    u1_colz = ((ABS(s_mvPred.i2_mv[0]) <= 1)
215
0
                                    && (ABS(s_mvPred.i2_mv[1]) <= 1))
216
0
                                    + (u1_field << 1);
217
0
218
0
                    ih264d_rep_mv_colz(ps_dec, &s_mvPred, ps_mv_nmb_start, 0,
219
0
                                       u1_colz, 4, 4);
220
0
                }
221
0
                else
222
0
                {
223
0
                    u1_sub_mb_x = u1_sub_mb_num & 0x03;
224
0
                    u1_sub_mb_y = u1_sub_mb_num >> 2;
225
0
                    u1_blk_no =
226
0
                                    (u1_num_part < 4) ?
227
0
                                                    j :
228
0
                                                    (((u1_sub_mb_y >> 1) << 1)
229
0
                                                                    + (u1_sub_mb_x
230
0
                                                                                    >> 1));
231
0
232
0
                    ps_mv_ntop = ps_mv_ntop_start + u1_sub_mb_x;
233
0
                    ps_mv_nmb = ps_mv_nmb_start + u1_sub_mb_num;
234
0
235
0
                    u1_wd = ps_part->u1_partwidth;
236
0
                    u1_ht = ps_part->u1_partheight;
237
0
238
0
                    /* Populate the colpic info and reference frames */
239
0
                    i1_ref_idx = pi1_ref_idx[u1_blk_no];
240
0
                    s_mvPred.i1_ref_frame[0] = i1_ref_idx;
241
0
242
0
                    /********************************************************/
243
0
                    /* Predict Mv                                           */
244
0
                    /* Add Mv Residuals and store back                      */
245
0
                    /********************************************************/
246
0
                    ps_dec->pf_mvpred(ps_dec, ps_cur_mb_info, ps_mv_nmb, ps_mv_ntop,
247
0
                                      &s_mvPred, u1_sub_mb_num, u1_wd, 0, 1,
248
0
                                      ps_cur_mb_info->u1_mb_mc_mode);
249
0
                    i2_mv_x = ps_mv_nmb->i2_mv[0];
250
0
                    i2_mv_y = ps_mv_nmb->i2_mv[1];
251
0
                    i2_mv_x += s_mvPred.i2_mv[0];
252
0
                    i2_mv_y += s_mvPred.i2_mv[1];
253
0
                    s_mvPred.i2_mv[0] = i2_mv_x;
254
0
                    s_mvPred.i2_mv[1] = i2_mv_y;
255
0
256
0
                    /********************************************************/
257
0
                    /* Transfer setup call                                  */
258
0
                    /* convert RefIdx if it is MbAff                        */
259
0
                    /* Pass Weight Offset and refFrame                      */
260
0
                    /********************************************************/
261
0
                    i1_ref_idx1 = i1_ref_idx >> u1_scale_ref;
262
0
                    if(u1_scale_ref && ((i1_ref_idx & 0x01) != u4_bot_mb))
263
0
                        i1_ref_idx1 += MAX_REF_BUFS;
264
0
                    ps_ref_frame = pps_ref_frame[i1_ref_idx1];
265
0
                    pu4_wt_offst = ppu4_wt_ofst[u1_blk_no];
266
0
267
0
268
0
269
0
270
0
271
0
272
0
                    {
273
0
                    pred_info_pkd_t *ps_pred_pkd;
274
0
                    ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx;
275
0
                    ih264d_fill_pred_info (s_mvPred.i2_mv,u1_wd,u1_ht,u1_sub_mb_num,PRED_L0,ps_pred_pkd,
276
0
                                           ps_ref_frame->u1_pic_buf_id,(i1_ref_idx >> u1_scale_ref),pu4_wt_offst,
277
0
                                           ps_ref_frame->u1_pic_type);
278
0
279
0
                    ps_dec->u4_pred_info_pkd_idx++;
280
0
                    ps_cur_mb_info->u1_num_pred_parts++;
281
0
                    }
282
0
283
0
284
0
285
0
                    /* Fill colocated info in MvPred structure */
286
0
                    s_mvPred.u1_col_ref_pic_idx = ps_ref_frame->u1_mv_buf_id;
287
0
                    s_mvPred.u1_pic_type = ps_ref_frame->u1_pic_type;
288
0
289
0
                    /* Calculating colocated zero information */
290
0
                    u1_colz =
291
0
                                    (u1_field << 1)
292
0
                                                    | ((i1_ref_idx == 0)
293
0
                                                                    && (ABS(i2_mv_x)
294
0
                                                                                    <= 1)
295
0
                                                                    && (ABS(i2_mv_y)
296
0
                                                                                    <= 1));
297
0
                    u1_colz |= ps_mb_part_info->u1_col_info[u1_blk_no];
298
0
299
0
                    /* Replicate the motion vectors and colzero u4_flag  */
300
0
                    /* for all sub-partitions                         */
301
0
302
0
                    ih264d_rep_mv_colz(ps_dec, &s_mvPred, ps_mv_nmb,
303
0
                                       u1_sub_mb_num, u1_colz, u1_ht,
304
0
                                       u1_wd);
305
0
                }
306
0
            }
307
0
308
0
        }
309
0
        else
310
0
        {
311
0
            /* Storing colocated zero information */
312
0
            ih264d_rep_mv_colz(ps_dec, &s_mvPred, ps_mv_nmb_start, 0,
313
0
                               (UWORD8)(u1_field << 1), 4, 4);
314
0
315
0
        }
316
0
        /*if num _cores is set to 3,compute bs will be done in another thread*/
317
0
        if(ps_dec->u4_num_cores < 3)
318
0
        {
319
0
320
0
            if(ps_dec->u4_app_disable_deblk_frm == 0)
321
0
                ps_dec->pf_compute_bs(ps_dec, ps_cur_mb_info,
322
0
                                     (UWORD16)(i >> u1_mbaff));
323
0
        }
324
0
    }
325
0
326
0
327
0
328
0
    return OK;
329
0
}
330
331
332
WORD32 ih264d_decode_recon_tfr_nmb(dec_struct_t * ps_dec,
333
                                   UWORD8 u1_mb_idx,
334
                                   UWORD8 u1_num_mbs,
335
                                   UWORD8 u1_num_mbs_next,
336
                                   UWORD8 u1_tfr_n_mb,
337
                                   UWORD8 u1_end_of_row)
338
0
{
339
0
    WORD32 i,j;
340
0
    UWORD32 u1_end_of_row_next;
341
0
    dec_mb_info_t * ps_cur_mb_info;
342
0
    UWORD32 u4_update_mbaff = 0;
343
0
    WORD32 ret;
344
0
    const UWORD32 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
345
0
    const UWORD32 u1_slice_type = ps_dec->ps_cur_slice->u1_slice_type;
346
0
    const WORD32 u1_skip_th = (
347
0
                    (u1_slice_type != I_SLICE) ?
348
0
                                    (ps_dec->u1_B ? B_8x8 : PRED_8x8R0) : -1);
349
0
    const UWORD32 u1_ipcm_th = (
350
0
                    (u1_slice_type != I_SLICE) ? (ps_dec->u1_B ? 23 : 5) : 0);
351
0
352
0
353
0
354
0
355
0
356
0
    /* N Mb MC Loop */
357
0
    for(i = u1_mb_idx; i < u1_num_mbs; i++)
358
0
    {
359
0
        ps_cur_mb_info = ps_dec->ps_nmb_info + i;
360
0
        ps_dec->u4_dma_buf_idx = 0;
361
0
        ps_dec->u4_pred_info_idx = 0;
362
0
363
0
        if(ps_cur_mb_info->u1_mb_type <= u1_skip_th)
364
0
        {
365
0
            {
366
0
                WORD32 pred_cnt = 0;
367
0
                pred_info_pkd_t *ps_pred_pkd;
368
0
                UWORD32 u4_pred_info_pkd_idx;
369
0
                WORD8 i1_pred;
370
0
371
0
                u4_pred_info_pkd_idx = ps_cur_mb_info->u4_pred_info_pkd_idx;
372
0
373
0
                while(pred_cnt < ps_cur_mb_info->u1_num_pred_parts)
374
0
                {
375
0
376
0
                    ps_pred_pkd = ps_dec->ps_pred_pkd + u4_pred_info_pkd_idx;
377
0
378
0
                     ps_dec->p_form_mb_part_info(ps_pred_pkd,ps_dec,
379
0
                                               ps_cur_mb_info->u2_mbx,ps_cur_mb_info->u2_mby,(i >> u1_mbaff),
380
0
                                         ps_cur_mb_info);
381
0
                    u4_pred_info_pkd_idx++;
382
0
                    pred_cnt++;
383
0
                }
384
0
            }
385
0
386
0
            ps_dec->p_motion_compensate(ps_dec, ps_cur_mb_info);
387
0
388
0
        }
389
0
        else if(ps_cur_mb_info->u1_mb_type == MB_SKIP)
390
0
        {
391
0
            {
392
0
                WORD32 pred_cnt = 0;
393
0
                pred_info_pkd_t *ps_pred_pkd;
394
0
                UWORD32 u4_pred_info_pkd_idx;
395
0
                WORD8 i1_pred;
396
0
397
0
                u4_pred_info_pkd_idx = ps_cur_mb_info->u4_pred_info_pkd_idx;
398
0
399
0
                while(pred_cnt < ps_cur_mb_info->u1_num_pred_parts)
400
0
                {
401
0
402
0
                    ps_pred_pkd = ps_dec->ps_pred_pkd + u4_pred_info_pkd_idx;
403
0
404
0
                    ps_dec->p_form_mb_part_info(ps_pred_pkd,ps_dec,
405
0
                                               ps_cur_mb_info->u2_mbx,ps_cur_mb_info->u2_mby,(i >> u1_mbaff),
406
0
                                         ps_cur_mb_info);
407
0
408
0
                    u4_pred_info_pkd_idx++;
409
0
                    pred_cnt++;
410
0
                }
411
0
            }
412
0
            /* Decode MB skip */
413
0
            ps_dec->p_motion_compensate(ps_dec, ps_cur_mb_info);
414
0
415
0
        }
416
0
417
0
     }
418
0
419
0
420
0
    /* N Mb IQ IT RECON  Loop */
421
0
    for(j = u1_mb_idx; j < i; j++)
422
0
    {
423
0
        ps_cur_mb_info = ps_dec->ps_nmb_info + j;
424
0
425
0
        if(ps_cur_mb_info->u1_mb_type <= u1_skip_th)
426
0
        {
427
0
            ih264d_process_inter_mb(ps_dec, ps_cur_mb_info, j);
428
0
429
0
        }
430
0
        else if(ps_cur_mb_info->u1_mb_type != MB_SKIP)
431
0
        {
432
0
            if((u1_ipcm_th + 25) != ps_cur_mb_info->u1_mb_type)
433
0
            {
434
0
                ps_cur_mb_info->u1_mb_type -= (u1_skip_th + 1);
435
0
                ih264d_process_intra_mb(ps_dec, ps_cur_mb_info, j);
436
0
            }
437
0
        }
438
0
439
0
440
0
        if(ps_dec->u4_use_intrapred_line_copy)
441
0
        {
442
0
            ih264d_copy_intra_pred_line(ps_dec, ps_cur_mb_info, j);
443
0
        }
444
0
445
0
    }
446
0
447
0
    /*N MB deblocking*/
448
0
    if(ps_dec->u4_nmb_deblk == 1)
449
0
    {
450
0
451
0
        UWORD32 u4_cur_mb, u4_right_mb;
452
0
        UWORD32 u4_mb_x, u4_mb_y;
453
0
        UWORD32 u4_wd_y, u4_wd_uv;
454
0
        tfr_ctxt_t *ps_tfr_cxt = &(ps_dec->s_tran_addrecon);
455
0
        UWORD8 u1_field_pic_flag = ps_dec->ps_cur_slice->u1_field_pic_flag;
456
0
        const WORD32 i4_cb_qp_idx_ofst =
457
0
                       ps_dec->ps_cur_pps->i1_chroma_qp_index_offset;
458
0
        const WORD32 i4_cr_qp_idx_ofst =
459
0
                       ps_dec->ps_cur_pps->i1_second_chroma_qp_index_offset;
460
0
461
0
        u4_wd_y = ps_dec->u2_frm_wd_y << u1_field_pic_flag;
462
0
        u4_wd_uv = ps_dec->u2_frm_wd_uv << u1_field_pic_flag;
463
0
464
0
465
0
        ps_cur_mb_info = ps_dec->ps_nmb_info + u1_mb_idx;
466
0
467
0
        ps_dec->u4_deblk_mb_x = ps_cur_mb_info->u2_mbx;
468
0
        ps_dec->u4_deblk_mb_y = ps_cur_mb_info->u2_mby;
469
0
470
0
        for(j = u1_mb_idx; j < i; j++)
471
0
        {
472
0
473
0
            ih264d_deblock_mb_nonmbaff(ps_dec, ps_tfr_cxt,
474
0
                                       i4_cb_qp_idx_ofst, i4_cr_qp_idx_ofst,
475
0
                                        u4_wd_y, u4_wd_uv);
476
0
477
0
478
0
        }
479
0
480
0
481
0
482
0
    }
483
0
484
0
485
0
486
0
    if(u1_tfr_n_mb)
487
0
    {
488
0
        /****************************************************************/
489
0
        /* Check for End Of Row in Next iteration                       */
490
0
        /****************************************************************/
491
0
        u1_end_of_row_next =
492
0
                        u1_num_mbs_next
493
0
                                        && (u1_num_mbs_next
494
0
                                                        <= (ps_dec->u1_recon_mb_grp
495
0
                                                                        >> u1_mbaff));
496
0
497
0
        /****************************************************************/
498
0
        /* Transfer the Following things                                */
499
0
        /* N-Mb DeblkParams Data    ( To Ext DeblkParams Buffer )       */
500
0
        /* N-Mb Recon Data          ( To Ext Frame Buffer )             */
501
0
        /* N-Mb Intrapredline Data  ( Updated Internally)               */
502
0
        /* N-Mb MV Data             ( To Ext MV Buffer )                */
503
0
        /* N-Mb MVTop/TopRight Data ( To Int MV Top Scratch Buffers)    */
504
0
        /****************************************************************/
505
0
        ih264d_transfer_mb_group_data(ps_dec, u1_num_mbs, u1_end_of_row,
506
0
                                      u1_end_of_row_next);
507
0
        ps_dec->u4_num_mbs_prev_nmb = u1_num_mbs;
508
0
509
0
        ps_dec->u4_pred_info_idx = 0;
510
0
        ps_dec->u4_dma_buf_idx = 0;
511
0
512
0
513
0
    }
514
0
    return OK;
515
0
}
516
517
/*!
518
 **************************************************************************
519
 * \if Function name : ih264d_process_inter_mb \endif
520
 *
521
 * \brief
522
 *    This function decodes an Inter MB.
523
 *
524
 *
525
 * \return
526
 *    0 on Success and Error code otherwise
527
 **************************************************************************
528
 */
529
WORD32 ih264d_process_inter_mb(dec_struct_t * ps_dec,
530
                               dec_mb_info_t * ps_cur_mb_info,
531
                               UWORD8 u1_mb_num)
532
0
{
533
0
    /* CHANGED CODE */
534
0
    UWORD8 *pu1_rec_y, *pu1_rec_u, *pu1_rec_v;
535
0
536
0
    /*CHANGED CODE */
537
0
    UWORD32 ui_rec_width, u4_recwidth_cr;
538
0
    WORD16 *pi2_y_coeff;
539
0
    UWORD32 u1_mb_field_decoding_flag;
540
0
    const UWORD8 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
541
0
    UWORD32 uc_botMb;
542
0
    UWORD32 u4_num_pmbair;
543
0
    /* CHANGED CODE */
544
0
    tfr_ctxt_t *ps_frame_buf = ps_dec->ps_frame_buf_ip_recon;
545
0
    UWORD32 u4_luma_dc_only_csbp = 0;
546
0
    UWORD32 u4_luma_dc_only_cbp = 0;
547
0
    /* CHANGED CODE */
548
0
549
0
    uc_botMb = 1 - ps_cur_mb_info->u1_topmb;
550
0
    u4_num_pmbair = (u1_mb_num >> u1_mbaff);
551
0
    u1_mb_field_decoding_flag = ps_cur_mb_info->u1_mb_field_decodingflag;
552
0
553
0
554
0
    /* CHANGED CODE */
555
0
    pu1_rec_y = ps_frame_buf->pu1_dest_y + (u4_num_pmbair << 4);
556
0
    pu1_rec_u =
557
0
                    ps_frame_buf->pu1_dest_u
558
0
                                    + (u4_num_pmbair << 3) * YUV420SP_FACTOR;
559
0
    pu1_rec_v = ps_frame_buf->pu1_dest_v + (u4_num_pmbair << 3);
560
0
    ui_rec_width = ps_dec->u2_frm_wd_y << u1_mb_field_decoding_flag;
561
0
    u4_recwidth_cr = ps_dec->u2_frm_wd_uv << u1_mb_field_decoding_flag;
562
0
563
0
    /* CHANGED CODE */
564
0
565
0
    if(u1_mbaff)
566
0
    {
567
0
        if(uc_botMb)
568
0
        {
569
0
            pu1_rec_y += (u1_mb_field_decoding_flag ?
570
0
                            (ui_rec_width >> 1) : (ui_rec_width << 4));
571
0
            pu1_rec_u += (u1_mb_field_decoding_flag ?
572
0
                            (u4_recwidth_cr >> 1) : (u4_recwidth_cr << 3));
573
0
            pu1_rec_v += (u1_mb_field_decoding_flag ?
574
0
                            (u4_recwidth_cr >> 1) : (u4_recwidth_cr << 3));
575
0
        }
576
0
    }
577
0
578
0
    if(!ps_cur_mb_info->u1_tran_form8x8)
579
0
    {
580
0
        u4_luma_dc_only_csbp = ih264d_unpack_luma_coeff4x4_mb(ps_dec,
581
0
                                       ps_cur_mb_info,
582
0
                                       0);
583
0
    }
584
0
    else
585
0
    {
586
0
        if(!ps_dec->ps_cur_pps->u1_entropy_coding_mode)
587
0
        {
588
0
            u4_luma_dc_only_cbp = ih264d_unpack_luma_coeff4x4_mb(ps_dec,
589
0
                                           ps_cur_mb_info,
590
0
                                           0);
591
0
        }
592
0
        else
593
0
        {
594
0
            u4_luma_dc_only_cbp = ih264d_unpack_luma_coeff8x8_mb(ps_dec,
595
0
                                           ps_cur_mb_info);
596
0
        }
597
0
    }
598
0
599
0
    pi2_y_coeff = ps_dec->pi2_coeff_data;
600
0
    /* Inverse Transform and Reconstruction */
601
0
    if(ps_cur_mb_info->u1_cbp & 0x0f)
602
0
    {
603
0
        /* CHANGED CODE */
604
0
        if(!ps_cur_mb_info->u1_tran_form8x8)
605
0
        {
606
0
            UWORD32 i;
607
0
            WORD16 ai2_tmp[16];
608
0
            for(i = 0; i < 16; i++)
609
0
            {
610
0
                if(CHECKBIT(ps_cur_mb_info->u2_luma_csbp, i))
611
0
                {
612
0
                    WORD16 *pi2_level = pi2_y_coeff + (i << 4);
613
0
                    UWORD8 *pu1_pred_sblk = pu1_rec_y + ((i & 0x3) * BLK_SIZE)
614
0
                                    + (i >> 2) * (ui_rec_width << 2);
615
0
                    PROFILE_DISABLE_IQ_IT_RECON()
616
0
                    {
617
0
                        if(CHECKBIT(u4_luma_dc_only_csbp, i))
618
0
                        {
619
0
                            ps_dec->pf_iquant_itrans_recon_luma_4x4_dc(
620
0
                                            pi2_level,
621
0
                                            pu1_pred_sblk,
622
0
                                            pu1_pred_sblk,
623
0
                                            ui_rec_width,
624
0
                                            ui_rec_width,
625
0
                                            gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qp_rem6],
626
0
                                            (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[3],
627
0
                                            ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0,
628
0
                                            NULL);
629
0
                        }
630
0
                        else
631
0
                        {
632
0
                            ps_dec->pf_iquant_itrans_recon_luma_4x4(
633
0
                                            pi2_level,
634
0
                                            pu1_pred_sblk,
635
0
                                            pu1_pred_sblk,
636
0
                                            ui_rec_width,
637
0
                                            ui_rec_width,
638
0
                                            gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qp_rem6],
639
0
                                            (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[3],
640
0
                                            ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0,
641
0
                                            NULL);
642
0
                        }
643
0
                    }
644
0
                }
645
0
            }
646
0
        }
647
0
        else
648
0
        {
649
0
            WORD16 *pi2_scale_matrix_ptr;
650
0
            WORD32 i;
651
0
652
0
            pi2_scale_matrix_ptr =
653
0
                            ps_dec->s_high_profile.i2_scalinglist8x8[1];
654
0
655
0
            for(i = 0; i < 4; i++)
656
0
            {
657
0
                WORD16 ai2_tmp[64];
658
0
                WORD16 *pi16_levelBlock = pi2_y_coeff + (i << 6); /* move to the next 8x8 adding 64 */
659
0
660
0
                UWORD8 *pu1_pred_sblk = pu1_rec_y + ((i & 0x1) * BLK8x8SIZE)
661
0
                                + (i >> 1) * (ui_rec_width << 3);
662
0
                if(CHECKBIT(ps_cur_mb_info->u1_cbp, i))
663
0
                {
664
0
                    PROFILE_DISABLE_IQ_IT_RECON()
665
0
                    {
666
0
                        if(CHECKBIT(u4_luma_dc_only_cbp, i))
667
0
                        {
668
0
                            ps_dec->pf_iquant_itrans_recon_luma_8x8_dc(
669
0
                                            pi16_levelBlock,
670
0
                                            pu1_pred_sblk,
671
0
                                            pu1_pred_sblk,
672
0
                                            ui_rec_width,
673
0
                                            ui_rec_width,
674
0
                                            gau1_ih264d_dequant8x8_cavlc[ps_cur_mb_info->u1_qp_rem6],
675
0
                                            (UWORD16 *)pi2_scale_matrix_ptr,
676
0
                                            ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0,
677
0
                                            NULL);
678
0
                        }
679
0
                        else
680
0
                        {
681
0
                            ps_dec->pf_iquant_itrans_recon_luma_8x8(
682
0
                                            pi16_levelBlock,
683
0
                                            pu1_pred_sblk,
684
0
                                            pu1_pred_sblk,
685
0
                                            ui_rec_width,
686
0
                                            ui_rec_width,
687
0
                                            gau1_ih264d_dequant8x8_cavlc[ps_cur_mb_info->u1_qp_rem6],
688
0
                                            (UWORD16 *)pi2_scale_matrix_ptr,
689
0
                                            ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0,
690
0
                                            NULL);
691
0
                        }
692
0
                    }
693
0
                }
694
0
            }
695
0
696
0
        }
697
0
    }
698
0
699
0
    /* Decode Chroma Block */
700
0
    ih264d_unpack_chroma_coeff4x4_mb(ps_dec,
701
0
                                     ps_cur_mb_info);
702
0
    /*--------------------------------------------------------------------*/
703
0
    /* Chroma Blocks decoding                                             */
704
0
    /*--------------------------------------------------------------------*/
705
0
    {
706
0
        UWORD8 u1_chroma_cbp = (UWORD8)(ps_cur_mb_info->u1_cbp >> 4);
707
0
708
0
        if(u1_chroma_cbp != CBPC_ALLZERO)
709
0
        {
710
0
            UWORD32 u4_scale_u = ps_cur_mb_info->u1_qpc_div6;
711
0
            UWORD32 u4_scale_v = ps_cur_mb_info->u1_qpcr_div6;
712
0
            UWORD16 u2_chroma_csbp = ps_cur_mb_info->u2_chroma_csbp;
713
0
714
0
            pi2_y_coeff = ps_dec->pi2_coeff_data;
715
0
716
0
            {
717
0
                UWORD32 i;
718
0
                WORD16 ai2_tmp[16];
719
0
                for(i = 0; i < 4; i++)
720
0
                {
721
0
                    WORD16 *pi2_level = pi2_y_coeff + (i << 4);
722
0
                    UWORD8 *pu1_pred_sblk = pu1_rec_u
723
0
                                    + ((i & 0x1) * BLK_SIZE * YUV420SP_FACTOR)
724
0
                                    + (i >> 1) * (u4_recwidth_cr << 2);
725
0
                    PROFILE_DISABLE_IQ_IT_RECON()
726
0
                    {
727
0
                        if(CHECKBIT(u2_chroma_csbp, i))
728
0
                        {
729
0
                            ps_dec->pf_iquant_itrans_recon_chroma_4x4(
730
0
                                            pi2_level,
731
0
                                            pu1_pred_sblk,
732
0
                                            pu1_pred_sblk,
733
0
                                            u4_recwidth_cr,
734
0
                                            u4_recwidth_cr,
735
0
                                            gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpc_rem6],
736
0
                                            (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[4],
737
0
                                            u4_scale_u, ai2_tmp, pi2_level);
738
0
                        }
739
0
                        else if(pi2_level[0] != 0)
740
0
                        {
741
0
                            ps_dec->pf_iquant_itrans_recon_chroma_4x4_dc(
742
0
                                            pi2_level,
743
0
                                            pu1_pred_sblk,
744
0
                                            pu1_pred_sblk,
745
0
                                            u4_recwidth_cr,
746
0
                                            u4_recwidth_cr,
747
0
                                            gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpc_rem6],
748
0
                                            (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[4],
749
0
                                            u4_scale_u, ai2_tmp, pi2_level);
750
0
                        }
751
0
                    }
752
0
                }
753
0
            }
754
0
755
0
            pi2_y_coeff += MB_CHROM_SIZE;
756
0
            u2_chroma_csbp >>= 4;
757
0
758
0
            {
759
0
                UWORD32 i;
760
0
                WORD16 ai2_tmp[16];
761
0
                for(i = 0; i < 4; i++)
762
0
                {
763
0
                    WORD16 *pi2_level = pi2_y_coeff + (i << 4);
764
0
                    UWORD8 *pu1_pred_sblk = pu1_rec_u + 1
765
0
                                    + ((i & 0x1) * BLK_SIZE * YUV420SP_FACTOR)
766
0
                                    + (i >> 1) * (u4_recwidth_cr << 2);
767
0
                    PROFILE_DISABLE_IQ_IT_RECON()
768
0
                    {
769
0
                        if(CHECKBIT(u2_chroma_csbp, i))
770
0
                        {
771
0
                            ps_dec->pf_iquant_itrans_recon_chroma_4x4(
772
0
                                            pi2_level,
773
0
                                            pu1_pred_sblk,
774
0
                                            pu1_pred_sblk,
775
0
                                            u4_recwidth_cr,
776
0
                                            u4_recwidth_cr,
777
0
                                            gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpcr_rem6],
778
0
                                            (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[5],
779
0
                                            u4_scale_v, ai2_tmp, pi2_level);
780
0
                        }
781
0
                        else if(pi2_level[0] != 0)
782
0
                        {
783
0
                            ps_dec->pf_iquant_itrans_recon_chroma_4x4_dc(
784
0
                                            pi2_level,
785
0
                                            pu1_pred_sblk,
786
0
                                            pu1_pred_sblk,
787
0
                                            u4_recwidth_cr,
788
0
                                            u4_recwidth_cr,
789
0
                                            gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpcr_rem6],
790
0
                                            (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[5],
791
0
                                            u4_scale_v, ai2_tmp, pi2_level);
792
0
                        }
793
0
                    }
794
0
                }
795
0
            }
796
0
        }
797
0
    }
798
0
    return (0);
799
0
}
800
801
/*!
802
 **************************************************************************
803
 * \if Function name : ih264d_parse_pred_weight_table \endif
804
 *
805
 * \brief
806
 *    Implements pred_weight_table() of 7.3.3.2.
807
 *
808
 * \return
809
 *    None
810
 *
811
 **************************************************************************
812
 */
813
WORD32 ih264d_parse_pred_weight_table(dec_slice_params_t * ps_cur_slice,
814
                                      dec_bit_stream_t * ps_bitstrm)
815
0
{
816
0
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
817
0
    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
818
0
    WORD8 i, cont, lx;
819
0
    UWORD8 uc_weight_flag;
820
0
    UWORD32 *pui32_weight_offset_lx;
821
0
    WORD16 c_weight, c_offset;
822
0
    UWORD32 ui32_y_def_weight_ofst, ui32_cr_def_weight_ofst;
823
0
    UWORD32 ui32_temp;
824
0
    UWORD8 uc_luma_log2_weight_denom;
825
0
    UWORD8 uc_chroma_log2_weight_denom;
826
0
827
0
    /* Variables for error resilience checks */
828
0
    UWORD32 u4_temp;
829
0
    WORD32 i_temp;
830
0
831
0
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
832
0
    if(u4_temp & MASK_LOG2_WEIGHT_DENOM)
833
0
    {
834
0
        return ERROR_PRED_WEIGHT_TABLE_T;
835
0
    }
836
0
    uc_luma_log2_weight_denom = u4_temp;
837
0
    COPYTHECONTEXT("SH: luma_log2_weight_denom",uc_luma_log2_weight_denom);
838
0
    ui32_y_def_weight_ofst = (1 << uc_luma_log2_weight_denom);
839
0
840
0
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
841
0
    if(u4_temp & MASK_LOG2_WEIGHT_DENOM)
842
0
    {
843
0
        return ERROR_PRED_WEIGHT_TABLE_T;
844
0
    }
845
0
    uc_chroma_log2_weight_denom = u4_temp;
846
0
    COPYTHECONTEXT("SH: chroma_log2_weight_denom",uc_chroma_log2_weight_denom);
847
0
    ui32_cr_def_weight_ofst = (1 << uc_chroma_log2_weight_denom);
848
0
849
0
    ps_cur_slice->u2_log2Y_crwd = uc_luma_log2_weight_denom
850
0
                    | (uc_chroma_log2_weight_denom << 8);
851
0
852
0
    cont = (ps_cur_slice->u1_slice_type == B_SLICE);
853
0
    lx = 0;
854
0
    do
855
0
    {
856
0
        for(i = 0; i < ps_cur_slice->u1_num_ref_idx_lx_active[lx]; i++)
857
0
        {
858
0
            pui32_weight_offset_lx = ps_cur_slice->u4_wt_ofst_lx[lx][i];
859
0
860
0
            uc_weight_flag = ih264d_get_bit_h264(ps_bitstrm);
861
0
            pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
862
0
            COPYTHECONTEXT("SH: luma_weight_l0_flag",uc_weight_flag);
863
0
            if(uc_weight_flag)
864
0
            {
865
0
                i_temp = ih264d_sev(pu4_bitstrm_ofst,
866
0
                                    pu4_bitstrm_buf);
867
0
                if((i_temp + 128) & MASK_PRED_WEIGHT_OFFSET)
868
0
                    return ERROR_PRED_WEIGHT_TABLE_T;
869
0
                c_weight = i_temp;
870
0
                COPYTHECONTEXT("SH: luma_weight_l0",c_weight);
871
0
872
0
                i_temp = ih264d_sev(pu4_bitstrm_ofst,
873
0
                                    pu4_bitstrm_buf);
874
0
                if((i_temp + 128) & MASK_PRED_WEIGHT_OFFSET)
875
0
                    return ERROR_PRED_WEIGHT_TABLE_T;
876
0
                c_offset = i_temp;
877
0
                COPYTHECONTEXT("SH: luma_offset_l0",c_offset);
878
0
879
0
                ui32_temp = (c_offset << 16) | (c_weight & 0xFFFF);
880
0
                pui32_weight_offset_lx[0] = ui32_temp;
881
0
            }
882
0
            else
883
0
            {
884
0
885
0
                pui32_weight_offset_lx[0] = ui32_y_def_weight_ofst;
886
0
            }
887
0
888
0
            {
889
0
                WORD8 c_weightCb, c_weightCr, c_offsetCb, c_offsetCr;
890
0
                uc_weight_flag = ih264d_get_bit_h264(ps_bitstrm);
891
0
                pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
892
0
                COPYTHECONTEXT("SH: chroma_weight_l0_flag",uc_weight_flag);
893
0
                if(uc_weight_flag)
894
0
                {
895
0
                    i_temp = ih264d_sev(pu4_bitstrm_ofst,
896
0
                                        pu4_bitstrm_buf);
897
0
                    if((i_temp + 128) & MASK_PRED_WEIGHT_OFFSET)
898
0
                        return ERROR_PRED_WEIGHT_TABLE_T;
899
0
                    c_weightCb = i_temp;
900
0
                    COPYTHECONTEXT("SH: chroma_weight_l0",c_weightCb);
901
0
902
0
                    i_temp = ih264d_sev(pu4_bitstrm_ofst,
903
0
                                        pu4_bitstrm_buf);
904
0
                    if((i_temp + 128) & MASK_PRED_WEIGHT_OFFSET)
905
0
                        return ERROR_PRED_WEIGHT_TABLE_T;
906
0
                    c_offsetCb = i_temp;
907
0
                    COPYTHECONTEXT("SH: chroma_weight_l0",c_offsetCb);
908
0
909
0
                    ui32_temp = (c_offsetCb << 16) | (c_weightCb & 0xFFFF);
910
0
                    pui32_weight_offset_lx[1] = ui32_temp;
911
0
912
0
                    i_temp = ih264d_sev(pu4_bitstrm_ofst,
913
0
                                        pu4_bitstrm_buf);
914
0
                    if((i_temp + 128) & MASK_PRED_WEIGHT_OFFSET)
915
0
                        return ERROR_PRED_WEIGHT_TABLE_T;
916
0
                    c_weightCr = i_temp;
917
0
                    COPYTHECONTEXT("SH: chroma_weight_l0",c_weightCr);
918
0
919
0
                    i_temp = ih264d_sev(pu4_bitstrm_ofst,
920
0
                                        pu4_bitstrm_buf);
921
0
                    if((i_temp + 128) & MASK_PRED_WEIGHT_OFFSET)
922
0
                        return ERROR_PRED_WEIGHT_TABLE_T;
923
0
                    c_offsetCr = i_temp;
924
0
                    COPYTHECONTEXT("SH: chroma_weight_l0",c_offsetCr);
925
0
926
0
                    ui32_temp = (c_offsetCr << 16) | (c_weightCr & 0xFFFF);
927
0
                    pui32_weight_offset_lx[2] = ui32_temp;
928
0
                }
929
0
                else
930
0
                {
931
0
                    pui32_weight_offset_lx[1] = ui32_cr_def_weight_ofst;
932
0
                    pui32_weight_offset_lx[2] = ui32_cr_def_weight_ofst;
933
0
                }
934
0
            }
935
0
        }
936
0
        lx++;
937
0
    }
938
0
    while(cont--);
939
0
940
0
    return OK;
941
0
}
942
943
944
/*****************************************************************************/
945
/*                                                                           */
946
/*  Function Name : ih264d_init_ref_idx_lx_p                                        */
947
/*                                                                           */
948
/*  Description   : This function initializes the reference picture L0 list  */
949
/*                  for P slices as per section 8.2.4.2.1 and 8.2.4.2.2.     */
950
/*                                                                           */
951
/*  Inputs        : pointer to ps_dec struture                               */
952
/*  Globals       : NO                                                       */
953
/*  Processing    : arranges all the short term pictures according to        */
954
/*                  pic_num in descending order starting from curr pic_num.  */
955
/*                  and inserts it in L0 list followed by all Long term      */
956
/*                  pictures in ascending order.                             */
957
/*                                                                           */
958
/*  Returns       : void                                                     */
959
/*                                                                           */
960
/*  Issues        : <List any issues or problems with this function>         */
961
/*                                                                           */
962
/*  Revision History:                                                        */
963
/*                                                                           */
964
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
965
/*         13 07 2002   Jay             Draft                                */
966
/*                                                                           */
967
/*****************************************************************************/
968
void ih264d_init_ref_idx_lx_p(dec_struct_t *ps_dec)
969
0
{
970
0
    struct pic_buffer_t *ps_ref_pic_buf_lx;
971
0
    dpb_manager_t *ps_dpb_mgr;
972
0
    struct dpb_info_t *ps_next_dpb;
973
0
    WORD8 i;
974
0
    UWORD8 u1_max_lt_index, u1_min_lt_index;
975
0
    UWORD32 u4_lt_index;
976
0
    UWORD8 u1_field_pic_flag;
977
0
    dec_slice_params_t *ps_cur_slice;
978
0
    UWORD8 u1_L0;
979
0
    WORD32 i4_cur_pic_num, i4_min_st_pic_num;
980
0
    WORD32 i4_temp_pic_num, i4_ref_pic_num;
981
0
    UWORD8 u1_num_short_term_bufs;
982
0
    UWORD8 u1_max_ref_idx_l0;
983
0
984
0
    ps_cur_slice = ps_dec->ps_cur_slice;
985
0
    u1_field_pic_flag = ps_cur_slice->u1_field_pic_flag;
986
0
    u1_max_ref_idx_l0 = ps_cur_slice->u1_num_ref_idx_lx_active[0]
987
0
                    << u1_field_pic_flag;
988
0
989
0
    ps_dpb_mgr = ps_dec->ps_dpb_mgr;
990
0
    /* Get the current frame number */
991
0
    i4_cur_pic_num = ps_dec->ps_cur_pic->i4_pic_num;
992
0
993
0
    /* Get Min pic_num,MinLt */
994
0
    i4_min_st_pic_num = i4_cur_pic_num;
995
0
    u1_max_lt_index = MAX_REF_BUFS + 1;
996
0
    u1_min_lt_index = MAX_REF_BUFS + 1;
997
0
998
0
    /* Start from ST head */
999
0
    ps_next_dpb = ps_dpb_mgr->ps_dpb_st_head;
1000
0
    for(i = 0; i < ps_dpb_mgr->u1_num_st_ref_bufs; i++)
1001
0
    {
1002
0
        i4_ref_pic_num = ps_next_dpb->ps_pic_buf->i4_pic_num;
1003
0
        if(i4_ref_pic_num < i4_cur_pic_num)
1004
0
        {
1005
0
            /* RefPic Buf pic_num is before Current pic_num in decode order */
1006
0
            i4_min_st_pic_num = MIN(i4_min_st_pic_num, i4_ref_pic_num);
1007
0
        }
1008
0
1009
0
        /* Chase the next link */
1010
0
        ps_next_dpb = ps_next_dpb->ps_prev_short;
1011
0
    }
1012
0
1013
0
    /* Start from LT head */
1014
0
    ps_next_dpb = ps_dpb_mgr->ps_dpb_ht_head;
1015
0
    if(ps_next_dpb)
1016
0
    {
1017
0
        u1_max_lt_index = ps_next_dpb->u1_lt_idx;
1018
0
        u1_min_lt_index = ps_next_dpb->u1_lt_idx;
1019
0
1020
0
        for(i = 0; i < ps_dpb_mgr->u1_num_lt_ref_bufs; i++)
1021
0
        {
1022
0
            u4_lt_index = ps_next_dpb->u1_lt_idx;
1023
0
            u1_max_lt_index = (UWORD8)(MAX(u1_max_lt_index, u4_lt_index));
1024
0
            u1_min_lt_index = (UWORD8)(MIN(u1_min_lt_index, u4_lt_index));
1025
0
1026
0
            /* Chase the next link */
1027
0
            ps_next_dpb = ps_next_dpb->ps_prev_long;
1028
0
        }
1029
0
    }
1030
0
    /* 1. Initialize refIdxL0 */
1031
0
    u1_L0 = 0;
1032
0
    if(u1_field_pic_flag)
1033
0
    {
1034
0
        ps_ref_pic_buf_lx = ps_dpb_mgr->ps_init_dpb[0][0];
1035
0
        ps_ref_pic_buf_lx += MAX_REF_BUFS;
1036
0
        i4_temp_pic_num = i4_cur_pic_num;
1037
0
    }
1038
0
    else
1039
0
    {
1040
0
        ps_ref_pic_buf_lx = ps_dpb_mgr->ps_init_dpb[0][0];
1041
0
        i4_temp_pic_num = i4_cur_pic_num;
1042
0
    }
1043
0
1044
0
    /* Arrange all short term buffers in output order as given by pic_num */
1045
0
    /* Arrange pic_num's less than Curr pic_num in the descending pic_num */
1046
0
    /* order starting from (Curr pic_num - 1)                             */
1047
0
    for(; i4_temp_pic_num >= i4_min_st_pic_num; i4_temp_pic_num--)
1048
0
    {
1049
0
        /* Start from ST head */
1050
0
        ps_next_dpb = ps_dpb_mgr->ps_dpb_st_head;
1051
0
        for(i = 0; i < ps_dpb_mgr->u1_num_st_ref_bufs; i++)
1052
0
        {
1053
0
            if((WORD32)ps_next_dpb->ps_pic_buf->i4_pic_num == i4_temp_pic_num)
1054
0
            {
1055
0
                /* Copy info in pic buffer */
1056
0
                ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx,
1057
0
                                                   ps_next_dpb->ps_pic_buf);
1058
0
                ps_ref_pic_buf_lx++;
1059
0
                u1_L0++;
1060
0
                break;
1061
0
            }
1062
0
            ps_next_dpb = ps_next_dpb->ps_prev_short;
1063
0
        }
1064
0
    }
1065
0
1066
0
    /* Arrange all Long term buffers in ascending order, in LongtermIndex */
1067
0
    /* Start from LT head */
1068
0
    u1_num_short_term_bufs = u1_L0;
1069
0
    for(u4_lt_index = u1_min_lt_index; u4_lt_index <= u1_max_lt_index;
1070
0
                    u4_lt_index++)
1071
0
    {
1072
0
        ps_next_dpb = ps_dpb_mgr->ps_dpb_ht_head;
1073
0
        for(i = 0; i < ps_dpb_mgr->u1_num_lt_ref_bufs; i++)
1074
0
        {
1075
0
            if(ps_next_dpb->u1_lt_idx == u4_lt_index)
1076
0
            {
1077
0
                ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx,
1078
0
                                                   ps_next_dpb->ps_pic_buf);
1079
0
1080
0
                ps_ref_pic_buf_lx->u1_long_term_pic_num =
1081
0
                                ps_ref_pic_buf_lx->u1_long_term_frm_idx;
1082
0
                ps_ref_pic_buf_lx++;
1083
0
                u1_L0++;
1084
0
                break;
1085
0
            }
1086
0
            ps_next_dpb = ps_next_dpb->ps_prev_long;
1087
0
        }
1088
0
    }
1089
0
1090
0
    if(u1_field_pic_flag)
1091
0
    {
1092
0
        /* Initialize the rest of the entries in the */
1093
0
        /* reference list to handle of errors        */
1094
0
        {
1095
0
            UWORD8 u1_i;
1096
0
            pic_buffer_t *ps_ref_pic;
1097
0
1098
0
            ps_ref_pic = ps_dpb_mgr->ps_init_dpb[0][0] + MAX_REF_BUFS;
1099
0
1100
0
            if(NULL == ps_ref_pic->pu1_buf1)
1101
0
            {
1102
0
                ps_ref_pic = ps_dec->ps_cur_pic;
1103
0
            }
1104
0
            for(u1_i = u1_L0; u1_i < u1_max_ref_idx_l0; u1_i++)
1105
0
            {
1106
0
                *ps_ref_pic_buf_lx = *ps_ref_pic;
1107
0
                ps_ref_pic_buf_lx++;
1108
0
            }
1109
0
        }
1110
0
1111
0
        ih264d_convert_frm_to_fld_list(
1112
0
                        ps_dpb_mgr->ps_init_dpb[0][0] + MAX_REF_BUFS, &u1_L0,
1113
0
                        ps_dec, u1_num_short_term_bufs);
1114
0
1115
0
        ps_ref_pic_buf_lx = ps_dpb_mgr->ps_init_dpb[0][0] + u1_L0;
1116
0
    }
1117
0
1118
0
    /* Initialize the rest of the entries in the */
1119
0
    /* reference list to handle of errors        */
1120
0
    {
1121
0
        UWORD8 u1_i;
1122
0
        pic_buffer_t *ps_ref_pic;
1123
0
1124
0
        ps_ref_pic = ps_dpb_mgr->ps_init_dpb[0][0];
1125
0
1126
0
        if(NULL == ps_ref_pic->pu1_buf1)
1127
0
        {
1128
0
            ps_ref_pic = ps_dec->ps_cur_pic;
1129
0
        }
1130
0
        for(u1_i = u1_L0; u1_i < u1_max_ref_idx_l0; u1_i++)
1131
0
        {
1132
0
            *ps_ref_pic_buf_lx = *ps_ref_pic;
1133
0
            ps_ref_pic_buf_lx++;
1134
0
        }
1135
0
    }
1136
0
    ps_dec->ps_cur_slice->u1_initial_list_size[0] = u1_L0;
1137
0
}
1138
/proc/self/cwd/external/libavc/decoder/ih264d_quant_scaling.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
#include "ih264_typedefs.h"
21
#include "ih264_macros.h"
22
#include "ih264_platform_macros.h"
23
#include "ih264d_bitstrm.h"
24
#include "ih264d_structs.h"
25
#include "ih264d_parse_cavlc.h"
26
#include "ih264d_defs.h"
27
#include "ih264d_defs.h"
28
#include "ih264d_defs.h"
29
30
#include "ih264d_parse_slice.h"
31
#include "ih264d_tables.h"
32
#include "ih264d_utils.h"
33
#include "ih264d_nal.h"
34
#include "ih264d_deblocking.h"
35
36
#include "ih264d_mem_request.h"
37
#include "ih264d_debug.h"
38
39
#include "ih264d_error_handler.h"
40
#include "ih264d_mb_utils.h"
41
#include "ih264d_sei.h"
42
#include "ih264d_vui.h"
43
#include "ih264d_tables.h"
44
45
#define IDCT_BLOCK_WIDTH8X8  8
46
47
void ih264d_scaling_list(WORD16 *pi2_scaling_list,
48
                         WORD32 i4_size_of_scalinglist,
49
                         UWORD8 *pu1_use_default_scaling_matrix_flag,
50
                         dec_bit_stream_t *ps_bitstrm)
51
0
{
52
0
    WORD32 i4_j, i4_delta_scale, i4_lastScale = 8, i4_nextScale = 8;
53
0
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
54
0
    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
55
0
56
0
    *pu1_use_default_scaling_matrix_flag = 0;
57
0
58
0
    for(i4_j = 0; i4_j < i4_size_of_scalinglist; i4_j++)
59
0
    {
60
0
        if(i4_nextScale != 0)
61
0
        {
62
0
            i4_delta_scale = ih264d_sev(pu4_bitstrm_ofst,
63
0
                                        pu4_bitstrm_buf);
64
0
65
0
            i4_nextScale = ((i4_lastScale + i4_delta_scale + 256) & 0xff);
66
0
67
0
            *pu1_use_default_scaling_matrix_flag = ((i4_j == 0)
68
0
                            && (i4_nextScale == 0));
69
0
70
0
        }
71
0
        pi2_scaling_list[i4_j] =
72
0
                        (i4_nextScale == 0) ? (i4_lastScale) : (i4_nextScale);
73
0
        i4_lastScale = pi2_scaling_list[i4_j];
74
0
    }
75
0
}
76
77
void ih264d_form_default_scaling_matrix(dec_struct_t *ps_dec)
78
11
{
79
11
80
11
    /*************************************************************************/
81
11
    /* perform the inverse scanning for the frame and field scaling matrices */
82
11
    /*************************************************************************/
83
11
    {
84
11
        UWORD8 *pu1_inv_scan;
85
11
        WORD32 i4_i, i4_j;
86
11
87
11
        pu1_inv_scan = (UWORD8 *)gau1_ih264d_inv_scan;
88
11
89
11
        /* for all 4x4 matrices */
90
77
        for(i4_i = 0; i4_i < 6; i4_i++)
91
66
        {
92
1.12k
            for(i4_j = 0; i4_j < 16; i4_j++)
93
1.05k
            {
94
1.05k
                ps_dec->s_high_profile.i2_scalinglist4x4[i4_i][pu1_inv_scan[i4_j]] =
95
1.05k
                                16;
96
1.05k
97
1.05k
            }
98
66
        }
99
11
100
11
        /* for all 8x8 matrices */
101
33
        for(i4_i = 0; i4_i < 2; i4_i++)
102
22
        {
103
1.43k
            for(i4_j = 0; i4_j < 64; i4_j++)
104
1.40k
            {
105
1.40k
                ps_dec->s_high_profile.i2_scalinglist8x8[i4_i][gau1_ih264d_inv_scan_prog8x8_cabac[i4_j]] =
106
1.40k
                                16;
107
1.40k
108
1.40k
            }
109
22
        }
110
11
    }
111
11
}
112
113
void ih264d_form_scaling_matrix_picture(dec_seq_params_t *ps_seq,
114
                                        dec_pic_params_t *ps_pic,
115
                                        dec_struct_t *ps_dec)
116
0
{
117
0
    /* default scaling matrices */
118
0
    WORD32 i4_i;
119
0
120
0
    /* check the SPS first */
121
0
    if(ps_seq->i4_seq_scaling_matrix_present_flag)
122
0
    {
123
0
        for(i4_i = 0; i4_i < 8; i4_i++)
124
0
        {
125
0
            if(i4_i < 6)
126
0
            {
127
0
                /* fall-back rule A */
128
0
                if(!ps_seq->u1_seq_scaling_list_present_flag[i4_i])
129
0
                {
130
0
                    if((i4_i == 0) || (i4_i == 3))
131
0
                    {
132
0
                        ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
133
0
                                        (i4_i == 0) ? (WORD16 *)(gai2_ih264d_default_intra4x4) : (WORD16 *)(gai2_ih264d_default_inter4x4);
134
0
                    }
135
0
                    else
136
0
                    {
137
0
                        ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
138
0
                                        ps_dec->s_high_profile.pi2_scale_mat[i4_i
139
0
                                                        - 1];
140
0
                    }
141
0
                }
142
0
                else
143
0
                {
144
0
                    if(ps_seq->u1_use_default_scaling_matrix_flag[i4_i])
145
0
                    {
146
0
                        ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
147
0
                                        (i4_i < 3) ? (WORD16 *)(gai2_ih264d_default_intra4x4) : (WORD16 *)(gai2_ih264d_default_inter4x4);
148
0
                    }
149
0
                    else
150
0
                    {
151
0
                        ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
152
0
                                        ps_seq->i2_scalinglist4x4[i4_i];
153
0
                    }
154
0
                }
155
0
156
0
            }
157
0
            else
158
0
            {
159
0
                /* fall-back rule A */
160
0
                if((!ps_seq->u1_seq_scaling_list_present_flag[i4_i])
161
0
                                || (ps_seq->u1_use_default_scaling_matrix_flag[i4_i]))
162
0
                {
163
0
                    ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
164
0
                                    (i4_i == 6) ? ((WORD16*)gai2_ih264d_default_intra8x8) : ((WORD16*)gai2_ih264d_default_inter8x8);
165
0
                }
166
0
                else
167
0
                {
168
0
                    ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
169
0
                                    ps_seq->i2_scalinglist8x8[i4_i - 6];
170
0
                }
171
0
            }
172
0
        }
173
0
    }
174
0
175
0
    /* checking for the PPS */
176
0
177
0
    if(ps_pic->i4_pic_scaling_matrix_present_flag)
178
0
    {
179
0
        for(i4_i = 0; i4_i < 8; i4_i++)
180
0
        {
181
0
            if(i4_i < 6)
182
0
            {
183
0
                /* fall back rule B */
184
0
                if(!ps_pic->u1_pic_scaling_list_present_flag[i4_i])
185
0
                {
186
0
                    if((i4_i == 0) || (i4_i == 3))
187
0
                    {
188
0
                        if(!ps_seq->i4_seq_scaling_matrix_present_flag)
189
0
                        {
190
0
                            ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
191
0
                                            (i4_i == 0) ? (WORD16 *)(gai2_ih264d_default_intra4x4) : (WORD16 *)(gai2_ih264d_default_inter4x4);
192
0
                        }
193
0
                    }
194
0
                    else
195
0
                    {
196
0
                        ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
197
0
                                        ps_dec->s_high_profile.pi2_scale_mat[i4_i
198
0
                                                        - 1];
199
0
                    }
200
0
                }
201
0
                else
202
0
                {
203
0
                    if(ps_pic->u1_pic_use_default_scaling_matrix_flag[i4_i])
204
0
                    {
205
0
                        ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
206
0
                                        (i4_i < 3) ? (WORD16 *)(gai2_ih264d_default_intra4x4) : (WORD16 *)(gai2_ih264d_default_inter4x4);
207
0
                    }
208
0
                    else
209
0
                    {
210
0
                        ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
211
0
                                        ps_pic->i2_pic_scalinglist4x4[i4_i];
212
0
                    }
213
0
                }
214
0
            }
215
0
            else
216
0
            {
217
0
                if(!ps_pic->u1_pic_scaling_list_present_flag[i4_i])
218
0
                {
219
0
                    if(!ps_seq->u1_seq_scaling_list_present_flag[i4_i])
220
0
                    {
221
0
                        ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
222
0
                                        (i4_i == 6) ? ((WORD16*)gai2_ih264d_default_intra8x8) : ((WORD16*)gai2_ih264d_default_inter8x8);
223
0
                    }
224
0
                }
225
0
                else
226
0
                {
227
0
                    if(ps_pic->u1_pic_use_default_scaling_matrix_flag[i4_i])
228
0
                    {
229
0
                        ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
230
0
                                        (i4_i == 6) ? (WORD16 *)(gai2_ih264d_default_intra8x8) : (WORD16 *)(gai2_ih264d_default_inter8x8);
231
0
                    }
232
0
                    else
233
0
                    {
234
0
                        ps_dec->s_high_profile.pi2_scale_mat[i4_i] =
235
0
                                        ps_pic->i2_pic_scalinglist8x8[i4_i - 6];
236
0
                    }
237
0
                }
238
0
            }
239
0
        }
240
0
    }
241
0
242
0
    /*************************************************************************/
243
0
    /* perform the inverse scanning for the frame and field scaling matrices */
244
0
    /*************************************************************************/
245
0
    {
246
0
        UWORD8 *pu1_inv_scan_4x4;
247
0
        WORD32 i4_i, i4_j;
248
0
249
0
        pu1_inv_scan_4x4 = (UWORD8 *)gau1_ih264d_inv_scan;
250
0
251
0
        /* for all 4x4 matrices */
252
0
        for(i4_i = 0; i4_i < 6; i4_i++)
253
0
        {
254
0
            for(i4_j = 0; i4_j < 16; i4_j++)
255
0
            {
256
0
                ps_dec->s_high_profile.i2_scalinglist4x4[i4_i][pu1_inv_scan_4x4[i4_j]] =
257
0
                                ps_dec->s_high_profile.pi2_scale_mat[i4_i][i4_j];
258
0
259
0
            }
260
0
        }
261
0
262
0
        /* for all 8x8 matrices */
263
0
        for(i4_i = 0; i4_i < 2; i4_i++)
264
0
        {
265
0
            for(i4_j = 0; i4_j < 64; i4_j++)
266
0
            {
267
0
                ps_dec->s_high_profile.i2_scalinglist8x8[i4_i][gau1_ih264d_inv_scan_prog8x8_cabac[i4_j]] =
268
0
                                ps_dec->s_high_profile.pi2_scale_mat[i4_i + 6][i4_j];
269
0
270
0
            }
271
0
        }
272
0
    }
273
0
}
274
/proc/self/cwd/external/libavc/decoder/ih264d_sei.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
21
/*****************************************************************************/
22
/*                                                                           */
23
/*  File Name         : ih264d_sei.c                                                */
24
/*                                                                           */
25
/*  Description       : This file contains routines to parse SEI NAL's       */
26
/*                                                                           */
27
/*  List of Functions : <List the functions defined in this file>            */
28
/*                                                                           */
29
/*  Issues / Problems : None                                                 */
30
/*                                                                           */
31
/*  Revision History  :                                                      */
32
/*                                                                           */
33
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
34
/*         25 05 2005   NS              Draft                                */
35
/*                                                                           */
36
/*****************************************************************************/
37
38
#include "ih264_typedefs.h"
39
#include "ih264_macros.h"
40
#include "ih264_platform_macros.h"
41
#include "ih264d_sei.h"
42
#include "ih264d_bitstrm.h"
43
#include "ih264d_structs.h"
44
#include "ih264d_error_handler.h"
45
#include "ih264d_vui.h"
46
#include "ih264d_parse_cavlc.h"
47
#include "ih264d_defs.h"
48
49
/*****************************************************************************/
50
/*                                                                           */
51
/*  Function Name : ih264d_parse_buffering_period                                   */
52
/*                                                                           */
53
/*  Description   : This function parses SEI message buffering_period        */
54
/*  Inputs        : ps_buf_prd pointer to struct buf_period_t                  */
55
/*                  ps_bitstrm    Bitstream                                */
56
/*  Globals       : None                                                     */
57
/*  Processing    : Parses SEI payload buffering period.                     */
58
/*  Outputs       : None                                                     */
59
/*  Returns       : None                                                     */
60
/*                                                                           */
61
/*  Issues        : Not implemented fully                                    */
62
/*                                                                           */
63
/*  Revision History:                                                        */
64
/*                                                                           */
65
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
66
/*         06 05 2002   NS              Draft                                */
67
/*                                                                           */
68
/*****************************************************************************/
69
70
WORD32 ih264d_parse_buffering_period(buf_period_t *ps_buf_prd,
71
                                     dec_bit_stream_t *ps_bitstrm,
72
                                     dec_struct_t *ps_dec)
73
0
{
74
0
    UWORD8 u1_seq_parameter_set_id;
75
0
    dec_seq_params_t *ps_seq;
76
0
    UWORD8 u1_nal_hrd_present, u1_vcl_hrd_present;
77
0
    UWORD32 i;
78
0
    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
79
0
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
80
0
    UNUSED(ps_buf_prd);
81
0
    u1_seq_parameter_set_id = ih264d_uev(pu4_bitstrm_ofst,
82
0
                                         pu4_bitstrm_buf);
83
0
    if(u1_seq_parameter_set_id >= MAX_NUM_SEQ_PARAMS)
84
0
        return ERROR_INVALID_SEQ_PARAM;
85
0
    ps_seq = &ps_dec->ps_sps[u1_seq_parameter_set_id];
86
0
    if(TRUE != ps_seq->u1_is_valid)
87
0
        return (-1);
88
0
89
0
    ps_dec->ps_sei->u1_seq_param_set_id = u1_seq_parameter_set_id;
90
0
    ps_dec->ps_cur_sps = ps_seq;
91
0
    if(FALSE == ps_seq->u1_is_valid)
92
0
        return ERROR_INVALID_SEQ_PARAM;
93
0
    if(1 == ps_seq->u1_vui_parameters_present_flag)
94
0
    {
95
0
        u1_nal_hrd_present = ps_seq->s_vui.u1_nal_hrd_params_present;
96
0
        if(u1_nal_hrd_present)
97
0
        {
98
0
            for(i = 0; i < ps_seq->s_vui.s_nal_hrd.u4_cpb_cnt; i++)
99
0
            {
100
0
                ih264d_get_bits_h264(
101
0
                                ps_bitstrm,
102
0
                                ps_seq->s_vui.s_nal_hrd.u1_initial_cpb_removal_delay);
103
0
                ih264d_get_bits_h264(
104
0
                                ps_bitstrm,
105
0
                                ps_seq->s_vui.s_nal_hrd.u1_initial_cpb_removal_delay);
106
0
            }
107
0
        }
108
0
109
0
        u1_vcl_hrd_present = ps_seq->s_vui.u1_vcl_hrd_params_present;
110
0
        if(u1_vcl_hrd_present)
111
0
        {
112
0
            for(i = 0; i < ps_seq->s_vui.s_vcl_hrd.u4_cpb_cnt; i++)
113
0
            {
114
0
                ih264d_get_bits_h264(
115
0
                                ps_bitstrm,
116
0
                                ps_seq->s_vui.s_vcl_hrd.u1_initial_cpb_removal_delay);
117
0
                ih264d_get_bits_h264(
118
0
                                ps_bitstrm,
119
0
                                ps_seq->s_vui.s_vcl_hrd.u1_initial_cpb_removal_delay);
120
0
            }
121
0
        }
122
0
    }
123
0
    return OK;
124
0
}
125
126
/*****************************************************************************/
127
/*                                                                           */
128
/*  Function Name : ih264d_parse_pic_timing                                         */
129
/*                                                                           */
130
/*  Description   : This function parses SEI message pic_timing              */
131
/*  Inputs        : ps_bitstrm    Bitstream                                */
132
/*                  ps_dec          Poniter decoder context                  */
133
/*                  ui4_payload_size pay load i4_size                           */
134
/*  Globals       : None                                                     */
135
/*  Processing    : Parses SEI payload picture timing                        */
136
/*  Outputs       : None                                                     */
137
/*  Returns       : None                                                     */
138
/*                                                                           */
139
/*  Issues        : Not implemented fully                                    */
140
/*                                                                           */
141
/*  Revision History:                                                        */
142
/*                                                                           */
143
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
144
/*         06 05 2002   NS              Draft                                */
145
/*                                                                           */
146
/*****************************************************************************/
147
WORD32 ih264d_parse_pic_timing(dec_bit_stream_t *ps_bitstrm,
148
                               dec_struct_t *ps_dec,
149
                               UWORD32 ui4_payload_size)
150
0
{
151
0
    sei *ps_sei;
152
0
    vui_t *ps_vu4;
153
0
    UWORD8 u1_cpb_dpb_present;
154
0
    UWORD8 u1_pic_struct_present_flag;
155
0
    UWORD32 u4_start_offset, u4_bits_consumed;
156
0
    UWORD8 u1_cpb_removal_delay_length, u1_dpb_output_delay_length;
157
0
158
0
    ps_sei = (sei *)ps_dec->ps_sei;
159
0
    ps_vu4 = &ps_dec->ps_cur_sps->s_vui;
160
0
161
0
    u1_cpb_dpb_present = ps_vu4->u1_vcl_hrd_params_present
162
0
                    + ps_vu4->u1_nal_hrd_params_present;
163
0
164
0
    if(ps_vu4->u1_vcl_hrd_params_present)
165
0
    {
166
0
        u1_cpb_removal_delay_length =
167
0
                        ps_vu4->s_vcl_hrd.u1_cpb_removal_delay_length;
168
0
        u1_dpb_output_delay_length =
169
0
                        ps_vu4->s_vcl_hrd.u1_dpb_output_delay_length;
170
0
    }
171
0
    else if(ps_vu4->u1_nal_hrd_params_present)
172
0
    {
173
0
        u1_cpb_removal_delay_length =
174
0
                        ps_vu4->s_nal_hrd.u1_cpb_removal_delay_length;
175
0
        u1_dpb_output_delay_length =
176
0
                        ps_vu4->s_nal_hrd.u1_dpb_output_delay_length;
177
0
    }
178
0
    else
179
0
    {
180
0
        u1_cpb_removal_delay_length = 24;
181
0
        u1_dpb_output_delay_length = 24;
182
0
183
0
    }
184
0
185
0
    u4_start_offset = ps_bitstrm->u4_ofst;
186
0
    if(u1_cpb_dpb_present)
187
0
    {
188
0
        ih264d_get_bits_h264(ps_bitstrm, u1_cpb_removal_delay_length);
189
0
        ih264d_get_bits_h264(ps_bitstrm, u1_dpb_output_delay_length);
190
0
    }
191
0
192
0
    u1_pic_struct_present_flag = ps_vu4->u1_pic_struct_present_flag;
193
0
    if(u1_pic_struct_present_flag)
194
0
    {
195
0
        ps_sei->u1_pic_struct = ih264d_get_bits_h264(ps_bitstrm, 4);
196
0
        ps_dec->u1_pic_struct_copy = ps_sei->u1_pic_struct;
197
0
        ps_sei->u1_is_valid = 1;
198
0
    }
199
0
    u4_bits_consumed = ps_bitstrm->u4_ofst - u4_start_offset;
200
0
    ih264d_flush_bits_h264(ps_bitstrm,
201
0
                           (ui4_payload_size << 3) - u4_bits_consumed);
202
0
203
0
    return (0);
204
0
}
205
206
/*****************************************************************************/
207
/*                                                                           */
208
/*  Function Name : ih264d_parse_recovery_point                                     */
209
/*                                                                           */
210
/*  Description   : This function parses SEI message recovery point          */
211
/*  Inputs        : ps_bitstrm    Bitstream                                */
212
/*                  ps_dec          Poniter decoder context                  */
213
/*                  ui4_payload_size pay load i4_size                           */
214
/*  Globals       : None                                                     */
215
/*  Processing    : Parses SEI payload picture timing                        */
216
/*  Outputs       : None                                                     */
217
/*  Returns       : None                                                     */
218
/*                                                                           */
219
/*  Issues        : Not implemented fully                                    */
220
/*                                                                           */
221
/*  Revision History:                                                        */
222
/*                                                                           */
223
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
224
/*         06 05 2002   NS              Draft                                */
225
/*                                                                           */
226
/*****************************************************************************/
227
WORD32 ih264d_parse_recovery_point(dec_bit_stream_t *ps_bitstrm,
228
                                   dec_struct_t *ps_dec,
229
                                   UWORD32 ui4_payload_size)
230
0
{
231
0
    sei *ps_sei = ps_dec->ps_sei;
232
0
    dec_err_status_t *ps_err = ps_dec->ps_dec_err_status;
233
0
    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
234
0
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
235
0
    UNUSED(ui4_payload_size);
236
0
    ps_sei->u2_recovery_frame_cnt = ih264d_uev(pu4_bitstrm_ofst,
237
0
                                               pu4_bitstrm_buf);
238
0
    ps_err->u4_frm_sei_sync = ps_err->u4_cur_frm
239
0
                    + ps_sei->u2_recovery_frame_cnt;
240
0
    ps_sei->u1_exact_match_flag = ih264d_get_bit_h264(ps_bitstrm);
241
0
    ps_sei->u1_broken_link_flag = ih264d_get_bit_h264(ps_bitstrm);
242
0
    ps_sei->u1_changing_slice_grp_idc = ih264d_get_bits_h264(ps_bitstrm, 2);
243
0
244
0
    return (0);
245
0
}
246
247
/*****************************************************************************/
248
/*                                                                           */
249
/*  Function Name : ih264d_parse_sei_payload                                        */
250
/*                                                                           */
251
/*  Description   : This function parses SEI pay loads. Currently it's       */
252
/*                  implemented partially.                                   */
253
/*  Inputs        : ps_bitstrm    Bitstream                                */
254
/*                  ui4_payload_type  SEI payload type                       */
255
/*                  ui4_payload_size  SEI payload i4_size                       */
256
/*  Globals       : None                                                     */
257
/*  Processing    : Parses SEI payloads units and stores the info            */
258
/*  Outputs       : None                                                     */
259
/*  Returns       : None                                                     */
260
/*                                                                           */
261
/*  Issues        : Not implemented fully                                    */
262
/*                                                                           */
263
/*  Revision History:                                                        */
264
/*                                                                           */
265
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
266
/*         06 05 2002   NS              Draft                                */
267
/*                                                                           */
268
/*****************************************************************************/
269
270
WORD32 ih264d_parse_sei_payload(dec_bit_stream_t *ps_bitstrm,
271
                                UWORD32 ui4_payload_type,
272
                                UWORD32 ui4_payload_size,
273
                                dec_struct_t *ps_dec)
274
0
{
275
0
    sei *ps_sei;
276
0
    WORD32 i4_status = 0;
277
0
    ps_sei = (sei *)ps_dec->ps_sei;
278
0
    switch(ui4_payload_type)
279
0
    {
280
0
        case SEI_BUF_PERIOD:
281
0
282
0
            i4_status = ih264d_parse_buffering_period(&ps_sei->s_buf_period,
283
0
                                                      ps_bitstrm, ps_dec);
284
0
            /*if(i4_status != OK)
285
0
                return i4_status;*/
286
0
            break;
287
0
        case SEI_PIC_TIMING:
288
0
            if(NULL == ps_dec->ps_cur_sps)
289
0
                ih264d_flush_bits_h264(ps_bitstrm, (ui4_payload_size << 3));
290
0
            else
291
0
                ih264d_parse_pic_timing(ps_bitstrm, ps_dec,
292
0
                                        ui4_payload_size);
293
0
            break;
294
0
        case SEI_RECOVERY_PT:
295
0
            ih264d_parse_recovery_point(ps_bitstrm, ps_dec,
296
0
                                        ui4_payload_size);
297
0
            break;
298
0
        default:
299
0
            ih264d_flush_bits_h264(ps_bitstrm, (ui4_payload_size << 3));
300
0
            break;
301
0
    }
302
0
    return (i4_status);
303
0
}
304
305
/*****************************************************************************/
306
/*                                                                           */
307
/*  Function Name : ih264d_parse_sei_message                                        */
308
/*                                                                           */
309
/*  Description   : This function is parses and decode SEI. Currently it's   */
310
/*                  not implemented fully.                                   */
311
/*  Inputs        : ps_dec    Decoder parameters                       */
312
/*                  ps_bitstrm    Bitstream                                */
313
/*  Globals       : None                                                     */
314
/*  Processing    : Parses SEI NAL units and stores the info                 */
315
/*  Outputs       : None                                                     */
316
/*  Returns       : None                                                     */
317
/*                                                                           */
318
/*  Issues        : Not implemented fully                                    */
319
/*                                                                           */
320
/*  Revision History:                                                        */
321
/*                                                                           */
322
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
323
/*         06 05 2002   NS              Draft                                */
324
/*                                                                           */
325
/*****************************************************************************/
326
327
WORD32 ih264d_parse_sei_message(dec_struct_t *ps_dec,
328
                                dec_bit_stream_t *ps_bitstrm)
329
0
{
330
0
    UWORD32 ui4_payload_type, ui4_payload_size;
331
0
    UWORD32 u4_bits;
332
0
    WORD32 i4_status = 0;
333
0
334
0
    do
335
0
    {
336
0
        ui4_payload_type = 0;
337
0
338
0
        u4_bits = ih264d_get_bits_h264(ps_bitstrm, 8);
339
0
        while(0xff == u4_bits && !EXCEED_OFFSET(ps_bitstrm))
340
0
        {
341
0
            u4_bits = ih264d_get_bits_h264(ps_bitstrm, 8);
342
0
            ui4_payload_type += 255;
343
0
        }
344
0
        ui4_payload_type += u4_bits;
345
0
346
0
        ui4_payload_size = 0;
347
0
        u4_bits = ih264d_get_bits_h264(ps_bitstrm, 8);
348
0
        while(0xff == u4_bits && !EXCEED_OFFSET(ps_bitstrm))
349
0
        {
350
0
            u4_bits = ih264d_get_bits_h264(ps_bitstrm, 8);
351
0
            ui4_payload_size += 255;
352
0
        }
353
0
        ui4_payload_size += u4_bits;
354
0
355
0
        i4_status = ih264d_parse_sei_payload(ps_bitstrm, ui4_payload_type,
356
0
                                             ui4_payload_size, ps_dec);
357
0
        if(i4_status == -1)
358
0
        {
359
0
            i4_status = 0;
360
0
            break;
361
0
        }
362
0
363
0
        if(i4_status != OK)
364
0
            return i4_status;
365
0
366
0
        if(ih264d_check_byte_aligned(ps_bitstrm) == 0)
367
0
        {
368
0
            u4_bits = ih264d_get_bit_h264(ps_bitstrm);
369
0
            if(0 == u4_bits)
370
0
            {
371
0
                H264_DEC_DEBUG_PRINT("\nError in parsing SEI message");
372
0
            }
373
0
            while(0 == ih264d_check_byte_aligned(ps_bitstrm)
374
0
                            && !EXCEED_OFFSET(ps_bitstrm))
375
0
            {
376
0
                u4_bits = ih264d_get_bit_h264(ps_bitstrm);
377
0
                if(u4_bits)
378
0
                {
379
0
                    H264_DEC_DEBUG_PRINT("\nError in parsing SEI message");
380
0
                }
381
0
            }
382
0
        }
383
0
    }
384
0
    while(ps_bitstrm->u4_ofst < ps_bitstrm->u4_max_ofst);
385
0
    return (i4_status);
386
0
}
387
/proc/self/cwd/external/libavc/decoder/ih264d_sei.h
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
21
/*****************************************************************************/
22
/*                                                                           */
23
/*  File Name         : ih264d_sei.h                                                */
24
/*                                                                           */
25
/*  Description       : This file contains routines to parse SEI NAL's       */
26
/*                                                                           */
27
/*  List of Functions : <List the functions defined in this file>            */
28
/*                                                                           */
29
/*  Issues / Problems : None                                                 */
30
/*                                                                           */
31
/*  Revision History  :                                                      */
32
/*                                                                           */
33
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
34
/*         25 05 2005   NS              Draft                                */
35
/*                                                                           */
36
/*****************************************************************************/
37
38
#ifndef _IH264D_SEI_H_
39
#define _IH264D_SEI_H_
40
41
#include "ih264_typedefs.h"
42
#include "ih264_macros.h"
43
#include "ih264_platform_macros.h"
44
#include "ih264d_bitstrm.h"
45
#include "ih264d_structs.h"
46
47
0
#define SEI_BUF_PERIOD      0
48
0
#define SEI_PIC_TIMING      1
49
#define SEI_PAN_SCAN_RECT   2
50
#define SEI_FILLER          3
51
#define SEI_UD_REG_T35      4
52
#define SEI_UD_UN_REG       5
53
0
#define SEI_RECOVERY_PT     6
54
#define SEI_DEC_REF_MARK    7
55
#define SEI_SPARE_PIC       8
56
#define SEI_SCENE_INFO      9
57
#define SEI_SUB_SEQN_INFO   10
58
#define SEI_SUB_SEQN_LAY_CHAR       11
59
#define SEI_SUB_SEQN_CHAR   12
60
#define SEI_FULL_FRAME_FREEZE       13
61
#define SEI_FULL_FRAME_FREEZE_REL   14
62
#define SEI_FULL_FRAME_SNAP_SHOT    15
63
#define SEI_PROG_REF_SEGMENT_START  16
64
#define SEI_PROG_REF_SEGMENT_END    17
65
#define SEI_MOT_CON_SLICE_GRP_SET   18
66
/* Declaration of dec_struct_t to avoid CCS compilation Error */
67
struct _DecStruct;
68
WORD32 ih264d_parse_sei_message(struct _DecStruct *ps_dec,
69
                                dec_bit_stream_t *ps_bitstrm);
70
typedef struct
71
{
72
    UWORD8 u1_seq_parameter_set_id;
73
    UWORD32 u4_initial_cpb_removal_delay;
74
    UWORD32 u4_nitial_cpb_removal_delay_offset;
75
76
} buf_period_t;
77
78
struct _sei
79
{
80
    UWORD8 u1_seq_param_set_id;
81
    buf_period_t s_buf_period;
82
    UWORD8 u1_pic_struct;
83
    UWORD16 u2_recovery_frame_cnt;
84
    UWORD8 u1_exact_match_flag;
85
    UWORD8 u1_broken_link_flag;
86
    UWORD8 u1_changing_slice_grp_idc;
87
    UWORD8 u1_is_valid;
88
};
89
typedef struct _sei sei;
90
#endif /* _IH264D_SEI_H_ */
91
/proc/self/cwd/external/libavc/decoder/ih264d_structs.h
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
#ifndef _IH264D_STRUCTS_H_
21
#define _IH264D_STRUCTS_H_
22
23
#include "ih264_typedefs.h"
24
#include "ih264_macros.h"
25
#include "ih264_platform_macros.h"
26
#include "iv.h"
27
#include "ivd.h"
28
29
#include "ih264d_transfer_address.h"
30
#include "ih264d_defs.h"
31
#include "ih264d_defs.h"
32
#include "ih264d_bitstrm.h"
33
#include "ih264d_debug.h"
34
#include "ih264d_dpb_manager.h"
35
/* includes for CABAC */
36
#include "ih264d_cabac.h"
37
#include "ih264d_dpb_manager.h"
38
39
#include "ih264d_vui.h"
40
#include "ih264d_sei.h"
41
#include "iv.h"
42
#include "ivd.h"
43
44
#include "ih264_weighted_pred.h"
45
#include "ih264_trans_quant_itrans_iquant.h"
46
#include "ih264_inter_pred_filters.h"
47
#include "ih264_mem_fns.h"
48
#include "ih264_padding.h"
49
#include "ih264_intra_pred_filters.h"
50
#include "ih264_deblk_edge_filters.h"
51
52
53
54
55
56
/** Number of Mb's whoose syntax will be read */
57
/************************************************************/
58
/* MB_GROUP should be a multiple of 2                       */
59
/************************************************************/
60
#define PARSE_MB_GROUP_4            4
61
62
/* MV_SCRATCH_BUFS assumed to be pow(2) */
63
20
#define MV_SCRATCH_BUFS             4
64
65
24
#define TOP_FIELD_ONLY      0x02
66
24
#define BOT_FIELD_ONLY      0x01
67
68
2
#define MAX_REF_BUF_SIZE       (3776*2*2)
69
70
struct _DecStruct;
71
struct _DecMbInfo;
72
73
typedef enum
74
{
75
    MB_TYPE_SI_SLICE = 0,
76
    MB_TYPE_I_SLICE = 3,
77
    MB_SKIP_FLAG_P_SLICE = 11,
78
    MB_TYPE_P_SLICE = 14,
79
    SUB_MB_TYPE_P_SLICE = 21,
80
    MB_SKIP_FLAG_B_SLICE = 24,
81
    MB_TYPE_B_SLICE = 27,
82
    SUB_MB_TYPE_B_SLICE = 36,
83
    MVD_X = 40,
84
    MVD_Y = 47,
85
    REF_IDX = 54,
86
    MB_QP_DELTA = 60,
87
    INTRA_CHROMA_PRED_MODE = 64,
88
    PREV_INTRA4X4_PRED_MODE_FLAG = 68,
89
    REM_INTRA4X4_PRED_MODE = 69,
90
    MB_FIELD_DECODING_FLAG = 70,
91
    CBP_LUMA = 73,
92
    CBP_CHROMA = 77,
93
    CBF = 85,
94
    SIGNIFICANT_COEFF_FLAG_FRAME = 105,
95
    SIGNIFICANT_COEFF_FLAG_FLD = 277,
96
    LAST_SIGNIFICANT_COEFF_FLAG_FRAME = 166,
97
    LAST_SIGNIFICANT_COEFF_FLAG_FLD = 338,
98
    COEFF_ABS_LEVEL_MINUS1 = 227,
99
100
    /* High profile related Syntax element CABAC offsets */
101
    TRANSFORM_SIZE_8X8_FLAG = 399,
102
    SIGNIFICANT_COEFF_FLAG_8X8_FRAME = 402,
103
    LAST_SIGNIFICANT_COEFF_FLAG_8X8_FRAME = 417,
104
    COEFF_ABS_LEVEL_MINUS1_8X8 = 426,
105
    SIGNIFICANT_COEFF_FLAG_8X8_FIELD = 436,
106
    LAST_SIGNIFICANT_COEFF_FLAG_8X8_FIELD = 451
107
108
} cabac_table_num_t;
109
110
typedef enum
111
{
112
    SIG_COEFF_CTXT_CAT_0_OFFSET = 0,
113
    SIG_COEFF_CTXT_CAT_1_OFFSET = 15,
114
    SIG_COEFF_CTXT_CAT_2_OFFSET = 29,
115
    SIG_COEFF_CTXT_CAT_3_OFFSET = 44,
116
    SIG_COEFF_CTXT_CAT_4_OFFSET = 47,
117
    SIG_COEFF_CTXT_CAT_5_OFFSET = 0,
118
    COEFF_ABS_LEVEL_CAT_0_OFFSET = 0,
119
    COEFF_ABS_LEVEL_CAT_1_OFFSET = 10,
120
    COEFF_ABS_LEVEL_CAT_2_OFFSET = 20,
121
    COEFF_ABS_LEVEL_CAT_3_OFFSET = 30,
122
    COEFF_ABS_LEVEL_CAT_4_OFFSET = 39,
123
    COEFF_ABS_LEVEL_CAT_5_OFFSET = 0
124
} cabac_blk_cat_offset_t;
125
126
/** Structure for the MV bank */
127
typedef struct _mv_pred_t
128
{
129
    WORD16 i2_mv[4]; /** 0- mvFwdX, 1- mvFwdY, 2- mvBwdX, 3- mvBwdY */
130
    WORD8 i1_ref_frame[2];
131
132
    UWORD8 u1_col_ref_pic_idx; /** Idx into the pic buff array */
133
    UWORD8 u1_pic_type; /** Idx into the pic buff array */
134
135
} mv_pred_t;
136
137
typedef struct
138
{
139
    WORD32 i4_mv_indices[16];
140
    WORD8 i1_submb_num[16];
141
    WORD8 i1_partitionsize[16];
142
    WORD8 i1_num_partitions;
143
    WORD8 u1_vert_mv_scale;
144
    UWORD8 u1_col_zeroflag_change;
145
} directmv_t;
146
147
typedef struct pic_buffer_t
148
{
149
    /**Different components of the picture */
150
    UWORD8 *pu1_buf1;
151
    UWORD8 *pu1_buf2;
152
    UWORD8 *pu1_buf3;
153
    UWORD16 u2_disp_width; /** Width of the display luma frame in pixels */
154
    UWORD16 u2_disp_height; /** Height of the display luma frame in pixels */
155
    UWORD32 u4_time_stamp; /** Time at which frame has to be displayed */
156
    UWORD16 u2_frm_wd_y; /** Width of the luma frame in pixels */
157
    UWORD16 u2_frm_wd_uv; /** Width of the chroma frame */
158
    UWORD16 u2_frm_ht_y; /** Height of the luma frame in pixels */
159
    UWORD16 u2_frm_ht_uv; /** Height of the chroma frame */
160
    /* Upto this is resembling the structure IH264DEC_DispUnit */
161
162
    /* If any member is to be added, add below this            */
163
164
    /* u4_ofst from start of picture buffer to display position for Y buffer  */
165
    UWORD16 u2_crop_offset_y;
166
167
    /* u4_ofst from start of picture buffer to display position for UV buffer */
168
    UWORD16 u2_crop_offset_uv;
169
170
    UWORD8 u1_is_short; /** (1: short 0: long) term ref pic */
171
    UWORD8 u1_pic_type; /** frame / field / complementary field pair */
172
    UWORD8 u1_pic_buf_id; /** Idx into the picBufAPI array */
173
    UWORD8 u1_mv_buf_id;
174
    WORD32 i4_seq;
175
    UWORD8 *pu1_col_zero_flag;
176
    mv_pred_t *ps_mv; /** Pointer to the MV bank array */
177
    WORD32 i4_poc; /** POC */
178
    WORD32 i4_pic_num;
179
    WORD32 i4_frame_num;
180
    WORD32 i4_top_field_order_cnt; /** TopPOC */
181
    WORD32 i4_bottom_field_order_cnt; /** BottomPOC */
182
    WORD32 i4_avg_poc; /** minPOC */
183
    UWORD8 u1_picturetype; /*Same as u1_pic_type..u1_pic_type gets overwritten whereas
184
     this doesnot get overwritten ...stores the pictype of
185
     frame/complementary field pair/ mbaff */
186
    UWORD8 u1_long_term_frm_idx;
187
    UWORD8 u1_long_term_pic_num;
188
    UWORD32 u4_pack_slc_typ; /* It will contain information about types of slices */
189
190
    /* ! */
191
    UWORD32 u4_ts;
192
    UWORD8 u1_pic_struct;/* Refer to SEI table D-1 */
193
194
} pic_buffer_t;
195
196
typedef struct
197
{
198
    void *u4_add[4];
199
} neighbouradd_t;
200
201
typedef struct
202
{
203
    const UWORD8 *pu1_inv_scan;
204
    void *pv_table[6];
205
} cavlc_cntxt_t;
206
207
/**
208
 ************************************************************************
209
 * \file ih264d_structs.h
210
 *
211
 * \brief
212
 *    Structures used in the H.264 decoder
213
 *
214
 * \date
215
 *    18/11/2002
216
 *
217
 * \author  Sriram Sethuraman
218
 *
219
 ************************************************************************
220
 */
221
222
/**
223
 * Structure to represent a MV Bank buffer and col flag
224
 */
225
typedef struct
226
{
227
    /**
228
     *  Pointer to buffer that holds col flag.
229
     */
230
    void *pv_col_zero_flag;
231
232
    /**
233
     * Pointer to buffer that holds mv_pred
234
     */
235
    void *pv_mv;
236
237
 }col_mv_buf_t;
238
239
240
typedef struct
241
{
242
    UWORD8 u1_dydx; /** 4*dy + dx for Y comp / 8*dy + dx for UV comp */
243
    UWORD8 u1_is_bi_direct; /** 1: is bi-direct 0: forward / backward only   */
244
    UWORD8 u1_wght_pred_type; /** 0-default 1-singleWeighted 2-BiWeighted      */
245
    WORD8 i1_mb_partwidth; /** Width of MB partition                        */
246
    WORD8 i1_mb_partheight; /** Height of MB partition                       */
247
    WORD8 i1_mc_wd; /** Number of bytes in a DMA stride              */
248
    WORD8 i1_dma_ht; /** Number of strides                            */
249
250
    WORD8 i1_pod_ht; /** Flag specifying height of pad on demand      */
251
    /** 0 (No pod) -ve(Top pod) +ve(Bottom pod)      */
252
    UWORD16 u2_dst_stride; /** Stride value of the destination              */
253
    UWORD16 u2_u1_ref_buf_wd; /** Width of the ref buffer                      */
254
    UWORD16 u2_frm_wd;
255
    UWORD16 u2_dummy;
256
257
    UWORD8 *u1_pi1_wt_ofst_rec_v; /** Pointer to packed weight and u4_ofst          */
258
    UWORD8 *pu1_rec_y_u; /** MB partition address in row buffer           */
259
    UWORD8 *pu1_dma_dest_addr; /** Destination address for DMA transfer         */
260
    UWORD8 *pu1_y_ref;
261
    UWORD8 *pu1_u_ref;
262
    UWORD8 *pu1_v_ref;
263
264
    UWORD8 *pu1_pred;
265
    UWORD8 *pu1_pred_u;
266
    UWORD8 *pu1_pred_v;
267
    UWORD8 u1_dma_wd_y;
268
    UWORD8 u1_dma_ht_y;
269
    UWORD8 u1_dma_wd_uv;
270
    UWORD8 u1_dma_ht_uv;
271
} pred_info_t;
272
273
typedef struct
274
{
275
    UWORD32 *pu4_wt_offst;
276
    WORD16 i2_mv[2];
277
278
    /***************************************************/
279
    /*packing information  i1_size_pos_info             */
280
    /* bit 1:0 -> X position in terms of  (4x4) units   */
281
    /* bit 3:2 -> Y position in terms of  (4x4) units   */
282
    /* bit 5:4 -> PU width 0:4,1:8,2:16                 */
283
    /* bit 7:6 -> PU height 0:4,1:8,2:16                */
284
     /***************************************************/
285
    WORD8 i1_size_pos_info;
286
287
    /***************************************************/
288
    /*packing information ref idx info                 */
289
    /* bit 5:0 ->ref_idx                              */
290
    /* bit 6:7   -> 0:l0,1:l1,2:bipred                  */
291
     /***************************************************/
292
    WORD8 i1_ref_idx_info;
293
294
    WORD8 i1_buf_id;
295
296
297
    UWORD8 u1_pic_type; /** frame /top field/bottom field/mbaff / complementary field pair */
298
299
}pred_info_pkd_t;
300
/*! Sequence level parameters */
301
302
typedef struct
303
{
304
    UWORD8 u1_seq_parameter_set_id; /** id for the seq par set 0-31 */
305
    UWORD8 u1_is_valid; /** is Seq Param set valid */
306
307
    UWORD16 u2_frm_wd_in_mbs; /** Frame width expressed in MB units */
308
    UWORD16 u2_frm_ht_in_mbs; /** Frame height expressed in MB units */
309
310
    /* Following are derived from the above two */
311
    UWORD16 u2_fld_ht_in_mbs; /** Field height expressed in MB units */
312
    UWORD16 u2_max_mb_addr; /** Total number of macroblocks in a coded picture */
313
    UWORD16 u2_total_num_of_mbs; /** Total number of macroblocks in a coded picture */
314
    UWORD32 u4_fld_ht; /** field height */
315
    UWORD32 u4_cwidth; /** chroma width */
316
    UWORD32 u4_chr_frm_ht; /** chroma height */
317
    UWORD32 u4_chr_fld_ht; /** chroma field height */
318
    UWORD8 u1_mb_aff_flag; /** 0 - no mb_aff; 1 - uses mb_aff */
319
320
    UWORD8 u1_profile_idc; /** profile value */
321
    UWORD8 u1_level_idc; /** level value */
322
323
    /* high profile related syntax elements   */
324
    WORD32 i4_chroma_format_idc;
325
    WORD32 i4_bit_depth_luma_minus8;
326
    WORD32 i4_bit_depth_chroma_minus8;
327
    WORD32 i4_qpprime_y_zero_transform_bypass_flag;
328
    WORD32 i4_seq_scaling_matrix_present_flag;
329
    UWORD8 u1_seq_scaling_list_present_flag[8];
330
    UWORD8 u1_use_default_scaling_matrix_flag[8];
331
    WORD16 i2_scalinglist4x4[6][16];
332
    WORD16 i2_scalinglist8x8[2][64];
333
    UWORD8 u1_more_than_one_slice_group_allowed_flag;
334
    UWORD8 u1_arbitrary_slice_order_allowed_flag;
335
    UWORD8 u1_redundant_slices_allowed_flag;
336
    UWORD8 u1_bits_in_frm_num; /** Number of bits in frame num */
337
    UWORD16 u2_u4_max_pic_num_minus1; /** Maximum frame num minus 1 */
338
    UWORD8 u1_pic_order_cnt_type; /** 0 - 2 indicates the method to code picture order count */
339
    UWORD8 u1_log2_max_pic_order_cnt_lsb_minus;
340
    WORD32 i4_max_pic_order_cntLsb;
341
    UWORD8 u1_num_ref_frames_in_pic_order_cnt_cycle;
342
    UWORD8 u1_delta_pic_order_always_zero_flag;
343
    WORD32 i4_ofst_for_non_ref_pic;
344
    WORD32 i4_ofst_for_top_to_bottom_field;
345
    WORD32 i4_ofst_for_ref_frame[MAX_NUM_REF_FRAMES_OFFSET];
346
    UWORD8 u1_num_ref_frames;
347
    UWORD8 u1_gaps_in_frame_num_value_allowed_flag;
348
    UWORD8 u1_frame_mbs_only_flag; /** 1 - frame only; 0 - field/frame pic */
349
    UWORD8 u1_direct_8x8_inference_flag;
350
    UWORD8 u1_vui_parameters_present_flag;
351
    vui_t s_vui;
352
} dec_seq_params_t;
353
354
typedef struct
355
{
356
    UWORD16 u2_frm_wd_in_mbs; /** Frame width expressed in MB units    */
357
    UWORD16 u2_frm_ht_in_mbs; /** Frame height expressed in MB units   */
358
    UWORD8 u1_frame_mbs_only_flag; /** 1 - frame only; 0 - field/frame pic  */
359
    UWORD8 u1_profile_idc; /** profile value                        */
360
    UWORD8 u1_level_idc; /** level value                          */
361
    UWORD8 u1_direct_8x8_inference_flag;
362
    UWORD8 u1_eoseq_pending;
363
} prev_seq_params_t;
364
365
/** Picture level parameters */
366
typedef struct
367
{
368
    dec_seq_params_t *ps_sps; /** applicable seq. parameter set */
369
370
    /* High profile related syntax elements */
371
    WORD32 i4_transform_8x8_mode_flag;
372
    WORD32 i4_pic_scaling_matrix_present_flag;
373
    UWORD8 u1_pic_scaling_list_present_flag[8];
374
    UWORD8 u1_pic_use_default_scaling_matrix_flag[8];
375
    WORD16 i2_pic_scalinglist4x4[6][16];
376
    WORD16 i2_pic_scalinglist8x8[2][64];
377
    WORD8 i1_second_chroma_qp_index_offset;
378
379
    UWORD32 u4_slice_group_change_rate;
380
    UWORD8 *pu1_slice_groupmb_map; /** MB map with slice membership labels */
381
    UWORD8 u1_pic_parameter_set_id; /** id for the picture par set 0-255*/
382
    UWORD8 u1_entropy_coding_mode; /** Entropy coding : 0-VLC; 1 - CABAC */
383
    UWORD8 u1_num_slice_groups; /** Number of slice groups */
384
    UWORD8 u1_pic_init_qp; /** Initial QPY for the picture {-26,25}*/
385
    WORD8 i1_chroma_qp_index_offset; /** Chroma QP u4_ofst w.r.t QPY {-12,12} */
386
    UWORD8 u1_dblk_filter_parms_flag; /** Slice layer has deblocking filter parameters */
387
    UWORD8 u1_constrained_intra_pred_flag; /** Constrained intra prediction u4_flag */
388
    UWORD8 u1_redundant_pic_cnt_present_flag; /** Redundant_pic_cnt is in slices using this PPS */
389
    UWORD8 u1_pic_order_present_flag; /** Pic order present u4_flag */
390
    UWORD8 u1_num_ref_idx_lx_active[2]; /** Maximum reference picture index in the reference list 0 : range [1 - 15] */
391
    UWORD8 u1_wted_pred_flag;
392
    UWORD8 u1_wted_bipred_idc;
393
    UWORD8 u1_pic_init_qs;
394
    UWORD8 u1_deblocking_filter_parameters_present_flag;
395
    UWORD8 u1_vui_pic_parameters_flag;
396
    UWORD8 u1_mb_slice_group_map_type;
397
    UWORD8 u1_slice_group_change_direction_flag;
398
    UWORD8 u1_frame_cropping_flag;
399
    UWORD8 u1_frame_cropping_rect_left_ofst;
400
    UWORD8 u1_frame_cropping_rect_right_ofst;
401
    UWORD8 u1_frame_cropping_rect_top_ofst;
402
    UWORD8 u1_frame_cropping_rect_bottom_ofst;
403
    void * pv_codec_handle; /* For Error Handling */
404
    WORD32 i4_top_field_order_cnt;
405
    WORD32 i4_bottom_field_order_cnt;
406
    WORD32 i4_avg_poc;
407
    UWORD8 u1_is_valid; /** is Pic Param set valid */
408
} dec_pic_params_t;
409
410
/** Picture Order Count Paramsters */
411
typedef struct
412
{
413
    WORD32 i4_pic_order_cnt_lsb;
414
    WORD32 i4_pic_order_cnt_msb;
415
    WORD32 i4_delta_pic_order_cnt_bottom;
416
    WORD32 i4_delta_pic_order_cnt[2];
417
    WORD32 i4_prev_frame_num_ofst;
418
    UWORD8 u1_mmco_equalto5;
419
    UWORD8 u1_bot_field;
420
    UWORD16 u2_frame_num;
421
    WORD32 i4_top_field_order_count;
422
    WORD32 i4_bottom_field_order_count;
423
} pocstruct_t;
424
425
/*****************************************************************************/
426
/* parse_mb_pers_info contains necessary mb info data required persistently  */
427
/* in the form of top and left neighbours.                                   */
428
/*****************************************************************************/
429
typedef struct
430
{
431
    void *u4_pic_addrress[4]; /* picture address for BS calc */
432
    WORD8 pi1_intrapredmodes[4]; /* calc Intra pred modes */
433
    UWORD8 pu1_nnz_y[4];
434
    UWORD8 pu1_nnz_uv[4];
435
    UWORD8 u1_mb_fld;
436
    UWORD8 u1_mb_type;
437
    UWORD16 u2_luma_csbp; /* Luma csbp used for BS calc */
438
    UWORD8 u1_tran_form8x8;
439
} mb_neigbour_params_t;
440
441
/* This info is required for decoding purposes except Deblockng */
442
typedef struct _DecMbInfo
443
{
444
    UWORD8 u1_mb_type; /** macroblock type: I/P/B/SI/SP */
445
    UWORD8 u1_chroma_pred_mode;
446
    UWORD8 u1_cbp;
447
    UWORD8 u1_mb_mc_mode; /** 16x16, 2 16x8, 2 8x16, 4 8x8 */
448
    UWORD8 u1_topmb; /** top Mb u4_flag */
449
    UWORD8 u1_mb_ngbr_availablity;
450
    UWORD8 u1_end_of_slice;
451
    UWORD8 u1_mb_field_decodingflag;
452
    UWORD8 u1_topleft_mb_fld;
453
    UWORD8 u1_topleft_mbtype;
454
    WORD8 i1_offset;
455
    UWORD8 u1_Mux;
456
    UWORD8 u1_qp_div6;
457
    UWORD8 u1_qp_rem6;
458
    UWORD8 u1_qpc_div6;
459
    UWORD8 u1_qpcr_div6;
460
    UWORD8 u1_qpc_rem6;
461
    UWORD8 u1_qpcr_rem6;
462
    UWORD8 u1_tran_form8x8;
463
    UWORD8 u1_num_pred_parts;
464
    UWORD8 u1_yuv_dc_block_flag;
465
    UWORD16 u2_top_right_avail_mask;
466
    UWORD16 u2_top_left_avail_mask;
467
    UWORD16 u2_luma_csbp; /** Coded 4x4 Sub Block Pattern */
468
    UWORD16 u2_chroma_csbp; /** Coded 4x4 Sub Block Pattern */
469
    UWORD16 u2_mbx;
470
    UWORD16 u2_mby;
471
    UWORD16 u2_mask[2];
472
473
    UWORD32 u4_pred_info_pkd_idx;
474
475
    mb_neigbour_params_t *ps_left_mb;
476
    mb_neigbour_params_t *ps_top_mb;
477
    mb_neigbour_params_t *ps_top_right_mb;
478
    mb_neigbour_params_t *ps_curmb;
479
} dec_mb_info_t;
480
481
482
/** Slice level parameters */
483
typedef struct
484
{
485
    dec_pic_params_t *ps_pps; /** PPS used */
486
    WORD32 i4_delta_pic_order_cnt[2];
487
    WORD32 i4_poc; /** Pic order cnt of picture to which slice belongs*/
488
    UWORD32 u4_idr_pic_id; /** IDR pic ID */
489
    UWORD16 u2_first_mb_in_slice; /** Address of first MB in slice*/
490
    UWORD16 u2_frame_num; /** Frame number from prev IDR pic */
491
492
    UWORD8 u1_mbaff_frame_flag; /** Mb adaptive frame field u4_flag */
493
    UWORD8 u1_field_pic_flag; /** Field picture or not */
494
    UWORD8 u1_bottom_field_flag; /** If slice belongs to bot field pic */
495
    UWORD8 u1_slice_type; /** I/P/B/SI/SP */
496
    WORD32 i4_pic_order_cnt_lsb; /** Picture Order Count */
497
    UWORD8 u1_slice_qp; /** Add slice_qp_delta to pic_init_QP */
498
    UWORD8 u1_disable_dblk_filter_idc; /** 0-dblk all edges; 1 - suppress; 2 - suppress only edges */
499
    WORD8 i1_slice_alpha_c0_offset; /** dblk: alpha and C0 table u4_ofst {-12,12}*/
500
    WORD8 i1_slice_beta_offset; /** dblk: beta table u4_ofst {-12, 12}*/
501
    UWORD8 u1_sp_for_switch_flag;
502
    UWORD8 u1_no_output_of_prior_pics_flag;
503
    UWORD8 u1_long_term_reference_flag;
504
    UWORD8 u1_num_ref_idx_lx_active[2];
505
    UWORD8 u1_cabac_init_idc; /** cabac_init_idc */
506
    UWORD8 u1_num_ref_idx_active_override_flag;
507
    UWORD8 u1_direct_spatial_mv_pred_flag;
508
    WORD32 (*pf_decodeDirect)(struct _DecStruct *ps_dec,
509
                              UWORD8 u1_wd_x,
510
                              dec_mb_info_t *ps_cur_mb_info,
511
                              UWORD8 u1_mb_num);
512
    UWORD8 u1_redundant_pic_cnt;
513
    WORD8 i1_slice_qs_delta;
514
    UWORD8 u1_nal_ref_idc; /** NAL ref idc of the Slice NAL unit */
515
    UWORD8 u1_nal_unit_type; /** NAL unit type of the Slice NAL */
516
    UWORD8 u1_direct_8x8_inference_flag;
517
    UWORD8 u1_mmco_equalto5; /** any of the MMCO command equal to 5 */
518
    UWORD8 u1_pic_order_cnt_type;
519
    pocstruct_t s_POC;
520
    /* DataStructures required for weighted prediction */
521
    UWORD16 u2_log2Y_crwd; /** Packed luma and chroma log2_weight_denom */
522
    /* [list0/list1]:[ref pics index]:[0-Y 1-Cb 2-Cr] [weight/u4_ofst],
523
     weights and offsets are signed numbers, since they are packed, it is defined
524
     unsigned. LSB byte : weight and MSB byte: u4_ofst */
525
    UWORD32 u4_wt_ofst_lx[2][MAX_REF_BUFS][3];
526
    void * pv_codec_handle; /* For Error Handling */
527
528
    /*  This is used when reordering is done in Forward or    */
529
    /*  backward lists. This is because reordering can point  */
530
    /*  to any valid entry in initial list irrespective of    */
531
    /*  num_ref_idx_active which could be overwritten using   */
532
    /*  ref_idx_reorder_flag                                  */
533
    UWORD8 u1_initial_list_size[2];
534
    UWORD32 u4_mbs_in_slice;
535
} dec_slice_params_t;
536
537
538
typedef struct
539
{
540
    UWORD8 u1_mb_type; /* Bit representations, X- reserved */
541
    /** |Field/Frame|X|X|X|X|Bslice u4_flag|PRED_NON_16x16 u4_flag |Intra Mbflag| */
542
    UWORD8 u1_mb_qp;
543
    UWORD8 u1_deblocking_mode; /** dblk: Mode [ NO / NO TOP / NO LEFT] filter */
544
    WORD8 i1_slice_alpha_c0_offset; /** dblk: alpha and C0 table u4_ofst {-12,12}*/
545
    WORD8 i1_slice_beta_offset; /** dblk: beta table u4_ofst {-12, 12}*/
546
    UWORD8 u1_single_call;
547
    UWORD8 u1_topmb_qp;
548
    UWORD8 u1_left_mb_qp;
549
    UWORD32 u4_bs_table[10]; /* Boundary strength */
550
551
} deblk_mb_t;
552
553
typedef struct
554
{
555
    UWORD8 u1_mb_type;
556
    UWORD8 u1_mb_qp;
557
} deblkmb_neighbour_t;
558
559
#define MAX_MV_RESIDUAL_INFO_PER_MB    32
560
#define MAX_REFIDX_INFO_PER_MB         4
561
0
#define PART_NOT_DIRECT                0
562
#define PART_DIRECT_8x8                1
563
0
#define PART_DIRECT_16x16              2
564
typedef struct
565
{
566
    UWORD8 u1_is_direct;
567
    UWORD8 u1_pred_mode;
568
    UWORD8 u1_sub_mb_num;
569
    UWORD8 u1_partheight;
570
    UWORD8 u1_partwidth;
571
} parse_part_params_t;
572
573
typedef struct
574
{
575
    UWORD8 u1_isI_mb;
576
    UWORD8 u1_num_part;
577
    UWORD32 *pu4_wt_offst[MAX_REFIDX_INFO_PER_MB];
578
    WORD8 i1_ref_idx[2][MAX_REFIDX_INFO_PER_MB];
579
    UWORD8 u1_col_info[MAX_REFIDX_INFO_PER_MB];
580
} parse_pmbarams_t;
581
582
typedef struct
583
{
584
    UWORD8 u1_vert_pad_top; /* flip-flop u4_flag remembering pad area (Vert) */
585
    UWORD8 u1_vert_pad_bot; /* flip-flop u4_flag remembering pad area (Vert) */
586
    UWORD8 u1_horz_pad; /* flip-flop u4_flag remembering pad area (Vert) */
587
    UWORD8 u1_pad_len_y_v; /* vertical pad amount for luma               */
588
    UWORD8 u1_pad_len_cr_v; /* vertical pad amount for chroma             */
589
} pad_mgr_t;
590
591
592
13
#define ACCEPT_ALL_PICS   (0x00)
593
22
#define REJECT_CUR_PIC    (0x01)
594
11
#define REJECT_PB_PICS    (0x02)
595
596
11
#define MASK_REJECT_CUR_PIC (0xFE)
597
#define MASK_REJECT_PB_PICS (0xFD)
598
599
4
#define PIC_TYPE_UNKNOWN  (0xFF)
600
22
#define PIC_TYPE_I        (0x00)
601
2
#define SYNC_FRM_DEFAULT  (0xFFFFFFFF)
602
2
#define INIT_FRAME        (0xFFFFFF)
603
604
typedef struct dec_err_status_t
605
{
606
    UWORD8 u1_cur_pic_type;
607
    UWORD8 u1_pic_aud_i;
608
    UWORD8 u1_err_flag;
609
    UWORD32 u4_frm_sei_sync;
610
    UWORD32 u4_cur_frm;
611
} dec_err_status_t;
612
613
/**************************************************************************/
614
/* Structure holds information about all high profile toolsets            */
615
/**************************************************************************/
616
typedef struct
617
{
618
    /*****************************************/
619
    /* variables required for scaling        */
620
    /*****************************************/
621
    UWORD8 u1_scaling_present;
622
    WORD16 *pi2_scale_mat[8];
623
624
    /*************************************************/
625
    /* scaling matrices for frame macroblocks after  */
626
    /* inverse scanning                              */
627
    /*************************************************/
628
    WORD16 i2_scalinglist4x4[6][16];
629
    WORD16 i2_scalinglist8x8[2][64];
630
631
632
    /*****************************************/
633
    /* variables required for transform8x8   */
634
    /*****************************************/
635
    UWORD8 u1_transform8x8_present;
636
    UWORD8 u1_direct_8x8_inference_flag;
637
    /* temporary variable to get noSubMbPartSizeLessThan8x8Flag from ih264d_parse_bmb_non_direct_cavlc */
638
    UWORD8 u1_no_submb_part_size_lt8x8_flag;
639
640
    /* needed for inverse scanning */
641
    cavlc_cntxt_t s_cavlc_ctxt;
642
643
    /* contexts for the CABAC related parsing */
644
    bin_ctxt_model_t *ps_transform8x8_flag;
645
    bin_ctxt_model_t *ps_sigcoeff_8x8_frame;
646
    bin_ctxt_model_t *ps_last_sigcoeff_8x8_frame;
647
    bin_ctxt_model_t *ps_coeff_abs_levelminus1;
648
    bin_ctxt_model_t *ps_sigcoeff_8x8_field;
649
    bin_ctxt_model_t *ps_last_sigcoeff_8x8_field;
650
651
/* variables required for intra8x8 */
652
653
/* variables required for handling different Qp for Cb and Cr */
654
655
} high_profile_tools_t;
656
657
typedef struct
658
{
659
    UWORD32 u4_num_bufs; /* Number of buffers in each display frame. 2 for 420SP and 3 for 420P and so on */
660
    void *buf[3]; /* Pointers to each of the components */
661
    UWORD32 u4_bufsize[3];
662
    UWORD32 u4_ofst[3];
663
} disp_buf_t;
664
typedef struct _dec_slice_struct
665
{
666
    volatile UWORD32 u4_first_mb_in_slice;
667
    volatile UWORD32 slice_type;
668
    volatile UWORD16 u2_log2Y_crwd;
669
    volatile void **ppv_map_ref_idx_to_poc;
670
    volatile void *pv_tu_coeff_data_start;
671
} dec_slice_struct_t;
672
673
/**
674
 * Structure to hold coefficient info for a 4x4 transform
675
 */
676
typedef struct
677
{
678
    /**
679
     * significant coefficient map
680
     */
681
    UWORD16 u2_sig_coeff_map;
682
683
    /**
684
     * holds coefficients
685
     */
686
    WORD16  ai2_level[16];
687
}tu_sblk4x4_coeff_data_t;
688
689
/**
690
 * Structure to hold coefficient info for a 8x8 transform
691
 */
692
typedef struct
693
{
694
695
    /**
696
     * significant coefficient map
697
     */
698
    UWORD32 au4_sig_coeff_map[2];
699
700
    /**
701
     * holds coefficients
702
     */
703
    WORD16  ai2_level[64];
704
}tu_blk8x8_coeff_data_t;
705
706
/** Aggregating structure that is globally available */
707
typedef struct _DecStruct
708
{
709
710
    /* Add below all other static memory allocations and pointers to items
711
     that are dynamically allocated once per session */
712
    dec_bit_stream_t *ps_bitstrm;
713
    dec_seq_params_t *ps_cur_sps;
714
    dec_pic_params_t *ps_cur_pps;
715
    dec_slice_params_t *ps_cur_slice;
716
717
    dec_pic_params_t *ps_pps;
718
    dec_seq_params_t *ps_sps;
719
    const UWORD16 *pu2_quant_scale_y;
720
    const UWORD16 *pu2_quant_scale_u;
721
    const UWORD16 *pu2_quant_scale_v;
722
    UWORD16 u2_mbx;
723
    UWORD16 u2_mby;
724
725
    UWORD16 u2_frm_wd_y; /** Width for luma buff */
726
    UWORD16 u2_frm_ht_y; /** Height for luma buff */
727
    UWORD16 u2_frm_wd_uv; /** Width for chroma buff */
728
    UWORD16 u2_frm_ht_uv; /** Height for chroma buff */
729
    UWORD16 u2_frm_wd_in_mbs; /** Frame width expressed in MB units */
730
    UWORD16 u2_frm_ht_in_mbs; /** Frame height expressed in MB units */
731
    WORD32 i4_submb_ofst; /** Offset in subMbs from the top left edge */
732
    /* Pointer to colocated Zero frame Image, will be used in B_DIRECT mode */
733
    /* colZeroFlag | // 0th bit
734
     field_flag  | // 1st bit
735
     XX          | // 2:3 bit don't cares
736
     subMbMode   | // 4:5 bit
737
     MbMode      | // 6:7 bit */
738
739
    UWORD8 *pu1_col_zero_flag;
740
741
    UWORD16 u2_pic_wd; /** Width of the picture being decoded */
742
    UWORD16 u2_pic_ht; /** Height of the picture being decoded */
743
744
    UWORD8 u1_first_slice_in_stream;
745
    UWORD8 u1_mb_ngbr_availablity;
746
    UWORD8 u1_ref_idxl0_active_minus1;
747
    UWORD8 u1_qp;
748
    UWORD8 u1_qp_y_div6;
749
    UWORD8 u1_qp_u_div6;
750
    UWORD8 u1_qp_y_rem6;
751
    UWORD8 u1_qp_u_rem6;
752
753
    /*********************************/
754
    /* configurable mb-group numbers */
755
    /* very critical to the decoder  */
756
    /*********************************/
757
    /************************************************************/
758
    /* MB_GROUP should be a multiple of 2                       */
759
    /************************************************************/
760
    UWORD8 u1_recon_mb_grp;
761
    UWORD8 u1_recon_mb_grp_pair;
762
    /* Variables to handle Cabac */
763
    decoding_envirnoment_t s_cab_dec_env; /* < Structure for decoding_envirnoment_t */
764
    /* These things need to be updated at each MbLevel */
765
    WORD8 i1_next_ctxt_idx; /* < next Ctxt Index */
766
    UWORD8 u1_currB_type;
767
    WORD8 i1_prev_mb_qp_delta; /* Prev MbQpDelta */
768
    UWORD8 u1_nal_unit_type;
769
770
    ctxt_inc_mb_info_t *p_ctxt_inc_mb_map; /* Pointer to ctxt_inc_mb_info_t map */
771
    ctxt_inc_mb_info_t *p_left_ctxt_mb_info; /* Pointer to left ctxt_inc_mb_info_t */
772
    ctxt_inc_mb_info_t *p_top_ctxt_mb_info; /* Pointer to top ctxt_inc_mb_info_t */
773
    ctxt_inc_mb_info_t *ps_curr_ctxt_mb_info; /* Pointer to current ctxt_inc_mb_info_t */
774
    ctxt_inc_mb_info_t *ps_def_ctxt_mb_info; /* Pointer to default ctxt_inc_mb_info_t */
775
776
    /* mv contexts for mv decoding using cabac */
777
    //UWORD8   u1_top_mv_ctxt_inc[4][4];
778
    /* Dimensions for u1_left_mv_ctxt_inc_arr is [2][4][4] for Mbaff case */
779
    UWORD8 u1_left_mv_ctxt_inc_arr[2][4][4];
780
    UWORD8 (*pu1_left_mv_ctxt_inc)[4];
781
782
    UWORD8 u1_sub_mb_num;
783
    UWORD8 u1_B; /** if B slice u1_B = 1 else 0 */
784
    WORD16 i2_only_backwarddma_info_idx;
785
    mv_pred_t *ps_mv; /** Pointer to the MV bank array */
786
    mv_pred_t *ps_mv_bank_cur; /** Pointer to the MV bank array */
787
    mv_pred_t s_default_mv_pred; /** Structure containing the default values
788
     for MV predictor */
789
790
    pred_info_t *ps_pred; /** Stores info to cfg MC */
791
    pred_info_t *ps_pred_start;
792
793
    UWORD32 u4_pred_info_idx;
794
    pred_info_pkd_t *ps_pred_pkd;
795
    pred_info_pkd_t *ps_pred_pkd_start;
796
    UWORD32 u4_pred_info_pkd_idx;
797
    UWORD8 *pu1_ref_buff; /** Destination buffer for DMAs */
798
    UWORD32 u4_dma_buf_idx;
799
800
    UWORD8 *pu1_y;
801
    UWORD8 *pu1_u;
802
    UWORD8 *pu1_v;
803
804
    WORD16 *pi2_y_coeff;
805
    UWORD8 *pu1_inv_scan;
806
807
    /**
808
     * Pointer frame level TU subblock coeff data
809
     */
810
    void *pv_pic_tu_coeff_data;
811
812
    /**
813
     * Pointer to TU subblock coeff data and number of subblocks and scan idx
814
     * Incremented each time a coded subblock is processed
815
     *
816
     */
817
    void *pv_parse_tu_coeff_data;
818
    void *pv_prev_mb_parse_tu_coeff_data;
819
820
    void *pv_proc_tu_coeff_data;
821
822
    WORD16 *pi2_coeff_data;
823
824
    cavlc_cntxt_t s_cavlc_ctxt;
825
826
    UWORD32 u4_n_leftY[2];
827
    UWORD32 u4_n_left_cr[2];
828
    UWORD32 u4_n_left_temp_y;
829
830
    UWORD8 pu1_left_nnz_y[4];
831
    UWORD8 pu1_left_nnz_uv[4];
832
    UWORD32 u4_n_left_temp_uv;
833
    /***************************************************************************/
834
    /*          Base pointer to all the cabac contexts                         */
835
    /***************************************************************************/
836
    bin_ctxt_model_t *p_cabac_ctxt_table_t;
837
838
    /***************************************************************************/
839
    /* cabac context pointers for every SE mapped into in p_cabac_ctxt_table_t */
840
    /***************************************************************************/
841
    bin_ctxt_model_t *p_mb_type_t;
842
    bin_ctxt_model_t *p_mb_skip_flag_t;
843
    bin_ctxt_model_t *p_sub_mb_type_t;
844
    bin_ctxt_model_t *p_mvd_x_t;
845
    bin_ctxt_model_t *p_mvd_y_t;
846
    bin_ctxt_model_t *p_ref_idx_t;
847
    bin_ctxt_model_t *p_mb_qp_delta_t;
848
    bin_ctxt_model_t *p_intra_chroma_pred_mode_t;
849
    bin_ctxt_model_t *p_prev_intra4x4_pred_mode_flag_t;
850
    bin_ctxt_model_t *p_rem_intra4x4_pred_mode_t;
851
    bin_ctxt_model_t *p_mb_field_dec_flag_t;
852
    bin_ctxt_model_t *p_cbp_luma_t;
853
    bin_ctxt_model_t *p_cbp_chroma_t;
854
    bin_ctxt_model_t *p_cbf_t[NUM_CTX_CAT];
855
    bin_ctxt_model_t *p_significant_coeff_flag_t[NUM_CTX_CAT];
856
    bin_ctxt_model_t *p_coeff_abs_level_minus1_t[NUM_CTX_CAT];
857
858
    UWORD32 u4_num_pmbair; /** MB pair number */
859
    mv_pred_t *ps_mv_left; /** Pointer to left motion vector bank */
860
    mv_pred_t *ps_mv_top_left; /** Pointer to top left motion vector bank */
861
    mv_pred_t *ps_mv_top_right; /** Pointer to top right motion vector bank */
862
863
    UWORD8 *pu1_left_yuv_dc_csbp;
864
865
866
    deblkmb_neighbour_t deblk_left_mb[2];
867
    deblkmb_neighbour_t *ps_deblk_top_mb;
868
    neighbouradd_t (*ps_left_mvpred_addr)[2]; /* Left MvPred Address Ping Pong*/
869
870
    /***************************************************************************/
871
    /*       Ref_idx contexts  are stored in the following way                 */
872
    /*  Array Idx 0,1 for reference indices in Forward direction               */
873
    /*  Array Idx 2,3 for reference indices in backward direction              */
874
    /***************************************************************************/
875
876
    /* Dimensions for u1_left_ref_ctxt_inc_arr is [2][4] for Mbaff:Top and Bot */
877
    WORD8 i1_left_ref_idx_ctx_inc_arr[2][4];
878
    WORD8 *pi1_left_ref_idx_ctxt_inc;
879
880
    /*************************************************************************/
881
    /*               Arrangnment of DC CSBP                                  */
882
    /*        bits:  b7  b6  b5  b4  b3  b2  b1  b0                          */
883
    /*        CSBP:   x   x   x   x   x  Vdc Udc Ydc                         */
884
    /*************************************************************************/
885
    /*************************************************************************/
886
    /*  Points either to u1_yuv_dc_csbp_topmb or  u1_yuv_dc_csbp_bot_mb     */
887
    /*************************************************************************/
888
    UWORD8 u1_yuv_dc_csbp_topmb;
889
    UWORD8 u1_yuv_dc_csbp_bot_mb;
890
891
    /* DMA SETUP */
892
    tfr_ctxt_t s_tran_addrecon_parse;
893
    tfr_ctxt_t s_tran_addrecon;
894
    tfr_ctxt_t s_tran_iprecon;
895
    tfr_ctxt_t *ps_frame_buf_ip_recon;
896
    WORD8 i1_recon_in_thread3_flag;
897
898
    /* slice Header Simplification */
899
    UWORD8 u1_pr_sl_type;
900
    WORD32 i4_frametype;
901
    UWORD32 u4_app_disp_width;
902
    WORD32 i4_error_code;
903
    UWORD32 u4_bitoffset;
904
905
    /* Variables added to handle field pics */
906
907
    UWORD8 u1_second_field;
908
    WORD32 i4_pic_type;
909
    WORD32 i4_content_type;
910
    WORD32 i4_decode_header;
911
    WORD32 i4_header_decoded;
912
    UWORD32 u4_total_frames_decoded;
913
914
    ctxt_inc_mb_info_t *ps_left_mb_ctxt_info; /* structure containing the left MB's
915
     context info, incase of Mbaff */
916
    pocstruct_t s_prev_pic_poc;
917
    pocstruct_t s_cur_pic_poc;
918
    WORD32 i4_cur_display_seq;
919
    WORD32 i4_prev_max_display_seq;
920
    WORD32 i4_max_poc;
921
    deblk_mb_t *ps_cur_deblk_mb;
922
923
    /* Pointers to local scratch buffers */
924
    deblk_mb_t *ps_deblk_pic;
925
926
    /* Pointers to Picture Buffers (Given by BufAPI Lib) */
927
    struct pic_buffer_t *ps_cur_pic; /** Pointer to Current picture buffer */
928
929
    /* Scratch Picture Buffers (Given by BufAPI Lib) */
930
    struct pic_buffer_t s_cur_pic;
931
932
    /* Current Slice related information */
933
    volatile UWORD16 u2_cur_slice_num;
934
    volatile UWORD16 u2_cur_slice_num_dec_thread;
935
936
    /* Variables needed for Buffer API handling */
937
    UWORD8 u1_nal_buf_id;
938
    UWORD8 u1_pic_buf_id;
939
    UWORD8 u1_pic_bufs;
940
941
    WORD16 *pi2_pred1; //[441];  /** Temp predictor buffer for MC */
942
    /* Pointer to refernce Pic buffers list, 0:fwd, 1:bwd */
943
    pic_buffer_t **ps_ref_pic_buf_lx[2];
944
    /* refIdx to POC mapping */
945
    void **ppv_map_ref_idx_to_poc;
946
    void **ppv_map_ref_idx_to_poc_base;
947
    UWORD32 *pu4_wts_ofsts_mat;
948
    UWORD32 *pu4_wt_ofsts;
949
    UWORD32 *pu4_mbaff_wt_mat;
950
    /* Function pointers to read Params common to CAVLC and CABAC */
951
    WORD32 (*pf_parse_inter_mb)(struct _DecStruct * ps_dec,
952
                                dec_mb_info_t * ps_cur_mb_info,
953
                                UWORD8 u1_mb_num,
954
                                UWORD8 u1_num_mbsNby2);
955
    WORD32 (*pf_mvpred_ref_tfr_nby2mb)(struct _DecStruct * ps_dec,
956
                                     UWORD8 u1_num_mbs,
957
                                     UWORD8 u1_num_mbsNby2);
958
959
    WORD32 (*pf_parse_inter_slice)(struct _DecStruct * ps_dec,
960
                                   dec_slice_params_t * ps_slice,
961
                                   UWORD16 u2_first_mb_in_slice);
962
963
    UWORD32 (*pf_get_mb_info)(struct _DecStruct * ps_dec,
964
                              const UWORD16 u2_cur_mb_address,
965
                              dec_mb_info_t * ps_cur_mb_info,
966
                              UWORD32 u4_mbskip_run);
967
968
    /* Variables for Decode Buffer Management */
969
    dpb_manager_t *ps_dpb_mgr;
970
    dpb_commands_t *ps_dpb_cmds;
971
    dpb_commands_t s_dpb_cmds_scratch;
972
973
    /* Variables Required for N MB design */
974
    dec_mb_info_t *ps_nmb_info;
975
976
    UWORD8 *pu1_y_intra_pred_line;
977
    UWORD8 *pu1_u_intra_pred_line;
978
    UWORD8 *pu1_v_intra_pred_line;
979
980
    UWORD8 *pu1_cur_y_intra_pred_line;
981
    UWORD8 *pu1_cur_u_intra_pred_line;
982
    UWORD8 *pu1_cur_v_intra_pred_line;
983
984
    UWORD8 *pu1_cur_y_intra_pred_line_base;
985
    UWORD8 *pu1_cur_u_intra_pred_line_base;
986
    UWORD8 *pu1_cur_v_intra_pred_line_base;
987
988
    UWORD8 *pu1_prev_y_intra_pred_line;
989
    UWORD8 *pu1_prev_u_intra_pred_line;
990
    UWORD8 *pu1_prev_v_intra_pred_line;
991
992
    UWORD32 u4_intra_pred_line_ofst;
993
994
    UWORD8 u1_res_changed;
995
996
    mv_pred_t *ps_mv_cur; /** pointer to current motion vector bank */
997
    mv_pred_t *ps_mv_top; /** pointer to top motion vector bank */
998
    mv_pred_t *ps_mv_top_right2;/** Pointer to top right motion vector bank */
999
    mv_pred_t *ps_mv_p[2]; /** Scratch ping motion vector bank */
1000
    mv_pred_t *ps_mv_top_p[MV_SCRATCH_BUFS]; /** Scratch top pong motion vector bank */
1001
    UWORD8 u1_mv_top_p;
1002
1003
    deblk_mb_t *ps_deblk_mbn;
1004
1005
    UWORD8 *pu1_temp_mc_buffer;
1006
1007
    struct _sei *ps_sei;
1008
    UWORD8 u1_pic_struct_copy;
1009
    /* Variables required for cropping */
1010
    UWORD16 u2_disp_width;
1011
    UWORD16 u2_disp_height;
1012
    UWORD16 u2_crop_offset_y;
1013
    UWORD16 u2_crop_offset_uv;
1014
1015
    /* Variable required to get presentation time stamp through application */
1016
    UWORD32 u4_pts;
1017
1018
    /* Variables used for gaps in frame number */
1019
    UWORD16 u2_prev_ref_frame_num;
1020
1021
    UWORD8 u1_mb_idx;
1022
    struct pic_buffer_t *ps_col_pic;
1023
    void (*pf_parse_mvdirect)(struct _DecStruct*,
1024
                           struct pic_buffer_t*,
1025
                           directmv_t*,
1026
                           UWORD8,
1027
                           WORD32,
1028
                           dec_mb_info_t *);
1029
    void *pv_dec_out;
1030
    void *pv_dec_in;
1031
    void *pv_scratch_sps_pps; /*used temeporarily store sps/ spps while parsing*/
1032
1033
    /* state pointers to mb and partition information */
1034
    parse_pmbarams_t *ps_parse_mb_data;
1035
    parse_part_params_t *ps_parse_part_params;
1036
1037
    /* scratch pointers to mb and partition information */
1038
    parse_part_params_t *ps_part;
1039
1040
    UWORD8 u1_max_dec_frame_buffering;
1041
    pad_mgr_t s_pad_mgr;
1042
    UWORD8 (*pf_mvpred)(struct _DecStruct *ps_dec,
1043
                        struct _DecMbInfo *ps_cur_mb_info,
1044
                        mv_pred_t *ps_mv_pred,
1045
                        mv_pred_t *ps_mv_nmb,
1046
                        mv_pred_t *ps_mv_ntop,
1047
                        UWORD8 u1_sub_mb_num,
1048
                        UWORD8 uc_mb_part_width,
1049
                        UWORD8 uc_lxstart,
1050
                        UWORD8 uc_lxend,
1051
                        UWORD8 u1_mb_mc_mode);
1052
    void (*pf_compute_bs)(struct _DecStruct * ps_dec,
1053
                         struct _DecMbInfo * ps_cur_mb_info,
1054
                         const UWORD16 u2_mbxn_mb);
1055
    UWORD8 u1_init_dec_flag;
1056
    prev_seq_params_t s_prev_seq_params;
1057
    UWORD8 u1_cur_mb_fld_dec_flag; /* current Mb fld or Frm */
1058
1059
    UWORD8 u1_topleft_mb_fld;
1060
    UWORD8 u1_topleft_mbtype;
1061
    UWORD8 u1_topleft_mb_fld_bot;
1062
    UWORD8 u1_topleft_mbtype_bot;
1063
    WORD16 i2_prev_slice_mbx;
1064
    WORD16 i2_prev_slice_mby;
1065
    UWORD16 u2_top_left_mask;
1066
    UWORD16 u2_top_right_mask;
1067
    dec_err_status_t * ps_dec_err_status;
1068
    /* Ensure pi1_left_pred_mode is aligned to 4 byte boundary,
1069
    by declaring this after a pointer or an integer */
1070
    WORD8 pi1_left_pred_mode[8];
1071
1072
    UWORD8 u1_mb_idx_mv;
1073
    UWORD16 u2_mv_2mb[2];
1074
    UWORD32 u4_skip_frm_mask;
1075
1076
    /* variable for finding the no.of mbs decoded in the current picture */
1077
    UWORD16 u2_total_mbs_coded;
1078
    /* member added for supporting fragmented annex - B */
1079
//  frg_annex_read_t s_frag_annex_read;
1080
    /* added for vui_t, sei support*/
1081
    WORD32 i4_vui_frame_rate;
1082
    /* To Store the value of ref_idx_active for previous slice */
1083
    /* useful in error handling                                */
1084
    UWORD8 u1_num_ref_idx_lx_active_prev;
1085
    /* Flag added to come out of process call in annex-b if&if frame is decoded */
1086
    /* presence of access unit delimters and pps and sps                        */
1087
    UWORD8 u1_frame_decoded_flag;
1088
1089
    /* To keep track of whether the last picture was decoded or not */
1090
    /* in case of skip mode set by the application                  */
1091
    UWORD8 u1_last_pic_not_decoded;
1092
1093
    WORD32 e_dec_status;
1094
    UWORD32 u4_num_fld_in_frm;
1095
1096
    /* Function pointer for 4x4 residual cavlc parsing based on total coeff */
1097
    WORD32 (*pf_cavlc_4x4res_block[3])(UWORD32 u4_isdc,
1098
                                    UWORD32 u4_total_coeff_trail_one, /**TotalCoefficients<<16+trailingones*/
1099
                                    dec_bit_stream_t *ps_bitstrm);
1100
1101
    /* Function pointer array for interpolate functions in called from motion compensattion module */
1102
    void (*p_mc_interpolate_x_y[16][3])(UWORD8*,
1103
                                        UWORD8*,
1104
                                        UWORD8*,
1105
                                        UWORD8,
1106
                                        UWORD16,
1107
                                        UWORD16,
1108
                                        UWORD8);
1109
1110
    /**************************************************************************/
1111
    /* Function pointer for 4x4 totalcoeff, trlone and residual cavlc parsing */
1112
    /* based on u4_n (neigbourinng nnz average)                               */
1113
    /* These point to two functions depending on (u4_n > 7) and (u4_n <= 7)   */
1114
    /**************************************************************************/
1115
    WORD32 (*pf_cavlc_parse4x4coeff[2])(WORD16 *pi2_coeff_block,
1116
                                        UWORD32 u4_isdc, /* is it a DC block */
1117
                                        WORD32 u4_n,
1118
                                        struct _DecStruct *ps_dec, /** Decoder Parameters */
1119
                                        UWORD32 *pu4_total_coeff);
1120
1121
    /**************************************************************************/
1122
    /* Function pointer for luma 8x8block cavlc parsing based on top and left */
1123
    /* neigbour availability.                                                 */
1124
    /**************************************************************************/
1125
    WORD32 (*pf_cavlc_parse_8x8block[4])(WORD16 *pi2_coeff_block,
1126
                                         UWORD32 u4_sub_block_strd,
1127
                                         UWORD32 u4_isdc,
1128
                                         struct _DecStruct *ps_dec,
1129
                                         UWORD8 *pu1_top_nnz,
1130
                                         UWORD8 *pu1_left_nnz,
1131
                                         UWORD8 u1_tran_form8x8,
1132
                                         UWORD8 u1_mb_field_decodingflag,
1133
                                         UWORD32 *pu4_csbp);
1134
1135
    /**************************************************************************/
1136
    /* Ping pong top and current rows of mb neigbour_params                   */
1137
    /**************************************************************************/
1138
    mb_neigbour_params_t *ps_nbr_mb_row;
1139
    mb_neigbour_params_t *ps_cur_mb_row;
1140
    mb_neigbour_params_t *ps_top_mb_row;
1141
1142
    /**************************************************************************/
1143
    /* Function pointer for 16x16 and non16x16 Bs1 calculations depending on   */
1144
    /* P and B slice.                                                          */
1145
    /***************************************************************************/
1146
    void (*pf_fill_bs1[2][2])(mv_pred_t *ps_cur_mv_pred,
1147
                              mv_pred_t *ps_top_mv_pred,
1148
                              void **ppv_map_ref_idx_to_poc,
1149
                              UWORD32 *pu4_bs_table, /* pointer to the BsTable array */
1150
                              mv_pred_t *ps_leftmost_mv_pred,
1151
                              neighbouradd_t *ps_left_addr,
1152
                              void **u4_pic_addrress,
1153
                              WORD32 i4_ver_mvlimit);
1154
1155
    void (*pf_fill_bs_xtra_left_edge[2])(UWORD32 *pu4_bs, /* Base pointer of BS table */
1156
                                         WORD32 u4_left_mb_t_csbp, /* left mbpair's top csbp   */
1157
                                         WORD32 u4_left_mb_b_csbp, /* left mbpair's bottom csbp*/
1158
                                         WORD32 u4_cur_mb_csbp, /* csbp of current mb */
1159
                                         UWORD32 u4_cur_mb_bot /* is top or bottom mb */
1160
1161
                                         );
1162
    /* Function pointer array for BP and MP functions for MC*/
1163
    void (*p_motion_compensate)(struct _DecStruct * ps_dec,
1164
                               dec_mb_info_t *ps_cur_mb_info);
1165
1166
1167
    void (*p_mc_dec_thread)(struct _DecStruct * ps_dec, dec_mb_info_t *ps_cur_mb_info);
1168
1169
    /* Function pointer array for BP and MP functions for formMbPartInfo*/
1170
1171
    WORD32 (*p_form_mb_part_info)(pred_info_pkd_t *ps_pred_pkd,
1172
                                struct _DecStruct * ps_dec,
1173
                                     UWORD16 u2_mb_x,
1174
                                     UWORD16 u2_mb_y,
1175
                                     WORD32 mb_index,
1176
                                     dec_mb_info_t *ps_cur_mb_info);
1177
1178
    WORD32 (*p_form_mb_part_info_thread)(pred_info_pkd_t *ps_pred_pkd,
1179
                                struct _DecStruct * ps_dec,
1180
                                     UWORD16 u2_mb_x,
1181
                                     UWORD16 u2_mb_y,
1182
                                     WORD32 mb_index,
1183
                                     dec_mb_info_t *ps_cur_mb_info);
1184
1185
1186
    /* Required for cabac mbaff bottom mb */
1187
    UWORD32 u4_next_mb_skip;
1188
1189
    void (*p_DeblockPicture[2])(struct _DecStruct *);
1190
1191
    /* ! */
1192
    UWORD32 u4_ts;
1193
    UWORD8 u1_flushfrm;
1194
1195
    /* Output format sent by the application */
1196
    UWORD8 u1_chroma_format;
1197
    UWORD8 u1_pic_decode_done;
1198
    UWORD8 u1_slice_header_done;
1199
    WORD32 init_done;
1200
1201
    /******************************************/
1202
    /* For the high profile related variables */
1203
    /******************************************/
1204
    high_profile_tools_t s_high_profile;
1205
    /* CBCR */
1206
    UWORD8 u1_qp_v_div6;
1207
    UWORD8 u1_qp_v_rem6;
1208
    /*
1209
     * TO help solve the dangling field case.
1210
     * Check for the previous frame number and the current frame number.
1211
     */
1212
    UWORD16 u2_prv_frame_num;
1213
    UWORD8 u1_top_bottom_decoded;
1214
    UWORD8 u1_dangling_field;
1215
1216
    IVD_DISPLAY_FRAME_OUT_MODE_T                e_frm_out_mode;
1217
1218
    UWORD8 *pu1_bits_buf_static;
1219
    UWORD8 *pu1_bits_buf_dynamic;
1220
1221
    UWORD32 u4_static_bits_buf_size;
1222
    UWORD32 u4_dynamic_bits_buf_size;
1223
1224
    UWORD32 u4_num_disp_bufs_requested;
1225
    WORD32 i4_display_delay;
1226
    UWORD32 u4_slice_start_code_found;
1227
1228
    UWORD32 u4_nmb_deblk;
1229
    UWORD32 u4_use_intrapred_line_copy;
1230
    UWORD32 u4_num_mbs_prev_nmb;
1231
    UWORD32 u4_num_mbs_cur_nmb;
1232
    UWORD32 u4_app_deblk_disable_level;
1233
    UWORD32 u4_app_disable_deblk_frm;
1234
    WORD32 i4_app_skip_mode;
1235
    WORD32 i4_mv_frac_mask;
1236
1237
    disp_buf_t disp_bufs[MAX_DISP_BUFS_NEW];
1238
    UWORD32 u4_disp_buf_mapping[MAX_DISP_BUFS_NEW];
1239
    UWORD32 u4_disp_buf_to_be_freed[MAX_DISP_BUFS_NEW];
1240
    UWORD32 u4_share_disp_buf;
1241
    UWORD32 u4_num_disp_bufs;
1242
    UWORD32 u4_prev_nal_skipped;
1243
    UWORD32 u4_return_to_app;
1244
    WORD32 i4_dec_skip_mode;
1245
1246
    UWORD32 u4_bs_deblk_thread_created;
1247
    volatile UWORD32 u4_start_recon_deblk;
1248
    void *pv_bs_deblk_thread_handle;
1249
1250
    UWORD32 u4_cur_bs_mb_num;
1251
    UWORD32 u4_bs_cur_slice_num_mbs;
1252
    UWORD32 u4_cur_deblk_mb_num;
1253
    UWORD32 u4_sps_cnt_in_process;
1254
    volatile UWORD16 u2_cur_slice_num_bs;
1255
1256
    UWORD32 u4_deblk_mb_x;
1257
    UWORD32 u4_deblk_mb_y;
1258
1259
1260
1261
    iv_yuv_buf_t s_disp_frame_info;
1262
    UWORD32 u4_fmt_conv_num_rows;
1263
    UWORD32 u4_fmt_conv_cur_row;
1264
    ivd_out_bufdesc_t *ps_out_buffer;
1265
    ivd_get_display_frame_op_t s_disp_op;
1266
    UWORD32 u4_output_present;
1267
1268
    volatile UWORD16 cur_dec_mb_num;
1269
    volatile UWORD16 cur_recon_mb_num;
1270
    volatile UWORD16 u2_cur_mb_addr;
1271
    WORD16 i2_dec_thread_mb_y;
1272
    WORD16 i2_recon_thread_mb_y;
1273
1274
    UWORD8 u1_separate_parse;
1275
    UWORD32 u4_dec_thread_created;
1276
    void *pv_dec_thread_handle;
1277
    volatile UWORD8 *pu1_dec_mb_map;
1278
    volatile UWORD8 *pu1_recon_mb_map;
1279
    volatile UWORD16 *pu2_slice_num_map;
1280
    dec_slice_struct_t *ps_dec_slice_buf;
1281
    void *pv_map_ref_idx_to_poc_buf;
1282
    dec_mb_info_t *ps_frm_mb_info;
1283
    volatile dec_slice_struct_t * volatile ps_parse_cur_slice;
1284
    volatile dec_slice_struct_t * volatile ps_decode_cur_slice;
1285
    volatile dec_slice_struct_t * volatile ps_computebs_cur_slice;
1286
    UWORD32 u4_cur_slice_decode_done;
1287
    UWORD32 u4_extra_mem_used;
1288
1289
    /* 2 first slice not parsed , 1 :first slice parsed , 0 :first valid slice header parsed*/
1290
    UWORD32 u4_first_slice_in_pic;
1291
    UWORD32 u4_num_cores;
1292
    IVD_ARCH_T e_processor_arch;
1293
    IVD_SOC_T e_processor_soc;
1294
1295
    /**
1296
     * Pictures that are are degraded
1297
     * 0 : No degrade
1298
     * 1 : Only on non-reference frames
1299
     * 2 : Use interval specified by u4_nondegrade_interval
1300
     * 3 : All non-key frames
1301
     * 4 : All frames
1302
     */
1303
    WORD32 i4_degrade_pics;
1304
1305
    /**
1306
     * Interval for pictures which are completely decoded without any degradation
1307
     */
1308
    WORD32 i4_nondegrade_interval;
1309
1310
    /**
1311
     * bit position (lsb is zero): Type of degradation
1312
     * 1 : Disable deblocking
1313
     * 2 : Faster inter prediction filters
1314
     * 3 : Fastest inter prediction filters
1315
     */
1316
    WORD32 i4_degrade_type;
1317
1318
    /** Degrade pic count, Used to maintain the interval between non-degraded pics
1319
     *
1320
     */
1321
    WORD32 i4_degrade_pic_cnt;
1322
1323
    UWORD32 u4_pic_buf_got;
1324
1325
    /**
1326
     * Col flag and mv pred buffer manager
1327
     */
1328
    void *pv_mv_buf_mgr;
1329
1330
    /**
1331
     * Picture buffer manager
1332
     */
1333
    void *pv_pic_buf_mgr;
1334
1335
    /**
1336
     * Display buffer manager
1337
     */
1338
    void *pv_disp_buf_mgr;
1339
1340
    void *apv_buf_id_pic_buf_map[MAX_DISP_BUFS_NEW];
1341
1342
    UWORD8 au1_pic_buf_id_mv_buf_id_map[MAX_DISP_BUFS_NEW];
1343
1344
    UWORD8 au1_pic_buf_ref_flag[MAX_DISP_BUFS_NEW];
1345
1346
    struct pic_buffer_t *ps_pic_buf_base;
1347
1348
    UWORD8 *pu1_ref_buff_base;
1349
    col_mv_buf_t *ps_col_mv_base;
1350
    void *(*pf_aligned_alloc)(void *pv_mem_ctxt, WORD32 alignment, WORD32 size);
1351
    void (*pf_aligned_free)(void *pv_mem_ctxt, void *pv_buf);
1352
    void *pv_mem_ctxt;
1353
1354
    UWORD8 *pu1_pic_buf_base;
1355
    UWORD8 *pu1_mv_bank_buf_base;
1356
    UWORD8 *pu1_init_dpb_base;
1357
1358
    ih264_default_weighted_pred_ft *pf_default_weighted_pred_luma;
1359
1360
    ih264_default_weighted_pred_ft *pf_default_weighted_pred_chroma;
1361
1362
    ih264_weighted_pred_ft *pf_weighted_pred_luma;
1363
1364
    ih264_weighted_pred_ft *pf_weighted_pred_chroma;
1365
1366
    ih264_weighted_bi_pred_ft *pf_weighted_bi_pred_luma;
1367
1368
    ih264_weighted_bi_pred_ft *pf_weighted_bi_pred_chroma;
1369
1370
    ih264_pad *pf_pad_top;
1371
    ih264_pad *pf_pad_bottom;
1372
    ih264_pad *pf_pad_left_luma;
1373
    ih264_pad *pf_pad_left_chroma;
1374
    ih264_pad *pf_pad_right_luma;
1375
    ih264_pad *pf_pad_right_chroma;
1376
1377
    ih264_inter_pred_chroma_ft *pf_inter_pred_chroma;
1378
1379
    ih264_inter_pred_luma_ft *apf_inter_pred_luma[16];
1380
1381
    ih264_intra_pred_luma_ft *apf_intra_pred_luma_16x16[4];
1382
1383
    ih264_intra_pred_luma_ft *apf_intra_pred_luma_8x8[9];
1384
1385
    ih264_intra_pred_luma_ft *apf_intra_pred_luma_4x4[9];
1386
1387
    ih264_intra_pred_ref_filtering_ft *pf_intra_pred_ref_filtering;
1388
1389
    ih264_intra_pred_chroma_ft *apf_intra_pred_chroma[4];
1390
1391
    ih264_iquant_itrans_recon_ft *pf_iquant_itrans_recon_luma_4x4;
1392
1393
    ih264_iquant_itrans_recon_ft *pf_iquant_itrans_recon_luma_4x4_dc;
1394
1395
    ih264_iquant_itrans_recon_ft *pf_iquant_itrans_recon_luma_8x8;
1396
1397
    ih264_iquant_itrans_recon_ft *pf_iquant_itrans_recon_luma_8x8_dc;
1398
1399
    ih264_iquant_itrans_recon_chroma_ft *pf_iquant_itrans_recon_chroma_4x4;
1400
1401
    ih264_iquant_itrans_recon_chroma_ft *pf_iquant_itrans_recon_chroma_4x4_dc;
1402
1403
    ih264_ihadamard_scaling_ft *pf_ihadamard_scaling_4x4;
1404
1405
    /**
1406
     * deblock vertical luma edge with blocking strength 4
1407
     */
1408
    ih264_deblk_edge_bs4_ft *pf_deblk_luma_vert_bs4;
1409
1410
    /**
1411
     * deblock vertical luma edge with blocking strength less than 4
1412
     */
1413
    ih264_deblk_edge_bslt4_ft *pf_deblk_luma_vert_bslt4;
1414
1415
    /**
1416
     * deblock vertical luma edge with blocking strength 4 for mbaff
1417
     */
1418
    ih264_deblk_edge_bs4_ft *pf_deblk_luma_vert_bs4_mbaff;
1419
1420
    /**
1421
     * deblock vertical luma edge with blocking strength less than 4 for mbaff
1422
     */
1423
    ih264_deblk_edge_bslt4_ft *pf_deblk_luma_vert_bslt4_mbaff;
1424
1425
    /**
1426
     * deblock vertical chroma edge with blocking strength 4
1427
     */
1428
    ih264_deblk_chroma_edge_bs4_ft *pf_deblk_chroma_vert_bs4;
1429
1430
    /**
1431
     * deblock vertical chroma edge with blocking strength less than 4
1432
     */
1433
    ih264_deblk_chroma_edge_bslt4_ft *pf_deblk_chroma_vert_bslt4;
1434
1435
    /**
1436
     * deblock vertical chroma edge with blocking strength 4 for mbaff
1437
     */
1438
    ih264_deblk_chroma_edge_bs4_ft *pf_deblk_chroma_vert_bs4_mbaff;
1439
1440
    /**
1441
     * deblock vertical chroma edge with blocking strength less than 4 for mbaff
1442
     */
1443
    ih264_deblk_chroma_edge_bslt4_ft *pf_deblk_chroma_vert_bslt4_mbaff;
1444
1445
    /**
1446
     * deblock horizontal luma edge with blocking strength 4
1447
     */
1448
    ih264_deblk_edge_bs4_ft *pf_deblk_luma_horz_bs4;
1449
1450
    /**
1451
     * deblock horizontal luma edge with blocking strength less than 4
1452
     */
1453
    ih264_deblk_edge_bslt4_ft *pf_deblk_luma_horz_bslt4;
1454
1455
    /**
1456
     * deblock horizontal chroma edge with blocking strength 4
1457
     */
1458
    ih264_deblk_chroma_edge_bs4_ft *pf_deblk_chroma_horz_bs4;
1459
1460
    /**
1461
     * deblock horizontal chroma edge with blocking strength less than 4
1462
     */
1463
    ih264_deblk_chroma_edge_bslt4_ft *pf_deblk_chroma_horz_bslt4;
1464
1465
1466
} dec_struct_t;
1467
1468
#endif /* _H264_DEC_STRUCTS_H */
/proc/self/cwd/external/libavc/decoder/ih264d_thread_compute_bs.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
21
/*!
22
 **************************************************************************
23
 * \file ih264d_thread_compute_bs.c
24
 *
25
 * \brief
26
 *    Contains routines that for multi-thread decoder
27
 *
28
 * Detailed_description
29
 *
30
 * \date
31
 *    20/02/2012
32
 *
33
 * \author  ZR
34
 **************************************************************************
35
 */
36
#include "ih264d_error_handler.h"
37
#include "ih264d_debug.h"
38
#include <string.h>
39
#include "ih264d_defs.h"
40
#include "ih264d_debug.h"
41
#include "ih264d_tables.h"
42
#include "ih264d_structs.h"
43
#include "ih264d_defs.h"
44
#include "ih264d_mb_utils.h"
45
46
#include "ih264d_thread_compute_bs.h"
47
#include "ithread.h"
48
#include "ih264d_deblocking.h"
49
#include "ih264d_process_pslice.h"
50
#include "ih264d_process_intra_mb.h"
51
#include "ih264d_mb_utils.h"
52
#include "ih264d_tables.h"
53
#include "ih264d_format_conv.h"
54
#include "ih264d_defs.h"
55
UWORD16 ih264d_update_csbp_8x8(UWORD16 u2_luma_csbp);
56
void ih264d_fill_bs2_horz_vert(UWORD32 *pu4_bs, /* Base pointer of BS table */
57
                               WORD32 u4_left_mb_csbp, /* csbp of left mb */
58
                               WORD32 u4_top_mb_csbp, /* csbp of top mb */
59
                               WORD32 u4_cur_mb_csbp, /* csbp of current mb */
60
                               const UWORD32 *pu4_packed_bs2, const UWORD16 *pu2_4x4_v2h_reorder);
61
void ih264d_copy_intra_pred_line(dec_struct_t *ps_dec,
62
                                 dec_mb_info_t *ps_cur_mb_info,
63
                                 UWORD32 nmb_index);
64
65
#define BS_MB_GROUP 4
66
#define DEBLK_MB_GROUP 1
67
#define FORMAT_CONV_MB_GROUP 4
68
69
/*****************************************************************************/
70
/*                                                                           */
71
/*  Function Name : ih264d_compute_bs_non_mbaff_thread                                           */
72
/*                                                                           */
73
/*  Description   : This function computes the pointers of left,top & current*/
74
/*                : Nnz, MvPred & deblk_mb_t and supplies to FillBs function for*/
75
/*                : Boundary Strength Calculation .this function is used     */
76
/*                : BS being calculated in separate thread                   */
77
/*  Inputs        : pointer to decoder context,cur_mb_info,u4_mb_num            */
78
/*  Processing    :                                                          */
79
/*                                                                           */
80
/*  Outputs       : Produces the Boundary Strength for Current Mb            */
81
/*  Returns       : None                                                     */
82
/*                                                                           */
83
/*  Revision History:                                                        */
84
/*                                                                           */
85
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
86
/*                      ITTIAM                                               */
87
/*****************************************************************************/
88
89
void ih264d_compute_bs_non_mbaff_thread(dec_struct_t * ps_dec,
90
                                        dec_mb_info_t * ps_cur_mb_info,
91
                                        UWORD32 u4_mb_num)
92
5.06k
{
93
5.06k
    /* Mvpred and Nnz for top and Courrent */
94
5.06k
    mv_pred_t *ps_cur_mv_pred, *ps_top_mv_pred = NULL, *ps_left_mv_pred;
95
5.06k
    /* deblk_mb_t Params */
96
5.06k
    deblk_mb_t *ps_cur_mb_params; /*< Parameters of current MacroBlock */
97
5.06k
    deblkmb_neighbour_t *ps_deblk_top_mb;
98
5.06k
99
5.06k
    /* Reference Index to POC mapping*/
100
5.06k
    void ** apv_map_ref_idx_to_poc;
101
5.06k
    UWORD32 u4_leftmbtype;
102
5.06k
103
5.06k
    UWORD16 u2_left_csbp, u2_top_csbp, u2_cur_csbp;
104
5.06k
105
5.06k
    /* Set of flags */
106
5.06k
    UWORD32 u4_cur_mb_intra, u1_top_mb_typ, u4_cur_mb_fld;
107
5.06k
    UWORD32 u1_cur_mb_type;
108
5.06k
    UWORD32 * pu4_bs_table;
109
5.06k
110
5.06k
    /* Neighbour availability */
111
5.06k
    /* Initialization */
112
5.06k
    const UWORD32 u2_mbx = ps_cur_mb_info->u2_mbx;
113
5.06k
    const UWORD32 u2_mby = ps_cur_mb_info->u2_mby;
114
5.06k
    const UWORD32 u1_pingpong = u2_mbx & 0x01;
115
5.06k
116
5.06k
    PROFILE_DISABLE_BOUNDARY_STRENGTH()
117
5.06k
    ps_deblk_top_mb = ps_dec->ps_deblk_top_mb + u2_mbx;
118
5.06k
119
5.06k
    /* Pointer assignment for Current DeblkMB, Current Mv Pred  */
120
5.06k
    ps_cur_mb_params = ps_dec->ps_deblk_pic + u4_mb_num;
121
5.06k
    ps_cur_mv_pred = ps_dec->s_cur_pic.ps_mv + (u4_mb_num << 4);
122
5.06k
123
5.06k
    apv_map_ref_idx_to_poc =
124
5.06k
                    (void **)ps_dec->ps_computebs_cur_slice->ppv_map_ref_idx_to_poc
125
5.06k
                                    + 1;
126
5.06k
    u1_cur_mb_type = ps_cur_mb_params->u1_mb_type;
127
5.06k
    u1_top_mb_typ = ps_deblk_top_mb->u1_mb_type;
128
5.06k
    ps_deblk_top_mb->u1_mb_type = u1_cur_mb_type;
129
5.06k
130
5.06k
    {
131
5.06k
        ps_cur_mb_params->u1_topmb_qp = ps_deblk_top_mb->u1_mb_qp;
132
5.06k
        ps_deblk_top_mb->u1_mb_qp = ps_cur_mb_params->u1_mb_qp;
133
5.06k
134
5.06k
        ps_cur_mb_params->u1_left_mb_qp = ps_dec->deblk_left_mb[1].u1_mb_qp;
135
5.06k
        ps_dec->deblk_left_mb[1].u1_mb_qp = ps_cur_mb_params->u1_mb_qp;
136
5.06k
137
5.06k
    }
138
5.06k
139
5.06k
    /* if no deblocking required for current Mb then continue */
140
5.06k
    /* Check next Mbs   in Mb group                           */
141
5.06k
    if(ps_cur_mb_params->u1_deblocking_mode & MB_DISABLE_FILTERING)
142
5.06k
    {
143
0
        void ** pu4_map_ref_idx_to_poc_l1 = apv_map_ref_idx_to_poc +
144
0
        POC_LIST_L0_TO_L1_DIFF;
145
0
        {
146
0
            /* Store Parameter for Top MvPred refernce frame Address */
147
0
148
0
            void ** ppv_top_mv_pred_addr = ps_cur_mb_info->ps_curmb->u4_pic_addrress;
149
0
            WORD8 * p1_refTop0 = (ps_cur_mv_pred + 12)->i1_ref_frame;
150
0
            WORD8 * p1_refTop1 = (ps_cur_mv_pred + 14)->i1_ref_frame;
151
0
152
0
            /* Store Left addresses for Next Mb   */
153
0
            void ** ppv_left_mv_pred_addr =
154
0
                            ps_dec->ps_left_mvpred_addr[!u1_pingpong][1].u4_add;
155
0
            WORD8 * p1_refleft0 = (ps_cur_mv_pred + 3)->i1_ref_frame;
156
0
157
0
158
0
            ppv_top_mv_pred_addr[0] = apv_map_ref_idx_to_poc[p1_refTop0[0]];
159
0
            ppv_top_mv_pred_addr[1] = pu4_map_ref_idx_to_poc_l1[p1_refTop0[1]];
160
0
161
0
            ppv_left_mv_pred_addr[2] = apv_map_ref_idx_to_poc[p1_refTop1[0]];
162
0
            ppv_top_mv_pred_addr[2] = apv_map_ref_idx_to_poc[p1_refTop1[0]];
163
0
            ppv_left_mv_pred_addr[3] = pu4_map_ref_idx_to_poc_l1[p1_refTop1[1]];
164
0
            ppv_top_mv_pred_addr[3] = pu4_map_ref_idx_to_poc_l1[p1_refTop1[1]];
165
0
166
0
            ppv_left_mv_pred_addr[0] = apv_map_ref_idx_to_poc[p1_refleft0[0]];
167
0
            ppv_left_mv_pred_addr[1] = pu4_map_ref_idx_to_poc_l1[p1_refleft0[1]];
168
0
            //}
169
0
            /* Storing the leftMbtype for next Mb */
170
0
            ps_dec->deblk_left_mb[1].u1_mb_type = ps_cur_mb_params->u1_mb_type;
171
0
        }
172
0
173
0
        return;
174
0
    }
175
5.06k
176
5.06k
    /* Flag for extra left Edge */
177
5.06k
    ps_cur_mb_params->u1_single_call = 1;
178
5.06k
179
5.06k
    /* Update the Left deblk_mb_t and Left MvPred Parameters           */
180
5.06k
    if(!u2_mbx)
181
220
    {
182
220
        u4_leftmbtype = 0;
183
220
184
220
        /* Initialize the ps_left_mv_pred with Junk but Valid Location */
185
220
        /* to avoid invalid memory access                           */
186
220
        /* this is read only pointer                                */
187
220
        ps_left_mv_pred = ps_cur_mv_pred + 3;
188
220
    }
189
4.84k
    else
190
4.84k
    {
191
4.84k
        u4_leftmbtype = ps_dec->deblk_left_mb[1].u1_mb_type;
192
4.84k
193
4.84k
        /* Come to Left Most Edge of the MB */
194
4.84k
        ps_left_mv_pred = ps_cur_mv_pred - (1 << 4) + 3;
195
4.84k
    }
196
5.06k
197
5.06k
    if(!u2_mby)
198
253
        u1_top_mb_typ = 0;
199
5.06k
200
5.06k
    /* MvPred Pointer Calculation */
201
5.06k
    /* CHANGED CODE */
202
5.06k
    ps_top_mv_pred = ps_cur_mv_pred - (ps_dec->u2_frm_wd_in_mbs << 4) + 12;
203
5.06k
204
5.06k
    u4_cur_mb_intra = u1_cur_mb_type & D_INTRA_MB;
205
5.06k
    u4_cur_mb_fld = !!(u1_cur_mb_type & D_FLD_MB);
206
5.06k
    /* Compute BS function */
207
5.06k
    pu4_bs_table = ps_cur_mb_params->u4_bs_table;
208
5.06k
209
5.06k
    u2_cur_csbp = ps_cur_mb_info->ps_curmb->u2_luma_csbp;
210
5.06k
    u2_left_csbp = ps_cur_mb_info->ps_left_mb->u2_luma_csbp;
211
5.06k
    u2_top_csbp = ps_cur_mb_info->ps_top_mb->u2_luma_csbp;
212
5.06k
213
5.06k
    /* Compute BS function */
214
5.06k
    if(ps_dec->ps_cur_sps->u1_profile_idc == HIGH_PROFILE_IDC)
215
5.06k
    {
216
0
        if(ps_cur_mb_info->u1_tran_form8x8 == 1)
217
0
        {
218
0
            u2_cur_csbp = ih264d_update_csbp_8x8(
219
0
                            ps_cur_mb_info->ps_curmb->u2_luma_csbp);
220
0
        }
221
0
222
0
        if(ps_cur_mb_info->ps_left_mb->u1_tran_form8x8 == 1)
223
0
        {
224
0
            u2_left_csbp = ih264d_update_csbp_8x8(
225
0
                            ps_cur_mb_info->ps_left_mb->u2_luma_csbp);
226
0
        }
227
0
228
0
        if(ps_cur_mb_info->ps_top_mb->u1_tran_form8x8 == 1)
229
0
        {
230
0
            u2_top_csbp = ih264d_update_csbp_8x8(
231
0
                            ps_cur_mb_info->ps_top_mb->u2_luma_csbp);
232
0
        }
233
0
    }
234
5.06k
    if(u4_cur_mb_intra)
235
5.06k
    {
236
5.06k
237
5.06k
        pu4_bs_table[4] = 0x04040404;
238
5.06k
        pu4_bs_table[0] = u4_cur_mb_fld ? 0x03030303 : 0x04040404;
239
5.06k
        pu4_bs_table[1] = 0x03030303;
240
5.06k
        pu4_bs_table[2] = 0x03030303;
241
5.06k
        pu4_bs_table[3] = 0x03030303;
242
5.06k
        pu4_bs_table[5] = 0x03030303;
243
5.06k
        pu4_bs_table[6] = 0x03030303;
244
5.06k
        pu4_bs_table[7] = 0x03030303;
245
5.06k
    }
246
0
    else
247
0
    {
248
0
        UWORD32 u4_is_non16x16 = !!(u1_cur_mb_type & D_PRED_NON_16x16);
249
0
        UWORD32 u4_is_b =
250
0
                        (ps_dec->ps_computebs_cur_slice->slice_type == B_SLICE);
251
0
252
0
253
0
254
0
255
0
256
0
257
0
        ih264d_fill_bs2_horz_vert(pu4_bs_table, u2_left_csbp, u2_top_csbp,
258
0
                                  u2_cur_csbp, gau4_ih264d_packed_bs2,
259
0
                                  gau2_ih264d_4x4_v2h_reorder);
260
0
261
0
        if(u4_leftmbtype & D_INTRA_MB)
262
0
            pu4_bs_table[4] = 0x04040404;
263
0
264
0
        if(u1_top_mb_typ & D_INTRA_MB)
265
0
            pu4_bs_table[0] = u4_cur_mb_fld ? 0x03030303 : 0x04040404;
266
0
267
0
        ps_dec->pf_fill_bs1[u4_is_b][u4_is_non16x16](
268
0
                        ps_cur_mv_pred, ps_top_mv_pred, apv_map_ref_idx_to_poc,
269
0
                        pu4_bs_table, ps_left_mv_pred,
270
0
                        &(ps_dec->ps_left_mvpred_addr[u1_pingpong][1]),
271
0
                        ps_cur_mb_info->ps_top_mb->u4_pic_addrress,
272
0
                        (4 >> u4_cur_mb_fld));
273
0
    }
274
5.06k
275
5.06k
    {
276
5.06k
        void ** pu4_map_ref_idx_to_poc_l1 = apv_map_ref_idx_to_poc +
277
5.06k
        POC_LIST_L0_TO_L1_DIFF;
278
5.06k
        {
279
5.06k
            /* Store Parameter for Top MvPred refernce frame Address */
280
5.06k
281
5.06k
            void ** ppv_top_mv_pred_addr = ps_cur_mb_info->ps_curmb->u4_pic_addrress;
282
5.06k
            WORD8 * p1_refTop0 = (ps_cur_mv_pred + 12)->i1_ref_frame;
283
5.06k
            WORD8 * p1_refTop1 = (ps_cur_mv_pred + 14)->i1_ref_frame;
284
5.06k
285
5.06k
            /* Store Left addresses for Next Mb   */
286
5.06k
            void ** ppv_left_mv_pred_addr =
287
5.06k
                            ps_dec->ps_left_mvpred_addr[!u1_pingpong][1].u4_add;
288
5.06k
            WORD8 * p1_refleft0 = (ps_cur_mv_pred + 3)->i1_ref_frame;
289
5.06k
290
5.06k
            ppv_top_mv_pred_addr[0] = apv_map_ref_idx_to_poc[p1_refTop0[0]];
291
5.06k
            ppv_top_mv_pred_addr[1] = pu4_map_ref_idx_to_poc_l1[p1_refTop0[1]];
292
5.06k
293
5.06k
            ppv_left_mv_pred_addr[2] = apv_map_ref_idx_to_poc[p1_refTop1[0]];
294
5.06k
            ppv_top_mv_pred_addr[2] = apv_map_ref_idx_to_poc[p1_refTop1[0]];
295
5.06k
            ppv_left_mv_pred_addr[3] = pu4_map_ref_idx_to_poc_l1[p1_refTop1[1]];
296
5.06k
            ppv_top_mv_pred_addr[3] = pu4_map_ref_idx_to_poc_l1[p1_refTop1[1]];
297
5.06k
298
5.06k
            ppv_left_mv_pred_addr[0] = apv_map_ref_idx_to_poc[p1_refleft0[0]];
299
5.06k
            ppv_left_mv_pred_addr[1] = pu4_map_ref_idx_to_poc_l1[p1_refleft0[1]];
300
5.06k
301
5.06k
            /* Storing the leftMbtype for next Mb */
302
5.06k
            ps_dec->deblk_left_mb[1].u1_mb_type = ps_cur_mb_params->u1_mb_type;
303
5.06k
304
5.06k
        }
305
5.06k
    }
306
5.06k
307
5.06k
    /* For transform 8x8 disable deblocking of the intrernal edges of a 8x8 block */
308
5.06k
    if(ps_cur_mb_info->u1_tran_form8x8)
309
0
    {
310
0
        pu4_bs_table[1] = 0;
311
0
        pu4_bs_table[3] = 0;
312
0
        pu4_bs_table[5] = 0;
313
0
        pu4_bs_table[7] = 0;
314
0
    }
315
5.06k
}
316
317
318
void ih264d_check_mb_map_deblk(dec_struct_t *ps_dec,
319
                                    UWORD32 deblk_mb_grp,
320
                                    tfr_ctxt_t *ps_tfr_cxt,
321
                                    UWORD32 u4_check_mb_map)
322
220
{
323
220
    UWORD32 i = 0;
324
220
    UWORD32 u4_mb_num;
325
220
    UWORD32 u4_cond;
326
220
    volatile UWORD8 *mb_map = ps_dec->pu1_recon_mb_map;
327
220
    const WORD32 i4_cb_qp_idx_ofst =
328
220
                    ps_dec->ps_cur_pps->i1_chroma_qp_index_offset;
329
220
    const WORD32 i4_cr_qp_idx_ofst =
330
220
                    ps_dec->ps_cur_pps->i1_second_chroma_qp_index_offset;
331
220
332
220
    UWORD32 u4_wd_y, u4_wd_uv;
333
220
    UWORD8 u1_field_pic_flag = ps_dec->ps_cur_slice->u1_field_pic_flag;
334
220
335
220
336
220
    u4_wd_y = ps_dec->u2_frm_wd_y << u1_field_pic_flag;
337
220
    u4_wd_uv = ps_dec->u2_frm_wd_uv << u1_field_pic_flag;
338
220
339
220
340
5.28k
    for(i = 0; i < deblk_mb_grp; i++)
341
5.06k
    {
342
5.06k
        WORD32 nop_cnt = 8*128;
343
5.06k
        while(u4_check_mb_map == 1)
344
0
        {
345
0
            u4_mb_num = ps_dec->u4_cur_deblk_mb_num;
346
0
            /*we wait for the right mb because of intra pred data dependency*/
347
0
            u4_mb_num = MIN(u4_mb_num + 1, (ps_dec->u4_deblk_mb_y + 1) * ps_dec->u2_frm_wd_in_mbs - 1);
348
0
            CHECK_MB_MAP_BYTE(u4_mb_num, mb_map, u4_cond);
349
0
350
0
            if(u4_cond)
351
0
            {
352
0
                break;
353
0
            }
354
0
            else
355
0
            {
356
0
                if(nop_cnt > 0)
357
0
                {
358
0
                    nop_cnt -= 128;
359
0
                    NOP(128);
360
0
                }
361
0
                else
362
0
                {
363
0
                    nop_cnt = 8*128;
364
0
                    ithread_yield();
365
0
                }
366
0
            }
367
0
        }
368
5.06k
369
5.06k
        ih264d_deblock_mb_nonmbaff(ps_dec, ps_tfr_cxt,
370
5.06k
                                   i4_cb_qp_idx_ofst, i4_cr_qp_idx_ofst,
371
5.06k
                                    u4_wd_y, u4_wd_uv);
372
5.06k
373
5.06k
374
5.06k
    }
375
220
376
220
377
220
}
378
void ih264d_recon_deblk_slice(dec_struct_t *ps_dec, tfr_ctxt_t *ps_tfr_cxt)
379
11
{
380
11
    dec_mb_info_t *p_cur_mb;
381
11
    UWORD32 u4_max_addr;
382
11
    WORD32 i;
383
11
    UWORD32 u1_mb_aff;
384
11
    UWORD16 u2_slice_num;
385
11
    UWORD32 u4_mb_num;
386
11
    UWORD16 u2_first_mb_in_slice;
387
11
    UWORD32 i2_pic_wdin_mbs;
388
11
    UWORD8 u1_num_mbsleft, u1_end_of_row;
389
11
    UWORD8 u1_mbaff;
390
11
    UWORD16 i16_mb_x, i16_mb_y;
391
11
    WORD32 j;
392
11
    dec_mb_info_t * ps_cur_mb_info;
393
11
    UWORD32 u1_slice_type, u1_B;
394
11
    WORD32 u1_skip_th;
395
11
    UWORD32 u1_ipcm_th;
396
11
    WORD32 ret;
397
11
    tfr_ctxt_t *ps_trns_addr;
398
11
    UWORD32 u4_frame_stride;
399
11
    UWORD32 x_offset, y_offset;
400
11
    UWORD32 u4_slice_end;
401
11
    pad_mgr_t *ps_pad_mgr ;
402
11
403
11
    /*check for mb map of first mb in slice to ensure slice header is parsed*/
404
312
    while(1)
405
312
    {
406
312
        UWORD32 u4_mb_num = ps_dec->cur_recon_mb_num;
407
312
        UWORD32 u4_cond = 0;
408
312
        WORD32 nop_cnt = 8*128;
409
312
410
312
        CHECK_MB_MAP_BYTE(u4_mb_num, ps_dec->pu1_recon_mb_map, u4_cond);
411
312
        if(u4_cond)
412
11
        {
413
11
            break;
414
11
        }
415
301
        else
416
301
        {
417
301
            if(nop_cnt > 0)
418
301
            {
419
301
                nop_cnt -= 128;
420
301
                NOP(128);
421
301
            }
422
0
            else
423
0
            {
424
0
                if(ps_dec->u4_output_present &&
425
0
                   (ps_dec->u4_fmt_conv_cur_row < ps_dec->s_disp_frame_info.u4_y_ht))
426
0
                {
427
0
                    ps_dec->u4_fmt_conv_num_rows =
428
0
                                    MIN(FMT_CONV_NUM_ROWS,
429
0
                                        (ps_dec->s_disp_frame_info.u4_y_ht
430
0
                                                        - ps_dec->u4_fmt_conv_cur_row));
431
0
                    ih264d_format_convert(ps_dec, &(ps_dec->s_disp_op),
432
0
                                          ps_dec->u4_fmt_conv_cur_row,
433
0
                                          ps_dec->u4_fmt_conv_num_rows);
434
0
                    ps_dec->u4_fmt_conv_cur_row += ps_dec->u4_fmt_conv_num_rows;
435
0
                }
436
0
                else
437
0
                {
438
0
                    nop_cnt = 8*128;
439
0
                    ithread_yield();
440
0
                }
441
0
            }
442
301
            DEBUG_THREADS_PRINTF("waiting for mb mapcur_dec_mb_num = %d,ps_dec->u2_cur_mb_addr  = %d\n",u2_cur_dec_mb_num,
443
301
                            ps_dec->u2_cur_mb_addr);
444
301
445
301
        }
446
312
    }
447
11
448
11
    u4_max_addr = ps_dec->ps_cur_sps->u2_max_mb_addr;
449
11
    u1_mb_aff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
450
11
    u2_first_mb_in_slice = ps_dec->ps_computebs_cur_slice->u4_first_mb_in_slice;
451
11
    i2_pic_wdin_mbs = ps_dec->u2_frm_wd_in_mbs;
452
11
    u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
453
11
    ps_pad_mgr = &ps_dec->s_pad_mgr;
454
11
455
11
    if(u2_first_mb_in_slice == 0)
456
11
    ih264d_init_deblk_tfr_ctxt(ps_dec, ps_pad_mgr, ps_tfr_cxt,
457
11
                               ps_dec->u2_frm_wd_in_mbs, 0);
458
11
459
11
460
11
    i16_mb_x = MOD(u2_first_mb_in_slice, i2_pic_wdin_mbs);
461
11
    i16_mb_y = DIV(u2_first_mb_in_slice, i2_pic_wdin_mbs);
462
11
    i16_mb_y <<= u1_mbaff;
463
11
    ps_dec->i2_recon_thread_mb_y = i16_mb_y;
464
11
    u4_frame_stride = ps_dec->u2_frm_wd_y
465
11
                    << ps_dec->ps_cur_slice->u1_field_pic_flag;
466
11
467
11
    x_offset = i16_mb_x << 4;
468
11
    y_offset = (i16_mb_y * u4_frame_stride) << 4;
469
11
    ps_trns_addr = &ps_dec->s_tran_iprecon;
470
11
471
11
    ps_trns_addr->pu1_dest_y = ps_dec->s_cur_pic.pu1_buf1 + x_offset + y_offset;
472
11
473
11
    u4_frame_stride = ps_dec->u2_frm_wd_uv
474
11
                    << ps_dec->ps_cur_slice->u1_field_pic_flag;
475
11
    x_offset >>= 1;
476
11
    y_offset = (i16_mb_y * u4_frame_stride) << 3;
477
11
478
11
    x_offset *= YUV420SP_FACTOR;
479
11
480
11
    ps_trns_addr->pu1_dest_u = ps_dec->s_cur_pic.pu1_buf2 + x_offset + y_offset;
481
11
    ps_trns_addr->pu1_dest_v = ps_dec->s_cur_pic.pu1_buf3 + x_offset + y_offset;
482
11
483
11
    ps_trns_addr->pu1_mb_y = ps_trns_addr->pu1_dest_y;
484
11
    ps_trns_addr->pu1_mb_u = ps_trns_addr->pu1_dest_u;
485
11
    ps_trns_addr->pu1_mb_v = ps_trns_addr->pu1_dest_v;
486
11
487
11
    ps_dec->cur_recon_mb_num = u2_first_mb_in_slice << u1_mbaff;
488
11
489
11
    u4_slice_end = 0;
490
11
    ps_dec->u4_bs_cur_slice_num_mbs = 0;
491
11
    ps_dec->u4_cur_bs_mb_num =
492
11
                    (ps_dec->ps_computebs_cur_slice->u4_first_mb_in_slice)
493
11
                                    << u1_mb_aff;
494
11
495
11
    if(ps_dec->i1_recon_in_thread3_flag)
496
11
    {
497
11
        ps_dec->pv_proc_tu_coeff_data =
498
11
                (void *) ps_dec->ps_computebs_cur_slice->pv_tu_coeff_data_start;
499
11
    }
500
11
501
11
    u1_slice_type = ps_dec->ps_computebs_cur_slice->slice_type;
502
11
503
11
    u1_B = (u1_slice_type == B_SLICE);
504
11
505
11
    u1_skip_th = ((u1_slice_type != I_SLICE) ?
506
11
                                    (u1_B ? B_8x8 : PRED_8x8R0) : -1);
507
11
508
11
    u1_ipcm_th = ((u1_slice_type != I_SLICE) ? (u1_B ? 23 : 5) : 0);
509
11
510
11
511
11
512
231
    while(u4_slice_end != 1)
513
220
    {
514
220
        WORD32 recon_mb_grp,bs_mb_grp;
515
220
        WORD32 nop_cnt = 8*128;
516
220
        u1_num_mbsleft = ((i2_pic_wdin_mbs - i16_mb_x) << u1_mbaff);
517
220
        if(u1_num_mbsleft <= ps_dec->u1_recon_mb_grp)
518
220
        {
519
220
            recon_mb_grp = u1_num_mbsleft;
520
220
            u1_end_of_row = 1;
521
220
            i16_mb_x = 0;
522
220
        }
523
0
        else
524
0
        {
525
0
            recon_mb_grp = ps_dec->u1_recon_mb_grp;
526
0
            u1_end_of_row = 0;
527
0
            i16_mb_x += (recon_mb_grp >> u1_mbaff);
528
0
        }
529
220
530
220
531
506
        while(1)
532
506
        {
533
506
            UWORD32 u4_cond = 0;
534
506
            UWORD32 u4_mb_num = ps_dec->cur_recon_mb_num + recon_mb_grp - 1;
535
506
536
506
            /*
537
506
             * Wait for one extra mb of MC, because some chroma IQ-IT functions
538
506
             * sometimes loads the pixels of the right mb and stores with the loaded
539
506
             * values.
540
506
             */
541
506
            u4_mb_num = MIN(u4_mb_num + 1, (ps_dec->i2_recon_thread_mb_y + 1) * i2_pic_wdin_mbs - 1);
542
506
543
506
            CHECK_MB_MAP_BYTE(u4_mb_num, ps_dec->pu1_recon_mb_map, u4_cond);
544
506
            if(u4_cond)
545
220
            {
546
220
                break;
547
220
            }
548
286
            else
549
286
            {
550
286
                if(nop_cnt > 0)
551
226
                {
552
226
                    nop_cnt -= 128;
553
226
                    NOP(128);
554
226
                }
555
60
                else
556
60
                {
557
60
                    if(ps_dec->u4_output_present &&
558
60
                       (ps_dec->u4_fmt_conv_cur_row < ps_dec->s_disp_frame_info.u4_y_ht))
559
42
                    {
560
42
                        ps_dec->u4_fmt_conv_num_rows =
561
42
                                        MIN(FMT_CONV_NUM_ROWS,
562
42
                                            (ps_dec->s_disp_frame_info.u4_y_ht
563
42
                                                            - ps_dec->u4_fmt_conv_cur_row));
564
42
                        ih264d_format_convert(ps_dec, &(ps_dec->s_disp_op),
565
42
                                              ps_dec->u4_fmt_conv_cur_row,
566
42
                                              ps_dec->u4_fmt_conv_num_rows);
567
42
                        ps_dec->u4_fmt_conv_cur_row += ps_dec->u4_fmt_conv_num_rows;
568
42
                    }
569
18
                    else
570
18
                    {
571
18
                        nop_cnt = 8*128;
572
18
                        ithread_yield();
573
18
                    }
574
60
                }
575
286
            }
576
506
        }
577
220
578
5.28k
        for(j = 0; j < recon_mb_grp; j++)
579
5.06k
        {
580
5.06k
            GET_SLICE_NUM_MAP(ps_dec->pu2_slice_num_map, ps_dec->cur_recon_mb_num,
581
5.06k
                              u2_slice_num);
582
5.06k
583
5.06k
            if(u2_slice_num != ps_dec->u2_cur_slice_num_bs)
584
0
            {
585
0
                u4_slice_end = 1;
586
0
                break;
587
0
            }
588
5.06k
            if(ps_dec->i1_recon_in_thread3_flag)
589
5.06k
            {
590
5.06k
                ps_cur_mb_info = &ps_dec->ps_frm_mb_info[ps_dec->cur_recon_mb_num];
591
5.06k
592
5.06k
                if(ps_cur_mb_info->u1_mb_type <= u1_skip_th)
593
0
                {
594
0
                    ih264d_process_inter_mb(ps_dec, ps_cur_mb_info, j);
595
0
                }
596
5.06k
                else if(ps_cur_mb_info->u1_mb_type != MB_SKIP)
597
5.06k
                {
598
5.06k
                    if((u1_ipcm_th + 25) != ps_cur_mb_info->u1_mb_type)
599
5.06k
                    {
600
5.06k
                        ps_cur_mb_info->u1_mb_type -= (u1_skip_th + 1);
601
5.06k
                        ih264d_process_intra_mb(ps_dec, ps_cur_mb_info, j);
602
5.06k
                    }
603
5.06k
                }
604
5.06k
605
5.06k
                ih264d_copy_intra_pred_line(ps_dec, ps_cur_mb_info, j);
606
5.06k
            }
607
5.06k
            ps_dec->cur_recon_mb_num++;
608
5.06k
        }
609
220
610
220
        if(j != recon_mb_grp)
611
0
        {
612
0
            u1_end_of_row = 0;
613
0
        }
614
220
615
220
        {
616
220
            tfr_ctxt_t *ps_trns_addr = &ps_dec->s_tran_iprecon;
617
220
            UWORD16 u2_mb_y;
618
220
619
220
            ps_trns_addr->pu1_dest_y += ps_trns_addr->u4_inc_y[u1_end_of_row];
620
220
            ps_trns_addr->pu1_dest_u += ps_trns_addr->u4_inc_uv[u1_end_of_row];
621
220
            ps_trns_addr->pu1_dest_v += ps_trns_addr->u4_inc_uv[u1_end_of_row];
622
220
623
220
            if(u1_end_of_row)
624
220
            {
625
220
                ps_dec->i2_recon_thread_mb_y += (1 << u1_mbaff);
626
220
                u2_mb_y = ps_dec->i2_recon_thread_mb_y;
627
220
                y_offset = (u2_mb_y * u4_frame_stride) << 4;
628
220
                ps_trns_addr->pu1_dest_y = ps_dec->s_cur_pic.pu1_buf1 + y_offset;
629
220
630
220
                u4_frame_stride = ps_dec->u2_frm_wd_uv
631
220
                                << ps_dec->ps_cur_slice->u1_field_pic_flag;
632
220
                y_offset = (u2_mb_y * u4_frame_stride) << 3;
633
220
                ps_trns_addr->pu1_dest_u = ps_dec->s_cur_pic.pu1_buf2 + y_offset;
634
220
                ps_trns_addr->pu1_dest_v = ps_dec->s_cur_pic.pu1_buf3 + y_offset;
635
220
636
220
                ps_trns_addr->pu1_mb_y = ps_trns_addr->pu1_dest_y;
637
220
                ps_trns_addr->pu1_mb_u = ps_trns_addr->pu1_dest_u;
638
220
                ps_trns_addr->pu1_mb_v = ps_trns_addr->pu1_dest_v;
639
220
640
220
            }
641
220
        }
642
220
643
220
        bs_mb_grp = j;
644
220
        /* Compute BS for NMB group*/
645
5.28k
        for(i = 0; i < bs_mb_grp; i++)
646
5.06k
        {
647
5.06k
            p_cur_mb = &ps_dec->ps_frm_mb_info[ps_dec->u4_cur_bs_mb_num];
648
5.06k
649
5.06k
            DEBUG_THREADS_PRINTF("ps_dec->u4_cur_bs_mb_num = %d\n",ps_dec->u4_cur_bs_mb_num);
650
5.06k
            ih264d_compute_bs_non_mbaff_thread(ps_dec, p_cur_mb,
651
5.06k
                                               ps_dec->u4_cur_bs_mb_num);
652
5.06k
            ps_dec->u4_cur_bs_mb_num++;
653
5.06k
            ps_dec->u4_bs_cur_slice_num_mbs++;
654
5.06k
655
5.06k
        }
656
220
657
220
        if(ps_dec->u4_cur_bs_mb_num > u4_max_addr)
658
11
        {
659
11
            u4_slice_end = 1;
660
11
        }
661
220
662
220
        /*deblock MB group*/
663
220
        {
664
220
            UWORD32 u4_num_mbs;
665
220
666
220
            if(ps_dec->u4_cur_bs_mb_num > ps_dec->u4_cur_deblk_mb_num)
667
220
            {
668
220
                if(u1_end_of_row)
669
220
                {
670
220
                    u4_num_mbs = ps_dec->u4_cur_bs_mb_num
671
220
                                    - ps_dec->u4_cur_deblk_mb_num;
672
220
                }
673
0
                else
674
0
                {
675
0
                    u4_num_mbs = ps_dec->u4_cur_bs_mb_num
676
0
                                    - ps_dec->u4_cur_deblk_mb_num - 1;
677
0
                }
678
220
            }
679
0
            else
680
0
                u4_num_mbs = 0;
681
220
682
220
            ih264d_check_mb_map_deblk(ps_dec, u4_num_mbs, ps_tfr_cxt,0);
683
220
        }
684
220
685
220
    }
686
11
}
687
688
void ih264d_recon_deblk_thread(dec_struct_t *ps_dec)
689
11
{
690
11
    tfr_ctxt_t s_tfr_ctxt;
691
11
    tfr_ctxt_t *ps_tfr_cxt = &s_tfr_ctxt; // = &ps_dec->s_tran_addrecon;
692
11
693
11
694
11
    UWORD32 yield_cnt = 0;
695
11
696
11
    ithread_set_name("ih264d_recon_deblk_thread");
697
11
698
11
    while(1)
699
11
    {
700
11
701
11
        DEBUG_THREADS_PRINTF(" Entering compute bs slice\n");
702
11
        ih264d_recon_deblk_slice(ps_dec, ps_tfr_cxt);
703
11
704
11
        DEBUG_THREADS_PRINTF(" Exit  compute bs slice \n");
705
11
706
11
        if(ps_dec->cur_recon_mb_num > ps_dec->ps_cur_sps->u2_max_mb_addr)
707
11
        {
708
11
                break;
709
11
        }
710
0
        else
711
0
        {
712
0
            ps_dec->ps_computebs_cur_slice++;
713
0
            ps_dec->u2_cur_slice_num_bs++;
714
0
        }
715
11
        DEBUG_THREADS_PRINTF("CBS thread:Got next slice/end of frame signal \n ");
716
0
717
0
    }
718
11
719
11
    if(ps_dec->u4_output_present &&
720
11
       (3 == ps_dec->u4_num_cores) &&
721
11
       (ps_dec->u4_fmt_conv_cur_row < ps_dec->s_disp_frame_info.u4_y_ht))
722
9
    {
723
9
        ps_dec->u4_fmt_conv_num_rows =
724
9
                        (ps_dec->s_disp_frame_info.u4_y_ht
725
9
                                        - ps_dec->u4_fmt_conv_cur_row);
726
9
        ih264d_format_convert(ps_dec, &(ps_dec->s_disp_op),
727
9
                              ps_dec->u4_fmt_conv_cur_row,
728
9
                              ps_dec->u4_fmt_conv_num_rows);
729
9
        ps_dec->u4_fmt_conv_cur_row += ps_dec->u4_fmt_conv_num_rows;
730
9
731
9
    }
732
11
733
11
734
11
735
11
}
736
737
/proc/self/cwd/external/libavc/decoder/ih264d_thread_parse_decode.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/*!
21
 **************************************************************************
22
 * \file ih264d_thread_parse_decode.c
23
 *
24
 * \brief
25
 *    Contains routines that for multi-thread decoder
26
 *
27
 * Detailed_description
28
 *
29
 * \date
30
 *    20/02/2012
31
 *
32
 * \author  ZR
33
 **************************************************************************
34
 */
35
36
#include "ih264d_error_handler.h"
37
#include "ih264d_debug.h"
38
#include "ithread.h"
39
#include <string.h>
40
#include "ih264d_defs.h"
41
#include "ih264d_debug.h"
42
#include "ih264d_tables.h"
43
#include "ih264d_structs.h"
44
#include "ih264d_defs.h"
45
#include "ih264d_mb_utils.h"
46
#include "ih264d_thread_parse_decode.h"
47
#include "ih264d_inter_pred.h"
48
49
#include "ih264d_process_pslice.h"
50
#include "ih264d_process_intra_mb.h"
51
#include "ih264d_deblocking.h"
52
#include "ih264d_format_conv.h"
53
54
void ih264d_deblock_mb_level(dec_struct_t *ps_dec,
55
                             dec_mb_info_t *ps_cur_mb_info,
56
                             UWORD32 nmb_index);
57
58
void ih264d_copy_intra_pred_line(dec_struct_t *ps_dec,
59
                                 dec_mb_info_t *ps_cur_mb_info,
60
                                 UWORD32 nmb_index);
61
62
void ih264d_parse_tfr_nmb(dec_struct_t * ps_dec,
63
                          UWORD8 u1_mb_idx,
64
                          UWORD8 u1_num_mbs,
65
                          UWORD8 u1_num_mbs_next,
66
                          UWORD8 u1_tfr_n_mb,
67
                          UWORD8 u1_end_of_row)
68
220
{
69
220
    WORD32 i, u4_mb_num;
70
220
71
220
    const UWORD32 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
72
220
    UWORD32 u4_n_mb_start;
73
220
74
220
    UNUSED(u1_mb_idx);
75
220
    UNUSED(u1_num_mbs_next);
76
220
    if(u1_tfr_n_mb)
77
220
    {
78
220
79
220
80
220
        u4_n_mb_start = (ps_dec->u2_cur_mb_addr + 1) - u1_num_mbs;
81
220
82
220
        // copy into s_frmMbInfo
83
220
84
220
        u4_mb_num = u4_n_mb_start;
85
220
        u4_mb_num = (ps_dec->u2_cur_mb_addr + 1) - u1_num_mbs;
86
220
87
5.28k
        for(i = 0; i < u1_num_mbs; i++)
88
5.06k
        {
89
5.06k
            UPDATE_SLICE_NUM_MAP(ps_dec->pu2_slice_num_map, u4_mb_num,
90
5.06k
                                 ps_dec->u2_cur_slice_num);
91
5.06k
            DATA_SYNC();
92
5.06k
            UPDATE_MB_MAP_MBNUM_BYTE(ps_dec->pu1_dec_mb_map, u4_mb_num);
93
5.06k
94
5.06k
            u4_mb_num++;
95
5.06k
        }
96
220
97
220
        /****************************************************************/
98
220
        /* Check for End Of Row in Next iteration                       */
99
220
        /****************************************************************/
100
220
101
220
        /****************************************************************/
102
220
        /* Transfer the Following things                                */
103
220
        /* N-Mb DeblkParams Data    ( To Ext DeblkParams Buffer )       */
104
220
        /* N-Mb Recon Data          ( To Ext Frame Buffer )             */
105
220
        /* N-Mb Intrapredline Data  ( Updated Internally)               */
106
220
        /* N-Mb MV Data             ( To Ext MV Buffer )                */
107
220
        /* N-Mb MVTop/TopRight Data ( To Int MV Top Scratch Buffers)    */
108
220
        /****************************************************************/
109
220
110
220
        /* Swap top and current pointers */
111
220
112
220
        ps_dec->s_tran_addrecon_parse.pu1_dest_y +=
113
220
                        ps_dec->s_tran_addrecon_parse.u4_inc_y[u1_end_of_row];
114
220
        ps_dec->s_tran_addrecon_parse.pu1_dest_u +=
115
220
                        ps_dec->s_tran_addrecon_parse.u4_inc_uv[u1_end_of_row];
116
220
        ps_dec->s_tran_addrecon_parse.pu1_dest_v +=
117
220
                        ps_dec->s_tran_addrecon_parse.u4_inc_uv[u1_end_of_row];
118
220
119
220
        if(u1_end_of_row)
120
220
        {
121
220
            UWORD16 u2_mb_y;
122
220
            UWORD32 u4_frame_stride, y_offset;
123
220
124
220
            ps_dec->ps_top_mb_row = ps_dec->ps_cur_mb_row;
125
220
            ps_dec->ps_cur_mb_row += ((ps_dec->u2_frm_wd_in_mbs) << u1_mbaff);
126
220
127
220
            u2_mb_y = ps_dec->u2_mby + (1 + u1_mbaff);
128
220
            u4_frame_stride = ps_dec->u2_frm_wd_y
129
220
                            << ps_dec->ps_cur_slice->u1_field_pic_flag;
130
220
            y_offset = (u2_mb_y * u4_frame_stride) << 4;
131
220
            ps_dec->s_tran_addrecon_parse.pu1_dest_y =
132
220
                            ps_dec->s_cur_pic.pu1_buf1 + y_offset;
133
220
134
220
            u4_frame_stride = ps_dec->u2_frm_wd_uv
135
220
                            << ps_dec->ps_cur_slice->u1_field_pic_flag;
136
220
            y_offset = (u2_mb_y * u4_frame_stride) << 3;
137
220
            ps_dec->s_tran_addrecon_parse.pu1_dest_u =
138
220
                            ps_dec->s_cur_pic.pu1_buf2 + y_offset;
139
220
            ps_dec->s_tran_addrecon_parse.pu1_dest_v =
140
220
                            ps_dec->s_cur_pic.pu1_buf3 + y_offset;
141
220
142
220
        }
143
220
144
220
        ps_dec->ps_deblk_mbn += u1_num_mbs;
145
220
146
220
        /*
147
220
         * The Slice boundary is also a valid condition to transfer. So recalculate
148
220
         * the Left increment, in case the number of MBs is lesser than the
149
220
         * N MB value. c_numMbs will be equal to N of N MB if the entire N Mb is
150
220
         * decoded.
151
220
         */
152
220
        ps_dec->s_tran_addrecon.u2_mv_left_inc = ((u1_num_mbs >> u1_mbaff) - 1)
153
220
                        << (4 + u1_mbaff);
154
220
        ps_dec->s_tran_addrecon.u2_mv_top_left_inc = (u1_num_mbs << 2) - 1
155
220
                        - (u1_mbaff << 2);
156
220
157
220
        /* reassign left MV and cur MV pointers */
158
220
        ps_dec->ps_mv_left = ps_dec->ps_mv_cur
159
220
                        + ps_dec->s_tran_addrecon.u2_mv_left_inc;
160
220
161
220
        ps_dec->ps_mv_cur += (u1_num_mbs << 4);
162
220
        ps_dec->u4_num_mbs_prev_nmb = u1_num_mbs;
163
220
164
220
    }
165
220
}
166
167
void ih264d_decode_tfr_nmb(dec_struct_t * ps_dec,
168
                           UWORD8 u1_num_mbs,
169
                           UWORD8 u1_num_mbs_next,
170
                           UWORD8 u1_end_of_row)
171
220
{
172
220
173
220
    UWORD32 u1_end_of_row_next;
174
220
175
220
    const UWORD32 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
176
220
177
220
    /****************************************************************/
178
220
    /* Check for End Of Row in Next iteration                       */
179
220
    /****************************************************************/
180
220
    u1_end_of_row_next = u1_num_mbs_next &&
181
220
                        ((u1_num_mbs_next) <= (ps_dec->u1_recon_mb_grp >> u1_mbaff));
182
220
183
220
    /****************************************************************/
184
220
    /* Transfer the Following things                                */
185
220
    /* N-Mb DeblkParams Data    ( To Ext DeblkParams Buffer )       */
186
220
    /* N-Mb Recon Data          ( To Ext Frame Buffer )             */
187
220
    /* N-Mb Intrapredline Data  ( Updated Internally)               */
188
220
    /* N-Mb MV Data             ( To Ext MV Buffer )                */
189
220
    /* N-Mb MVTop/TopRight Data ( To Int MV Top Scratch Buffers)    */
190
220
    /****************************************************************/
191
220
    if(u1_end_of_row)
192
220
    {
193
220
        ps_dec->i2_dec_thread_mb_y += (1 << u1_mbaff);
194
220
    }
195
220
    ih264d_transfer_mb_group_data(ps_dec, u1_num_mbs, u1_end_of_row,
196
220
                                  u1_end_of_row_next);
197
220
198
220
}
199
200
WORD32 ih264d_decode_recon_tfr_nmb_thread(dec_struct_t * ps_dec,
201
                                          UWORD8 u1_num_mbs,
202
                                          UWORD8 u1_num_mbs_next,
203
                                          UWORD8 u1_end_of_row)
204
220
{
205
220
    WORD32 i,j;
206
220
    dec_mb_info_t * ps_cur_mb_info;
207
220
    UWORD32 u4_update_mbaff = 0;
208
220
    const UWORD32 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
209
220
    UWORD32 u1_slice_type, u1_B;
210
220
    WORD32 u1_skip_th;
211
220
    UWORD32 u1_ipcm_th;
212
220
    UWORD32 u4_cond;
213
220
    UWORD16 u2_slice_num,u2_cur_dec_mb_num;
214
220
    WORD32 ret;
215
220
    UWORD32 u4_mb_num;
216
220
    WORD32 nop_cnt = 8*128;
217
220
    u1_slice_type = ps_dec->ps_decode_cur_slice->slice_type;
218
220
219
220
    u1_B = (u1_slice_type == B_SLICE);
220
220
221
220
    u1_skip_th = ((u1_slice_type != I_SLICE) ?
222
220
                                    (u1_B ? B_8x8 : PRED_8x8R0) : -1);
223
220
224
220
    u1_ipcm_th = ((u1_slice_type != I_SLICE) ? (u1_B ? 23 : 5) : 0);
225
220
226
220
    u2_cur_dec_mb_num = ps_dec->cur_dec_mb_num;
227
220
228
33.0k
    while(1)
229
33.0k
    {
230
33.0k
231
33.0k
        UWORD32 u4_max_mb = (UWORD32)(ps_dec->i2_dec_thread_mb_y + (1 << u1_mbaff)) * ps_dec->u2_frm_wd_in_mbs - 1;
232
33.0k
        u4_mb_num = u2_cur_dec_mb_num;
233
33.0k
        /*introducing 1 MB delay*/
234
33.0k
        u4_mb_num = MIN(u4_mb_num + u1_num_mbs + 1, u4_max_mb);
235
33.0k
236
33.0k
        CHECK_MB_MAP_BYTE(u4_mb_num, ps_dec->pu1_dec_mb_map, u4_cond);
237
33.0k
        if(u4_cond)
238
220
        {
239
220
            break;
240
220
        }
241
32.7k
        else
242
32.7k
        {
243
32.7k
            if(nop_cnt > 0)
244
29.2k
            {
245
29.2k
                nop_cnt -= 128;
246
29.2k
                NOP(128);
247
29.2k
            }
248
3.55k
            else
249
3.55k
            {
250
3.55k
                if(ps_dec->u4_output_present && (2 == ps_dec->u4_num_cores) &&
251
3.55k
                   (ps_dec->u4_fmt_conv_cur_row < ps_dec->s_disp_frame_info.u4_y_ht))
252
0
                {
253
0
                    ps_dec->u4_fmt_conv_num_rows =
254
0
                                MIN(FMT_CONV_NUM_ROWS,
255
0
                                    (ps_dec->s_disp_frame_info.u4_y_ht
256
0
                                                    - ps_dec->u4_fmt_conv_cur_row));
257
0
                    ih264d_format_convert(ps_dec, &(ps_dec->s_disp_op),
258
0
                                          ps_dec->u4_fmt_conv_cur_row,
259
0
                                          ps_dec->u4_fmt_conv_num_rows);
260
0
                    ps_dec->u4_fmt_conv_cur_row += ps_dec->u4_fmt_conv_num_rows;
261
0
                }
262
3.55k
                else
263
3.55k
                {
264
3.55k
                    nop_cnt = 8*128;
265
3.55k
                    ithread_yield();
266
3.55k
                }
267
3.55k
            }
268
32.7k
        }
269
33.0k
    }
270
220
    /* N Mb MC Loop */
271
5.28k
    for(i = 0; i < u1_num_mbs; i++)
272
5.06k
    {
273
5.06k
        u4_mb_num = u2_cur_dec_mb_num;
274
5.06k
275
5.06k
        GET_SLICE_NUM_MAP(ps_dec->pu2_slice_num_map, u2_cur_dec_mb_num,
276
5.06k
                          u2_slice_num);
277
5.06k
278
5.06k
        if(u2_slice_num != ps_dec->u2_cur_slice_num_dec_thread)
279
0
        {
280
0
            ps_dec->u4_cur_slice_decode_done = 1;
281
0
            break;
282
0
        }
283
5.06k
284
5.06k
        ps_cur_mb_info = &ps_dec->ps_frm_mb_info[u2_cur_dec_mb_num];
285
5.06k
286
5.06k
        ps_dec->u4_dma_buf_idx = 0;
287
5.06k
        ps_dec->u4_pred_info_idx = 0;
288
5.06k
289
5.06k
        if(ps_cur_mb_info->u1_mb_type <= u1_skip_th)
290
0
        {
291
0
            WORD32 pred_cnt = 0;
292
0
            pred_info_pkd_t *ps_pred_pkd;
293
0
            UWORD32 u4_pred_info_pkd_idx;
294
0
            WORD8 i1_pred;
295
0
296
0
            u4_pred_info_pkd_idx = ps_cur_mb_info->u4_pred_info_pkd_idx;
297
0
298
0
            while(pred_cnt < ps_cur_mb_info->u1_num_pred_parts)
299
0
            {
300
0
                ps_pred_pkd = ps_dec->ps_pred_pkd + u4_pred_info_pkd_idx;
301
0
302
0
                ps_dec->p_form_mb_part_info_thread(ps_pred_pkd,ps_dec,
303
0
                                                   ps_cur_mb_info->u2_mbx,
304
0
                                                   ps_cur_mb_info->u2_mby,
305
0
                                                   (i >> u1_mbaff),
306
0
                                                   ps_cur_mb_info);
307
0
308
0
                u4_pred_info_pkd_idx++;
309
0
                pred_cnt++;
310
0
            }
311
0
            ps_dec->p_mc_dec_thread(ps_dec, ps_cur_mb_info);
312
0
        }
313
5.06k
        else if(ps_cur_mb_info->u1_mb_type == MB_SKIP)
314
5.06k
        {
315
0
            WORD32 pred_cnt = 0;
316
0
            pred_info_pkd_t *ps_pred_pkd;
317
0
            UWORD32 u4_pred_info_pkd_idx;
318
0
            WORD8 i1_pred;
319
0
320
0
            u4_pred_info_pkd_idx = ps_cur_mb_info->u4_pred_info_pkd_idx;
321
0
322
0
            while(pred_cnt < ps_cur_mb_info->u1_num_pred_parts)
323
0
            {
324
0
                ps_pred_pkd = ps_dec->ps_pred_pkd + u4_pred_info_pkd_idx;
325
0
326
0
                ps_dec->p_form_mb_part_info_thread(ps_pred_pkd,ps_dec,
327
0
                                                   ps_cur_mb_info->u2_mbx,
328
0
                                                   ps_cur_mb_info->u2_mby,
329
0
                                                   (i >> u1_mbaff),
330
0
                                                   ps_cur_mb_info);
331
0
332
0
                u4_pred_info_pkd_idx++;
333
0
                pred_cnt++;
334
0
            }
335
0
            /* Decode MB skip */
336
0
            ps_dec->p_mc_dec_thread(ps_dec, ps_cur_mb_info);
337
0
        }
338
5.06k
339
5.06k
        u2_cur_dec_mb_num++;
340
5.06k
    }
341
220
342
220
    /* N Mb IQ IT RECON  Loop */
343
5.28k
    for(j = 0; j < i; j++)
344
5.06k
    {
345
5.06k
        ps_cur_mb_info = &ps_dec->ps_frm_mb_info[ps_dec->cur_dec_mb_num];
346
5.06k
347
5.06k
        if((ps_dec->u4_num_cores == 2) || !ps_dec->i1_recon_in_thread3_flag)
348
0
        {
349
0
            if(ps_cur_mb_info->u1_mb_type <= u1_skip_th)
350
0
            {
351
0
                ih264d_process_inter_mb(ps_dec, ps_cur_mb_info, j);
352
0
            }
353
0
            else if(ps_cur_mb_info->u1_mb_type != MB_SKIP)
354
0
            {
355
0
                if((u1_ipcm_th + 25) != ps_cur_mb_info->u1_mb_type)
356
0
                {
357
0
                    ps_cur_mb_info->u1_mb_type -= (u1_skip_th + 1);
358
0
                    ih264d_process_intra_mb(ps_dec, ps_cur_mb_info, j);
359
0
                }
360
0
            }
361
0
362
0
363
0
         if(ps_dec->u4_use_intrapred_line_copy == 1)
364
0
                ih264d_copy_intra_pred_line(ps_dec, ps_cur_mb_info, j);
365
0
        }
366
5.06k
367
5.06k
        DATA_SYNC();
368
5.06k
369
5.06k
        if(u1_mbaff)
370
0
        {
371
0
            if(u4_update_mbaff)
372
0
            {
373
0
                UWORD32 u4_mb_num = ps_cur_mb_info->u2_mbx
374
0
                                + ps_dec->u2_frm_wd_in_mbs
375
0
                                                * (ps_cur_mb_info->u2_mby >> 1);
376
0
                UPDATE_MB_MAP_MBNUM_BYTE(ps_dec->pu1_recon_mb_map, u4_mb_num);
377
0
                u4_update_mbaff = 0;
378
0
            }
379
0
            else
380
0
            {
381
0
                u4_update_mbaff = 1;
382
0
            }
383
0
        }
384
5.06k
        else
385
5.06k
        {
386
5.06k
            UWORD32 u4_mb_num = ps_cur_mb_info->u2_mbx
387
5.06k
                            + ps_dec->u2_frm_wd_in_mbs * ps_cur_mb_info->u2_mby;
388
5.06k
            UPDATE_MB_MAP_MBNUM_BYTE(ps_dec->pu1_recon_mb_map, u4_mb_num);
389
5.06k
        }
390
5.06k
        ps_dec->cur_dec_mb_num++;
391
5.06k
     }
392
220
393
220
    /*N MB deblocking*/
394
220
    if(ps_dec->u4_nmb_deblk == 1)
395
0
    {
396
0
        UWORD32 u4_wd_y, u4_wd_uv;
397
0
        tfr_ctxt_t *ps_tfr_cxt = &(ps_dec->s_tran_addrecon);
398
0
        UWORD8 u1_field_pic_flag = ps_dec->ps_cur_slice->u1_field_pic_flag;
399
0
        const WORD32 i4_cb_qp_idx_ofst =
400
0
                       ps_dec->ps_cur_pps->i1_chroma_qp_index_offset;
401
0
        const WORD32 i4_cr_qp_idx_ofst =
402
0
                       ps_dec->ps_cur_pps->i1_second_chroma_qp_index_offset;
403
0
404
0
        u4_wd_y = ps_dec->u2_frm_wd_y << u1_field_pic_flag;
405
0
        u4_wd_uv = ps_dec->u2_frm_wd_uv << u1_field_pic_flag;
406
0
407
0
        ps_cur_mb_info = &ps_dec->ps_frm_mb_info[ps_dec->u4_cur_deblk_mb_num];
408
0
409
0
        ps_dec->u4_deblk_mb_x = ps_cur_mb_info->u2_mbx;
410
0
        ps_dec->u4_deblk_mb_y = ps_cur_mb_info->u2_mby;
411
0
412
0
413
0
        for(j = 0; j < i; j++)
414
0
        {
415
0
            ih264d_deblock_mb_nonmbaff(ps_dec, ps_tfr_cxt,
416
0
                                       i4_cb_qp_idx_ofst, i4_cr_qp_idx_ofst,
417
0
                                        u4_wd_y, u4_wd_uv);
418
0
419
0
        }
420
0
    }
421
220
422
220
    /*handle the last mb in picture case*/
423
220
    if(ps_dec->cur_dec_mb_num > ps_dec->ps_cur_sps->u2_max_mb_addr)
424
11
        ps_dec->u4_cur_slice_decode_done = 1;
425
220
426
220
    if(i != u1_num_mbs)
427
0
    {
428
0
        u1_end_of_row = 0;
429
0
        /*Number of MB's left in row*/
430
0
        u1_num_mbs_next = u1_num_mbs_next + ((u1_num_mbs - i) >> u1_mbaff);
431
0
    }
432
220
433
220
    ih264d_decode_tfr_nmb(ps_dec, (i), u1_num_mbs_next, u1_end_of_row);
434
220
435
220
    return OK;
436
220
}
437
438
WORD32 ih264d_decode_slice_thread(dec_struct_t *ps_dec)
439
11
{
440
11
    UWORD8 u1_num_mbs_next, u1_num_mbsleft, u1_end_of_row = 0;
441
11
    const UWORD32 i2_pic_wdin_mbs = ps_dec->u2_frm_wd_in_mbs;
442
11
    UWORD8 u1_mbaff, u1_num_mbs;
443
11
444
11
    UWORD16 u2_first_mb_in_slice;
445
11
    UWORD16 i16_mb_x, i16_mb_y;
446
11
    UWORD8 u1_field_pic;
447
11
    UWORD32 u4_frame_stride, x_offset, y_offset;
448
11
    WORD32 ret;
449
11
450
11
    tfr_ctxt_t *ps_trns_addr;
451
11
452
11
    /*check for mb map of first mb in slice to ensure slice header is parsed*/
453
702
    while(1)
454
702
    {
455
702
        UWORD32 u4_mb_num = ps_dec->cur_dec_mb_num;
456
702
        UWORD32 u4_cond = 0;
457
702
        WORD32 nop_cnt = 8 * 128;
458
702
        CHECK_MB_MAP_BYTE(u4_mb_num, ps_dec->pu1_dec_mb_map, u4_cond);
459
702
        if(u4_cond)
460
11
        {
461
11
            break;
462
11
        }
463
691
        else
464
691
        {
465
691
            if(nop_cnt > 0)
466
691
            {
467
691
                nop_cnt -= 128;
468
691
                NOP(128);
469
691
            }
470
0
            else if(ps_dec->u4_output_present && (2 == ps_dec->u4_num_cores) &&
471
0
               (ps_dec->u4_fmt_conv_cur_row < ps_dec->s_disp_frame_info.u4_y_ht))
472
0
            {
473
0
                ps_dec->u4_fmt_conv_num_rows =
474
0
                                MIN(FMT_CONV_NUM_ROWS,
475
0
                                    (ps_dec->s_disp_frame_info.u4_y_ht
476
0
                                                    - ps_dec->u4_fmt_conv_cur_row));
477
0
                ih264d_format_convert(ps_dec, &(ps_dec->s_disp_op),
478
0
                                      ps_dec->u4_fmt_conv_cur_row,
479
0
                                      ps_dec->u4_fmt_conv_num_rows);
480
0
                ps_dec->u4_fmt_conv_cur_row += ps_dec->u4_fmt_conv_num_rows;
481
0
            }
482
0
            else
483
0
            {
484
0
                nop_cnt = 8*128;
485
0
                ithread_yield();
486
0
            }
487
691
            DEBUG_THREADS_PRINTF("waiting for mb mapcur_dec_mb_num = %d,ps_dec->u2_cur_mb_addr  = %d\n",u2_cur_dec_mb_num,
488
691
                            ps_dec->u2_cur_mb_addr);
489
691
490
691
        }
491
702
    }
492
11
493
11
494
11
495
11
    u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
496
11
497
11
    u2_first_mb_in_slice = ps_dec->ps_decode_cur_slice->u4_first_mb_in_slice;
498
11
499
11
    i16_mb_x = MOD(u2_first_mb_in_slice, i2_pic_wdin_mbs);
500
11
    i16_mb_y = DIV(u2_first_mb_in_slice, i2_pic_wdin_mbs);
501
11
    i16_mb_y <<= u1_mbaff;
502
11
    ps_dec->i2_dec_thread_mb_y = i16_mb_y;
503
11
504
11
505
11
    ps_dec->cur_dec_mb_num = u2_first_mb_in_slice << u1_mbaff;
506
11
507
11
    if((ps_dec->u4_num_cores == 2) || !ps_dec->i1_recon_in_thread3_flag)
508
0
    {
509
0
        ps_dec->pv_proc_tu_coeff_data =
510
0
                (void *) ps_dec->ps_decode_cur_slice->pv_tu_coeff_data_start;
511
0
    }
512
11
513
11
    // recalculate recon pointers
514
11
    u1_field_pic = ps_dec->ps_cur_slice->u1_field_pic_flag;
515
11
    u4_frame_stride = ps_dec->u2_frm_wd_y << u1_field_pic;
516
11
    x_offset = i16_mb_x << 4;
517
11
    y_offset = (i16_mb_y * u4_frame_stride) << 4;
518
11
519
11
    ps_trns_addr = &(ps_dec->s_tran_addrecon);
520
11
521
11
    ps_trns_addr->pu1_dest_y = ps_dec->s_cur_pic.pu1_buf1 + x_offset + y_offset;
522
11
523
11
    u4_frame_stride = ps_dec->u2_frm_wd_uv << u1_field_pic;
524
11
    x_offset >>= 1;
525
11
    y_offset = (i16_mb_y * u4_frame_stride) << 3;
526
11
527
11
    x_offset *= YUV420SP_FACTOR;
528
11
529
11
    ps_trns_addr->pu1_dest_u = ps_dec->s_cur_pic.pu1_buf2 + x_offset + y_offset;
530
11
    ps_trns_addr->pu1_dest_v = ps_dec->s_cur_pic.pu1_buf3 + x_offset + y_offset;
531
11
532
11
    ps_trns_addr->pu1_mb_y = ps_trns_addr->pu1_dest_y;
533
11
    ps_trns_addr->pu1_mb_u = ps_trns_addr->pu1_dest_u;
534
11
    ps_trns_addr->pu1_mb_v = ps_trns_addr->pu1_dest_v;
535
11
536
11
537
11
    /* Initialise MC and formMbPartInfo fn ptrs one time based on profile_idc */
538
11
    {
539
11
        ps_dec->p_mc_dec_thread = ih264d_motion_compensate_bp;
540
11
        ps_dec->p_form_mb_part_info_thread = ih264d_form_mb_part_info_bp;
541
11
    }
542
11
    {
543
11
        UWORD8 uc_nofield_nombaff;
544
11
        uc_nofield_nombaff = ((ps_dec->ps_cur_slice->u1_field_pic_flag == 0)
545
11
                        && (ps_dec->ps_cur_slice->u1_mbaff_frame_flag == 0)
546
11
                        && (ps_dec->ps_decode_cur_slice->slice_type != B_SLICE)
547
11
                        && (ps_dec->ps_cur_pps->u1_wted_pred_flag == 0));
548
11
549
11
        if(uc_nofield_nombaff == 0)
550
0
        {
551
0
            ps_dec->p_mc_dec_thread = ih264d_motion_compensate_mp;
552
0
            ps_dec->p_form_mb_part_info_thread = ih264d_form_mb_part_info_mp;
553
0
        }
554
11
555
11
    }
556
11
557
11
    ps_dec->u4_cur_slice_decode_done = 0;
558
11
559
11
560
231
    while(ps_dec->u4_cur_slice_decode_done != 1)
561
220
    {
562
220
563
220
        u1_num_mbsleft = ((i2_pic_wdin_mbs - i16_mb_x) << u1_mbaff);
564
220
565
220
        if(u1_num_mbsleft <= ps_dec->u1_recon_mb_grp)
566
220
        {
567
220
            u1_num_mbs = u1_num_mbsleft;
568
220
569
220
            /*Indicate number of mb's left in a row*/
570
220
            u1_num_mbs_next = 0;
571
220
            u1_end_of_row = 1;
572
220
            i16_mb_x = 0;
573
220
        }
574
0
        else
575
0
        {
576
0
            u1_num_mbs = ps_dec->u1_recon_mb_grp;
577
0
578
0
            /*Indicate number of mb's left in a row*/
579
0
            u1_num_mbs_next = i2_pic_wdin_mbs - i16_mb_x
580
0
                            - (ps_dec->u1_recon_mb_grp >> u1_mbaff);
581
0
            i16_mb_x += (u1_num_mbs >> u1_mbaff);
582
0
            u1_end_of_row = 0;
583
0
584
0
        }
585
220
        ret = ih264d_decode_recon_tfr_nmb_thread(ps_dec, u1_num_mbs, u1_num_mbs_next,
586
220
                                           u1_end_of_row);
587
220
        if(ret != OK)
588
220
            return ret;
589
220
    }
590
11
    return OK;
591
11
}
592
593
void ih264d_decode_picture_thread(dec_struct_t *ps_dec )
594
11
{
595
11
    ithread_set_name("ih264d_decode_picture_thread");
596
11
    while(1)
597
11
    {
598
11
        /*Complete all writes before processing next slice*/
599
11
600
11
        DEBUG_THREADS_PRINTF(" Entering decode slice\n");
601
11
602
11
        ih264d_decode_slice_thread(ps_dec);
603
11
        DEBUG_THREADS_PRINTF(" Exit  ih264d_decode_slice_thread \n");
604
11
605
11
606
11
        if(ps_dec->cur_dec_mb_num
607
11
                        > ps_dec->ps_cur_sps->u2_max_mb_addr)
608
11
        {
609
11
            /*Last slice in frame*/
610
11
            break;
611
11
        }
612
0
        else
613
0
        {
614
0
            ps_dec->ps_decode_cur_slice++;
615
0
            ps_dec->u2_cur_slice_num_dec_thread++;
616
0
        }
617
11
618
11
    }
619
11
    if(ps_dec->u4_output_present && (2 == ps_dec->u4_num_cores) &&
620
11
       (ps_dec->u4_fmt_conv_cur_row < ps_dec->s_disp_frame_info.u4_y_ht))
621
0
    {
622
0
        ps_dec->u4_fmt_conv_num_rows =
623
0
                        (ps_dec->s_disp_frame_info.u4_y_ht
624
0
                                        - ps_dec->u4_fmt_conv_cur_row);
625
0
        ih264d_format_convert(ps_dec, &(ps_dec->s_disp_op),
626
0
                              ps_dec->u4_fmt_conv_cur_row,
627
0
                              ps_dec->u4_fmt_conv_num_rows);
628
0
        ps_dec->u4_fmt_conv_cur_row += ps_dec->u4_fmt_conv_num_rows;
629
0
    }
630
11
}
631
632
void ih264d_signal_decode_thread(dec_struct_t *ps_dec)
633
13
{
634
13
    if(ps_dec->u4_dec_thread_created == 1)
635
11
    {
636
11
        ithread_join(ps_dec->pv_dec_thread_handle, NULL);
637
11
        ps_dec->u4_dec_thread_created = 0;
638
11
    }
639
13
}
640
void ih264d_signal_bs_deblk_thread(dec_struct_t *ps_dec)
641
26
{
642
26
    if(ps_dec->u4_bs_deblk_thread_created)
643
11
    {
644
11
        ithread_join(ps_dec->pv_bs_deblk_thread_handle, NULL);
645
11
        ps_dec->u4_bs_deblk_thread_created = 0;
646
11
    }
647
26
648
26
}
/proc/self/cwd/external/libavc/decoder/ih264d_utils.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/*!
21
 **************************************************************************
22
 * \file ih264d_utils.c
23
 *
24
 * \brief
25
 *    Contains routines that handle of start and end of pic processing
26
 *
27
 * \date
28
 *    19/12/2002
29
 *
30
 * \author  AI
31
 **************************************************************************
32
 */
33
34
#include <string.h>
35
#include "ih264_typedefs.h"
36
#include "ithread.h"
37
#include "ih264d_deblocking.h"
38
#include "ih264d_parse_slice.h"
39
#include "ih264d_parse_cavlc.h"
40
#include "ih264d_dpb_manager.h"
41
#include "ih264d_defs.h"
42
#include "ih264d_structs.h"
43
#include "ih264d_mem_request.h"
44
#include "ih264_typedefs.h"
45
#include "ih264_macros.h"
46
#include "ih264_platform_macros.h"
47
#include "ih264d_tables.h"
48
#include "ih264d_debug.h"
49
#include "ih264d_mb_utils.h"
50
#include "ih264d_error_handler.h"
51
#include "ih264d_dpb_manager.h"
52
#include "ih264d_utils.h"
53
#include "ih264d_defs.h"
54
#include "ih264d_tables.h"
55
#include "ih264d_inter_pred.h"
56
#include "ih264d_dpb_manager.h"
57
#include "iv.h"
58
#include "ivd.h"
59
#include "ih264d_format_conv.h"
60
#include "ih264_error.h"
61
#include "ih264_disp_mgr.h"
62
#include "ih264_buf_mgr.h"
63
#include "ih264d_utils.h"
64
65
/*!
66
 **************************************************************************
67
 * \if Function name : ih264d_is_end_of_pic \endif
68
 *
69
 * \brief
70
 *    Determines whether current slice is first slice of a new picture as
71
 *    defined in 7.4.1.2.4 of 14496-10.
72
 *
73
 * \return
74
 *    Return 1 if current slice is first slice of a new picture
75
 *    Otherwise it returns 0
76
 **************************************************************************
77
 */
78
UWORD8 ih264d_is_end_of_pic(UWORD16 u2_frame_num,
79
                            UWORD8 u1_nal_ref_idc,
80
                            pocstruct_t *ps_cur_poc,
81
                            pocstruct_t *ps_prev_poc,
82
                            dec_slice_params_t * ps_prev_slice, /*!< Previous slice parameters*/
83
                            UWORD8 u1_pic_order_cnt_type,
84
                            UWORD8 u1_nal_unit_type,
85
                            UWORD32 u4_idr_pic_id,
86
                            UWORD8 u1_field_pic_flag,
87
                            UWORD8 u1_bottom_field_flag)
88
0
{
89
0
    WORD8 i1_is_end_of_pic;
90
0
    WORD8 a, b, c, d, e, f, g, h;
91
0
92
0
    a = b = c = d = e = f = g = h = 0;
93
0
    a = (ps_prev_slice->u2_frame_num != u2_frame_num);
94
0
    b = (ps_prev_slice->u1_field_pic_flag != u1_field_pic_flag);
95
0
    if(u1_field_pic_flag && ps_prev_slice->u1_field_pic_flag)
96
0
        c = (u1_bottom_field_flag != ps_prev_slice->u1_bottom_field_flag);
97
0
    d =
98
0
                    (u1_nal_ref_idc == 0 && ps_prev_slice->u1_nal_ref_idc != 0)
99
0
                                    || (u1_nal_ref_idc != 0
100
0
                                                    && ps_prev_slice->u1_nal_ref_idc
101
0
                                                                    == 0);
102
0
    if(!a)
103
0
    {
104
0
        if((u1_pic_order_cnt_type == 0)
105
0
                        && (ps_prev_slice->u1_pic_order_cnt_type == 0))
106
0
        {
107
0
            e =
108
0
                            ((ps_cur_poc->i4_pic_order_cnt_lsb
109
0
                                            != ps_prev_poc->i4_pic_order_cnt_lsb)
110
0
                                            || (ps_cur_poc->i4_delta_pic_order_cnt_bottom
111
0
                                                            != ps_prev_poc->i4_delta_pic_order_cnt_bottom));
112
0
        }
113
0
114
0
        if((u1_pic_order_cnt_type == 1)
115
0
                        && (ps_prev_slice->u1_pic_order_cnt_type == 1))
116
0
        {
117
0
            f =
118
0
                            ((ps_cur_poc->i4_delta_pic_order_cnt[0]
119
0
                                            != ps_prev_poc->i4_delta_pic_order_cnt[0])
120
0
                                            || (ps_cur_poc->i4_delta_pic_order_cnt[1]
121
0
                                                            != ps_prev_poc->i4_delta_pic_order_cnt[1]));
122
0
        }
123
0
    }
124
0
125
0
    if((u1_nal_unit_type == IDR_SLICE_NAL)
126
0
                    && (ps_prev_slice->u1_nal_unit_type == IDR_SLICE_NAL))
127
0
    {
128
0
        g = (u4_idr_pic_id != ps_prev_slice->u4_idr_pic_id);
129
0
    }
130
0
131
0
    if((u1_nal_unit_type == IDR_SLICE_NAL)
132
0
                    && (ps_prev_slice->u1_nal_unit_type != IDR_SLICE_NAL))
133
0
    {
134
0
        h = 1;
135
0
    }
136
0
    i1_is_end_of_pic = a + b + c + d + e + f + g + h;
137
0
    return (i1_is_end_of_pic);
138
0
}
139
140
/*!
141
 **************************************************************************
142
 * \if Function name : ih264d_decode_pic_order_cnt \endif
143
 *
144
 * \brief
145
 *    Calculates picture order count of picture.
146
 *
147
 * \return
148
 *    Returns the pic order count of the picture to which current
149
 *    Slice belongs.
150
 *
151
 **************************************************************************
152
 */
153
WORD32 ih264d_decode_pic_order_cnt(UWORD8 u1_is_idr_slice,
154
                                   UWORD32 u2_frame_num,
155
                                   pocstruct_t *ps_prev_poc,
156
                                   pocstruct_t *ps_cur_poc,
157
                                   dec_slice_params_t *ps_cur_slice, /*!< Pointer to current slice Params*/
158
                                   dec_pic_params_t * ps_pps,
159
                                   UWORD8 u1_nal_ref_idc,
160
                                   UWORD8 u1_bottom_field_flag,
161
                                   UWORD8 u1_field_pic_flag,
162
                                   WORD32 *pi4_poc)
163
11
{
164
11
    WORD16 i1_pic_msb;
165
11
    WORD32 i4_top_field_order_cnt = 0, i4_bottom_field_order_cnt = 0;
166
11
    dec_seq_params_t *ps_seq = ps_pps->ps_sps;
167
11
    WORD32 i4_prev_frame_num_ofst;
168
11
169
11
    switch(ps_seq->u1_pic_order_cnt_type)
170
11
    {
171
11
        case 0:
172
11
            /* POC TYPE 0 */
173
11
            if(u1_is_idr_slice)
174
11
            {
175
11
                ps_prev_poc->i4_pic_order_cnt_msb = 0;
176
11
                ps_prev_poc->i4_pic_order_cnt_lsb = 0;
177
11
            }
178
11
            if(ps_prev_poc->u1_mmco_equalto5)
179
0
            {
180
0
                if(ps_prev_poc->u1_bot_field != 1)
181
0
                {
182
0
                    ps_prev_poc->i4_pic_order_cnt_msb = 0;
183
0
                    ps_prev_poc->i4_pic_order_cnt_lsb =
184
0
                                    ps_prev_poc->i4_top_field_order_count;
185
0
                }
186
0
                else
187
0
                {
188
0
                    ps_prev_poc->i4_pic_order_cnt_msb = 0;
189
0
                    ps_prev_poc->i4_pic_order_cnt_lsb = 0;
190
0
                }
191
0
            }
192
11
193
11
            if((ps_cur_poc->i4_pic_order_cnt_lsb
194
11
                            < ps_prev_poc->i4_pic_order_cnt_lsb)
195
11
                            && ((ps_prev_poc->i4_pic_order_cnt_lsb
196
0
                                            - ps_cur_poc->i4_pic_order_cnt_lsb)
197
0
                                            >= (ps_seq->i4_max_pic_order_cntLsb
198
0
                                                            >> 1)))
199
0
            {
200
0
                i1_pic_msb = ps_prev_poc->i4_pic_order_cnt_msb
201
0
                                + ps_seq->i4_max_pic_order_cntLsb;
202
0
            }
203
11
            else if((ps_cur_poc->i4_pic_order_cnt_lsb
204
11
                            > ps_prev_poc->i4_pic_order_cnt_lsb)
205
11
                            && ((ps_cur_poc->i4_pic_order_cnt_lsb
206
0
                                            - ps_prev_poc->i4_pic_order_cnt_lsb)
207
0
                                            >= (ps_seq->i4_max_pic_order_cntLsb
208
0
                                                            >> 1)))
209
0
            {
210
0
                i1_pic_msb = ps_prev_poc->i4_pic_order_cnt_msb
211
0
                                - ps_seq->i4_max_pic_order_cntLsb;
212
0
            }
213
11
            else
214
11
            {
215
11
                i1_pic_msb = ps_prev_poc->i4_pic_order_cnt_msb;
216
11
            }
217
11
218
11
            if(!u1_field_pic_flag || !u1_bottom_field_flag)
219
11
                i4_top_field_order_cnt = i1_pic_msb
220
11
                                + ps_cur_poc->i4_pic_order_cnt_lsb;
221
11
222
11
            if(!u1_field_pic_flag)
223
11
            {
224
11
                i4_bottom_field_order_cnt = i4_top_field_order_cnt
225
11
                                + ps_cur_poc->i4_delta_pic_order_cnt_bottom;
226
11
            }
227
0
            else if(u1_bottom_field_flag)
228
0
            {
229
0
                i4_bottom_field_order_cnt = i1_pic_msb
230
0
                                + ps_cur_poc->i4_pic_order_cnt_lsb;
231
0
            }
232
11
            ps_cur_poc->i4_pic_order_cnt_msb = i1_pic_msb;
233
11
            break;
234
11
235
11
        case 1:
236
0
        {
237
0
            /* POC TYPE 1 */
238
0
            UWORD8 i;
239
0
            WORD32 prev_frame_num;
240
0
            WORD32 frame_num_ofst;
241
0
            WORD32 abs_frm_num;
242
0
            WORD32 poc_cycle_cnt, frame_num_in_poc_cycle;
243
0
            WORD32 expected_delta_poc_cycle;
244
0
            WORD32 expected_poc;
245
0
246
0
            prev_frame_num = (WORD32)ps_cur_slice->u2_frame_num;
247
0
            if(!u1_is_idr_slice)
248
0
            {
249
0
                if(ps_cur_slice->u1_mmco_equalto5)
250
0
                {
251
0
                    prev_frame_num = 0;
252
0
                    i4_prev_frame_num_ofst = 0;
253
0
                }
254
0
                else
255
0
                {
256
0
                    i4_prev_frame_num_ofst = ps_prev_poc->i4_prev_frame_num_ofst;
257
0
                }
258
0
            }
259
0
            else
260
0
                i4_prev_frame_num_ofst = 0;
261
0
262
0
            /* 1. Derivation for FrameNumOffset */
263
0
            if(u1_is_idr_slice)
264
0
            {
265
0
                frame_num_ofst = 0;
266
0
                ps_cur_poc->i4_delta_pic_order_cnt[0] = 0;
267
0
                ps_cur_poc->i4_delta_pic_order_cnt[1] = 0;
268
0
            }
269
0
            else if(prev_frame_num > ((WORD32)u2_frame_num))
270
0
            {
271
0
                frame_num_ofst = i4_prev_frame_num_ofst
272
0
                                + ps_seq->u2_u4_max_pic_num_minus1 + 1;
273
0
            }
274
0
            else
275
0
                frame_num_ofst = i4_prev_frame_num_ofst;
276
0
277
0
            /* 2. Derivation for absFrameNum */
278
0
            if(0 != ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle)
279
0
                abs_frm_num = frame_num_ofst + u2_frame_num;
280
0
            else
281
0
                abs_frm_num = 0;
282
0
            if((u1_nal_ref_idc == 0) && (abs_frm_num > 0))
283
0
                abs_frm_num = abs_frm_num - 1;
284
0
285
0
            /* 4. expectedDeltaPerPicOrderCntCycle is derived as */
286
0
            expected_delta_poc_cycle = 0;
287
0
            for(i = 0; i < ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle;
288
0
                            i++)
289
0
            {
290
0
                expected_delta_poc_cycle +=
291
0
                                ps_seq->i4_ofst_for_ref_frame[i];
292
0
            }
293
0
294
0
            /* 3. When absFrameNum > 0, picOrderCntCycleCnt and
295
0
             frame_num_in_poc_cycle are derived as : */
296
0
            /* 5. expectedPicOrderCnt is derived as : */
297
0
            if(abs_frm_num > 0)
298
0
            {
299
0
                poc_cycle_cnt =
300
0
                                DIV((abs_frm_num - 1),
301
0
                                    ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle);
302
0
                frame_num_in_poc_cycle =
303
0
                                MOD((abs_frm_num - 1),
304
0
                                    ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle);
305
0
306
0
                expected_poc = poc_cycle_cnt
307
0
                                * expected_delta_poc_cycle;
308
0
                for(i = 0; i <= frame_num_in_poc_cycle; i++)
309
0
                {
310
0
                    expected_poc = expected_poc
311
0
                                    + ps_seq->i4_ofst_for_ref_frame[i];
312
0
                }
313
0
            }
314
0
            else
315
0
                expected_poc = 0;
316
0
317
0
            if(u1_nal_ref_idc == 0)
318
0
            {
319
0
                expected_poc = expected_poc
320
0
                                + ps_seq->i4_ofst_for_non_ref_pic;
321
0
            }
322
0
323
0
            /* 6. TopFieldOrderCnt or BottomFieldOrderCnt are derived as */
324
0
            if(!u1_field_pic_flag)
325
0
            {
326
0
                i4_top_field_order_cnt = expected_poc
327
0
                                + ps_cur_poc->i4_delta_pic_order_cnt[0];
328
0
                i4_bottom_field_order_cnt = i4_top_field_order_cnt
329
0
                                + ps_seq->i4_ofst_for_top_to_bottom_field
330
0
                                + ps_cur_poc->i4_delta_pic_order_cnt[1];
331
0
            }
332
0
            else if(!u1_bottom_field_flag)
333
0
            {
334
0
                i4_top_field_order_cnt = expected_poc
335
0
                                + ps_cur_poc->i4_delta_pic_order_cnt[0];
336
0
            }
337
0
            else
338
0
            {
339
0
                i4_bottom_field_order_cnt = expected_poc
340
0
                                + ps_seq->i4_ofst_for_top_to_bottom_field
341
0
                                + ps_cur_poc->i4_delta_pic_order_cnt[0];
342
0
            }
343
0
            /* Copy the current POC info into Previous POC structure */
344
0
            ps_cur_poc->i4_prev_frame_num_ofst = frame_num_ofst;
345
0
        }
346
0
347
0
            break;
348
11
        case 2:
349
0
        {
350
0
            /* POC TYPE 2 */
351
0
            WORD32 prev_frame_num;
352
0
            WORD32 frame_num_ofst;
353
0
            WORD32 tmp_poc;
354
0
355
0
            prev_frame_num = (WORD32)ps_cur_slice->u2_frame_num;
356
0
            if(!u1_is_idr_slice)
357
0
            {
358
0
                if(ps_cur_slice->u1_mmco_equalto5)
359
0
                {
360
0
                    prev_frame_num = 0;
361
0
                    i4_prev_frame_num_ofst = 0;
362
0
                }
363
0
                else
364
0
                    i4_prev_frame_num_ofst = ps_prev_poc->i4_prev_frame_num_ofst;
365
0
            }
366
0
            else
367
0
                i4_prev_frame_num_ofst = 0;
368
0
369
0
            /* 1. Derivation for FrameNumOffset */
370
0
            if(u1_is_idr_slice)
371
0
            {
372
0
                frame_num_ofst = 0;
373
0
                ps_cur_poc->i4_delta_pic_order_cnt[0] = 0;
374
0
                ps_cur_poc->i4_delta_pic_order_cnt[1] = 0;
375
0
            }
376
0
            else if(prev_frame_num > ((WORD32)u2_frame_num))
377
0
            {
378
0
                frame_num_ofst = i4_prev_frame_num_ofst
379
0
                                + ps_seq->u2_u4_max_pic_num_minus1 + 1;
380
0
            }
381
0
            else
382
0
                frame_num_ofst = i4_prev_frame_num_ofst;
383
0
384
0
            /* 2. Derivation for tempPicOrderCnt */
385
0
            if(u1_is_idr_slice)
386
0
                tmp_poc = 0;
387
0
            else if(u1_nal_ref_idc == 0)
388
0
                tmp_poc = ((frame_num_ofst + u2_frame_num) << 1)
389
0
                                - 1;
390
0
            else
391
0
                tmp_poc = ((frame_num_ofst + u2_frame_num) << 1);
392
0
393
0
            /* 6. TopFieldOrderCnt or BottomFieldOrderCnt are derived as */
394
0
            if(!u1_field_pic_flag)
395
0
            {
396
0
                i4_top_field_order_cnt = tmp_poc;
397
0
                i4_bottom_field_order_cnt = tmp_poc;
398
0
            }
399
0
            else if(!u1_bottom_field_flag)
400
0
                i4_top_field_order_cnt = tmp_poc;
401
0
            else
402
0
                i4_bottom_field_order_cnt = tmp_poc;
403
0
404
0
            /* Copy the current POC info into Previous POC structure */
405
0
            ps_prev_poc->i4_prev_frame_num_ofst = frame_num_ofst;
406
0
            ps_cur_poc->i4_prev_frame_num_ofst = frame_num_ofst;
407
0
        }
408
0
            break;
409
11
        default:
410
0
            return ERROR_INV_POC_TYPE_T;
411
11
            break;
412
11
    }
413
11
414
11
    if(!u1_field_pic_flag) // or a complementary field pair
415
11
    {
416
11
        *pi4_poc = MIN(i4_top_field_order_cnt, i4_bottom_field_order_cnt);
417
11
        ps_pps->i4_top_field_order_cnt = i4_top_field_order_cnt;
418
11
        ps_pps->i4_bottom_field_order_cnt = i4_bottom_field_order_cnt;
419
11
    }
420
0
    else if(!u1_bottom_field_flag)
421
0
    {
422
0
        *pi4_poc = i4_top_field_order_cnt;
423
0
        ps_pps->i4_top_field_order_cnt = i4_top_field_order_cnt;
424
0
    }
425
0
    else
426
0
    {
427
0
        *pi4_poc = i4_bottom_field_order_cnt;
428
0
        ps_pps->i4_bottom_field_order_cnt = i4_bottom_field_order_cnt;
429
0
    }
430
11
431
11
    ps_pps->i4_avg_poc = *pi4_poc;
432
11
433
11
    return OK;
434
11
}
435
436
/*!
437
 **************************************************************************
438
 * \if Function name : ih264d_end_of_pic_processing \endif
439
 *
440
 * \brief
441
 *    Performs the end of picture processing.
442
 *
443
 * It performs deblocking on the current picture and sets the i4_status of
444
 * current picture as decoded.
445
 *
446
 * \return
447
 *    0 on Success and Error code otherwise.
448
 **************************************************************************
449
 */
450
WORD32 ih264d_end_of_pic_processing(dec_struct_t *ps_dec)
451
11
{
452
11
    UWORD8 u1_pic_type, u1_nal_ref_idc;
453
11
    dec_slice_params_t *ps_cur_slice = ps_dec->ps_cur_slice;
454
11
455
11
    /* If nal_ref_idc is equal to 0 for one slice or slice data partition NAL
456
11
     unit of a particular picture, it shall be equal to 0 for all slice and
457
11
     slice data partition NAL units of the picture. nal_ref_idc greater
458
11
     than 0 indicates that the content of the NAL unit belongs to a decoded
459
11
     picture that is stored and marked for use as a reference picture in the
460
11
     decoded picture buffer. */
461
11
462
11
    /* 1. Do MMCO
463
11
     2. Add Cur Pic to list of reference pics.
464
11
     */
465
11
466
11
    /* Call MMCO */
467
11
    u1_pic_type = 0;
468
11
    u1_nal_ref_idc = ps_cur_slice->u1_nal_ref_idc;
469
11
470
11
    if(u1_nal_ref_idc)
471
11
    {
472
11
        if(ps_cur_slice->u1_nal_unit_type == IDR_SLICE_NAL)
473
11
        {
474
11
            if(ps_dec->ps_dpb_cmds->u1_long_term_reference_flag == 0)
475
11
            {
476
11
                ih264d_reset_ref_bufs(ps_dec->ps_dpb_mgr);
477
11
                /* ignore DPB errors */
478
11
                ih264d_insert_st_node(ps_dec->ps_dpb_mgr,
479
11
                                      ps_dec->ps_cur_pic,
480
11
                                      ps_dec->u1_pic_buf_id,
481
11
                                      ps_cur_slice->u2_frame_num);
482
11
            }
483
0
            else
484
0
            {
485
0
                /* Equivalent of inserting a pic directly as longterm Pic */
486
0
487
0
                {
488
0
                    /* ignore DPB errors */
489
0
                    ih264d_insert_st_node(ps_dec->ps_dpb_mgr,
490
0
                                          ps_dec->ps_cur_pic,
491
0
                                          ps_dec->u1_pic_buf_id,
492
0
                                          ps_cur_slice->u2_frame_num);
493
0
494
0
                    /* Set longTermIdx = 0, MaxLongTermFrameIdx = 0 */
495
0
                    ih264d_delete_st_node_or_make_lt(
496
0
                                    ps_dec->ps_dpb_mgr,
497
0
                                    ps_cur_slice->u2_frame_num, 0,
498
0
                                    ps_cur_slice->u1_field_pic_flag);
499
0
500
0
                    ps_dec->ps_dpb_mgr->u1_max_lt_pic_idx_plus1 = 1;
501
0
                }
502
0
            }
503
11
        }
504
0
        else
505
0
        {
506
0
507
0
            {
508
0
                UWORD16 u2_pic_num = ps_cur_slice->u2_frame_num;
509
0
510
0
                /* ignore DPB errors */
511
0
                ih264d_do_mmco_buffer(ps_dec->ps_dpb_cmds, ps_dec->ps_dpb_mgr,
512
0
                              ps_dec->ps_cur_sps->u1_num_ref_frames, u2_pic_num,
513
0
                              (ps_dec->ps_cur_sps->u2_u4_max_pic_num_minus1),
514
0
                              ps_dec->u1_nal_unit_type, ps_dec->ps_cur_pic,
515
0
                              ps_dec->u1_pic_buf_id,
516
0
                              ps_cur_slice->u1_field_pic_flag,
517
0
                              ps_dec->e_dec_status);
518
0
519
0
520
0
            }
521
0
        }
522
11
        ih264d_update_default_index_list(ps_dec->ps_dpb_mgr);
523
11
    }
524
11
525
11
    if(ps_cur_slice->u1_field_pic_flag)
526
0
    {
527
0
        if(ps_cur_slice->u1_bottom_field_flag)
528
0
        {
529
0
            if(u1_nal_ref_idc)
530
0
                u1_pic_type = u1_pic_type | BOT_REF;
531
0
            u1_pic_type = u1_pic_type | BOT_FLD;
532
0
        }
533
0
        else
534
0
        {
535
0
            if(u1_nal_ref_idc)
536
0
                u1_pic_type = u1_pic_type | TOP_REF;
537
0
            u1_pic_type = u1_pic_type | TOP_FLD;
538
0
        }
539
0
    }
540
11
    else
541
11
        u1_pic_type = TOP_REF | BOT_REF;
542
11
    ps_dec->ps_cur_pic->u1_pic_type |= u1_pic_type;
543
11
544
11
545
11
    if(ps_cur_slice->u1_field_pic_flag)
546
0
    {
547
0
        H264_DEC_DEBUG_PRINT("Toggling secondField\n");
548
0
        ps_dec->u1_second_field = 1 - ps_dec->u1_second_field;
549
0
    }
550
11
551
11
    return OK;
552
11
}
553
554
/*****************************************************************************/
555
/*                                                                           */
556
/*  Function Name : init_dpb_size                                            */
557
/*                                                                           */
558
/*  Description   : This function calculates the DBP i4_size in frames          */
559
/*  Inputs        : ps_seq - current sequence params                         */
560
/*                                                                           */
561
/*  Globals       : None                                                     */
562
/*                                                                           */
563
/*  Outputs       : None                                                     */
564
/*                                                                           */
565
/*  Returns       : DPB in frames                                            */
566
/*                                                                           */
567
/*  Issues        : None                                                     */
568
/*                                                                           */
569
/*  Revision History:                                                        */
570
/*                                                                           */
571
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
572
/*         28 04 2005   NS              Draft                                */
573
/*                                                                           */
574
/*****************************************************************************/
575
WORD32 ih264d_get_dpb_size(dec_seq_params_t *ps_seq)
576
1
{
577
1
    WORD32 i4_size;
578
1
    UWORD8 u1_level_idc;
579
1
580
1
    u1_level_idc = ps_seq->u1_level_idc;
581
1
582
1
    switch(u1_level_idc)
583
1
    {
584
1
        case 10:
585
0
            i4_size = 152064;
586
0
            break;
587
1
        case 11:
588
0
            i4_size = 345600;
589
0
            break;
590
1
        case 12:
591
0
            i4_size = 912384;
592
0
            break;
593
1
        case 13:
594
0
            i4_size = 912384;
595
0
            break;
596
1
        case 20:
597
0
            i4_size = 912384;
598
0
            break;
599
1
        case 21:
600
0
            i4_size = 1824768;
601
0
            break;
602
1
        case 22:
603
0
            i4_size = 3110400;
604
0
            break;
605
1
        case 30:
606
0
            i4_size = 3110400;
607
0
            break;
608
1
        case 31:
609
1
            i4_size = 6912000;
610
1
            break;
611
1
        case 32:
612
0
            i4_size = 7864320;
613
0
            break;
614
1
        case 40:
615
0
            i4_size = 12582912;
616
0
            break;
617
1
        case 41:
618
0
            i4_size = 12582912;
619
0
            break;
620
1
        case 42:
621
0
            i4_size = 12582912;
622
0
            break;
623
1
        case 50:
624
0
            i4_size = 42393600;
625
0
            break;
626
1
        case 51:
627
0
            i4_size = 70778880;
628
0
            break;
629
1
        case 52:
630
0
            i4_size = 70778880;
631
0
            break;
632
1
        default:
633
0
            i4_size = 70778880;
634
0
            break;
635
1
    }
636
1
637
1
    i4_size /= (ps_seq->u2_frm_wd_in_mbs * (ps_seq->u2_frm_ht_in_mbs << (1 - ps_seq->u1_frame_mbs_only_flag)));
638
1
    i4_size /= 384;
639
1
    i4_size = MIN(i4_size, 16);
640
1
    i4_size = MAX(i4_size, 1);
641
1
    return (i4_size);
642
1
}
643
644
/**************************************************************************/
645
/* This function initialises the value of ps_dec->u1_recon_mb_grp         */
646
/* ps_dec->u1_recon_mb_grp must satisfy the following criteria            */
647
/*  - multiple of 2 (required for N/2 parse-mvpred design)                */
648
/*  - multiple of 4 (if it is not a frame_mbs_only sequence),             */
649
/*         in this case N/2 itself needs to be even for mbpair processing */
650
/*  - lesser than ps_dec->u2_frm_wd_in_mbs/2 (at least 3 N-Chunks       */
651
/*         should make a row to ensure proper MvTop transferring)         */
652
/**************************************************************************/
653
WORD32 ih264d_init_dec_mb_grp(dec_struct_t *ps_dec)
654
1
{
655
1
    dec_seq_params_t *ps_seq = ps_dec->ps_cur_sps;
656
1
    UWORD8 u1_frm = ps_seq->u1_frame_mbs_only_flag;
657
1
658
1
    ps_dec->u1_recon_mb_grp = ps_dec->u2_frm_wd_in_mbs << ps_seq->u1_mb_aff_flag;
659
1
660
1
    ps_dec->u1_recon_mb_grp_pair = ps_dec->u1_recon_mb_grp >> 1;
661
1
662
1
    if(!ps_dec->u1_recon_mb_grp)
663
0
    {
664
0
        return ERROR_MB_GROUP_ASSGN_T;
665
0
    }
666
1
667
1
    ps_dec->u4_num_mbs_prev_nmb = ps_dec->u1_recon_mb_grp;
668
1
669
1
    return OK;
670
1
}
671
672
673
/*!
674
 **************************************************************************
675
 * \if Function name : ih264d_init_pic \endif
676
 *
677
 * \brief
678
 *    Initializes the picture.
679
 *
680
 * \return
681
 *    0 on Success and Error code otherwise
682
 *
683
 * \note
684
 *    This function is called when first slice of the
685
 *    NON -IDR picture is encountered.
686
 **************************************************************************
687
 */
688
WORD32 ih264d_init_pic(dec_struct_t *ps_dec,
689
                       UWORD16 u2_frame_num,
690
                       WORD32 i4_poc,
691
                       dec_pic_params_t *ps_pps)
692
11
{
693
11
    dec_seq_params_t *ps_seq = ps_pps->ps_sps;
694
11
    prev_seq_params_t * ps_prev_seq_params = &ps_dec->s_prev_seq_params;
695
11
    WORD32 i4_pic_bufs;
696
11
    WORD32 ret;
697
11
698
11
    ps_dec->ps_cur_slice->u2_frame_num = u2_frame_num;
699
11
    ps_dec->ps_cur_slice->i4_poc = i4_poc;
700
11
    ps_dec->ps_cur_pps = ps_pps;
701
11
    ps_dec->ps_cur_pps->pv_codec_handle = ps_dec;
702
11
703
11
    ps_dec->ps_cur_sps = ps_seq;
704
11
    ps_dec->ps_dpb_mgr->i4_max_frm_num = ps_seq->u2_u4_max_pic_num_minus1
705
11
                    + 1;
706
11
707
11
    ps_dec->ps_dpb_mgr->u2_pic_ht = ps_dec->u2_pic_ht;
708
11
    ps_dec->ps_dpb_mgr->u2_pic_wd = ps_dec->u2_pic_wd;
709
11
    ps_dec->i4_pic_type = -1;
710
11
    ps_dec->i4_frametype = -1;
711
11
    ps_dec->i4_content_type = -1;
712
11
713
11
    /*--------------------------------------------------------------------*/
714
11
    /* Get the value of MaxMbAddress and frmheight in Mbs                 */
715
11
    /*--------------------------------------------------------------------*/
716
11
    ps_seq->u2_max_mb_addr =
717
11
                    (ps_seq->u2_frm_wd_in_mbs
718
11
                                    * (ps_dec->u2_pic_ht
719
11
                                                    >> (4
720
11
                                                                    + ps_dec->ps_cur_slice->u1_field_pic_flag)))
721
11
                                    - 1;
722
11
    ps_dec->u2_frm_ht_in_mbs = (ps_dec->u2_pic_ht
723
11
                    >> (4 + ps_dec->ps_cur_slice->u1_field_pic_flag));
724
11
725
11
    /***************************************************************************/
726
11
    /* If change in Level or the required PicBuffers i4_size is more than the  */
727
11
    /* current one FREE the current PicBuffers and allocate affresh            */
728
11
    /***************************************************************************/
729
11
    if(!ps_dec->u1_init_dec_flag)
730
1
    {
731
1
        ps_dec->u1_max_dec_frame_buffering = ih264d_get_dpb_size(ps_seq);
732
1
733
1
        ps_dec->i4_display_delay = ps_dec->u1_max_dec_frame_buffering;
734
1
        if((1 == ps_seq->u1_vui_parameters_present_flag) &&
735
1
           (1 == ps_seq->s_vui.u1_bitstream_restriction_flag))
736
1
        {
737
1
            if(ps_seq->u1_frame_mbs_only_flag == 1)
738
1
                ps_dec->i4_display_delay = ps_seq->s_vui.u4_num_reorder_frames + 1;
739
0
            else
740
0
                ps_dec->i4_display_delay = ps_seq->s_vui.u4_num_reorder_frames * 2 + 2;
741
1
        }
742
1
743
1
        if(IVD_DECODE_FRAME_OUT == ps_dec->e_frm_out_mode)
744
0
            ps_dec->i4_display_delay = 0;
745
1
746
1
        if(ps_dec->u4_share_disp_buf == 0)
747
1
        {
748
1
            if(ps_seq->u1_frame_mbs_only_flag == 1)
749
1
                ps_dec->u1_pic_bufs = ps_dec->i4_display_delay + ps_seq->u1_num_ref_frames + 1;
750
0
            else
751
0
                ps_dec->u1_pic_bufs = ps_dec->i4_display_delay + ps_seq->u1_num_ref_frames * 2 + 2;
752
1
        }
753
0
        else
754
0
        {
755
0
            ps_dec->u1_pic_bufs = (WORD32)ps_dec->u4_num_disp_bufs;
756
0
        }
757
1
758
1
        /* Ensure at least two buffers are allocated */
759
1
        ps_dec->u1_pic_bufs = MAX(ps_dec->u1_pic_bufs, 2);
760
1
761
1
        if(ps_dec->u4_share_disp_buf == 0)
762
1
            ps_dec->u1_pic_bufs = MIN(ps_dec->u1_pic_bufs,
763
1
                                      (H264_MAX_REF_PICS * 2));
764
1
765
1
        ps_dec->u1_max_dec_frame_buffering = MIN(
766
1
                        ps_dec->u1_max_dec_frame_buffering,
767
1
                        ps_dec->u1_pic_bufs);
768
1
769
1
        /* Temporary hack to run Tractor Cav/Cab/MbAff Profiler streams  also for CAFI1_SVA_C.264 in conformance*/
770
1
        if(ps_dec->u1_init_dec_flag)
771
0
        {
772
0
            ih264d_release_pics_in_dpb((void *)ps_dec,
773
0
                                       ps_dec->u1_pic_bufs);
774
0
            ih264d_release_display_bufs(ps_dec);
775
0
            ih264d_reset_ref_bufs(ps_dec->ps_dpb_mgr);
776
0
        }
777
1
778
1
        /*********************************************************************/
779
1
        /* Configuring decoder parameters based on level and then            */
780
1
        /* fresh pointer initialisation in decoder scratch and state buffers */
781
1
        /*********************************************************************/
782
1
        if(!ps_dec->u1_init_dec_flag ||
783
1
                ((ps_seq->u1_level_idc < H264_LEVEL_3_0) ^ (ps_prev_seq_params->u1_level_idc < H264_LEVEL_3_0)))
784
1
        {
785
1
            ret = ih264d_init_dec_mb_grp(ps_dec);
786
1
            if(ret != OK)
787
1
                return ret;
788
1
        }
789
1
790
1
        ret = ih264d_allocate_dynamic_bufs(ps_dec);
791
1
        if(ret != OK)
792
1
        {
793
0
            /* Free any dynamic buffers that are allocated */
794
0
            ih264d_free_dynamic_bufs(ps_dec);
795
0
            ps_dec->i4_error_code = IVD_MEM_ALLOC_FAILED;
796
0
            return IVD_MEM_ALLOC_FAILED;
797
0
        }
798
1
799
1
        ret = ih264d_create_pic_buffers(ps_dec->u1_pic_bufs,
800
1
                                        ps_dec);
801
1
        if(ret != OK)
802
1
            return ret;
803
1
804
1
805
1
806
1
        ret = ih264d_create_mv_bank(ps_dec, ps_dec->u2_pic_wd,
807
1
                                    ps_dec->u2_pic_ht);
808
1
        if(ret != OK)
809
1
            return ret;
810
1
811
1
        /* In shared mode, set all of them as used by display */
812
1
        if(ps_dec->u4_share_disp_buf == 1)
813
0
        {
814
0
            WORD32 i;
815
0
816
0
            for(i = 0; i < ps_dec->u1_pic_bufs; i++)
817
0
            {
818
0
                ih264_buf_mgr_set_status((buf_mgr_t *)ps_dec->pv_pic_buf_mgr, i,
819
0
                                         BUF_MGR_IO);
820
0
            }
821
0
        }
822
1
823
1
        ps_dec->u1_init_dec_flag = 1;
824
1
        ps_prev_seq_params->u2_frm_wd_in_mbs = ps_seq->u2_frm_wd_in_mbs;
825
1
        ps_prev_seq_params->u1_level_idc = ps_seq->u1_level_idc;
826
1
        ps_prev_seq_params->u1_profile_idc = ps_seq->u1_profile_idc;
827
1
        ps_prev_seq_params->u2_frm_ht_in_mbs = ps_seq->u2_frm_ht_in_mbs;
828
1
        ps_prev_seq_params->u1_frame_mbs_only_flag =
829
1
                        ps_seq->u1_frame_mbs_only_flag;
830
1
        ps_prev_seq_params->u1_direct_8x8_inference_flag =
831
1
                        ps_seq->u1_direct_8x8_inference_flag;
832
1
833
1
        ps_dec->i4_cur_display_seq = 0;
834
1
        ps_dec->i4_prev_max_display_seq = 0;
835
1
        ps_dec->i4_max_poc = 0;
836
1
837
1
        {
838
1
            /* 0th entry of CtxtIncMbMap will be always be containing default values
839
1
             for CABAC context representing MB not available */
840
1
            ctxt_inc_mb_info_t *p_DefCtxt = ps_dec->p_ctxt_inc_mb_map - 1;
841
1
            UWORD8 *pu1_temp;
842
1
            WORD8 i;
843
1
            p_DefCtxt->u1_mb_type = CAB_SKIP;
844
1
845
1
            p_DefCtxt->u1_cbp = 0x0f;
846
1
            p_DefCtxt->u1_intra_chroma_pred_mode = 0;
847
1
848
1
            p_DefCtxt->u1_yuv_dc_csbp = 0x7;
849
1
850
1
            p_DefCtxt->u1_transform8x8_ctxt = 0;
851
1
852
1
            pu1_temp = (UWORD8*)p_DefCtxt->i1_ref_idx;
853
5
            for(i = 0; i < 4; i++, pu1_temp++)
854
4
                (*pu1_temp) = 0;
855
1
            pu1_temp = (UWORD8*)p_DefCtxt->u1_mv;
856
17
            for(i = 0; i < 16; i++, pu1_temp++)
857
16
                (*pu1_temp) = 0;
858
1
            ps_dec->ps_def_ctxt_mb_info = p_DefCtxt;
859
1
        }
860
1
861
1
    }
862
11
    /* reset DBP commands read u4_flag */
863
11
    ps_dec->ps_dpb_cmds->u1_dpb_commands_read = 0;
864
11
865
11
    return OK;
866
11
}
867
868
/*****************************************************************************/
869
/*                                                                           */
870
/*  Function Name : ih264d_get_next_display_field                                   */
871
/*                                                                           */
872
/*  Description   : Application calls this module to get the next field      */
873
/*                  to be displayed                                          */
874
/*                                                                           */
875
/*  Inputs        : 1.   IBUFAPI_Handle Hnadle to the Display buffer         */
876
/*                  2.   IH264DEC_DispUnit    Pointer to the display struct  */
877
/*                                                                           */
878
/*  Globals       :                                                          */
879
/*                                                                           */
880
/*                                                                           */
881
/*  Processing    : None                                                     */
882
/*  Outputs       : None                                                     */
883
/*  Returns       : None                                                     */
884
/*  Issues        : None                                                     */
885
/*                                                                           */
886
/*  Revision History:                                                        */
887
/*                                                                           */
888
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
889
/*         27 05 2005   Ittiam          Draft                                */
890
/*                                                                           */
891
/*****************************************************************************/
892
893
WORD32 ih264d_get_next_display_field(dec_struct_t * ps_dec,
894
                                  ivd_out_bufdesc_t *ps_out_buffer,
895
                                  ivd_get_display_frame_op_t *pv_disp_op)
896
11
{
897
11
    pic_buffer_t *pic_buf;
898
11
899
11
    UWORD8 i1_cur_fld;
900
11
    WORD32 u4_api_ret = -1;
901
11
    WORD32 i4_disp_buf_id;
902
11
    iv_yuv_buf_t *ps_op_frm;
903
11
904
11
905
11
906
11
    ps_op_frm = &(ps_dec->s_disp_frame_info);
907
11
    H264_MUTEX_LOCK(&ps_dec->process_disp_mutex);
908
11
    pic_buf = (pic_buffer_t *)ih264_disp_mgr_get(
909
11
                    (disp_mgr_t *)ps_dec->pv_disp_buf_mgr, &i4_disp_buf_id);
910
11
    ps_dec->u4_num_fld_in_frm = 0;
911
11
    u4_api_ret = -1;
912
11
    pv_disp_op->u4_ts = -1;
913
11
    pv_disp_op->e_output_format = ps_dec->u1_chroma_format;
914
11
915
11
    pv_disp_op->s_disp_frm_buf.pv_y_buf = ps_out_buffer->pu1_bufs[0];
916
11
    pv_disp_op->s_disp_frm_buf.pv_u_buf = ps_out_buffer->pu1_bufs[1];
917
11
    pv_disp_op->s_disp_frm_buf.pv_v_buf = ps_out_buffer->pu1_bufs[2];
918
11
    if(pic_buf != NULL)
919
11
    {
920
9
        pv_disp_op->e4_fld_type = 0;
921
9
        pv_disp_op->u4_disp_buf_id = i4_disp_buf_id;
922
9
923
9
        ps_op_frm->u4_y_ht = pic_buf->u2_disp_height << 1;
924
9
        ps_op_frm->u4_u_ht = ps_op_frm->u4_v_ht = ps_op_frm->u4_y_ht >> 1;
925
9
        ps_op_frm->u4_y_wd = pic_buf->u2_disp_width;
926
9
927
9
        ps_op_frm->u4_u_wd = ps_op_frm->u4_v_wd = ps_op_frm->u4_y_wd >> 1;
928
9
929
9
        ps_op_frm->u4_y_strd = pic_buf->u2_frm_wd_y;
930
9
        ps_op_frm->u4_u_strd = ps_op_frm->u4_v_strd = pic_buf->u2_frm_wd_uv;
931
9
932
9
        /* ! */
933
9
        pv_disp_op->u4_ts = pic_buf->u4_ts;
934
9
935
9
        /* set the start of the Y, U and V buffer pointer for display    */
936
9
        ps_op_frm->pv_y_buf = pic_buf->pu1_buf1 + pic_buf->u2_crop_offset_y;
937
9
        ps_op_frm->pv_u_buf = pic_buf->pu1_buf2 + pic_buf->u2_crop_offset_uv;
938
9
        ps_op_frm->pv_v_buf = pic_buf->pu1_buf3 + pic_buf->u2_crop_offset_uv;
939
9
        ps_dec->u4_num_fld_in_frm++;
940
9
        ps_dec->u4_num_fld_in_frm++;
941
9
        u4_api_ret = 0;
942
9
943
9
        if(pic_buf->u1_picturetype == 0)
944
9
            pv_disp_op->u4_progressive_frame_flag = 1;
945
0
        else
946
0
            pv_disp_op->u4_progressive_frame_flag = 0;
947
9
948
9
    } H264_MUTEX_UNLOCK(&ps_dec->process_disp_mutex);
949
11
    pv_disp_op->u4_error_code = u4_api_ret;
950
11
    pv_disp_op->e_pic_type = 0xFFFFFFFF; //Junk;
951
11
952
11
    if(u4_api_ret)
953
2
    {
954
2
        pv_disp_op->u4_error_code = 1; //put a proper error code here
955
2
    }
956
9
    else
957
9
    {
958
9
959
9
        //Release the buffer if being sent for display
960
9
        UWORD32 temp;
961
9
        UWORD32 dest_inc_Y = 0, dest_inc_UV = 0;
962
9
963
9
        pv_disp_op->s_disp_frm_buf.u4_y_wd = temp = MIN(ps_op_frm->u4_y_wd,
964
9
                                                        ps_op_frm->u4_y_strd);
965
9
        pv_disp_op->s_disp_frm_buf.u4_u_wd = pv_disp_op->s_disp_frm_buf.u4_y_wd
966
9
                        >> 1;
967
9
        pv_disp_op->s_disp_frm_buf.u4_v_wd = pv_disp_op->s_disp_frm_buf.u4_y_wd
968
9
                        >> 1;
969
9
970
9
        pv_disp_op->s_disp_frm_buf.u4_y_ht = ps_op_frm->u4_y_ht;
971
9
        pv_disp_op->s_disp_frm_buf.u4_u_ht = pv_disp_op->s_disp_frm_buf.u4_y_ht
972
9
                        >> 1;
973
9
        pv_disp_op->s_disp_frm_buf.u4_v_ht = pv_disp_op->s_disp_frm_buf.u4_y_ht
974
9
                        >> 1;
975
9
        if(0 == ps_dec->u4_share_disp_buf)
976
9
        {
977
9
            pv_disp_op->s_disp_frm_buf.u4_y_strd =
978
9
                            pv_disp_op->s_disp_frm_buf.u4_y_wd;
979
9
            pv_disp_op->s_disp_frm_buf.u4_u_strd =
980
9
                            pv_disp_op->s_disp_frm_buf.u4_y_wd >> 1;
981
9
            pv_disp_op->s_disp_frm_buf.u4_v_strd =
982
9
                            pv_disp_op->s_disp_frm_buf.u4_y_wd >> 1;
983
9
984
9
        }
985
0
        else
986
0
        {
987
0
            pv_disp_op->s_disp_frm_buf.u4_y_strd = ps_op_frm->u4_y_strd;
988
0
        }
989
9
990
9
        if(ps_dec->u4_app_disp_width)
991
9
        {
992
9
            pv_disp_op->s_disp_frm_buf.u4_y_strd = MAX(
993
9
                            ps_dec->u4_app_disp_width,
994
9
                            pv_disp_op->s_disp_frm_buf.u4_y_strd);
995
9
        }
996
9
997
9
        pv_disp_op->u4_error_code = 0;
998
9
        if(pv_disp_op->e_output_format == IV_YUV_420P)
999
9
        {
1000
9
            UWORD32 i;
1001
9
            pv_disp_op->s_disp_frm_buf.u4_u_strd =
1002
9
                            pv_disp_op->s_disp_frm_buf.u4_y_strd >> 1;
1003
9
            pv_disp_op->s_disp_frm_buf.u4_v_strd =
1004
9
                            pv_disp_op->s_disp_frm_buf.u4_y_strd >> 1;
1005
9
1006
9
            pv_disp_op->s_disp_frm_buf.u4_u_wd = ps_op_frm->u4_y_wd >> 1;
1007
9
            pv_disp_op->s_disp_frm_buf.u4_v_wd = ps_op_frm->u4_y_wd >> 1;
1008
9
1009
9
            if(1 == ps_dec->u4_share_disp_buf)
1010
0
            {
1011
0
                pv_disp_op->s_disp_frm_buf.pv_y_buf = ps_op_frm->pv_y_buf;
1012
0
1013
0
                for(i = 0; i < MAX_DISP_BUFS_NEW; i++)
1014
0
                {
1015
0
                    UWORD8 *buf = ps_dec->disp_bufs[i].buf[0];
1016
0
                    buf += ps_dec->disp_bufs[i].u4_ofst[0];
1017
0
                    if(((UWORD8 *)pv_disp_op->s_disp_frm_buf.pv_y_buf
1018
0
                                    - pic_buf->u2_crop_offset_y) == buf)
1019
0
                    {
1020
0
                        buf = ps_dec->disp_bufs[i].buf[1];
1021
0
                        buf += ps_dec->disp_bufs[i].u4_ofst[1];
1022
0
                        pv_disp_op->s_disp_frm_buf.pv_u_buf = buf
1023
0
                                        + (pic_buf->u2_crop_offset_uv
1024
0
                                           / YUV420SP_FACTOR);
1025
0
1026
0
                        buf = ps_dec->disp_bufs[i].buf[2];
1027
0
                        buf += ps_dec->disp_bufs[i].u4_ofst[2];
1028
0
                        pv_disp_op->s_disp_frm_buf.pv_v_buf = buf
1029
0
                                        + (pic_buf->u2_crop_offset_uv
1030
0
                                           / YUV420SP_FACTOR);
1031
0
1032
0
                    }
1033
0
                }
1034
0
            }
1035
9
1036
9
        }
1037
0
        else if((pv_disp_op->e_output_format == IV_YUV_420SP_UV)
1038
0
                        || (pv_disp_op->e_output_format == IV_YUV_420SP_VU))
1039
0
        {
1040
0
            pv_disp_op->s_disp_frm_buf.u4_u_strd =
1041
0
                            pv_disp_op->s_disp_frm_buf.u4_y_strd;
1042
0
            pv_disp_op->s_disp_frm_buf.u4_v_strd = 0;
1043
0
1044
0
            if(1 == ps_dec->u4_share_disp_buf)
1045
0
            {
1046
0
                UWORD32 i;
1047
0
1048
0
                pv_disp_op->s_disp_frm_buf.pv_y_buf = ps_op_frm->pv_y_buf;
1049
0
1050
0
                for(i = 0; i < MAX_DISP_BUFS_NEW; i++)
1051
0
                {
1052
0
                    UWORD8 *buf = ps_dec->disp_bufs[i].buf[0];
1053
0
                    buf += ps_dec->disp_bufs[i].u4_ofst[0];
1054
0
                    if((UWORD8 *)pv_disp_op->s_disp_frm_buf.pv_y_buf
1055
0
                                    - pic_buf->u2_crop_offset_y == buf)
1056
0
                    {
1057
0
                        buf = ps_dec->disp_bufs[i].buf[1];
1058
0
                        buf += ps_dec->disp_bufs[i].u4_ofst[1];
1059
0
                        pv_disp_op->s_disp_frm_buf.pv_u_buf = buf
1060
0
                                        + pic_buf->u2_crop_offset_uv;
1061
0
                        ;
1062
0
1063
0
                        buf = ps_dec->disp_bufs[i].buf[2];
1064
0
                        buf += ps_dec->disp_bufs[i].u4_ofst[2];
1065
0
                        pv_disp_op->s_disp_frm_buf.pv_v_buf = buf
1066
0
                                        + pic_buf->u2_crop_offset_uv;
1067
0
                        ;
1068
0
                    }
1069
0
                }
1070
0
            }
1071
0
            pv_disp_op->s_disp_frm_buf.u4_u_wd =
1072
0
                            pv_disp_op->s_disp_frm_buf.u4_y_wd;
1073
0
            pv_disp_op->s_disp_frm_buf.u4_v_wd = 0;
1074
0
1075
0
        }
1076
0
        else if((pv_disp_op->e_output_format == IV_RGB_565)
1077
0
                        || (pv_disp_op->e_output_format == IV_YUV_422ILE))
1078
0
        {
1079
0
1080
0
            pv_disp_op->s_disp_frm_buf.u4_u_strd = 0;
1081
0
            pv_disp_op->s_disp_frm_buf.u4_v_strd = 0;
1082
0
            pv_disp_op->s_disp_frm_buf.u4_u_wd = 0;
1083
0
            pv_disp_op->s_disp_frm_buf.u4_v_wd = 0;
1084
0
            pv_disp_op->s_disp_frm_buf.u4_u_ht = 0;
1085
0
            pv_disp_op->s_disp_frm_buf.u4_v_ht = 0;
1086
0
1087
0
        }
1088
9
1089
9
1090
9
    }
1091
11
1092
11
    return u4_api_ret;
1093
11
}
1094
1095
1096
/*****************************************************************************/
1097
/*  Function Name : ih264d_release_display_field                                         */
1098
/*                                                                           */
1099
/*  Description   : This function releases the display field that was returned   */
1100
/*                  here.                                                    */
1101
/*  Inputs        : ps_dec - Decoder parameters                              */
1102
/*  Globals       : None                                                     */
1103
/*  Processing    : Refer bumping process in the standard                    */
1104
/*  Outputs       : Assigns display sequence number.                         */
1105
/*  Returns       : None                                                     */
1106
/*                                                                           */
1107
/*  Issues        : None                                                     */
1108
/*                                                                           */
1109
/*  Revision History:                                                        */
1110
/*                                                                           */
1111
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1112
/*         27 04 2005   NS              Draft                                */
1113
/*                                                                           */
1114
/*****************************************************************************/
1115
void ih264d_release_display_field(dec_struct_t *ps_dec,
1116
                                  ivd_get_display_frame_op_t *pv_disp_op)
1117
13
{
1118
13
    if(1 == pv_disp_op->u4_error_code)
1119
4
    {
1120
4
        if(1 == ps_dec->u1_flushfrm)
1121
0
        {
1122
0
            UWORD32 i;
1123
0
1124
0
            if(1 == ps_dec->u4_share_disp_buf)
1125
0
            {
1126
0
                H264_MUTEX_LOCK(&ps_dec->process_disp_mutex);
1127
0
                for(i = 0; i < (MAX_DISP_BUFS_NEW); i++)
1128
0
                {
1129
0
                    if(1 == ps_dec->u4_disp_buf_mapping[i])
1130
0
                    {
1131
0
                        ih264_buf_mgr_release(
1132
0
                                        (buf_mgr_t *)ps_dec->pv_pic_buf_mgr, i,
1133
0
                                        BUF_MGR_IO);
1134
0
                        ps_dec->u4_disp_buf_mapping[i] = 0;
1135
0
                    }
1136
0
                } H264_MUTEX_UNLOCK(&ps_dec->process_disp_mutex);
1137
0
1138
0
                memset(ps_dec->u4_disp_buf_to_be_freed, 0,
1139
0
                       (MAX_DISP_BUFS_NEW) * sizeof(UWORD32));
1140
0
                for(i = 0; i < ps_dec->u1_pic_bufs; i++)
1141
0
                    ps_dec->u4_disp_buf_mapping[i] = 1;
1142
0
            }
1143
0
            ps_dec->u1_flushfrm = 0;
1144
0
1145
0
        }
1146
4
    }
1147
9
    else
1148
9
    {
1149
9
        H264_MUTEX_LOCK(&ps_dec->process_disp_mutex);
1150
9
1151
9
        if(0 == ps_dec->u4_share_disp_buf)
1152
9
        {
1153
9
            ih264_buf_mgr_release((buf_mgr_t *)ps_dec->pv_pic_buf_mgr,
1154
9
                                  pv_disp_op->u4_disp_buf_id,
1155
9
                                  BUF_MGR_IO);
1156
9
1157
9
        }
1158
0
        else
1159
0
        {
1160
0
            ps_dec->u4_disp_buf_mapping[pv_disp_op->u4_disp_buf_id] = 1;
1161
0
        } H264_MUTEX_UNLOCK(&ps_dec->process_disp_mutex);
1162
9
1163
9
    }
1164
13
}
1165
/*****************************************************************************/
1166
/*  Function Name : ih264d_assign_display_seq                                         */
1167
/*                                                                           */
1168
/*  Description   : This function implments bumping process. Every outgoing  */
1169
/*                  frame from DPB is assigned a display sequence number     */
1170
/*                  which increases monotonically. System looks for this     */
1171
/*                  number to display a frame.                              */
1172
/*                  here.                                                    */
1173
/*  Inputs        : ps_dec - Decoder parameters                              */
1174
/*  Globals       : None                                                     */
1175
/*  Processing    : Refer bumping process in the standard                    */
1176
/*  Outputs       : Assigns display sequence number.                         */
1177
/*  Returns       : None                                                     */
1178
/*                                                                           */
1179
/*  Issues        : None                                                     */
1180
/*                                                                           */
1181
/*  Revision History:                                                        */
1182
/*                                                                           */
1183
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1184
/*         27 04 2005   NS              Draft                                */
1185
/*                                                                           */
1186
/*****************************************************************************/
1187
WORD32 ih264d_assign_display_seq(dec_struct_t *ps_dec)
1188
11
{
1189
11
    WORD32 i;
1190
11
    WORD32 i4_min_poc;
1191
11
    WORD32 i4_min_poc_buf_id;
1192
11
    WORD32 i4_min_index;
1193
11
    dpb_manager_t *ps_dpb_mgr = ps_dec->ps_dpb_mgr;
1194
11
    WORD32 (*i4_poc_buf_id_map)[3] = ps_dpb_mgr->ai4_poc_buf_id_map;
1195
11
1196
11
    i4_min_poc = 0x7fffffff;
1197
11
    i4_min_poc_buf_id = -1;
1198
11
    i4_min_index = -1;
1199
11
1200
11
    if(ps_dpb_mgr->i1_poc_buf_id_entries >= ps_dec->i4_display_delay)
1201
0
    {
1202
0
        for(i = 0; i < MAX_FRAMES; i++)
1203
0
        {
1204
0
            if((i4_poc_buf_id_map[i][0] != -1)
1205
0
                            && (DO_NOT_DISP
1206
0
                                            != ps_dpb_mgr->ai4_poc_buf_id_map[i][0]))
1207
0
            {
1208
0
                if(i4_poc_buf_id_map[i][1] < i4_min_poc)
1209
0
                {
1210
0
                    i4_min_poc = i4_poc_buf_id_map[i][1];
1211
0
                    i4_min_poc_buf_id = i4_poc_buf_id_map[i][0];
1212
0
                    i4_min_index = i;
1213
0
                }
1214
0
            }
1215
0
        }
1216
0
1217
0
        if((i4_min_index != -1) && (DO_NOT_DISP != i4_min_poc_buf_id))
1218
0
        {
1219
0
            ps_dec->i4_cur_display_seq++;
1220
0
            ih264_disp_mgr_add(
1221
0
                            (disp_mgr_t *)ps_dec->pv_disp_buf_mgr,
1222
0
                            i4_min_poc_buf_id, ps_dec->i4_cur_display_seq,
1223
0
                            ps_dec->apv_buf_id_pic_buf_map[i4_min_poc_buf_id]);
1224
0
            i4_poc_buf_id_map[i4_min_index][0] = -1;
1225
0
            i4_poc_buf_id_map[i4_min_index][1] = 0x7fffffff;
1226
0
            ps_dpb_mgr->i1_poc_buf_id_entries--;
1227
0
        }
1228
0
        else if(DO_NOT_DISP == i4_min_poc_buf_id)
1229
0
        {
1230
0
            WORD32 i4_error_code;
1231
0
            i4_error_code = ERROR_GAPS_IN_FRM_NUM;
1232
0
//          i4_error_code |= 1<<IVD_CORRUPTEDDATA;
1233
0
            return i4_error_code;
1234
0
        }
1235
11
    }
1236
11
    return OK;
1237
11
}
1238
1239
/*****************************************************************************/
1240
/*                                                                           */
1241
/*  Function Name : ih264d_release_display_bufs                                       */
1242
/*                                                                           */
1243
/*  Description   : This function implments bumping process when mmco = 5.   */
1244
/*                  Each outgoing frame from DPB is assigned a display       */
1245
/*                  sequence number which increases monotonically. System    */
1246
/*                  looks for this number to display a frame.                */
1247
/*  Inputs        : ps_dec - Decoder parameters                              */
1248
/*  Globals       : None                                                     */
1249
/*  Processing    : Refer bumping process in the standard for mmco = 5       */
1250
/*  Outputs       : Assigns display sequence number.                         */
1251
/*  Returns       : None                                                     */
1252
/*                                                                           */
1253
/*  Issues        : None                                                     */
1254
/*                                                                           */
1255
/*  Revision History:                                                        */
1256
/*                                                                           */
1257
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1258
/*         27 04 2005   NS              Draft                                */
1259
/*                                                                           */
1260
/*****************************************************************************/
1261
void ih264d_release_display_bufs(dec_struct_t *ps_dec)
1262
11
{
1263
11
    WORD32 i, j;
1264
11
    WORD32 i4_min_poc;
1265
11
    WORD32 i4_min_poc_buf_id;
1266
11
    WORD32 i4_min_index;
1267
11
    dpb_manager_t *ps_dpb_mgr = ps_dec->ps_dpb_mgr;
1268
11
    WORD32 (*i4_poc_buf_id_map)[3] = ps_dpb_mgr->ai4_poc_buf_id_map;
1269
11
1270
11
    i4_min_poc = 0x7fffffff;
1271
11
    i4_min_poc_buf_id = -1;
1272
11
    i4_min_index = -1;
1273
11
1274
11
    ih264d_delete_nonref_nondisplay_pics(ps_dpb_mgr);
1275
11
1276
21
    for(j = 0; j < ps_dpb_mgr->i1_poc_buf_id_entries; j++)
1277
10
    {
1278
10
        i4_min_poc = 0x7fffffff;
1279
170
        for(i = 0; i < MAX_FRAMES; i++)
1280
160
        {
1281
160
            if(i4_poc_buf_id_map[i][0] != -1)
1282
10
            {
1283
10
                if(i4_poc_buf_id_map[i][1] < i4_min_poc)
1284
10
                {
1285
10
                    i4_min_poc = i4_poc_buf_id_map[i][1];
1286
10
                    i4_min_poc_buf_id = i4_poc_buf_id_map[i][0];
1287
10
                    i4_min_index = i;
1288
10
                }
1289
10
            }
1290
160
        }
1291
10
1292
10
        if(DO_NOT_DISP != i4_min_poc_buf_id)
1293
10
        {
1294
10
            ps_dec->i4_cur_display_seq++;
1295
10
            ih264_disp_mgr_add(
1296
10
                            (disp_mgr_t *)ps_dec->pv_disp_buf_mgr,
1297
10
                            i4_min_poc_buf_id, ps_dec->i4_cur_display_seq,
1298
10
                            ps_dec->apv_buf_id_pic_buf_map[i4_min_poc_buf_id]);
1299
10
            i4_poc_buf_id_map[i4_min_index][0] = -1;
1300
10
            i4_poc_buf_id_map[i4_min_index][1] = 0x7fffffff;
1301
10
            ps_dpb_mgr->ai4_poc_buf_id_map[i4_min_index][2] = 0;
1302
10
        }
1303
0
        else
1304
0
        {
1305
0
            i4_poc_buf_id_map[i4_min_index][0] = -1;
1306
0
            i4_poc_buf_id_map[i4_min_index][1] = 0x7fffffff;
1307
0
            ps_dpb_mgr->ai4_poc_buf_id_map[i4_min_index][2] = 0;
1308
0
        }
1309
10
    }
1310
11
    ps_dpb_mgr->i1_poc_buf_id_entries = 0;
1311
11
    ps_dec->i4_prev_max_display_seq = ps_dec->i4_prev_max_display_seq
1312
11
                    + ps_dec->i4_max_poc + ps_dec->u1_max_dec_frame_buffering
1313
11
                    + 1;
1314
11
    ps_dec->i4_max_poc = 0;
1315
11
}
1316
1317
/*****************************************************************************/
1318
/*                                                                           */
1319
/*  Function Name : ih264d_assign_pic_num                                           */
1320
/*                                                                           */
1321
/*  Description   : This function assigns pic num to each reference frame    */
1322
/*                  depending on the cur_frame_num as speified in section    */
1323
/*                  8.2.4.1                                                  */
1324
/*                                                                           */
1325
/*  Inputs        : ps_dec                                                   */
1326
/*                                                                           */
1327
/*  Globals       : NO globals used                                          */
1328
/*                                                                           */
1329
/*  Processing    : for all ST pictures                                      */
1330
/*                    if( FrameNum > cur_frame_num)                          */
1331
/*                    PicNum = FrameNum - MaxFrameNum                        */
1332
/*                    else                                                   */
1333
/*                    PicNum = FrameNum                                      */
1334
/*                                                                           */
1335
/*  Returns       : void                                                     */
1336
/*                                                                           */
1337
/*  Issues        : NO                                                       */
1338
/*                                                                           */
1339
/*  Revision History:                                                        */
1340
/*                                                                           */
1341
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1342
/*         13 07 2002   Jay             Draft                                */
1343
/*                                                                           */
1344
/*****************************************************************************/
1345
1346
void ih264d_assign_pic_num(dec_struct_t *ps_dec)
1347
11
{
1348
11
    dpb_manager_t *ps_dpb_mgr;
1349
11
    struct dpb_info_t *ps_next_dpb;
1350
11
    WORD8 i;
1351
11
    WORD32 i4_cur_frame_num, i4_max_frame_num;
1352
11
    WORD32 i4_ref_frame_num;
1353
11
    UWORD8 u1_fld_pic_flag = ps_dec->ps_cur_slice->u1_field_pic_flag;
1354
11
1355
11
    i4_max_frame_num = ps_dec->ps_cur_sps->u2_u4_max_pic_num_minus1 + 1;
1356
11
    i4_cur_frame_num = ps_dec->ps_cur_pic->i4_frame_num;
1357
11
    ps_dpb_mgr = ps_dec->ps_dpb_mgr;
1358
11
1359
11
    /* Start from ST head */
1360
11
    ps_next_dpb = ps_dpb_mgr->ps_dpb_st_head;
1361
21
    for(i = 0; i < ps_dpb_mgr->u1_num_st_ref_bufs; i++)
1362
10
    {
1363
10
        WORD32 i4_pic_num;
1364
10
1365
10
        i4_ref_frame_num = ps_next_dpb->ps_pic_buf->i4_frame_num;
1366
10
        if(i4_ref_frame_num > i4_cur_frame_num)
1367
0
        {
1368
0
            /* RefPic Buf frame_num is before Current frame_num in decode order */
1369
0
            i4_pic_num = i4_ref_frame_num - i4_max_frame_num;
1370
0
        }
1371
10
        else
1372
10
        {
1373
10
            /* RefPic Buf frame_num is after Current frame_num in decode order */
1374
10
            i4_pic_num = i4_ref_frame_num;
1375
10
        }
1376
10
1377
10
        ps_next_dpb->ps_pic_buf->i4_pic_num = i4_pic_num;
1378
10
        ps_next_dpb->i4_frame_num = i4_pic_num;
1379
10
        ps_next_dpb->ps_pic_buf->u1_long_term_frm_idx = MAX_REF_BUFS + 1;
1380
10
        if(u1_fld_pic_flag)
1381
0
        {
1382
0
            /* Assign the pic num to top fields and bot fields */
1383
0
1384
0
            ps_next_dpb->s_top_field.i4_pic_num = i4_pic_num * 2
1385
0
                            + !(ps_dec->ps_cur_slice->u1_bottom_field_flag);
1386
0
            ps_next_dpb->s_bot_field.i4_pic_num = i4_pic_num * 2
1387
0
                            + ps_dec->ps_cur_slice->u1_bottom_field_flag;
1388
0
        }
1389
10
        /* Chase the next link */
1390
10
        ps_next_dpb = ps_next_dpb->ps_prev_short;
1391
10
    }
1392
11
1393
11
    if(ps_dec->ps_cur_sps->u1_gaps_in_frame_num_value_allowed_flag
1394
11
                    && ps_dpb_mgr->u1_num_gaps)
1395
0
    {
1396
0
        WORD32 i4_start_frm, i4_end_frm;
1397
0
        /* Assign pic numbers for gaps */
1398
0
        for(i = 0; i < MAX_FRAMES; i++)
1399
0
        {
1400
0
            i4_start_frm = ps_dpb_mgr->ai4_gaps_start_frm_num[i];
1401
0
            if(i4_start_frm != INVALID_FRAME_NUM)
1402
0
            {
1403
0
                if(i4_start_frm > i4_cur_frame_num)
1404
0
                {
1405
0
                    /* gap's frame_num is before Current frame_num in
1406
0
                     decode order */
1407
0
                    i4_start_frm -= i4_max_frame_num;
1408
0
                }
1409
0
                ps_dpb_mgr->ai4_gaps_start_frm_num[i] = i4_start_frm;
1410
0
                i4_end_frm = ps_dpb_mgr->ai4_gaps_end_frm_num[i];
1411
0
1412
0
                if(i4_end_frm > i4_cur_frame_num)
1413
0
                {
1414
0
                    /* gap's frame_num is before Current frame_num in
1415
0
                     decode order */
1416
0
                    i4_end_frm -= i4_max_frame_num;
1417
0
                }
1418
0
                ps_dpb_mgr->ai4_gaps_end_frm_num[i] = i4_end_frm;
1419
0
            }
1420
0
        }
1421
0
    }
1422
11
}
1423
1424
/*!
1425
 **************************************************************************
1426
 * \if Function name : ih264d_update_qp \endif
1427
 *
1428
 * \brief
1429
 *    Updates the values of QP and its related entities
1430
 *
1431
 * \return
1432
 *    0 on Success and Error code otherwise
1433
 *
1434
 **************************************************************************
1435
 */
1436
WORD32 ih264d_update_qp(dec_struct_t * ps_dec, const WORD8 i1_qp)
1437
11
{
1438
11
    WORD32 i_temp;
1439
11
    i_temp = (ps_dec->u1_qp + i1_qp + 52) % 52;
1440
11
1441
11
    if((i_temp < 0) || (i_temp > 51) || (i1_qp < -26) || (i1_qp > 25))
1442
0
        return ERROR_INV_RANGE_QP_T;
1443
11
1444
11
    ps_dec->u1_qp = i_temp;
1445
11
    ps_dec->u1_qp_y_rem6 = ps_dec->u1_qp % 6;
1446
11
    ps_dec->u1_qp_y_div6 = ps_dec->u1_qp / 6;
1447
11
    i_temp = CLIP3(0, 51, ps_dec->u1_qp + ps_dec->ps_cur_pps->i1_chroma_qp_index_offset);
1448
11
    ps_dec->u1_qp_u_rem6 = MOD(gau1_ih264d_qp_scale_cr[12 + i_temp], 6);
1449
11
    ps_dec->u1_qp_u_div6 = DIV(gau1_ih264d_qp_scale_cr[12 + i_temp], 6);
1450
11
1451
11
    i_temp = CLIP3(0, 51, ps_dec->u1_qp + ps_dec->ps_cur_pps->i1_second_chroma_qp_index_offset);
1452
11
    ps_dec->u1_qp_v_rem6 = MOD(gau1_ih264d_qp_scale_cr[12 + i_temp], 6);
1453
11
    ps_dec->u1_qp_v_div6 = DIV(gau1_ih264d_qp_scale_cr[12 + i_temp], 6);
1454
11
1455
11
    ps_dec->pu2_quant_scale_y =
1456
11
                    gau2_ih264_iquant_scale_4x4[ps_dec->u1_qp_y_rem6];
1457
11
    ps_dec->pu2_quant_scale_u =
1458
11
                    gau2_ih264_iquant_scale_4x4[ps_dec->u1_qp_u_rem6];
1459
11
    ps_dec->pu2_quant_scale_v =
1460
11
                    gau2_ih264_iquant_scale_4x4[ps_dec->u1_qp_v_rem6];
1461
11
    return OK;
1462
11
}
1463
1464
/*****************************************************************************/
1465
/*                                                                           */
1466
/*  Function Name : ih264d_decode_gaps_in_frame_num                                 */
1467
/*                                                                           */
1468
/*  Description   : This function decodes gaps in frame number               */
1469
/*                                                                           */
1470
/*  Inputs        : ps_dec          Decoder parameters                       */
1471
/*                  u2_frame_num   current frame number                     */
1472
/*                                                                           */
1473
/*  Globals       : None                                                     */
1474
/*  Processing    : This functionality needs to be implemented               */
1475
/*  Outputs       : None                                                     */
1476
/*  Returns       : None                                                     */
1477
/*                                                                           */
1478
/*  Issues        : Not implemented                                          */
1479
/*                                                                           */
1480
/*  Revision History:                                                        */
1481
/*                                                                           */
1482
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
1483
/*         06 05 2002   NS              Draft                                */
1484
/*                                                                           */
1485
/*****************************************************************************/
1486
WORD32 ih264d_decode_gaps_in_frame_num(dec_struct_t *ps_dec,
1487
                                       UWORD16 u2_frame_num)
1488
0
{
1489
0
    UWORD32 u4_next_frm_num, u4_start_frm_num;
1490
0
    UWORD32 u4_max_frm_num;
1491
0
    pocstruct_t s_tmp_poc;
1492
0
    WORD32 i4_poc;
1493
0
    dec_slice_params_t *ps_cur_slice;
1494
0
1495
0
    dec_pic_params_t *ps_pic_params;
1496
0
    WORD8 i1_gap_idx;
1497
0
    WORD32 *i4_gaps_start_frm_num;
1498
0
    dpb_manager_t *ps_dpb_mgr;
1499
0
    WORD32 i4_frame_gaps;
1500
0
    WORD8 *pi1_gaps_per_seq;
1501
0
    WORD32 ret;
1502
0
1503
0
    ps_cur_slice = ps_dec->ps_cur_slice;
1504
0
    if(ps_cur_slice->u1_field_pic_flag)
1505
0
    {
1506
0
        if(ps_dec->u2_prev_ref_frame_num == u2_frame_num)
1507
0
            return 0;
1508
0
    }
1509
0
1510
0
    u4_next_frm_num = ps_dec->u2_prev_ref_frame_num + 1;
1511
0
    u4_max_frm_num = ps_dec->ps_cur_sps->u2_u4_max_pic_num_minus1 + 1;
1512
0
1513
0
    // check
1514
0
    if(u4_next_frm_num >= u4_max_frm_num)
1515
0
    {
1516
0
        u4_next_frm_num -= u4_max_frm_num;
1517
0
    }
1518
0
1519
0
    if(u4_next_frm_num == u2_frame_num)
1520
0
    {
1521
0
        return (0);
1522
0
    }
1523
0
1524
0
    // check
1525
0
    if((ps_dec->u1_nal_unit_type == IDR_SLICE_NAL)
1526
0
                    && (u4_next_frm_num >= u2_frame_num))
1527
0
    {
1528
0
        return (0);
1529
0
    }
1530
0
    u4_start_frm_num = u4_next_frm_num;
1531
0
1532
0
    s_tmp_poc.i4_pic_order_cnt_lsb = 0;
1533
0
    s_tmp_poc.i4_delta_pic_order_cnt_bottom = 0;
1534
0
    s_tmp_poc.i4_pic_order_cnt_lsb = 0;
1535
0
    s_tmp_poc.i4_delta_pic_order_cnt_bottom = 0;
1536
0
    s_tmp_poc.i4_delta_pic_order_cnt[0] = 0;
1537
0
    s_tmp_poc.i4_delta_pic_order_cnt[1] = 0;
1538
0
1539
0
    ps_cur_slice = ps_dec->ps_cur_slice;
1540
0
    ps_pic_params = ps_dec->ps_cur_pps;
1541
0
1542
0
    i4_frame_gaps = 0;
1543
0
    ps_dpb_mgr = ps_dec->ps_dpb_mgr;
1544
0
1545
0
    /* Find a empty slot to store gap seqn info */
1546
0
    i4_gaps_start_frm_num = ps_dpb_mgr->ai4_gaps_start_frm_num;
1547
0
    for(i1_gap_idx = 0; i1_gap_idx < MAX_FRAMES; i1_gap_idx++)
1548
0
    {
1549
0
        if(INVALID_FRAME_NUM == i4_gaps_start_frm_num[i1_gap_idx])
1550
0
            break;
1551
0
    }
1552
0
    if(MAX_FRAMES == i1_gap_idx)
1553
0
    {
1554
0
        UWORD32 i4_error_code;
1555
0
        i4_error_code = ERROR_DBP_MANAGER_T;
1556
0
//          i4_error_code |= 1<<IVD_CORRUPTEDDATA;
1557
0
        return i4_error_code;
1558
0
    }
1559
0
1560
0
    i4_poc = 0;
1561
0
    i4_gaps_start_frm_num[i1_gap_idx] = u4_start_frm_num;
1562
0
    ps_dpb_mgr->ai4_gaps_end_frm_num[i1_gap_idx] = u2_frame_num - 1;
1563
0
    pi1_gaps_per_seq = ps_dpb_mgr->ai1_gaps_per_seq;
1564
0
    pi1_gaps_per_seq[i1_gap_idx] = 0;
1565
0
    while(u4_next_frm_num != u2_frame_num)
1566
0
    {
1567
0
        ih264d_delete_nonref_nondisplay_pics(ps_dpb_mgr);
1568
0
        if(ps_pic_params->ps_sps->u1_pic_order_cnt_type)
1569
0
        {
1570
0
            /* allocate a picture buffer and insert it as ST node */
1571
0
            ret = ih264d_decode_pic_order_cnt(0, u4_next_frm_num,
1572
0
                                              &ps_dec->s_prev_pic_poc,
1573
0
                                              &s_tmp_poc, ps_cur_slice,
1574
0
                                              ps_pic_params, 1, 0, 0,
1575
0
                                              &i4_poc);
1576
0
            if(ret != OK)
1577
0
                return ret;
1578
0
1579
0
            /* Display seq no calculations */
1580
0
            if(i4_poc >= ps_dec->i4_max_poc)
1581
0
                ps_dec->i4_max_poc = i4_poc;
1582
0
            /* IDR Picture or POC wrap around */
1583
0
            if(i4_poc == 0)
1584
0
            {
1585
0
                ps_dec->i4_prev_max_display_seq =
1586
0
                                ps_dec->i4_prev_max_display_seq
1587
0
                                                + ps_dec->i4_max_poc
1588
0
                                                + ps_dec->u1_max_dec_frame_buffering
1589
0
                                                + 1;
1590
0
                ps_dec->i4_max_poc = 0;
1591
0
            }
1592
0
1593
0
            ps_cur_slice->u1_mmco_equalto5 = 0;
1594
0
            ps_cur_slice->u2_frame_num = u4_next_frm_num;
1595
0
        }
1596
0
1597
0
        // check
1598
0
        if(ps_dpb_mgr->i1_poc_buf_id_entries
1599
0
                        >= ps_dec->u1_max_dec_frame_buffering)
1600
0
        {
1601
0
            ret = ih264d_assign_display_seq(ps_dec);
1602
0
            if(ret != OK)
1603
0
                return ret;
1604
0
        }
1605
0
1606
0
        ret = ih264d_insert_pic_in_display_list(
1607
0
                        ps_dec->ps_dpb_mgr, (WORD8) DO_NOT_DISP,
1608
0
                        (WORD32)(ps_dec->i4_prev_max_display_seq + i4_poc),
1609
0
                        u4_next_frm_num);
1610
0
        if(ret != OK)
1611
0
            return ret;
1612
0
1613
0
        pi1_gaps_per_seq[i1_gap_idx]++;
1614
0
        ret = ih264d_do_mmco_for_gaps(ps_dpb_mgr,
1615
0
                                ps_dec->ps_cur_sps->u1_num_ref_frames);
1616
0
        if(ret != OK)
1617
0
            return ret;
1618
0
1619
0
        ih264d_delete_nonref_nondisplay_pics(ps_dpb_mgr);
1620
0
1621
0
        u4_next_frm_num++;
1622
0
        if(u4_next_frm_num >= u4_max_frm_num)
1623
0
        {
1624
0
            u4_next_frm_num -= u4_max_frm_num;
1625
0
        }
1626
0
1627
0
        i4_frame_gaps++;
1628
0
    }
1629
0
1630
0
    return OK;
1631
0
}
1632
1633
/*!
1634
 **************************************************************************
1635
 * \if Function name : ih264d_create_pic_buffers \endif
1636
 *
1637
 * \brief
1638
 *    This function creates Picture Buffers.
1639
 *
1640
 * \return
1641
 *    0 on Success and -1 on error
1642
 **************************************************************************
1643
 */
1644
WORD32 ih264d_create_pic_buffers(UWORD8 u1_num_of_buf,
1645
                               dec_struct_t *ps_dec)
1646
1
{
1647
1
    struct pic_buffer_t *ps_pic_buf;
1648
1
    UWORD8 i;
1649
1
    UWORD32 u4_luma_size, u4_chroma_size;
1650
1
    UWORD8 u1_frm = ps_dec->ps_cur_sps->u1_frame_mbs_only_flag;
1651
1
    WORD32 j;
1652
1
    UWORD8 *pu1_buf;
1653
1
1654
1
    ps_pic_buf = ps_dec->ps_pic_buf_base;
1655
1
    ih264_disp_mgr_init((disp_mgr_t *)ps_dec->pv_disp_buf_mgr);
1656
1
    ih264_buf_mgr_init((buf_mgr_t *)ps_dec->pv_pic_buf_mgr);
1657
1
    u4_luma_size = ps_dec->u2_frm_wd_y * ps_dec->u2_frm_ht_y;
1658
1
    u4_chroma_size = ps_dec->u2_frm_wd_uv * ps_dec->u2_frm_ht_uv;
1659
1
1660
1
    {
1661
1
        if(ps_dec->u4_share_disp_buf == 1)
1662
0
        {
1663
0
            /* In case of buffers getting shared between application and library
1664
0
             there is no need of reference memtabs. Instead of setting the i4_size
1665
0
             to zero, it is reduced to a small i4_size to ensure that changes
1666
0
             in the code are minimal */
1667
0
            if((ps_dec->u1_chroma_format == IV_YUV_420SP_UV)
1668
0
                            || (ps_dec->u1_chroma_format == IV_YUV_420SP_VU)
1669
0
                            || (ps_dec->u1_chroma_format == IV_YUV_420P))
1670
0
            {
1671
0
                u4_luma_size = 64;
1672
0
            }
1673
0
1674
0
            if(ps_dec->u1_chroma_format == IV_YUV_420SP_UV)
1675
0
            {
1676
0
                u4_chroma_size = 64;
1677
0
            }
1678
0
1679
0
        }
1680
1
    }
1681
1
1682
1
    pu1_buf = ps_dec->pu1_pic_buf_base;
1683
1
1684
1
    /* Allocate memory for refernce buffers */
1685
5
    for(i = 0; i < u1_num_of_buf; i++)
1686
4
    {
1687
4
        UWORD32 u4_offset;
1688
4
        WORD32 buf_ret;
1689
4
        UWORD8 *pu1_luma, *pu1_chroma;
1690
4
        void *pv_mem_ctxt = ps_dec->pv_mem_ctxt;
1691
4
1692
4
        pu1_luma = pu1_buf;
1693
4
        pu1_buf += ALIGN64(u4_luma_size);
1694
4
        pu1_chroma = pu1_buf;
1695
4
        pu1_buf += ALIGN64(u4_chroma_size);
1696
4
1697
4
        /* Offset to the start of the pic from the top left corner of the frame
1698
4
         buffer */
1699
4
1700
4
        if((0 == ps_dec->u4_share_disp_buf)
1701
4
                        || (NULL == ps_dec->disp_bufs[i].buf[0]))
1702
4
        {
1703
4
            UWORD32 pad_len_h, pad_len_v;
1704
4
1705
4
            u4_offset = ps_dec->u2_frm_wd_y * (PAD_LEN_Y_V << 1) + PAD_LEN_Y_H;
1706
4
            ps_pic_buf->pu1_buf1 = (UWORD8 *)(pu1_luma) + u4_offset;
1707
4
1708
4
            pad_len_h = MAX(PAD_LEN_UV_H, (PAD_LEN_Y_H >> 1));
1709
4
            pad_len_v = MAX(PAD_LEN_UV_V, PAD_LEN_Y_V);
1710
4
1711
4
            u4_offset = ps_dec->u2_frm_wd_uv * pad_len_v + pad_len_h;
1712
4
1713
4
            ps_pic_buf->pu1_buf2 = (UWORD8 *)(pu1_chroma) + u4_offset;
1714
4
            ps_pic_buf->pu1_buf3 = (UWORD8 *)(NULL) + u4_offset;
1715
4
1716
4
        }
1717
0
        else
1718
0
        {
1719
0
            UWORD32 pad_len_h, pad_len_v;
1720
0
            u4_offset = ps_dec->u2_frm_wd_y * (PAD_LEN_Y_V << 1) + PAD_LEN_Y_H;
1721
0
            ps_pic_buf->pu1_buf1 = (UWORD8 *)ps_dec->disp_bufs[i].buf[0]
1722
0
                            + u4_offset;
1723
0
1724
0
            ps_dec->disp_bufs[i].u4_ofst[0] = u4_offset;
1725
0
1726
0
            if(ps_dec->u1_chroma_format == IV_YUV_420P)
1727
0
            {
1728
0
                pad_len_h = MAX(PAD_LEN_UV_H * YUV420SP_FACTOR,
1729
0
                                (PAD_LEN_Y_H >> 1));
1730
0
                pad_len_v = MAX(PAD_LEN_UV_V, PAD_LEN_Y_V);
1731
0
1732
0
                u4_offset = ps_dec->u2_frm_wd_uv * pad_len_v + pad_len_h;
1733
0
                ps_pic_buf->pu1_buf2 = (UWORD8 *)(pu1_chroma) + u4_offset;
1734
0
                ps_pic_buf->pu1_buf3 = (UWORD8 *)(NULL) + u4_offset;
1735
0
1736
0
                ps_dec->disp_bufs[i].u4_ofst[1] = u4_offset;
1737
0
                ps_dec->disp_bufs[i].u4_ofst[2] = u4_offset;
1738
0
1739
0
            }
1740
0
            else
1741
0
            {
1742
0
                pad_len_h = MAX(PAD_LEN_UV_H * YUV420SP_FACTOR,
1743
0
                                (PAD_LEN_Y_H >> 1));
1744
0
                pad_len_v = MAX(PAD_LEN_UV_V, PAD_LEN_Y_V);
1745
0
1746
0
                u4_offset = ps_dec->u2_frm_wd_uv * pad_len_v + pad_len_h;
1747
0
                ps_pic_buf->pu1_buf2 = (UWORD8 *)(ps_dec->disp_bufs[i].buf[1])
1748
0
                                + u4_offset;
1749
0
                ps_pic_buf->pu1_buf3 = (UWORD8 *)(ps_dec->disp_bufs[i].buf[1])
1750
0
                                + u4_offset;
1751
0
1752
0
                ps_dec->disp_bufs[i].u4_ofst[1] = u4_offset;
1753
0
                ps_dec->disp_bufs[i].u4_ofst[2] = u4_offset;
1754
0
            }
1755
0
        }
1756
4
1757
4
        ps_pic_buf->u2_frm_ht_y = ps_dec->u2_frm_ht_y;
1758
4
        ps_pic_buf->u2_frm_ht_uv = ps_dec->u2_frm_ht_uv;
1759
4
        ps_pic_buf->u2_frm_wd_y = ps_dec->u2_frm_wd_y;
1760
4
        ps_pic_buf->u2_frm_wd_uv = ps_dec->u2_frm_wd_uv;
1761
4
1762
4
        ps_pic_buf->u1_pic_buf_id = i;
1763
4
1764
4
        buf_ret = ih264_buf_mgr_add((buf_mgr_t *)ps_dec->pv_pic_buf_mgr,
1765
4
                                    ps_pic_buf, i);
1766
4
        if(0 != buf_ret)
1767
0
        {
1768
0
            ps_dec->i4_error_code = ERROR_BUF_MGR;
1769
0
            return ERROR_BUF_MGR;
1770
0
        }
1771
4
1772
4
        ps_dec->apv_buf_id_pic_buf_map[i] = (void *)ps_pic_buf;
1773
4
        ps_pic_buf++;
1774
4
    }
1775
1
1776
1
    if(1 == ps_dec->u4_share_disp_buf)
1777
0
    {
1778
0
        for(i = 0; i < u1_num_of_buf; i++)
1779
0
            ps_dec->u4_disp_buf_mapping[i] = 1;
1780
0
    }
1781
1
    return OK;
1782
1
}
1783
1784
/*!
1785
 **************************************************************************
1786
 * \if Function name : ih264d_allocate_dynamic_bufs \endif
1787
 *
1788
 * \brief
1789
 *    This function allocates memory required by Decoder.
1790
 *
1791
 * \param ps_dec: Pointer to dec_struct_t.
1792
 *
1793
 * \return
1794
 *    Returns i4_status as returned by MemManager.
1795
 *
1796
 **************************************************************************
1797
 */
1798
WORD16 ih264d_allocate_dynamic_bufs(dec_struct_t * ps_dec)
1799
1
{
1800
1
    struct MemReq s_MemReq;
1801
1
    struct MemBlock *p_MemBlock;
1802
1
1803
1
    pred_info_t *ps_pred_frame;
1804
1
    dec_mb_info_t *ps_frm_mb_info;
1805
1
    dec_slice_struct_t *ps_dec_slice_buf;
1806
1
    UWORD8 *pu1_dec_mb_map, *pu1_recon_mb_map;
1807
1
    UWORD16 *pu2_slice_num_map;
1808
1
1809
1
    WORD16 *pi16_res_coeff;
1810
1
    WORD16 i16_status = 0;
1811
1
    UWORD8 uc_frmOrFld = (1 - ps_dec->ps_cur_sps->u1_frame_mbs_only_flag);
1812
1
    UWORD16 u4_luma_wd = ps_dec->u2_frm_wd_y;
1813
1
    UWORD16 u4_chroma_wd = ps_dec->u2_frm_wd_uv;
1814
1
    WORD8 c_i = 0;
1815
1
    dec_seq_params_t *ps_sps = ps_dec->ps_cur_sps;
1816
1
    UWORD32 u4_total_mbs = ps_sps->u2_total_num_of_mbs << uc_frmOrFld;
1817
1
    UWORD32 u4_wd_mbs = ps_dec->u2_frm_wd_in_mbs;
1818
1
    UWORD32 u4_ht_mbs = ps_dec->u2_frm_ht_in_mbs;
1819
1
    UWORD32 u4_blk_wd;
1820
1
    UWORD32 ui_size = 0;
1821
1
    UWORD32 u4_int_scratch_size = 0, u4_ref_pred_size = 0;
1822
1
    UWORD8 *pu1_buf;
1823
1
    WORD32 num_entries;
1824
1
    WORD32 size;
1825
1
    void *pv_buf;
1826
1
    UWORD32 u4_num_bufs;
1827
1
    UWORD32 u4_luma_size, u4_chroma_size;
1828
1
    void *pv_mem_ctxt = ps_dec->pv_mem_ctxt;
1829
1
1830
1
    size = u4_total_mbs;
1831
1
    pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size);
1832
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1833
1
    ps_dec->pu1_dec_mb_map = pv_buf;
1834
1
1835
1
    size = u4_total_mbs;
1836
1
    pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size);
1837
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1838
1
    ps_dec->pu1_recon_mb_map = pv_buf;
1839
1
1840
1
    size = u4_total_mbs * sizeof(UWORD16);
1841
1
    pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size);
1842
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1843
1
    ps_dec->pu2_slice_num_map = pv_buf;
1844
1
1845
1
    /************************************************************/
1846
1
    /* Post allocation Initialisations                          */
1847
1
    /************************************************************/
1848
1
    ps_dec->ps_parse_cur_slice = &(ps_dec->ps_dec_slice_buf[0]);
1849
1
    ps_dec->ps_decode_cur_slice = &(ps_dec->ps_dec_slice_buf[0]);
1850
1
    ps_dec->ps_computebs_cur_slice = &(ps_dec->ps_dec_slice_buf[0]);
1851
1
1852
1
    ps_dec->ps_pred_start = ps_dec->ps_pred;
1853
1
1854
1
    size = sizeof(parse_pmbarams_t) * (ps_dec->u1_recon_mb_grp);
1855
1
    pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size);
1856
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1857
1
    memset(pv_buf, 0, size);
1858
1
    ps_dec->ps_parse_mb_data = pv_buf;
1859
1
1860
1
    size = sizeof(parse_part_params_t)
1861
1
                        * ((ps_dec->u1_recon_mb_grp) << 4);
1862
1
    pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size);
1863
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1864
1
    ps_dec->ps_parse_part_params = pv_buf;
1865
1
1866
1
    size = ((u4_wd_mbs * sizeof(deblkmb_neighbour_t)) << uc_frmOrFld);
1867
1
    pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size);
1868
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1869
1
    ps_dec->ps_deblk_top_mb = pv_buf;
1870
1
1871
1
    size = ((sizeof(ctxt_inc_mb_info_t))
1872
1
                        * (((u4_wd_mbs + 1) << uc_frmOrFld) + 1));
1873
1
    pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size);
1874
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1875
1
    ps_dec->p_ctxt_inc_mb_map = pv_buf;
1876
1
1877
1
    /* 0th entry of CtxtIncMbMap will be always be containing default values
1878
1
     for CABAC context representing MB not available */
1879
1
    ps_dec->p_ctxt_inc_mb_map += 1;
1880
1
1881
1
    size = (sizeof(mv_pred_t) * ps_dec->u1_recon_mb_grp
1882
1
                        * 16);
1883
1
    pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size);
1884
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1885
1
    ps_dec->ps_mv_p[0] = pv_buf;
1886
1
1887
1
    size = (sizeof(mv_pred_t) * ps_dec->u1_recon_mb_grp
1888
1
                        * 16);
1889
1
    pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size);
1890
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1891
1
    ps_dec->ps_mv_p[1] = pv_buf;
1892
1
1893
1
    {
1894
1
        UWORD8 i;
1895
5
        for(i = 0; i < MV_SCRATCH_BUFS; i++)
1896
4
        {
1897
4
            size = (sizeof(mv_pred_t)
1898
4
                            * ps_dec->u1_recon_mb_grp * 4);
1899
4
            pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size);
1900
4
            RETURN_IF((NULL == pv_buf), IV_FAIL);
1901
4
            ps_dec->ps_mv_top_p[i] = pv_buf;
1902
4
        }
1903
1
    }
1904
1
1905
1
    size = sizeof(UWORD8) * ((u4_wd_mbs + 2) * MB_SIZE) * 2;
1906
1
    pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size);
1907
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1908
1
    ps_dec->pu1_y_intra_pred_line = pv_buf;
1909
1
    memset(ps_dec->pu1_y_intra_pred_line, 0, size);
1910
1
    ps_dec->pu1_y_intra_pred_line += MB_SIZE;
1911
1
1912
1
    size = sizeof(UWORD8) * ((u4_wd_mbs + 2) * MB_SIZE) * 2;
1913
1
    pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size);
1914
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1915
1
    ps_dec->pu1_u_intra_pred_line = pv_buf;
1916
1
    memset(ps_dec->pu1_u_intra_pred_line, 0, size);
1917
1
    ps_dec->pu1_u_intra_pred_line += MB_SIZE;
1918
1
1919
1
    size = sizeof(UWORD8) * ((u4_wd_mbs + 2) * MB_SIZE) * 2;
1920
1
    pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size);
1921
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1922
1
    ps_dec->pu1_v_intra_pred_line = pv_buf;
1923
1
    memset(ps_dec->pu1_v_intra_pred_line, 0, size);
1924
1
    ps_dec->pu1_v_intra_pred_line += MB_SIZE;
1925
1
1926
1
    if(ps_dec->u1_separate_parse)
1927
1
    {
1928
1
        /* Needs one extra row of info, to hold top row data */
1929
1
        size = sizeof(mb_neigbour_params_t)
1930
1
                        * 2 * ((u4_wd_mbs + 2) * (u4_ht_mbs + 1));
1931
1
    }
1932
0
    else
1933
0
    {
1934
0
        size = sizeof(mb_neigbour_params_t)
1935
0
                        * 2 * ((u4_wd_mbs + 2) << uc_frmOrFld);
1936
0
    }
1937
1
    pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size);
1938
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1939
1
1940
1
    ps_dec->ps_nbr_mb_row = pv_buf;
1941
1
    memset(ps_dec->ps_nbr_mb_row, 0, size);
1942
1
1943
1
    /* Allocate deblock MB info */
1944
1
    size = (u4_total_mbs + u4_wd_mbs) * sizeof(deblk_mb_t);
1945
1
1946
1
    pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size);
1947
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1948
1
    ps_dec->ps_deblk_pic = pv_buf;
1949
1
1950
1
    memset(ps_dec->ps_deblk_pic, 0, size);
1951
1
1952
1
    /* Allocate frame level mb info */
1953
1
    size = sizeof(dec_mb_info_t) * u4_total_mbs;
1954
1
    pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size);
1955
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1956
1
    ps_dec->ps_frm_mb_info = pv_buf;
1957
1
    memset(ps_dec->ps_frm_mb_info, 0, size);
1958
1
1959
1
    /* Allocate memory for slice headers dec_slice_struct_t */
1960
1
    num_entries = MAX_FRAMES;
1961
1
    if((1 >= ps_dec->ps_cur_sps->u1_num_ref_frames) &&
1962
1
        (0 == ps_dec->i4_display_delay))
1963
0
    {
1964
0
        num_entries = 1;
1965
0
    }
1966
1
    num_entries = ((2 * num_entries) + 1);
1967
1
    num_entries *= 2;
1968
1
1969
1
    size = num_entries * sizeof(void *);
1970
1
    size += PAD_MAP_IDX_POC * sizeof(void *);
1971
1
    size *= u4_total_mbs;
1972
1
    size += sizeof(dec_slice_struct_t) * u4_total_mbs;
1973
1
    pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size);
1974
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1975
1
1976
1
    ps_dec->ps_dec_slice_buf = pv_buf;
1977
1
    memset(ps_dec->ps_dec_slice_buf, 0, size);
1978
1
    pu1_buf = (UWORD8 *)ps_dec->ps_dec_slice_buf;
1979
1
    pu1_buf += sizeof(dec_slice_struct_t) * u4_total_mbs;
1980
1
    ps_dec->pv_map_ref_idx_to_poc_buf = (void *)pu1_buf;
1981
1
1982
1
    /* Allocate memory for packed pred info */
1983
1
    num_entries = u4_total_mbs;
1984
1
    num_entries *= 16 * 2;
1985
1
1986
1
    size = sizeof(pred_info_pkd_t) * num_entries;
1987
1
    pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size);
1988
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
1989
1
    ps_dec->ps_pred_pkd = pv_buf;
1990
1
1991
1
    /* Allocate memory for coeff data */
1992
1
    size = MB_LUM_SIZE * sizeof(WORD16);
1993
1
    /*For I16x16 MBs, 16 4x4 AC coeffs and 1 4x4 DC coeff TU blocks will be sent
1994
1
    For all MBs along with 8 4x4 AC coeffs 2 2x2 DC coeff TU blocks will be sent
1995
1
    So use 17 4x4 TU blocks for luma and 9 4x4 TU blocks for chroma */
1996
1
    size += u4_total_mbs * (MAX(17 * sizeof(tu_sblk4x4_coeff_data_t),4 * sizeof(tu_blk8x8_coeff_data_t))
1997
1
                                            + 9 * sizeof(tu_sblk4x4_coeff_data_t));
1998
1
    //32 bytes for each mb to store u1_prev_intra4x4_pred_mode and u1_rem_intra4x4_pred_mode data
1999
1
    size += u4_total_mbs * 32;
2000
1
    pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size);
2001
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
2002
1
2003
1
    ps_dec->pi2_coeff_data = pv_buf;
2004
1
2005
1
    ps_dec->pv_pic_tu_coeff_data = (void *)(ps_dec->pi2_coeff_data + MB_LUM_SIZE);
2006
1
2007
1
    /* Allocate MV bank buffer */
2008
1
    {
2009
1
        UWORD32 col_flag_buffer_size, mvpred_buffer_size;
2010
1
2011
1
        col_flag_buffer_size = ((ps_dec->u2_pic_wd * ps_dec->u2_pic_ht) >> 4);
2012
1
        mvpred_buffer_size = sizeof(mv_pred_t)
2013
1
                        * ((ps_dec->u2_pic_wd * (ps_dec->u2_pic_ht + PAD_MV_BANK_ROW)) >> 4);
2014
1
2015
1
        u4_num_bufs = ps_dec->ps_cur_sps->u1_num_ref_frames + 1;
2016
1
2017
1
        u4_num_bufs = MIN(u4_num_bufs, ps_dec->u1_pic_bufs);
2018
1
        u4_num_bufs = MAX(u4_num_bufs, 2);
2019
1
        size = ALIGN64(mvpred_buffer_size) + ALIGN64(col_flag_buffer_size);
2020
1
        size *= u4_num_bufs;
2021
1
        pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size);
2022
1
        RETURN_IF((NULL == pv_buf), IV_FAIL);
2023
1
        ps_dec->pu1_mv_bank_buf_base = pv_buf;
2024
1
    }
2025
1
2026
1
    /* Allocate Pic buffer */
2027
1
    u4_luma_size = ps_dec->u2_frm_wd_y * ps_dec->u2_frm_ht_y;
2028
1
    u4_chroma_size = ps_dec->u2_frm_wd_uv * ps_dec->u2_frm_ht_uv;
2029
1
2030
1
    {
2031
1
        if(ps_dec->u4_share_disp_buf == 1)
2032
0
        {
2033
0
            /* In case of buffers getting shared between application and library
2034
0
             there is no need of reference memtabs. Instead of setting the i4_size
2035
0
             to zero, it is reduced to a small i4_size to ensure that changes
2036
0
             in the code are minimal */
2037
0
            if((ps_dec->u1_chroma_format == IV_YUV_420SP_UV)
2038
0
                            || (ps_dec->u1_chroma_format == IV_YUV_420SP_VU)
2039
0
                            || (ps_dec->u1_chroma_format == IV_YUV_420P))
2040
0
            {
2041
0
                u4_luma_size = 64;
2042
0
            }
2043
0
2044
0
            if(ps_dec->u1_chroma_format == IV_YUV_420SP_UV)
2045
0
            {
2046
0
                u4_chroma_size = 64;
2047
0
            }
2048
0
2049
0
        }
2050
1
    }
2051
1
2052
1
    size = ALIGN64(u4_luma_size) + ALIGN64(u4_chroma_size);
2053
1
    size *= ps_dec->u1_pic_bufs;
2054
1
    pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size);
2055
1
    RETURN_IF((NULL == pv_buf), IV_FAIL);
2056
1
    ps_dec->pu1_pic_buf_base = pv_buf;
2057
1
2058
1
    /* Post allocation Increment Actions */
2059
1
2060
1
    /***************************************************************************/
2061
1
    /*Initialize cabac context pointers for every SE that has fixed contextIdx */
2062
1
    /***************************************************************************/
2063
1
    {
2064
1
        bin_ctxt_model_t * const p_cabac_ctxt_table_t =
2065
1
                        ps_dec->p_cabac_ctxt_table_t;
2066
1
        bin_ctxt_model_t * * p_coeff_abs_level_minus1_t =
2067
1
                        ps_dec->p_coeff_abs_level_minus1_t;
2068
1
        bin_ctxt_model_t * * p_cbf_t = ps_dec->p_cbf_t;
2069
1
2070
1
        ps_dec->p_mb_field_dec_flag_t = p_cabac_ctxt_table_t
2071
1
                        + MB_FIELD_DECODING_FLAG;
2072
1
        ps_dec->p_prev_intra4x4_pred_mode_flag_t = p_cabac_ctxt_table_t
2073
1
                        + PREV_INTRA4X4_PRED_MODE_FLAG;
2074
1
        ps_dec->p_rem_intra4x4_pred_mode_t = p_cabac_ctxt_table_t
2075
1
                        + REM_INTRA4X4_PRED_MODE;
2076
1
        ps_dec->p_intra_chroma_pred_mode_t = p_cabac_ctxt_table_t
2077
1
                        + INTRA_CHROMA_PRED_MODE;
2078
1
        ps_dec->p_mb_qp_delta_t = p_cabac_ctxt_table_t + MB_QP_DELTA;
2079
1
        ps_dec->p_ref_idx_t = p_cabac_ctxt_table_t + REF_IDX;
2080
1
        ps_dec->p_mvd_x_t = p_cabac_ctxt_table_t + MVD_X;
2081
1
        ps_dec->p_mvd_y_t = p_cabac_ctxt_table_t + MVD_Y;
2082
1
        p_cbf_t[0] = p_cabac_ctxt_table_t + CBF + 0;
2083
1
        p_cbf_t[1] = p_cabac_ctxt_table_t + CBF + 4;
2084
1
        p_cbf_t[2] = p_cabac_ctxt_table_t + CBF + 8;
2085
1
        p_cbf_t[3] = p_cabac_ctxt_table_t + CBF + 12;
2086
1
        p_cbf_t[4] = p_cabac_ctxt_table_t + CBF + 16;
2087
1
        ps_dec->p_cbp_luma_t = p_cabac_ctxt_table_t + CBP_LUMA;
2088
1
        ps_dec->p_cbp_chroma_t = p_cabac_ctxt_table_t + CBP_CHROMA;
2089
1
2090
1
        p_coeff_abs_level_minus1_t[LUMA_DC_CTXCAT] = p_cabac_ctxt_table_t
2091
1
                        + COEFF_ABS_LEVEL_MINUS1 + COEFF_ABS_LEVEL_CAT_0_OFFSET;
2092
1
2093
1
        p_coeff_abs_level_minus1_t[LUMA_AC_CTXCAT] = p_cabac_ctxt_table_t
2094
1
                        + COEFF_ABS_LEVEL_MINUS1 + COEFF_ABS_LEVEL_CAT_1_OFFSET;
2095
1
2096
1
        p_coeff_abs_level_minus1_t[LUMA_4X4_CTXCAT] = p_cabac_ctxt_table_t
2097
1
                        + COEFF_ABS_LEVEL_MINUS1 + COEFF_ABS_LEVEL_CAT_2_OFFSET;
2098
1
2099
1
        p_coeff_abs_level_minus1_t[CHROMA_DC_CTXCAT] = p_cabac_ctxt_table_t
2100
1
                        + COEFF_ABS_LEVEL_MINUS1 + COEFF_ABS_LEVEL_CAT_3_OFFSET;
2101
1
2102
1
        p_coeff_abs_level_minus1_t[CHROMA_AC_CTXCAT] = p_cabac_ctxt_table_t
2103
1
                        + COEFF_ABS_LEVEL_MINUS1 + COEFF_ABS_LEVEL_CAT_4_OFFSET;
2104
1
2105
1
        p_coeff_abs_level_minus1_t[LUMA_8X8_CTXCAT] = p_cabac_ctxt_table_t
2106
1
                        + COEFF_ABS_LEVEL_MINUS1_8X8
2107
1
                        + COEFF_ABS_LEVEL_CAT_5_OFFSET;
2108
1
2109
1
        /********************************************************/
2110
1
        /* context for the high profile related syntax elements */
2111
1
        /* This is maintained seperately in s_high_profile     */
2112
1
        /********************************************************/
2113
1
        {
2114
1
2115
1
            ps_dec->s_high_profile.ps_transform8x8_flag = p_cabac_ctxt_table_t
2116
1
                            + TRANSFORM_SIZE_8X8_FLAG;
2117
1
2118
1
            ps_dec->s_high_profile.ps_sigcoeff_8x8_frame = p_cabac_ctxt_table_t
2119
1
                            + SIGNIFICANT_COEFF_FLAG_8X8_FRAME;
2120
1
2121
1
            ps_dec->s_high_profile.ps_last_sigcoeff_8x8_frame =
2122
1
                            p_cabac_ctxt_table_t
2123
1
                                            + LAST_SIGNIFICANT_COEFF_FLAG_8X8_FRAME;
2124
1
2125
1
            ps_dec->s_high_profile.ps_coeff_abs_levelminus1 =
2126
1
                            p_cabac_ctxt_table_t + COEFF_ABS_LEVEL_MINUS1_8X8;
2127
1
2128
1
            ps_dec->s_high_profile.ps_sigcoeff_8x8_field = p_cabac_ctxt_table_t
2129
1
                            + SIGNIFICANT_COEFF_FLAG_8X8_FIELD;
2130
1
2131
1
            ps_dec->s_high_profile.ps_last_sigcoeff_8x8_field =
2132
1
                            p_cabac_ctxt_table_t
2133
1
                                            + LAST_SIGNIFICANT_COEFF_FLAG_8X8_FIELD;
2134
1
        }
2135
1
    }
2136
1
    return (i16_status);
2137
1
}
2138
2139
/*!
2140
 **************************************************************************
2141
 * \if Function name : ih264d_free_dynamic_bufs \endif
2142
 *
2143
 * \brief
2144
 *    This function frees dynamic memory allocated by Decoder.
2145
 *
2146
 * \param ps_dec: Pointer to dec_struct_t.
2147
 *
2148
 * \return
2149
 *    Returns i4_status as returned by MemManager.
2150
 *
2151
 **************************************************************************
2152
 */
2153
WORD16 ih264d_free_dynamic_bufs(dec_struct_t * ps_dec)
2154
3
{
2155
3
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_bits_buf_dynamic);
2156
3
2157
3
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_deblk_pic);
2158
3
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_dec_mb_map);
2159
3
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_recon_mb_map);
2160
3
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu2_slice_num_map);
2161
3
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_dec_slice_buf);
2162
3
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_frm_mb_info);
2163
3
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pi2_coeff_data);
2164
3
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_parse_mb_data);
2165
3
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_parse_part_params);
2166
3
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_deblk_top_mb);
2167
3
2168
3
    if(ps_dec->p_ctxt_inc_mb_map)
2169
1
    {
2170
1
        ps_dec->p_ctxt_inc_mb_map -= 1;
2171
1
        PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->p_ctxt_inc_mb_map);
2172
1
    }
2173
3
2174
3
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_mv_p[0]);
2175
3
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_mv_p[1]);
2176
3
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_pred_pkd);
2177
3
    {
2178
3
        UWORD8 i;
2179
15
        for(i = 0; i < MV_SCRATCH_BUFS; i++)
2180
12
        {
2181
12
            PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_mv_top_p[i]);
2182
12
        }
2183
3
    }
2184
3
2185
3
    if(ps_dec->pu1_y_intra_pred_line)
2186
1
    {
2187
1
        ps_dec->pu1_y_intra_pred_line -= MB_SIZE;
2188
1
    }
2189
3
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_y_intra_pred_line);
2190
3
2191
3
    if(ps_dec->pu1_u_intra_pred_line)
2192
1
    {
2193
1
        ps_dec->pu1_u_intra_pred_line -= MB_SIZE;
2194
1
    }
2195
3
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_u_intra_pred_line);
2196
3
2197
3
    if(ps_dec->pu1_v_intra_pred_line)
2198
1
    {
2199
1
        ps_dec->pu1_v_intra_pred_line -= MB_SIZE;
2200
1
    }
2201
3
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_v_intra_pred_line);
2202
3
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_nbr_mb_row);
2203
3
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_mv_bank_buf_base);
2204
3
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_pic_buf_base);
2205
3
    return 0;
2206
3
}
2207
2208
/*!
2209
 **************************************************************************
2210
 * \if Function name : ih264d_create_mv_bank \endif
2211
 *
2212
 * \brief
2213
 *    This function creates MV bank.
2214
 *
2215
 * \param memType  : Type of memory being handled
2216
 *                   0: Display Buffer
2217
 *                   1: Decoder Buffer
2218
 *                   2: Internal Buffer
2219
 * \param u1_num_of_buf: Number of decode or display buffers.
2220
 * \param u4_wd : Frame width.
2221
 * \param u4_ht : Frame Height.
2222
 * \param ps_pic_buf_api : Pointer to Picture Buffer API.
2223
 * \param ih264d_dec_mem_manager  : Memory manager utility supplied by system.
2224
 *
2225
 * \return
2226
 *    0 on Success and -1 on error
2227
 *
2228
 **************************************************************************
2229
 */
2230
WORD32 ih264d_create_mv_bank(void *pv_dec,
2231
                             UWORD32 ui_width,
2232
                             UWORD32 ui_height)
2233
1
{
2234
1
    UWORD8  i;
2235
1
    UWORD32 col_flag_buffer_size, mvpred_buffer_size;
2236
1
    UWORD8 *pu1_mv_buf_mgr_base, *pu1_mv_bank_base;
2237
1
    col_mv_buf_t *ps_col_mv;
2238
1
    mv_pred_t *ps_mv;
2239
1
    UWORD8 *pu1_col_zero_flag_buf;
2240
1
    dec_struct_t *ps_dec = (dec_struct_t *)pv_dec;
2241
1
    WORD32 buf_ret;
2242
1
    UWORD32 u4_num_bufs;
2243
1
    UWORD8 *pu1_buf;
2244
1
    WORD32 size;
2245
1
    void *pv_mem_ctxt = ps_dec->pv_mem_ctxt;
2246
1
2247
1
    col_flag_buffer_size = ((ui_width * ui_height) >> 4);
2248
1
    mvpred_buffer_size = sizeof(mv_pred_t)
2249
1
                    * ((ui_width * (ui_height + PAD_MV_BANK_ROW)) >> 4);
2250
1
2251
1
    ih264_buf_mgr_init((buf_mgr_t *)ps_dec->pv_mv_buf_mgr);
2252
1
2253
1
    ps_col_mv = ps_dec->ps_col_mv_base;
2254
1
2255
1
    u4_num_bufs = ps_dec->ps_cur_sps->u1_num_ref_frames + 1;
2256
1
2257
1
    u4_num_bufs = MIN(u4_num_bufs, ps_dec->u1_pic_bufs);
2258
1
    u4_num_bufs = MAX(u4_num_bufs, 2);
2259
1
    pu1_buf = ps_dec->pu1_mv_bank_buf_base;
2260
4
    for(i = 0 ; i < u4_num_bufs ; i++)
2261
3
    {
2262
3
        pu1_col_zero_flag_buf = pu1_buf;
2263
3
        pu1_buf += ALIGN64(col_flag_buffer_size);
2264
3
2265
3
        ps_mv = (mv_pred_t *)pu1_buf;
2266
3
        pu1_buf += ALIGN64(mvpred_buffer_size);
2267
3
2268
3
        memset(ps_mv, 0, ((ui_width * OFFSET_MV_BANK_ROW) >> 4) * sizeof(mv_pred_t));
2269
3
        ps_mv += (ui_width*OFFSET_MV_BANK_ROW) >> 4;
2270
3
2271
3
        ps_col_mv->pv_col_zero_flag = (void *)pu1_col_zero_flag_buf;
2272
3
        ps_col_mv->pv_mv = (void *)ps_mv;
2273
3
        buf_ret = ih264_buf_mgr_add((buf_mgr_t *)ps_dec->pv_mv_buf_mgr, ps_col_mv, i);
2274
3
        if(0 != buf_ret)
2275
0
        {
2276
0
            ps_dec->i4_error_code = ERROR_BUF_MGR;
2277
0
            return ERROR_BUF_MGR;
2278
0
        }
2279
3
        ps_col_mv++;
2280
3
    }
2281
1
    return OK;
2282
1
}
2283
2284
void ih264d_unpack_coeff4x4_dc_4x4blk(tu_sblk4x4_coeff_data_t *ps_tu_4x4,
2285
                                      WORD16 *pi2_out_coeff_data,
2286
                                      UWORD8 *pu1_inv_scan)
2287
3.31k
{
2288
3.31k
    UWORD16 u2_sig_coeff_map = ps_tu_4x4->u2_sig_coeff_map;
2289
3.31k
    WORD32 idx;
2290
3.31k
    WORD16 *pi2_coeff_data = &ps_tu_4x4->ai2_level[0];
2291
3.31k
2292
13.4k
    while(u2_sig_coeff_map)
2293
10.1k
    {
2294
10.1k
        idx = CLZ(u2_sig_coeff_map);
2295
10.1k
2296
10.1k
        idx = 31 - idx;
2297
10.1k
        RESET_BIT(u2_sig_coeff_map,idx);
2298
10.1k
2299
10.1k
        idx = pu1_inv_scan[idx];
2300
10.1k
        pi2_out_coeff_data[idx] = *pi2_coeff_data++;
2301
10.1k
2302
10.1k
    }
2303
3.31k
}
/proc/self/cwd/external/libavc/decoder/ih264d_utils.h
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
#ifndef  _IH264D_UTILS_H_
21
#define  _IH264D_UTILS_H_
22
/*!
23
**************************************************************************
24
* \file ih264d_utils.h
25
*
26
* \brief
27
*    Contains declaration of routines
28
*    that handle of start and end of pic processing
29
*
30
* \date
31
*    19/12/2002
32
*
33
* \author  AI
34
**************************************************************************
35
*/
36
#include "ih264d_defs.h"
37
#include "ih264_typedefs.h"
38
#include "ih264_macros.h"
39
#include "ih264_platform_macros.h"
40
#include "ih264d_structs.h"
41
#include "ih264d_parse_cavlc.h"
42
43
102
#define PS_DEC_ALIGNED_FREE(ps_dec, y) \
44
102
if(y) {ps_dec->pf_aligned_free(ps_dec->pv_mem_ctxt, ((void *)y)); (y) = NULL;}
45
void pad_frm_buff_vert(dec_struct_t *ps_dec);
46
47
UWORD8 ih264d_is_end_of_pic(UWORD16 u2_frame_num,
48
                            UWORD8 u1_nal_ref_idc,
49
                            pocstruct_t *ps_cur_poc,
50
                            pocstruct_t *ps_prev_poc,
51
                            dec_slice_params_t * ps_prev_slice,
52
                            UWORD8 u1_pic_order_cnt_type,
53
                            UWORD8 u1_nal_unit_type,
54
                            UWORD32 u4_idr_pic_id,
55
                            UWORD8 u1_field_pic_flag,
56
                            UWORD8 u1_bottom_field_flag);
57
58
WORD32 ih264d_end_of_pic_processing(dec_struct_t * ps_dec);
59
60
WORD32 ih264d_init_pic(dec_struct_t *ps_dec,
61
                       UWORD16 u2_frame_num,
62
                       WORD32 i4_poc,
63
                       dec_pic_params_t * ps_pps);
64
65
WORD32 ih264d_end_of_pic_processing(dec_struct_t * ps_dec);
66
WORD32 ih264d_decode_pic_order_cnt(UWORD8 u1_is_idr_slice,
67
                                   UWORD32 u2_frame_num,
68
                                   pocstruct_t *ps_prev_poc,
69
                                   pocstruct_t *ps_cur_poc,
70
                                   dec_slice_params_t *ps_cur_slice,
71
                                   dec_pic_params_t * ps_pps,
72
                                   UWORD8 u1_nal_ref_idc,
73
                                   UWORD8 u1_bottom_field_flag,
74
                                   UWORD8 u1_field_pic_flag,
75
                                   WORD32 *pi4_poc);
76
void ih264d_release_display_bufs(dec_struct_t *ps_dec);
77
WORD32 ih264d_assign_display_seq(dec_struct_t *ps_dec);
78
void ih264d_assign_pic_num(dec_struct_t *ps_dec);
79
80
void ih264d_unpack_coeff4x4_dc_4x4blk(tu_sblk4x4_coeff_data_t *ps_tu_4x4,
81
                                      WORD16 *pi2_out_coeff_data,
82
                                      UWORD8 *pu1_inv_scan);
83
84
WORD32 ih264d_update_qp(dec_struct_t * ps_dec, const WORD8 i1_qp);
85
WORD32 ih264d_decode_gaps_in_frame_num(dec_struct_t *ps_dec,
86
                                       UWORD16 u2_frame_num);
87
88
WORD32 ih264d_get_next_display_field(dec_struct_t * ps_dec,
89
                                  ivd_out_bufdesc_t *ps_out_buffer,
90
                                  ivd_get_display_frame_op_t *pv_disp_op);
91
92
void ih264d_release_display_field(dec_struct_t *ps_dec,
93
                                  ivd_get_display_frame_op_t *pv_disp_op);
94
void ih264d_close_video_decoder(iv_obj_t *iv_obj_t);
95
WORD32 ih264d_get_dpb_size(dec_seq_params_t *ps_seq);
96
WORD32 ih264d_get_next_nal_unit(UWORD8 *pu1_buf,
97
                                UWORD32 u4_cur_pos,
98
                                UWORD32 u4_max_ofst,
99
                                UWORD32 *pu4_length_of_start_code);
100
101
WORD16 ih264d_free_dynamic_bufs(dec_struct_t * ps_dec);
102
#endif /* _IH264D_UTILS_H_ */
/proc/self/cwd/external/libavc/decoder/ih264d_vui.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
21
/*****************************************************************************/
22
/*                                                                           */
23
/*  File Name         : ih264d_vui.c                                                */
24
/*                                                                           */
25
/*  Description       : This file contains routines to parse VUI NAL's       */
26
/*                                                                           */
27
/*  List of Functions : <List the functions defined in this file>            */
28
/*                                                                           */
29
/*  Issues / Problems : None                                                 */
30
/*                                                                           */
31
/*  Revision History  :                                                      */
32
/*                                                                           */
33
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
34
/*         25 05 2005   NS              Draft                                */
35
/*                                                                           */
36
/*****************************************************************************/
37
38
#include "ih264_typedefs.h"
39
#include "ih264_macros.h"
40
#include "ih264_platform_macros.h"
41
#include "ih264d_vui.h"
42
#include "ih264d_bitstrm.h"
43
#include "ih264d_parse_cavlc.h"
44
#include "ih264d_structs.h"
45
#include "ih264d_error_handler.h"
46
47
/*****************************************************************************/
48
/*                                                                           */
49
/*  Function Name : ih264d_parse_hrd_parametres                                     */
50
/*                                                                           */
51
/*  Description   : This function parses hrd_t parametres                      */
52
/*  Inputs        : ps_hrd          pointer to HRD params                    */
53
/*                  ps_bitstrm   Bitstream                                */
54
/*  Globals       : None                                                     */
55
/*  Processing    : Parses HRD params                                        */
56
/*  Outputs       : None                                                     */
57
/*  Returns       : None                                                     */
58
/*                                                                           */
59
/*  Issues        : None                                                     */
60
/*                                                                           */
61
/*  Revision History:                                                        */
62
/*                                                                           */
63
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
64
/*         06 05 2002   NS              Draft                                */
65
/*                                                                           */
66
/*****************************************************************************/
67
68
WORD32 ih264d_parse_hrd_parametres(hrd_t *ps_hrd,
69
                                   dec_bit_stream_t *ps_bitstrm)
70
1
{
71
1
    UWORD8 u1_index;
72
1
    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
73
1
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
74
1
75
1
    ps_hrd->u4_cpb_cnt = 1
76
1
                    + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
77
1
    if(ps_hrd->u4_cpb_cnt > 31)
78
0
        return ERROR_INV_SPS_PPS_T;
79
1
    ps_hrd->u1_bit_rate_scale = ih264d_get_bits_h264(ps_bitstrm, 4);
80
1
    ps_hrd->u1_cpb_size_scale = ih264d_get_bits_h264(ps_bitstrm, 4);
81
1
82
2
    for(u1_index = 0; u1_index < (UWORD8)ps_hrd->u4_cpb_cnt; u1_index++)
83
1
    {
84
1
        ps_hrd->u4_bit_rate[u1_index] = 1
85
1
                        + ih264d_uev(pu4_bitstrm_ofst,
86
1
                                     pu4_bitstrm_buf);
87
1
        ps_hrd->u4_cpb_size[u1_index] = 1
88
1
                        + ih264d_uev(pu4_bitstrm_ofst,
89
1
                                     pu4_bitstrm_buf);
90
1
        ps_hrd->u1_cbr_flag[u1_index] = ih264d_get_bits_h264(ps_bitstrm, 1);
91
1
    }
92
1
93
1
    ps_hrd->u1_initial_cpb_removal_delay = 1
94
1
                    + ih264d_get_bits_h264(ps_bitstrm, 5);
95
1
    ps_hrd->u1_cpb_removal_delay_length = 1
96
1
                    + ih264d_get_bits_h264(ps_bitstrm, 5);
97
1
    ps_hrd->u1_dpb_output_delay_length = 1
98
1
                    + ih264d_get_bits_h264(ps_bitstrm, 5);
99
1
    ps_hrd->u1_time_offset_length = ih264d_get_bits_h264(ps_bitstrm, 5);
100
1
101
1
    return OK;
102
1
}
103
104
/*****************************************************************************/
105
/*                                                                           */
106
/*  Function Name : ih264d_parse_vui_parametres                                     */
107
/*                                                                           */
108
/*  Description   : This function parses VUI NALs.                           */
109
/*  Inputs        : ps_vu4          pointer to VUI params                    */
110
/*                  ps_bitstrm   Bitstream                                */
111
/*  Globals       : None                                                     */
112
/*  Processing    : Parses VUI NAL's units and stores the info               */
113
/*  Outputs       : None                                                     */
114
/*  Returns       : None                                                     */
115
/*                                                                           */
116
/*  Issues        : None                                                     */
117
/*                                                                           */
118
/*  Revision History:                                                        */
119
/*                                                                           */
120
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
121
/*         06 05 2002   NS              Draft                                */
122
/*                                                                           */
123
/*****************************************************************************/
124
125
WORD32 ih264d_parse_vui_parametres(vui_t *ps_vu4,
126
                                   dec_bit_stream_t *ps_bitstrm)
127
1
{
128
1
    UWORD8 u4_bits;
129
1
    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
130
1
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
131
1
    WORD32 ret;
132
1
133
1
    u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
134
1
    if(u4_bits)
135
1
    {
136
1
        u4_bits = ih264d_get_bits_h264(ps_bitstrm, 8);
137
1
        ps_vu4->u1_aspect_ratio_idc = (UWORD8)u4_bits;
138
1
        if(VUI_EXTENDED_SAR == u4_bits)
139
1
        {
140
1
            ps_vu4->u2_sar_width = ih264d_get_bits_h264(ps_bitstrm, 16);
141
1
            ps_vu4->u2_sar_height = ih264d_get_bits_h264(ps_bitstrm, 16);
142
1
        }
143
1
    }
144
1
145
1
    u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
146
1
    if(u4_bits)
147
0
    {
148
0
        ps_vu4->u1_overscan_appropriate_flag = ih264d_get_bits_h264(
149
0
                        ps_bitstrm, 1);
150
0
    }
151
1
    u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
152
1
    /* Initialize to unspecified (5 for video_format and
153
1
       2 for colour_primaries, tfr_chars, matrix_coeffs  */
154
1
    ps_vu4->u1_video_format = 5;
155
1
    ps_vu4->u1_video_full_range_flag = 0;
156
1
    ps_vu4->u1_colour_primaries = 2;
157
1
    ps_vu4->u1_tfr_chars = 2;
158
1
    ps_vu4->u1_matrix_coeffs = 2;
159
1
160
1
    if(u4_bits)
161
1
    {
162
1
        ps_vu4->u1_video_format = ih264d_get_bits_h264(ps_bitstrm, 3);
163
1
        ps_vu4->u1_video_full_range_flag = ih264d_get_bits_h264(ps_bitstrm,
164
1
                                                                1);
165
1
        u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
166
1
        if(u4_bits)
167
0
        {
168
0
            ps_vu4->u1_colour_primaries = ih264d_get_bits_h264(ps_bitstrm,
169
0
                                                               8);
170
0
            ps_vu4->u1_tfr_chars = ih264d_get_bits_h264(ps_bitstrm, 8);
171
0
            ps_vu4->u1_matrix_coeffs = ih264d_get_bits_h264(ps_bitstrm, 8);
172
0
        }
173
1
    }
174
1
175
1
    u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
176
1
    if(u4_bits)
177
0
    {
178
0
        ps_vu4->u1_cr_top_field = ih264d_uev(pu4_bitstrm_ofst,
179
0
                                             pu4_bitstrm_buf);
180
0
        ps_vu4->u1_cr_bottom_field = ih264d_uev(pu4_bitstrm_ofst,
181
0
                                                pu4_bitstrm_buf);
182
0
    }
183
1
184
1
    u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
185
1
    if(u4_bits)
186
1
    {
187
1
        ps_vu4->u4_num_units_in_tick = ih264d_get_bits_h264(ps_bitstrm, 32);
188
1
        ps_vu4->u4_time_scale = ih264d_get_bits_h264(ps_bitstrm, 32);
189
1
        ps_vu4->u1_fixed_frame_rate_flag = ih264d_get_bits_h264(ps_bitstrm,
190
1
                                                                1);
191
1
    }
192
1
193
1
    u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
194
1
    ps_vu4->u1_nal_hrd_params_present = u4_bits;
195
1
    if(u4_bits)
196
1
    {
197
1
        ret = ih264d_parse_hrd_parametres(&ps_vu4->s_nal_hrd, ps_bitstrm);
198
1
        if(ret != OK)
199
1
            return ret;
200
1
    }
201
1
    u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
202
1
    ps_vu4->u1_vcl_hrd_params_present = u4_bits;
203
1
    if(u4_bits)
204
0
    {
205
0
        ret = ih264d_parse_hrd_parametres(&ps_vu4->s_vcl_hrd, ps_bitstrm);
206
0
        if(ret != OK)
207
0
            return ret;
208
1
    }
209
1
210
1
    if(ps_vu4->u1_nal_hrd_params_present || u4_bits)
211
1
    {
212
1
        ps_vu4->u1_low_delay_hrd_flag = ih264d_get_bits_h264(ps_bitstrm, 1);
213
1
    }
214
1
    ps_vu4->u1_pic_struct_present_flag = ih264d_get_bits_h264(ps_bitstrm, 1);
215
1
216
1
    ps_vu4->u1_bitstream_restriction_flag = ih264d_get_bits_h264(ps_bitstrm, 1);
217
1
218
1
    if(ps_vu4->u1_bitstream_restriction_flag)
219
1
    {
220
1
        ps_vu4->u1_mv_over_pic_boundaries_flag = ih264d_get_bits_h264(
221
1
                        ps_bitstrm, 1);
222
1
        ps_vu4->u4_max_bytes_per_pic_denom = ih264d_uev(pu4_bitstrm_ofst,
223
1
                                                        pu4_bitstrm_buf);
224
1
        ps_vu4->u4_max_bits_per_mb_denom = ih264d_uev(pu4_bitstrm_ofst,
225
1
                                                      pu4_bitstrm_buf);
226
1
        ps_vu4->u4_log2_max_mv_length_horz = ih264d_uev(pu4_bitstrm_ofst,
227
1
                                                        pu4_bitstrm_buf);
228
1
        ps_vu4->u4_log2_max_mv_length_vert = ih264d_uev(pu4_bitstrm_ofst,
229
1
                                                        pu4_bitstrm_buf);
230
1
        ps_vu4->u4_num_reorder_frames = ih264d_uev(pu4_bitstrm_ofst,
231
1
                                                   pu4_bitstrm_buf);
232
1
        ps_vu4->u4_max_dec_frame_buffering = ih264d_uev(pu4_bitstrm_ofst,
233
1
                                                        pu4_bitstrm_buf);
234
1
    }
235
0
    else
236
0
    {
237
0
        /* Setting this to a large value if not present */
238
0
        ps_vu4->u4_num_reorder_frames = 64;
239
0
        ps_vu4->u4_max_dec_frame_buffering = 64;
240
0
    }
241
1
242
1
    return OK;
243
1
}
/proc/self/cwd/external/libavc/decoder/ih264d_vui.h
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
21
/*****************************************************************************/
22
/*                                                                           */
23
/*  File Name         : ih264d_vui.h                                                */
24
/*                                                                           */
25
/*  Description       : This file contains routines to parse SEI NAL's       */
26
/*                                                                           */
27
/*  List of Functions : <List the functions defined in this file>            */
28
/*                                                                           */
29
/*  Issues / Problems : None                                                 */
30
/*                                                                           */
31
/*  Revision History  :                                                      */
32
/*                                                                           */
33
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
34
/*         25 05 2005   NS              Draft                                */
35
/*                                                                           */
36
/*****************************************************************************/
37
38
#ifndef _IH264D_VUI_H_
39
#define _IH264D_VUI_H_
40
41
#include "ih264_typedefs.h"
42
#include "ih264_macros.h"
43
#include "ih264_platform_macros.h"
44
#include "ih264d_bitstrm.h"
45
46
1
#define VUI_EXTENDED_SAR    255
47
48
typedef struct
49
{
50
    UWORD32 u4_cpb_cnt;
51
    UWORD8 u1_bit_rate_scale;
52
    UWORD8 u1_cpb_size_scale;
53
    UWORD32 u4_bit_rate[32];
54
    UWORD32 u4_cpb_size[32];
55
    UWORD8 u1_cbr_flag[32];
56
    UWORD8 u1_initial_cpb_removal_delay;
57
    UWORD8 u1_cpb_removal_delay_length;
58
    UWORD8 u1_dpb_output_delay_length;
59
    UWORD8 u1_time_offset_length;
60
} hrd_t;
61
62
typedef struct
63
{
64
    UWORD8 u1_aspect_ratio_idc;
65
    UWORD16 u2_sar_width;
66
    UWORD16 u2_sar_height;
67
    UWORD8 u1_overscan_appropriate_flag;
68
    UWORD8 u1_video_format;
69
    UWORD8 u1_video_full_range_flag;
70
    UWORD8 u1_colour_primaries;
71
    UWORD8 u1_tfr_chars;
72
    UWORD8 u1_matrix_coeffs;
73
    UWORD8 u1_cr_top_field;
74
    UWORD8 u1_cr_bottom_field;
75
    UWORD32 u4_num_units_in_tick;
76
    UWORD32 u4_time_scale;
77
    UWORD8 u1_fixed_frame_rate_flag;
78
    UWORD8 u1_nal_hrd_params_present;
79
    hrd_t s_nal_hrd;
80
    UWORD8 u1_vcl_hrd_params_present;
81
    hrd_t s_vcl_hrd;
82
    UWORD8 u1_low_delay_hrd_flag;
83
    UWORD8 u1_pic_struct_present_flag;
84
    UWORD8 u1_bitstream_restriction_flag;
85
    UWORD8 u1_mv_over_pic_boundaries_flag;
86
    UWORD32 u4_max_bytes_per_pic_denom;
87
    UWORD32 u4_max_bits_per_mb_denom;
88
    UWORD32 u4_log2_max_mv_length_horz;
89
    UWORD32 u4_log2_max_mv_length_vert;
90
    UWORD32 u4_num_reorder_frames;
91
    UWORD32 u4_max_dec_frame_buffering;
92
} vui_t;
93
94
WORD32 ih264d_parse_vui_parametres(vui_t *ps_vu4,
95
                                   dec_bit_stream_t *ps_bitstrm);
96
#endif /* _SEI_H_ */
97
/proc/self/cwd/external/libavc/decoder/ivd.h
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/**
21
*******************************************************************************
22
* @file
23
*  ivd.h
24
*
25
* @brief
26
*  This file contains all the necessary structure and  enumeration
27
* definitions needed for the Application  Program Interface(API) of the
28
* Ittiam Video Decoders
29
*
30
* @author
31
*  100239(RCY)
32
*
33
* @remarks
34
*  None
35
*
36
*******************************************************************************
37
*/
38
39
#ifndef _IVD_H
40
#define _IVD_H
41
42
/*****************************************************************************/
43
/* Constant Macros                                                           */
44
/*****************************************************************************/
45
13
#define IVD_VIDDEC_MAX_IO_BUFFERS 64
46
/*****************************************************************************/
47
/* Typedefs                                                                  */
48
/*****************************************************************************/
49
50
/*****************************************************************************/
51
/* Enums                                                                     */
52
/*****************************************************************************/
53
54
/* IVD_ARCH_T: Architecture Enumeration                               */
55
typedef enum
56
{
57
    ARCH_NA                 =   0x7FFFFFFF,
58
    ARCH_ARM_NONEON         =   0x0,
59
    ARCH_ARM_A9Q,
60
    ARCH_ARM_A9A,
61
    ARCH_ARM_A9,
62
    ARCH_ARM_A7,
63
    ARCH_ARM_A5,
64
    ARCH_ARM_A15,
65
    ARCH_ARM_NEONINTR,
66
    ARCH_ARMV8_GENERIC,
67
    ARCH_X86_GENERIC        =   0x100,
68
    ARCH_X86_SSSE3,
69
    ARCH_X86_SSE42,
70
    ARCH_X86_AVX2,
71
    ARCH_MIPS_GENERIC       =   0x200,
72
    ARCH_MIPS_32
73
}IVD_ARCH_T;
74
75
/* IVD_SOC_T: SOC Enumeration                               */
76
typedef enum
77
{
78
    SOC_NA                  = 0x7FFFFFFF,
79
    SOC_GENERIC             = 0x0,
80
    SOC_HISI_37X            = 0x100,
81
}IVD_SOC_T;
82
83
/* IVD_FRAME_SKIP_MODE_T:Skip mode Enumeration                               */
84
85
typedef enum {
86
    IVD_SKIP_NONE                               = 0x7FFFFFFF,
87
    IVD_SKIP_P                                  = 0x1,
88
    IVD_SKIP_B                                  = 0x2,
89
    IVD_SKIP_I                                  = 0x3,
90
    IVD_SKIP_IP                                 = 0x4,
91
    IVD_SKIP_IB                                 = 0x5,
92
    IVD_SKIP_PB                                 = 0x6,
93
    IVD_SKIP_IPB                                = 0x7,
94
    IVD_SKIP_IDR                                = 0x8,
95
    IVD_SKIP_DEFAULT                            = IVD_SKIP_NONE,
96
}IVD_FRAME_SKIP_MODE_T;
97
98
/* IVD_VIDEO_DECODE_MODE_T: Set decoder to decode either frame worth of data */
99
/* or only header worth of data                                              */
100
101
typedef enum {
102
    IVD_DECODE_MODE_NA                          = 0x7FFFFFFF,
103
104
    /* This enables the codec to process all decodable units */
105
    IVD_DECODE_FRAME                            = 0x0,
106
107
    /* This enables the codec to decode header only */
108
    IVD_DECODE_HEADER                           = 0x1,
109
110
111
112
}IVD_VIDEO_DECODE_MODE_T;
113
114
115
/* IVD_DISPLAY_FRAME_OUT_MODE_T: Video Display Frame Output Mode             */
116
117
typedef enum {
118
119
    IVD_DISPLAY_ORDER_NA                        = 0x7FFFFFFF,
120
    /* To set codec to fill output buffers in display order */
121
    IVD_DISPLAY_FRAME_OUT                       = 0x0,
122
123
    /* To set codec to fill output buffers in decode order */
124
    IVD_DECODE_FRAME_OUT                        = 0x1,
125
}IVD_DISPLAY_FRAME_OUT_MODE_T;
126
127
128
/* IVD_API_COMMAND_TYPE_T:API command type                                   */
129
typedef enum {
130
    IVD_CMD_VIDEO_NA                          = 0x7FFFFFFF,
131
    IVD_CMD_CREATE                            = IV_CMD_DUMMY_ELEMENT + 1,
132
    IVD_CMD_DELETE,
133
    IVD_CMD_VIDEO_CTL,
134
    IVD_CMD_VIDEO_DECODE,
135
    IVD_CMD_GET_DISPLAY_FRAME,
136
    IVD_CMD_REL_DISPLAY_FRAME,
137
    IVD_CMD_SET_DISPLAY_FRAME
138
}IVD_API_COMMAND_TYPE_T;
139
140
/* IVD_CONTROL_API_COMMAND_TYPE_T: Video Control API command type            */
141
142
typedef enum {
143
    IVD_CMD_NA                          = 0x7FFFFFFF,
144
    IVD_CMD_CTL_GETPARAMS               = 0x0,
145
    IVD_CMD_CTL_SETPARAMS               = 0x1,
146
    IVD_CMD_CTL_RESET                   = 0x2,
147
    IVD_CMD_CTL_SETDEFAULT              = 0x3,
148
    IVD_CMD_CTL_FLUSH                   = 0x4,
149
    IVD_CMD_CTL_GETBUFINFO              = 0x5,
150
    IVD_CMD_CTL_GETVERSION              = 0x6,
151
    IVD_CMD_CTL_CODEC_SUBCMD_START         = 0x7
152
}IVD_CONTROL_API_COMMAND_TYPE_T;
153
154
155
/* IVD_ERROR_BITS_T: A UWORD32 container will be used for reporting the error*/
156
/* code to the application. The first 8 bits starting from LSB have been     */
157
/* reserved for the codec to report internal error details. The rest of the  */
158
/* bits will be generic for all video decoders and each bit has an associated*/
159
/* meaning as mentioned below. The unused bit fields are reserved for future */
160
/* extenstions and will be zero in the current implementation                */
161
162
typedef enum {
163
    /* Bit 8  - Applied concealment.                                         */
164
    IVD_APPLIEDCONCEALMENT                      = 0x8,
165
    /* Bit 9 - Insufficient input data.                                     */
166
    IVD_INSUFFICIENTDATA                        = 0x9,
167
    /* Bit 10 - Data problem/corruption.                                     */
168
    IVD_CORRUPTEDDATA                           = 0xa,
169
    /* Bit 11 - Header problem/corruption.                                   */
170
    IVD_CORRUPTEDHEADER                         = 0xb,
171
    /* Bit 12 - Unsupported feature/parameter in input.                      */
172
    IVD_UNSUPPORTEDINPUT                        = 0xc,
173
    /* Bit 13 - Unsupported input parameter orconfiguration.                 */
174
    IVD_UNSUPPORTEDPARAM                        = 0xd,
175
    /* Bit 14 - Fatal error (stop the codec).If there is an                  */
176
    /* error and this bit is not set, the error is a recoverable one.        */
177
    IVD_FATALERROR                              = 0xe,
178
    /* Bit 15 - Invalid bitstream. Applies when Bitstream/YUV frame          */
179
    /* buffer for encode/decode call is made with non-valid or zero u4_size  */
180
    /* data                                                                  */
181
    IVD_INVALID_BITSTREAM                       = 0xf,
182
    /* Bit 16          */
183
    IVD_INCOMPLETE_BITSTREAM                    = 0x10,
184
    IVD_ERROR_BITS_T_DUMMY_ELEMENT              = 0x7FFFFFFF
185
}IVD_ERROR_BITS_T;
186
187
188
/* IVD_CONTROL_API_COMMAND_TYPE_T: Video Control API command type            */
189
typedef enum {
190
    IVD_ERROR_NONE                              = 0x0,
191
    IVD_NUM_MEM_REC_FAILED                      = 0x1,
192
    IVD_NUM_REC_NOT_SUFFICIENT                  = 0x2,
193
    IVD_FILL_MEM_REC_FAILED                     = 0x3,
194
    IVD_REQUESTED_WIDTH_NOT_SUPPPORTED          = 0x4,
195
    IVD_REQUESTED_HEIGHT_NOT_SUPPPORTED         = 0x5,
196
    IVD_INIT_DEC_FAILED                         = 0x6,
197
    IVD_INIT_DEC_NOT_SUFFICIENT                 = 0x7,
198
    IVD_INIT_DEC_WIDTH_NOT_SUPPPORTED           = 0x8,
199
    IVD_INIT_DEC_HEIGHT_NOT_SUPPPORTED          = 0x9,
200
    IVD_INIT_DEC_MEM_NOT_ALIGNED                = 0xa,
201
    IVD_INIT_DEC_COL_FMT_NOT_SUPPORTED          = 0xb,
202
    IVD_INIT_DEC_MEM_REC_NOT_SUFFICIENT         = 0xc,
203
    IVD_GET_VERSION_DATABUFFER_SZ_INSUFFICIENT  = 0xd,
204
    IVD_BUFFER_SIZE_SET_TO_ZERO                 = 0xe,
205
    IVD_UNEXPECTED_END_OF_STREAM                = 0xf,
206
    IVD_SEQUENCE_HEADER_NOT_DECODED             = 0x10,
207
    IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED       = 0x11,
208
    IVD_MAX_FRAME_LIMIT_REACHED                 = 0x12,
209
    IVD_IP_API_STRUCT_SIZE_INCORRECT            = 0x13,
210
    IVD_OP_API_STRUCT_SIZE_INCORRECT            = 0x14,
211
    IVD_HANDLE_NULL                             = 0x15,
212
    IVD_HANDLE_STRUCT_SIZE_INCORRECT            = 0x16,
213
    IVD_INVALID_HANDLE_NULL                     = 0x17,
214
    IVD_INVALID_API_CMD                         = 0x18,
215
    IVD_UNSUPPORTED_API_CMD                     = 0x19,
216
    IVD_MEM_REC_STRUCT_SIZE_INCORRECT           = 0x1a,
217
    IVD_DISP_FRM_ZERO_OP_BUFS                   = 0x1b,
218
    IVD_DISP_FRM_OP_BUF_NULL                    = 0x1c,
219
    IVD_DISP_FRM_ZERO_OP_BUF_SIZE               = 0x1d,
220
    IVD_DEC_FRM_BS_BUF_NULL                     = 0x1e,
221
    IVD_SET_CONFG_INVALID_DEC_MODE              = 0x1f,
222
    IVD_SET_CONFG_UNSUPPORTED_DISP_WIDTH        = 0x20,
223
    IVD_RESET_FAILED                            = 0x21,
224
    IVD_INIT_DEC_MEM_REC_OVERLAP_ERR            = 0x22,
225
    IVD_INIT_DEC_MEM_REC_BASE_NULL              = 0x23,
226
    IVD_INIT_DEC_MEM_REC_ALIGNMENT_ERR          = 0x24,
227
    IVD_INIT_DEC_MEM_REC_INSUFFICIENT_SIZE      = 0x25,
228
    IVD_INIT_DEC_MEM_REC_INCORRECT_TYPE         = 0x26,
229
    IVD_DEC_NUMBYTES_INV                        = 0x27,
230
    IVD_DEC_REF_BUF_NULL                        = 0x28,
231
    IVD_DEC_FRM_SKIPPED                         = 0x29,
232
    IVD_RES_CHANGED                             = 0x2a,
233
    IVD_MEM_ALLOC_FAILED                        = 0x2b,
234
    IVD_DUMMY_ELEMENT_FOR_CODEC_EXTENSIONS      = 0xD0,
235
}IVD_ERROR_CODES_T;
236
237
238
/*****************************************************************************/
239
/* Structure                                                                 */
240
/*****************************************************************************/
241
/* structure for passing output buffers to codec during get display buffer   */
242
/* call                                                                      */
243
typedef struct {
244
245
    /**
246
     * number of output buffers
247
     */
248
    UWORD32             u4_num_bufs;
249
250
    /**
251
     *list of pointers to output buffers
252
     */
253
    UWORD8              *pu1_bufs[IVD_VIDDEC_MAX_IO_BUFFERS];
254
255
    /**
256
     * sizes of each output buffer
257
     */
258
    UWORD32             u4_min_out_buf_size[IVD_VIDDEC_MAX_IO_BUFFERS];
259
260
}ivd_out_bufdesc_t;
261
262
/*****************************************************************************/
263
/*   Create decoder                                                          */
264
/*****************************************************************************/
265
266
/* IVD_API_COMMAND_TYPE_T::e_cmd = IVD_CMD_CREATE                            */
267
268
269
typedef struct {
270
    /**
271
     * u4_size of the structure
272
     */
273
    UWORD32                                 u4_size;
274
275
    /**
276
     *  e_cmd
277
     */
278
    IVD_API_COMMAND_TYPE_T                  e_cmd;
279
280
    /**
281
     * format in which codec has to give out frame data for display
282
     */
283
    IV_COLOR_FORMAT_T                       e_output_format;
284
285
    /**
286
     * Flag to indicate shared display buffer mode
287
     */
288
    UWORD32                                 u4_share_disp_buf;
289
290
    /**
291
     * Pointer to a function for aligned allocation.
292
     */
293
    void    *(*pf_aligned_alloc)(void *pv_mem_ctxt, WORD32 alignment, WORD32 size);
294
295
    /**
296
     * Pointer to a function for aligned free.
297
     */
298
    void   (*pf_aligned_free)(void *pv_mem_ctxt, void *pv_buf);
299
300
    /**
301
     * Pointer to memory context that is needed during alloc/free for custom
302
     * memory managers. This will be passed as first argument to pf_aligned_alloc and
303
     * pf_aligned_free.
304
     * If application is using standard memory functions like
305
     * malloc/aligned_malloc/memalign/free/aligned_free,
306
     * then this is not needed and can be set to NULL
307
     */
308
    void    *pv_mem_ctxt;
309
310
}ivd_create_ip_t;
311
312
313
typedef struct{
314
    /**
315
     * u4_size of the structure
316
     */
317
    UWORD32                                 u4_size;
318
319
    /**
320
     * u4_error_code
321
     */
322
    UWORD32                                 u4_error_code;
323
324
    /**
325
     * Codec Handle
326
     */
327
    void                                    *pv_handle;
328
329
}ivd_create_op_t;
330
331
332
/*****************************************************************************/
333
/*  Delete decoder                                                           */
334
/*****************************************************************************/
335
336
/* IVD_API_COMMAND_TYPE_T::e_cmd = IVD_CMD_DELETE                              */
337
338
339
340
typedef struct {
341
    /**
342
     * u4_size of the structure
343
     */
344
    UWORD32                                     u4_size;
345
346
    /**
347
     * cmd
348
     */
349
    IVD_API_COMMAND_TYPE_T                       e_cmd;
350
351
}ivd_delete_ip_t;
352
353
354
typedef struct{
355
    /**
356
     * u4_size of the structure
357
     */
358
    UWORD32                                     u4_size;
359
360
    /**
361
     * error_code
362
     */
363
    UWORD32                                     u4_error_code;
364
365
}ivd_delete_op_t;
366
367
/*****************************************************************************/
368
/*   Video Decode                                                            */
369
/*****************************************************************************/
370
371
372
/* IVD_API_COMMAND_TYPE_T::e_cmd = IVD_CMD_VIDEO_DECODE                      */
373
374
375
typedef struct {
376
    /**
377
     * u4_size of the structure
378
     */
379
    UWORD32                                 u4_size;
380
381
    /**
382
     * e_cmd
383
     */
384
    IVD_API_COMMAND_TYPE_T                  e_cmd;
385
386
    /**
387
     * u4_ts
388
     */
389
    UWORD32                                 u4_ts;
390
391
    /**
392
     * u4_num_Bytes
393
     */
394
    UWORD32                                 u4_num_Bytes;
395
396
    /**
397
     * pv_stream_buffer
398
     */
399
    void                                    *pv_stream_buffer;
400
401
    /**
402
     * output buffer desc
403
     */
404
    ivd_out_bufdesc_t                       s_out_buffer;
405
406
}ivd_video_decode_ip_t;
407
408
409
typedef struct{
410
    /**
411
     * u4_size of the structure
412
     */
413
    UWORD32                                 u4_size;
414
415
    /**
416
     * u4_error_code
417
     */
418
    UWORD32                                 u4_error_code;
419
420
    /**
421
     * num_bytes_consumed
422
     */
423
    UWORD32                                 u4_num_bytes_consumed;
424
425
    /**
426
     * pic_wd
427
     */
428
    UWORD32                                 u4_pic_wd;
429
430
    /**
431
     * pic_ht
432
     */
433
    UWORD32                                 u4_pic_ht;
434
435
    /**
436
     * pic_type
437
     */
438
    IV_PICTURE_CODING_TYPE_T                e_pic_type;
439
440
    /**
441
     * frame_decoded_flag
442
     */
443
    UWORD32                                 u4_frame_decoded_flag;
444
445
    /**
446
     * new_seq
447
     */
448
    UWORD32                                 u4_new_seq;
449
450
    /**
451
     * output_present
452
     */
453
    UWORD32                                 u4_output_present;
454
455
    /**
456
     * progressive_frame_flag
457
     */
458
    UWORD32                                 u4_progressive_frame_flag;
459
460
    /**
461
     * is_ref_flag
462
     */
463
    UWORD32                                 u4_is_ref_flag;
464
465
    /**
466
     * output_format
467
     */
468
    IV_COLOR_FORMAT_T                       e_output_format;
469
470
    /**
471
     * disp_frm_buf
472
     */
473
    iv_yuv_buf_t                            s_disp_frm_buf;
474
475
    /**
476
     * fld_type
477
     */
478
    IV_FLD_TYPE_T                           e4_fld_type;
479
480
    /**
481
     * ts
482
     */
483
    UWORD32                                 u4_ts;
484
485
    /**
486
     * disp_buf_id
487
     */
488
    UWORD32                                 u4_disp_buf_id;
489
}ivd_video_decode_op_t;
490
491
492
/*****************************************************************************/
493
/*   Get Display Frame                                                       */
494
/*****************************************************************************/
495
496
497
/* IVD_API_COMMAND_TYPE_T::e_cmd = IVD_CMD_GET_DISPLAY_FRAME                 */
498
499
typedef struct
500
{
501
    /**
502
     * u4_size of the structure
503
     */
504
    UWORD32                                 u4_size;
505
506
    /**
507
     * e_cmd
508
     */
509
    IVD_API_COMMAND_TYPE_T                  e_cmd;
510
511
    /**
512
     * output buffer desc
513
     */
514
    ivd_out_bufdesc_t                       s_out_buffer;
515
516
}ivd_get_display_frame_ip_t;
517
518
519
typedef struct
520
{
521
    /**
522
     * u4_size of the structure
523
     */
524
    UWORD32                                 u4_size;
525
526
    /**
527
     * error_code
528
     */
529
    UWORD32                                 u4_error_code;
530
531
    /**
532
     * progressive_frame_flag
533
     */
534
    UWORD32                                 u4_progressive_frame_flag;
535
536
    /**
537
     * pic_type
538
     */
539
    IV_PICTURE_CODING_TYPE_T                e_pic_type;
540
541
    /**
542
     * is_ref_flag
543
     */
544
    UWORD32                                 u4_is_ref_flag;
545
546
    /**
547
     * output_format
548
     */
549
    IV_COLOR_FORMAT_T                       e_output_format;
550
551
    /**
552
     * disp_frm_buf
553
     */
554
    iv_yuv_buf_t                            s_disp_frm_buf;
555
556
    /**
557
     * fld_type
558
     */
559
    IV_FLD_TYPE_T                           e4_fld_type;
560
561
    /**
562
     * ts
563
     */
564
    UWORD32                                 u4_ts;
565
566
    /**
567
     * disp_buf_id
568
     */
569
    UWORD32                                 u4_disp_buf_id;
570
}ivd_get_display_frame_op_t;
571
572
/*****************************************************************************/
573
/*   Set Display Frame                                                       */
574
/*****************************************************************************/
575
576
577
/* IVD_API_COMMAND_TYPE_T::e_cmd = IVD_CMD_SET_DISPLAY_FRAME                 */
578
579
typedef struct
580
{
581
    /**
582
     * u4_size of the structure
583
     */
584
    UWORD32                                 u4_size;
585
586
    /**
587
     * cmd
588
     */
589
    IVD_API_COMMAND_TYPE_T                  e_cmd;
590
591
    /**
592
     * num_disp_bufs
593
     */
594
    UWORD32                                 num_disp_bufs;
595
596
    /**
597
     * output buffer desc
598
     */
599
    ivd_out_bufdesc_t                       s_disp_buffer[IVD_VIDDEC_MAX_IO_BUFFERS];
600
601
}ivd_set_display_frame_ip_t;
602
603
604
typedef struct
605
{
606
    /**
607
     * u4_size of the structure
608
     */
609
    UWORD32                                 u4_size;
610
611
    /**
612
     * error code
613
     */
614
    UWORD32                                 u4_error_code;
615
}ivd_set_display_frame_op_t;
616
617
618
/*****************************************************************************/
619
/*   Release Display Frame                                                       */
620
/*****************************************************************************/
621
622
623
/* IVD_API_COMMAND_TYPE_T::e_cmd = IVD_CMD_SET_DISPLAY_FRAME                 */
624
625
typedef struct
626
{
627
    /**
628
     * u4_size of the structure
629
     */
630
    UWORD32                                 u4_size;
631
632
    /**
633
     * e_cmd
634
     */
635
    IVD_API_COMMAND_TYPE_T                  e_cmd;
636
637
    /**
638
     * disp_buf_id
639
     */
640
    UWORD32                                 u4_disp_buf_id;
641
}ivd_rel_display_frame_ip_t;
642
643
644
typedef struct
645
{
646
    /**
647
     * u4_size of the structure
648
     */
649
    UWORD32                                 u4_size;
650
651
    /**
652
     * error code
653
     */
654
    UWORD32                                 u4_error_code;
655
}ivd_rel_display_frame_op_t;
656
657
/*****************************************************************************/
658
/*   Video control  Flush                                                    */
659
/*****************************************************************************/
660
/* IVD_API_COMMAND_TYPE_T::e_cmd            = IVD_CMD_VIDEO_CTL              */
661
/* IVD_CONTROL_API_COMMAND_TYPE_T::e_sub_cmd    = IVD_CMD_ctl_FLUSH          */
662
663
664
665
typedef struct{
666
    /**
667
     * u4_size of the structure
668
     */
669
    UWORD32                                 u4_size;
670
671
    /**
672
     * cmd
673
     */
674
    IVD_API_COMMAND_TYPE_T                  e_cmd;
675
676
    /**
677
     * sub_cmd
678
     */
679
    IVD_CONTROL_API_COMMAND_TYPE_T          e_sub_cmd;
680
}ivd_ctl_flush_ip_t;
681
682
683
typedef struct{
684
    /**
685
     * u4_size of the structure
686
     */
687
    UWORD32                                 u4_size;
688
689
    /**
690
     * error code
691
     */
692
    UWORD32                                 u4_error_code;
693
}ivd_ctl_flush_op_t;
694
695
/*****************************************************************************/
696
/*   Video control reset                                                     */
697
/*****************************************************************************/
698
/* IVD_API_COMMAND_TYPE_T::e_cmd            = IVD_CMD_VIDEO_CTL              */
699
/* IVD_CONTROL_API_COMMAND_TYPE_T::e_sub_cmd    = IVD_CMD_ctl_RESET          */
700
701
702
typedef struct{
703
    /**
704
     * u4_size of the structure
705
     */
706
    UWORD32                                 u4_size;
707
708
    /**
709
     * cmd
710
     */
711
    IVD_API_COMMAND_TYPE_T                  e_cmd;
712
713
    /**
714
     * sub_cmd
715
     */
716
717
    IVD_CONTROL_API_COMMAND_TYPE_T          e_sub_cmd;
718
}ivd_ctl_reset_ip_t;
719
720
721
typedef struct{
722
    /**
723
     * u4_size of the structure
724
     */
725
    UWORD32                                 u4_size;
726
727
    /**
728
     * error code
729
     */
730
    UWORD32                                 u4_error_code;
731
}ivd_ctl_reset_op_t;
732
733
734
/*****************************************************************************/
735
/*   Video control  Set Params                                               */
736
/*****************************************************************************/
737
/* IVD_API_COMMAND_TYPE_T::e_cmd        = IVD_CMD_VIDEO_CTL                  */
738
/* IVD_CONTROL_API_COMMAND_TYPE_T::e_sub_cmd=IVD_CMD_ctl_SETPARAMS           */
739
/* IVD_CONTROL_API_COMMAND_TYPE_T::e_sub_cmd=IVD_CMD_ctl_SETDEFAULT          */
740
741
742
743
typedef struct {
744
    /**
745
     * u4_size of the structure
746
     */
747
    UWORD32                                     u4_size;
748
749
    /**
750
     * cmd
751
     */
752
    IVD_API_COMMAND_TYPE_T                      e_cmd;
753
754
    /**
755
     * sub_cmd
756
     */
757
    IVD_CONTROL_API_COMMAND_TYPE_T              e_sub_cmd;
758
759
    /**
760
     * vid_dec_mode
761
     */
762
    IVD_VIDEO_DECODE_MODE_T                     e_vid_dec_mode;
763
764
    /**
765
     * disp_wd
766
     */
767
    UWORD32                                     u4_disp_wd;
768
769
    /**
770
     * frm_skip_mode
771
     */
772
    IVD_FRAME_SKIP_MODE_T                       e_frm_skip_mode;
773
774
    /**
775
     * frm_out_mode
776
     */
777
    IVD_DISPLAY_FRAME_OUT_MODE_T                e_frm_out_mode;
778
}ivd_ctl_set_config_ip_t;
779
780
781
typedef struct{
782
    /**
783
     * u4_size of the structure
784
     */
785
    UWORD32                                     u4_size;
786
787
    /**
788
     * u4_error_code
789
     */
790
    UWORD32                                     u4_error_code;
791
}ivd_ctl_set_config_op_t;
792
793
/*****************************************************************************/
794
/*   Video control:Get Buf Info                                              */
795
/*****************************************************************************/
796
797
/* IVD_API_COMMAND_TYPE_T::e_cmd         = IVD_CMD_VIDEO_CTL                 */
798
/* IVD_CONTROL_API_COMMAND_TYPE_T::e_sub_cmd=IVD_CMD_ctl_GETBUFINFO          */
799
800
801
typedef struct{
802
    /**
803
     * u4_size of the structure
804
     */
805
    UWORD32                                     u4_size;
806
807
    /**
808
     *  e_cmd
809
     */
810
    IVD_API_COMMAND_TYPE_T                      e_cmd;
811
812
    /**
813
     * sub_cmd
814
     */
815
    IVD_CONTROL_API_COMMAND_TYPE_T              e_sub_cmd;
816
}ivd_ctl_getbufinfo_ip_t;
817
818
819
typedef struct{
820
    /**
821
     * u4_size of the structure
822
     */
823
    UWORD32                                     u4_size;
824
825
    /**
826
     * error code
827
     */
828
    UWORD32                                     u4_error_code;
829
830
    /**
831
     * no of display buffer sets required by codec
832
     */
833
    UWORD32                                     u4_num_disp_bufs;
834
835
    /**
836
     * no of input buffers required for codec
837
     */
838
    UWORD32                                     u4_min_num_in_bufs;
839
840
    /**
841
     * no of output buffers required for codec
842
     */
843
    UWORD32                                     u4_min_num_out_bufs;
844
845
    /**
846
     * sizes of each input buffer required
847
     */
848
    UWORD32                                     u4_min_in_buf_size[IVD_VIDDEC_MAX_IO_BUFFERS];
849
850
    /**
851
     * sizes of each output buffer required
852
     */
853
    UWORD32                                     u4_min_out_buf_size[IVD_VIDDEC_MAX_IO_BUFFERS];
854
}ivd_ctl_getbufinfo_op_t;
855
856
857
/*****************************************************************************/
858
/*   Video control:Getstatus Call                                            */
859
/*****************************************************************************/
860
861
862
/* IVD_API_COMMAND_TYPE_T::e_cmd        = IVD_CMD_VIDEO_CTL                  */
863
/* IVD_CONTROL_API_COMMAND_TYPE_T::e_sub_cmd=IVD_CMD_ctl_GETPARAMS           */
864
865
866
typedef struct{
867
    /**
868
     * u4_size of the structure
869
     */
870
    UWORD32                                     u4_size;
871
872
    /**
873
     * cmd
874
     */
875
    IVD_API_COMMAND_TYPE_T                      e_cmd;
876
877
    /**
878
     * sub_cmd
879
     */
880
    IVD_CONTROL_API_COMMAND_TYPE_T              e_sub_cmd;
881
}ivd_ctl_getstatus_ip_t;
882
883
884
typedef struct{
885
886
     /**
887
      * u4_size of the structure
888
      */
889
    UWORD32                  u4_size;
890
891
    /**
892
      * error code
893
      */
894
    UWORD32                  u4_error_code;
895
896
    /**
897
     * no of display buffer sets required by codec
898
     */
899
    UWORD32                  u4_num_disp_bufs;
900
901
    /**
902
     * u4_pic_ht
903
     */
904
    UWORD32                  u4_pic_ht;
905
906
    /**
907
     * u4_pic_wd
908
     */
909
    UWORD32                  u4_pic_wd;
910
911
    /**
912
     * frame_rate
913
     */
914
    UWORD32                  u4_frame_rate;
915
916
    /**
917
     * u4_bit_rate
918
     */
919
    UWORD32                  u4_bit_rate;
920
921
    /**
922
     * content_type
923
     */
924
    IV_CONTENT_TYPE_T        e_content_type;
925
926
    /**
927
     * output_chroma_format
928
     */
929
    IV_COLOR_FORMAT_T        e_output_chroma_format;
930
931
    /**
932
     * no of input buffers required for codec
933
     */
934
    UWORD32                  u4_min_num_in_bufs;
935
936
    /**
937
     * no of output buffers required for codec
938
     */
939
    UWORD32                  u4_min_num_out_bufs;
940
941
    /**
942
     * sizes of each input buffer required
943
     */
944
    UWORD32                  u4_min_in_buf_size[IVD_VIDDEC_MAX_IO_BUFFERS];
945
946
    /**
947
     * sizes of each output buffer required
948
     */
949
    UWORD32                  u4_min_out_buf_size[IVD_VIDDEC_MAX_IO_BUFFERS];
950
}ivd_ctl_getstatus_op_t;
951
952
953
/*****************************************************************************/
954
/*   Video control:Get Version Info                                          */
955
/*****************************************************************************/
956
957
/* IVD_API_COMMAND_TYPE_T::e_cmd        = IVD_CMD_VIDEO_CTL                  */
958
/* IVD_CONTROL_API_COMMAND_TYPE_T::e_sub_cmd=IVD_CMD_ctl_GETVERSION          */
959
960
961
typedef struct{
962
    /**
963
     * u4_size of the structure
964
     */
965
    UWORD32                                     u4_size;
966
967
    /**
968
     * cmd
969
     */
970
    IVD_API_COMMAND_TYPE_T                      e_cmd;
971
972
    /**
973
     * sub_cmd
974
     */
975
    IVD_CONTROL_API_COMMAND_TYPE_T              e_sub_cmd;
976
977
    /**
978
     * pv_version_buffer
979
     */
980
    void                                        *pv_version_buffer;
981
982
    /**
983
     * version_buffer_size
984
     */
985
    UWORD32                                     u4_version_buffer_size;
986
}ivd_ctl_getversioninfo_ip_t;
987
988
989
typedef struct{
990
    /**
991
     * u4_size of the structure
992
     */
993
    UWORD32                                     u4_size;
994
995
    /**
996
     * error code
997
     */
998
    UWORD32                                     u4_error_code;
999
}ivd_ctl_getversioninfo_op_t;
1000
1001
#endif /* __IVD_H__ */
1002
/proc/self/cwd/external/libavc/decoder/x86/ih264d_function_selector.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/**
21
*******************************************************************************
22
* @file
23
*  imp2d_function_selector.c
24
*
25
* @brief
26
*  Contains functions to initialize function pointers used in hevc
27
*
28
* @author
29
*  Naveen
30
*
31
* @par List of Functions:
32
* @remarks
33
*  None
34
*
35
*******************************************************************************
36
*/
37
/*****************************************************************************/
38
/* File Includes                                                             */
39
/*****************************************************************************/
40
41
#include <stdio.h>
42
#include <stddef.h>
43
#include <stdlib.h>
44
#include <string.h>
45
46
/* User Include files */
47
#include "ih264_typedefs.h"
48
#include "iv.h"
49
#include "ivd.h"
50
#include "ih264_defs.h"
51
#include "ih264_size_defs.h"
52
#include "ih264_error.h"
53
#include "ih264_trans_quant_itrans_iquant.h"
54
#include "ih264_inter_pred_filters.h"
55
56
#include "ih264d_structs.h"
57
#include "ih264d_function_selector.h"
58
59
void ih264d_init_function_ptr(dec_struct_t *ps_codec)
60
2
{
61
2
62
2
    ih264d_init_function_ptr_generic(ps_codec);
63
2
    switch(ps_codec->e_processor_arch)
64
2
    {
65
2
        case ARCH_X86_GENERIC:
66
0
            ih264d_init_function_ptr_generic(ps_codec);
67
0
        break;
68
2
        case ARCH_X86_SSSE3:
69
0
            ih264d_init_function_ptr_ssse3(ps_codec);
70
0
            break;
71
2
        case ARCH_X86_SSE42:
72
2
        default:
73
2
            ih264d_init_function_ptr_ssse3(ps_codec);
74
2
            ih264d_init_function_ptr_sse42(ps_codec);
75
2
        break;
76
2
    }
77
2
}
78
void ih264d_init_arch(dec_struct_t *ps_codec)
79
2
{
80
2
#ifdef DEFAULT_ARCH
81
2
#if DEFAULT_ARCH == D_ARCH_X86_SSE42
82
2
    ps_codec->e_processor_arch = ARCH_X86_SSE42;
83
#elif DEFAULT_ARCH == D_ARCH_X86_SSSE3
84
    ps_codec->e_processor_arch = ARCH_X86_SSSE3;
85
#elif DEFAULT_ARCH == D_ARCH_X86_AVX2
86
    ps_codec->e_processor_arch = D_ARCH_X86_AVX2;
87
#else
88
    ps_codec->e_processor_arch = ARCH_X86_GENERIC;
89
#endif
90
#else
91
    ps_codec->e_processor_arch = ARCH_X86_SSE42;
92
#endif
93
94
2
}
/proc/self/cwd/external/libavc/decoder/x86/ih264d_function_selector_sse42.c
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/**
21
*******************************************************************************
22
* @file
23
*  ih264e_function_selector_generic.c
24
*
25
* @brief
26
*  Contains functions to initialize function pointers of codec context
27
*
28
* @author
29
*  Ittiam
30
*
31
* @par List of Functions:
32
*  - ih264e_init_function_ptr_generic
33
*
34
* @remarks
35
*  None
36
*
37
*******************************************************************************
38
*/
39
40
41
/*****************************************************************************/
42
/* File Includes                                                             */
43
/*****************************************************************************/
44
45
/* System Include files */
46
#include <stdio.h>
47
#include <stddef.h>
48
#include <stdlib.h>
49
#include <string.h>
50
51
/* User Include files */
52
#include "ih264_typedefs.h"
53
#include "iv.h"
54
#include "ivd.h"
55
#include "ih264_defs.h"
56
#include "ih264_size_defs.h"
57
#include "ih264_error.h"
58
#include "ih264_trans_quant_itrans_iquant.h"
59
#include "ih264_inter_pred_filters.h"
60
61
#include "ih264d_structs.h"
62
63
64
/**
65
*******************************************************************************
66
*
67
* @brief Initialize the intra/inter/transform/deblk function pointers of
68
* codec context
69
*
70
* @par Description: the current routine initializes the function pointers of
71
* codec context basing on the architecture in use
72
*
73
* @param[in] ps_codec
74
*  Codec context pointer
75
*
76
* @returns  none
77
*
78
* @remarks none
79
*
80
*******************************************************************************
81
*/
82
void ih264d_init_function_ptr_sse42(dec_struct_t *ps_codec)
83
2
{
84
2
    ps_codec->pf_default_weighted_pred_luma = ih264_default_weighted_pred_luma_sse42;
85
2
    ps_codec->pf_default_weighted_pred_chroma = ih264_default_weighted_pred_chroma_sse42;
86
2
    ps_codec->pf_weighted_pred_luma = ih264_weighted_pred_luma_sse42;
87
2
    ps_codec->pf_weighted_pred_chroma = ih264_weighted_pred_chroma_sse42;
88
2
    ps_codec->pf_weighted_bi_pred_luma = ih264_weighted_bi_pred_luma_sse42;
89
2
    ps_codec->pf_weighted_bi_pred_chroma = ih264_weighted_bi_pred_chroma_sse42;
90
2
91
2
    ps_codec->pf_iquant_itrans_recon_luma_4x4 = ih264_iquant_itrans_recon_4x4_sse42;
92
2
    ps_codec->pf_iquant_itrans_recon_chroma_4x4 = ih264_iquant_itrans_recon_chroma_4x4_sse42;
93
2
    ps_codec->pf_ihadamard_scaling_4x4 = ih264_ihadamard_scaling_4x4_sse42;
94
2
    return;
95
2
}
/proc/self/cwd/external/libavc/decoder/x86/ih264d_function_selector_ssse3.c
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
/**
21
*******************************************************************************
22
* @file
23
*  ih264e_function_selector_generic.c
24
*
25
* @brief
26
*  Contains functions to initialize function pointers of codec context
27
*
28
* @author
29
*  Ittiam
30
*
31
* @par List of Functions:
32
*  - ih264e_init_function_ptr_generic
33
*
34
* @remarks
35
*  None
36
*
37
*******************************************************************************
38
*/
39
40
41
/*****************************************************************************/
42
/* File Includes                                                             */
43
/*****************************************************************************/
44
45
/* System Include files */
46
#include <stdio.h>
47
#include <stddef.h>
48
#include <stdlib.h>
49
#include <string.h>
50
51
/* User Include files */
52
#include "ih264_typedefs.h"
53
#include "iv.h"
54
#include "ivd.h"
55
#include "ih264_defs.h"
56
#include "ih264_size_defs.h"
57
#include "ih264_error.h"
58
#include "ih264_trans_quant_itrans_iquant.h"
59
#include "ih264_inter_pred_filters.h"
60
61
#include "ih264d_structs.h"
62
63
64
/**
65
*******************************************************************************
66
*
67
* @brief Initialize the intra/inter/transform/deblk function pointers of
68
* codec context
69
*
70
* @par Description: the current routine initializes the function pointers of
71
* codec context basing on the architecture in use
72
*
73
* @param[in] ps_codec
74
*  Codec context pointer
75
*
76
* @returns  none
77
*
78
* @remarks none
79
*
80
*******************************************************************************
81
*/
82
void ih264d_init_function_ptr_ssse3(dec_struct_t *ps_codec)
83
2
{
84
2
85
2
86
2
87
2
    /* Init function pointers for intra pred leaf level functions luma
88
2
     * Intra 16x16 */
89
2
    ps_codec->apf_intra_pred_luma_16x16[0] = ih264_intra_pred_luma_16x16_mode_vert_ssse3;
90
2
    ps_codec->apf_intra_pred_luma_16x16[1] = ih264_intra_pred_luma_16x16_mode_horz_ssse3;
91
2
    ps_codec->apf_intra_pred_luma_16x16[2] = ih264_intra_pred_luma_16x16_mode_dc_ssse3;
92
2
    ps_codec->apf_intra_pred_luma_16x16[3] = ih264_intra_pred_luma_16x16_mode_plane_ssse3;
93
2
94
2
    /* Init function pointers for intra pred leaf level functions luma
95
2
     * Intra 4x4 */
96
2
    ps_codec->apf_intra_pred_luma_4x4[0] = ih264_intra_pred_luma_4x4_mode_vert_ssse3;
97
2
    ps_codec->apf_intra_pred_luma_4x4[1] = ih264_intra_pred_luma_4x4_mode_horz_ssse3;
98
2
    ps_codec->apf_intra_pred_luma_4x4[2] = ih264_intra_pred_luma_4x4_mode_dc_ssse3;
99
2
    ps_codec->apf_intra_pred_luma_4x4[3] = ih264_intra_pred_luma_4x4_mode_diag_dl_ssse3;
100
2
    ps_codec->apf_intra_pred_luma_4x4[4] = ih264_intra_pred_luma_4x4_mode_diag_dr_ssse3;
101
2
    ps_codec->apf_intra_pred_luma_4x4[5] = ih264_intra_pred_luma_4x4_mode_vert_r_ssse3;
102
2
    ps_codec->apf_intra_pred_luma_4x4[6] = ih264_intra_pred_luma_4x4_mode_horz_d_ssse3;
103
2
    ps_codec->apf_intra_pred_luma_4x4[7] = ih264_intra_pred_luma_4x4_mode_vert_l_ssse3;
104
2
    ps_codec->apf_intra_pred_luma_4x4[8] = ih264_intra_pred_luma_4x4_mode_horz_u_ssse3;
105
2
106
2
    /* Init function pointers for intra pred leaf level functions luma
107
2
     * Intra 8x8 */
108
2
    ps_codec->apf_intra_pred_luma_8x8[0] = ih264_intra_pred_luma_8x8_mode_vert_ssse3;
109
2
    ps_codec->apf_intra_pred_luma_8x8[1] = ih264_intra_pred_luma_8x8_mode_horz_ssse3;
110
2
    ps_codec->apf_intra_pred_luma_8x8[2] = ih264_intra_pred_luma_8x8_mode_dc_ssse3;
111
2
    ps_codec->apf_intra_pred_luma_8x8[3] = ih264_intra_pred_luma_8x8_mode_diag_dl_ssse3;
112
2
    ps_codec->apf_intra_pred_luma_8x8[4] = ih264_intra_pred_luma_8x8_mode_diag_dr_ssse3;
113
2
    ps_codec->apf_intra_pred_luma_8x8[5] = ih264_intra_pred_luma_8x8_mode_vert_r_ssse3;
114
2
    ps_codec->apf_intra_pred_luma_8x8[6] = ih264_intra_pred_luma_8x8_mode_horz_d_ssse3;
115
2
    ps_codec->apf_intra_pred_luma_8x8[7] = ih264_intra_pred_luma_8x8_mode_vert_l_ssse3;
116
2
    ps_codec->apf_intra_pred_luma_8x8[8] = ih264_intra_pred_luma_8x8_mode_horz_u_ssse3;
117
2
118
2
    ps_codec->pf_intra_pred_ref_filtering = ih264_intra_pred_luma_8x8_mode_ref_filtering;
119
2
120
2
    /* Init function pointers for intra pred leaf level functions chroma
121
2
     * Intra 8x8 */
122
2
    ps_codec->apf_intra_pred_chroma[0] = ih264_intra_pred_chroma_8x8_mode_vert_ssse3;
123
2
    ps_codec->apf_intra_pred_chroma[1] = ih264_intra_pred_chroma_8x8_mode_horz_ssse3;
124
2
    ps_codec->apf_intra_pred_chroma[2] = ih264_intra_pred_chroma_8x8_mode_dc;
125
2
    ps_codec->apf_intra_pred_chroma[3] = ih264_intra_pred_chroma_8x8_mode_plane_ssse3;
126
2
127
2
128
2
    ps_codec->pf_pad_left_luma = ih264_pad_left_luma_ssse3;
129
2
    ps_codec->pf_pad_left_chroma = ih264_pad_left_chroma_ssse3;
130
2
    ps_codec->pf_pad_right_luma = ih264_pad_right_luma_ssse3;
131
2
    ps_codec->pf_pad_right_chroma = ih264_pad_right_chroma_ssse3;
132
2
133
2
134
2
    ps_codec->pf_iquant_itrans_recon_luma_4x4 = ih264_iquant_itrans_recon_4x4_ssse3;
135
2
    ps_codec->pf_iquant_itrans_recon_luma_4x4_dc = ih264_iquant_itrans_recon_4x4_dc_ssse3;
136
2
    ps_codec->pf_iquant_itrans_recon_luma_8x8 = ih264_iquant_itrans_recon_8x8_ssse3;
137
2
    ps_codec->pf_iquant_itrans_recon_luma_8x8_dc = ih264_iquant_itrans_recon_8x8_dc_ssse3;
138
2
139
2
    ps_codec->pf_iquant_itrans_recon_chroma_4x4_dc = ih264_iquant_itrans_recon_chroma_4x4_dc_ssse3;
140
2
141
2
    /* Init fn ptr luma deblocking */
142
2
    ps_codec->pf_deblk_luma_vert_bs4 = ih264_deblk_luma_vert_bs4_ssse3;
143
2
    ps_codec->pf_deblk_luma_vert_bslt4 = ih264_deblk_luma_vert_bslt4_ssse3;
144
2
    ps_codec->pf_deblk_luma_vert_bs4_mbaff = ih264_deblk_luma_vert_bs4_mbaff_ssse3;
145
2
    ps_codec->pf_deblk_luma_vert_bslt4_mbaff = ih264_deblk_luma_vert_bslt4_mbaff_ssse3;
146
2
147
2
    ps_codec->pf_deblk_luma_horz_bs4 = ih264_deblk_luma_horz_bs4_ssse3;
148
2
    ps_codec->pf_deblk_luma_horz_bslt4 = ih264_deblk_luma_horz_bslt4_ssse3;
149
2
150
2
    /* Init fn ptr chroma deblocking */
151
2
    ps_codec->pf_deblk_chroma_vert_bs4 = ih264_deblk_chroma_vert_bs4_ssse3;
152
2
    ps_codec->pf_deblk_chroma_horz_bs4 = ih264_deblk_chroma_horz_bs4_ssse3;
153
2
    ps_codec->pf_deblk_chroma_vert_bs4_mbaff = ih264_deblk_chroma_vert_bs4_mbaff_ssse3;
154
2
    ps_codec->pf_deblk_chroma_vert_bslt4 = ih264_deblk_chroma_vert_bslt4_ssse3;
155
2
    ps_codec->pf_deblk_chroma_horz_bslt4 = ih264_deblk_chroma_horz_bslt4_ssse3;
156
2
    ps_codec->pf_deblk_chroma_vert_bslt4_mbaff = ih264_deblk_chroma_vert_bslt4_mbaff_ssse3;
157
2
158
2
    /* Inter pred leaf level functions */
159
2
160
2
    ps_codec->apf_inter_pred_luma[0] = ih264_inter_pred_luma_copy_ssse3;
161
2
    ps_codec->apf_inter_pred_luma[1] = ih264_inter_pred_luma_horz_qpel_ssse3;
162
2
    ps_codec->apf_inter_pred_luma[2] = ih264_inter_pred_luma_horz_ssse3;
163
2
    ps_codec->apf_inter_pred_luma[3] = ih264_inter_pred_luma_horz_qpel_ssse3;
164
2
    ps_codec->apf_inter_pred_luma[4] = ih264_inter_pred_luma_vert_qpel_ssse3;
165
2
    ps_codec->apf_inter_pred_luma[5] = ih264_inter_pred_luma_horz_qpel_vert_qpel_ssse3;
166
2
    ps_codec->apf_inter_pred_luma[6] = ih264_inter_pred_luma_horz_hpel_vert_qpel_ssse3;
167
2
    ps_codec->apf_inter_pred_luma[7] = ih264_inter_pred_luma_horz_qpel_vert_qpel_ssse3;
168
2
    ps_codec->apf_inter_pred_luma[8] = ih264_inter_pred_luma_vert_ssse3;
169
2
    ps_codec->apf_inter_pred_luma[9] = ih264_inter_pred_luma_horz_qpel_vert_hpel_ssse3;
170
2
    ps_codec->apf_inter_pred_luma[10] = ih264_inter_pred_luma_horz_hpel_vert_hpel_ssse3;
171
2
    ps_codec->apf_inter_pred_luma[11] = ih264_inter_pred_luma_horz_qpel_vert_hpel_ssse3;
172
2
    ps_codec->apf_inter_pred_luma[12] = ih264_inter_pred_luma_vert_qpel_ssse3;
173
2
    ps_codec->apf_inter_pred_luma[13] = ih264_inter_pred_luma_horz_qpel_vert_qpel_ssse3;
174
2
    ps_codec->apf_inter_pred_luma[14] = ih264_inter_pred_luma_horz_hpel_vert_qpel_ssse3;
175
2
    ps_codec->apf_inter_pred_luma[15] = ih264_inter_pred_luma_horz_qpel_vert_qpel_ssse3;
176
2
177
2
    ps_codec->pf_inter_pred_chroma = ih264_inter_pred_chroma_ssse3;
178
2
179
2
180
2
    return;
181
2
}
/proc/self/cwd/external/libcxx/include/support/xlocale/__posix_l_fallback.h
Line
Count
Source (jump to first uncovered line)
1
// -*- C++ -*-
2
//===--------------- support/xlocale/__posix_l_fallback.h -----------------===//
3
//
4
//                     The LLVM Compiler Infrastructure
5
//
6
// This file is dual licensed under the MIT and the University of Illinois Open
7
// Source Licenses. See LICENSE.TXT for details.
8
//
9
//===----------------------------------------------------------------------===//
10
// These are reimplementations of some extended locale functions ( *_l ) that
11
// are normally part of POSIX.  This shared implementation provides parts of the
12
// extended locale support for libc's that normally don't have any (like
13
// Android's bionic and Newlib).
14
//===----------------------------------------------------------------------===//
15
16
#ifndef _LIBCPP_SUPPORT_XLOCALE_POSIX_L_FALLBACK_H
17
#define _LIBCPP_SUPPORT_XLOCALE_POSIX_L_FALLBACK_H
18
19
#ifdef __cplusplus
20
extern "C" {
21
#endif
22
23
0
inline _LIBCPP_ALWAYS_INLINE int isalnum_l(int c, locale_t) {
24
0
  return ::isalnum(c);
25
0
}
26
27
0
inline _LIBCPP_ALWAYS_INLINE int isalpha_l(int c, locale_t) {
28
0
  return ::isalpha(c);
29
0
}
30
31
0
inline _LIBCPP_ALWAYS_INLINE int isblank_l(int c, locale_t) {
32
0
  return ::isblank(c);
33
0
}
34
35
0
inline _LIBCPP_ALWAYS_INLINE int iscntrl_l(int c, locale_t) {
36
0
  return ::iscntrl(c);
37
0
}
38
39
0
inline _LIBCPP_ALWAYS_INLINE int isdigit_l(int c, locale_t) {
40
0
  return ::isdigit(c);
41
0
}
42
43
0
inline _LIBCPP_ALWAYS_INLINE int isgraph_l(int c, locale_t) {
44
0
  return ::isgraph(c);
45
0
}
46
47
0
inline _LIBCPP_ALWAYS_INLINE int islower_l(int c, locale_t) {
48
0
  return ::islower(c);
49
0
}
50
51
0
inline _LIBCPP_ALWAYS_INLINE int isprint_l(int c, locale_t) {
52
0
  return ::isprint(c);
53
0
}
54
55
0
inline _LIBCPP_ALWAYS_INLINE int ispunct_l(int c, locale_t) {
56
0
  return ::ispunct(c);
57
0
}
58
59
0
inline _LIBCPP_ALWAYS_INLINE int isspace_l(int c, locale_t) {
60
0
  return ::isspace(c);
61
0
}
62
63
0
inline _LIBCPP_ALWAYS_INLINE int isupper_l(int c, locale_t) {
64
0
  return ::isupper(c);
65
0
}
66
67
0
inline _LIBCPP_ALWAYS_INLINE int isxdigit_l(int c, locale_t) {
68
0
  return ::isxdigit(c);
69
0
}
70
71
0
inline _LIBCPP_ALWAYS_INLINE int iswalnum_l(wint_t c, locale_t) {
72
0
  return ::iswalnum(c);
73
0
}
74
75
0
inline _LIBCPP_ALWAYS_INLINE int iswalpha_l(wint_t c, locale_t) {
76
0
  return ::iswalpha(c);
77
0
}
78
79
0
inline _LIBCPP_ALWAYS_INLINE int iswblank_l(wint_t c, locale_t) {
80
0
  return ::iswblank(c);
81
0
}
82
83
0
inline _LIBCPP_ALWAYS_INLINE int iswcntrl_l(wint_t c, locale_t) {
84
0
  return ::iswcntrl(c);
85
0
}
86
87
0
inline _LIBCPP_ALWAYS_INLINE int iswdigit_l(wint_t c, locale_t) {
88
0
  return ::iswdigit(c);
89
0
}
90
91
0
inline _LIBCPP_ALWAYS_INLINE int iswgraph_l(wint_t c, locale_t) {
92
0
  return ::iswgraph(c);
93
0
}
94
95
0
inline _LIBCPP_ALWAYS_INLINE int iswlower_l(wint_t c, locale_t) {
96
0
  return ::iswlower(c);
97
0
}
98
99
0
inline _LIBCPP_ALWAYS_INLINE int iswprint_l(wint_t c, locale_t) {
100
0
  return ::iswprint(c);
101
0
}
102
103
0
inline _LIBCPP_ALWAYS_INLINE int iswpunct_l(wint_t c, locale_t) {
104
0
  return ::iswpunct(c);
105
0
}
106
107
0
inline _LIBCPP_ALWAYS_INLINE int iswspace_l(wint_t c, locale_t) {
108
0
  return ::iswspace(c);
109
0
}
110
111
0
inline _LIBCPP_ALWAYS_INLINE int iswupper_l(wint_t c, locale_t) {
112
0
  return ::iswupper(c);
113
0
}
114
115
0
inline _LIBCPP_ALWAYS_INLINE int iswxdigit_l(wint_t c, locale_t) {
116
0
  return ::iswxdigit(c);
117
0
}
118
119
0
inline _LIBCPP_ALWAYS_INLINE int toupper_l(int c, locale_t) {
120
0
  return ::toupper(c);
121
0
}
122
123
0
inline _LIBCPP_ALWAYS_INLINE int tolower_l(int c, locale_t) {
124
0
  return ::tolower(c);
125
0
}
126
127
0
inline _LIBCPP_ALWAYS_INLINE wint_t towupper_l(wint_t c, locale_t) {
128
0
  return ::towupper(c);
129
0
}
130
131
0
inline _LIBCPP_ALWAYS_INLINE wint_t towlower_l(wint_t c, locale_t) {
132
0
  return ::towlower(c);
133
0
}
134
135
inline _LIBCPP_ALWAYS_INLINE int strcoll_l(const char *s1, const char *s2,
136
0
                                           locale_t) {
137
0
  return ::strcoll(s1, s2);
138
0
}
139
140
inline _LIBCPP_ALWAYS_INLINE size_t strxfrm_l(char *dest, const char *src,
141
0
                                              size_t n, locale_t) {
142
0
  return ::strxfrm(dest, src, n);
143
0
}
144
145
inline _LIBCPP_ALWAYS_INLINE size_t strftime_l(char *s, size_t max,
146
                                               const char *format,
147
0
                                               const struct tm *tm, locale_t) {
148
0
  return ::strftime(s, max, format, tm);
149
0
}
150
151
inline _LIBCPP_ALWAYS_INLINE int wcscoll_l(const wchar_t *ws1,
152
0
                                           const wchar_t *ws2, locale_t) {
153
0
  return ::wcscoll(ws1, ws2);
154
0
}
155
156
inline _LIBCPP_ALWAYS_INLINE size_t wcsxfrm_l(wchar_t *dest, const wchar_t *src,
157
0
                                              size_t n, locale_t) {
158
0
  return ::wcsxfrm(dest, src, n);
159
0
}
160
161
#ifdef __cplusplus
162
}
163
#endif
164
165
#endif // _LIBCPP_SUPPORT_XLOCALE_POSIX_L_FALLBACK_H
/proc/self/cwd/frameworks/av/media/libmedia/include/media/IOMX.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2009 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef ANDROID_IOMX_H_
18
19
#define ANDROID_IOMX_H_
20
21
#include <binder/IInterface.h>
22
#include <utils/List.h>
23
#include <utils/String8.h>
24
#include <cutils/native_handle.h>
25
26
#include <list>
27
28
#include <hidl/HybridInterface.h>
29
#include <media/hardware/MetadataBufferType.h>
30
#include <android/hardware/media/omx/1.0/IOmxNode.h>
31
32
#include <media/openmax/OMX_Core.h>
33
#include <media/openmax/OMX_Video.h>
34
#include <media/openmax/OMX_VideoExt.h>
35
36
namespace android {
37
38
class IGraphicBufferProducer;
39
class IGraphicBufferSource;
40
class IMemory;
41
class IOMXBufferSource;
42
class IOMXNode;
43
class IOMXObserver;
44
class NativeHandle;
45
class OMXBuffer;
46
struct omx_message;
47
48
using hardware::media::omx::V1_0::IOmxNode;
49
50
class IOMX : public IInterface {
51
public:
52
    DECLARE_META_INTERFACE(OMX);
53
54
    typedef uint32_t buffer_id;
55
56
    enum {
57
        kFenceTimeoutMs = 1000
58
    };
59
60
    enum PortMode {
61
        kPortModePresetStart = 0,
62
        kPortModePresetByteBuffer,
63
        kPortModePresetANWBuffer,
64
        kPortModePresetSecureBuffer,
65
        kPortModePresetEnd,
66
67
        kPortModeDynamicStart = 100,
68
        kPortModeDynamicANWBuffer,      // uses metadata mode kMetadataBufferTypeANWBuffer
69
                                        // or kMetadataBufferTypeGrallocSource
70
        kPortModeDynamicNativeHandle,   // uses metadata mode kMetadataBufferTypeNativeHandleSource
71
        kPortModeDynamicEnd,
72
    };
73
74
    struct ComponentInfo {
75
        String8 mName;
76
        List<String8> mRoles;
77
    };
78
    virtual status_t listNodes(List<ComponentInfo> *list) = 0;
79
80
    virtual status_t allocateNode(
81
            const char *name, const sp<IOMXObserver> &observer,
82
            sp<IOMXNode> *omxNode) = 0;
83
84
    virtual status_t createInputSurface(
85
            sp<IGraphicBufferProducer> *bufferProducer,
86
            sp<IGraphicBufferSource> *bufferSource) = 0;
87
};
88
89
class IOMXNode : public IInterface {
90
public:
91
    DECLARE_HYBRID_META_INTERFACE(OMXNode, IOmxNode);
92
93
    typedef IOMX::buffer_id buffer_id;
94
95
    virtual status_t freeNode() = 0;
96
97
    virtual status_t sendCommand(
98
            OMX_COMMANDTYPE cmd, OMX_S32 param) = 0;
99
100
    virtual status_t getParameter(
101
            OMX_INDEXTYPE index, void *params, size_t size) = 0;
102
103
    virtual status_t setParameter(
104
            OMX_INDEXTYPE index, const void *params, size_t size) = 0;
105
106
    virtual status_t getConfig(
107
            OMX_INDEXTYPE index, void *params, size_t size) = 0;
108
109
    virtual status_t setConfig(
110
            OMX_INDEXTYPE index, const void *params, size_t size) = 0;
111
112
    virtual status_t setPortMode(
113
            OMX_U32 port_index, IOMX::PortMode mode) = 0;
114
115
    virtual status_t prepareForAdaptivePlayback(
116
            OMX_U32 portIndex, OMX_BOOL enable,
117
            OMX_U32 maxFrameWidth, OMX_U32 maxFrameHeight) = 0;
118
119
    virtual status_t configureVideoTunnelMode(
120
            OMX_U32 portIndex, OMX_BOOL tunneled,
121
            OMX_U32 audioHwSync, native_handle_t **sidebandHandle) = 0;
122
123
    virtual status_t getGraphicBufferUsage(
124
            OMX_U32 port_index, OMX_U32* usage) = 0;
125
126
    virtual status_t setInputSurface(
127
            const sp<IOMXBufferSource> &bufferSource) = 0;
128
129
    // Allocate an opaque buffer as a native handle. If component supports returning native
130
    // handles, those are returned in *native_handle. Otherwise, the allocated buffer is
131
    // returned in *buffer_data. This clearly only makes sense if the caller lives in the
132
    // same process as the callee, i.e. is the media_server, as the returned "buffer_data"
133
    // pointer is just that, a pointer into local address space.
134
    virtual status_t allocateSecureBuffer(
135
            OMX_U32 port_index, size_t size, buffer_id *buffer,
136
            void **buffer_data, sp<NativeHandle> *native_handle) = 0;
137
138
    // Instructs the component to use the buffer passed in via |omxBuf| on the
139
    // specified port. Returns in |*buffer| the buffer id that the component
140
    // assigns to this buffer. |omxBuf| must be one of:
141
    // 1) OMXBuffer::sPreset for meta-mode,
142
    // 2) type kBufferTypeANWBuffer for non-meta-graphic buffer mode,
143
    // 3) type kBufferTypeSharedMem for bytebuffer mode.
144
    virtual status_t useBuffer(
145
            OMX_U32 port_index, const OMXBuffer &omxBuf, buffer_id *buffer) = 0;
146
147
    // Frees the buffer on the specified port with buffer id |buffer|.
148
    virtual status_t freeBuffer(
149
            OMX_U32 port_index, buffer_id buffer) = 0;
150
151
    // Calls OMX_FillBuffer on buffer. Passes |fenceFd| to component if it
152
    // supports fences. Otherwise, it waits on |fenceFd| before calling
153
    // OMX_FillBuffer. Takes ownership of |fenceFd| even if this call fails.
154
    // If the port is in metadata mode, the buffer will be updated to point
155
    // to the new buffer passed in via |omxBuf| before OMX_FillBuffer is called.
156
    // Otherwise info in the |omxBuf| is not used.
157
    virtual status_t fillBuffer(
158
            buffer_id buffer, const OMXBuffer &omxBuf, int fenceFd = -1) = 0;
159
160
    // Calls OMX_EmptyBuffer on buffer. Passes |fenceFd| to component if it
161
    // supports fences. Otherwise, it waits on |fenceFd| before calling
162
    // OMX_EmptyBuffer. Takes ownership of |fenceFd| even if this call fails.
163
    // If the port is in metadata mode, the buffer will be updated to point
164
    // to the new buffer passed in via |omxBuf| before OMX_EmptyBuffer is called.
165
    virtual status_t emptyBuffer(
166
            buffer_id buffer, const OMXBuffer &omxBuf,
167
            OMX_U32 flags, OMX_TICKS timestamp, int fenceFd = -1) = 0;
168
169
    virtual status_t getExtensionIndex(
170
            const char *parameter_name,
171
            OMX_INDEXTYPE *index) = 0;
172
173
    virtual status_t dispatchMessage(const omx_message &msg) = 0;
174
};
175
176
struct omx_message {
177
    enum {
178
        EVENT,
179
        EMPTY_BUFFER_DONE,
180
        FILL_BUFFER_DONE,
181
        FRAME_RENDERED,
182
    } type;
183
184
    int fenceFd; // used for EMPTY_BUFFER_DONE and FILL_BUFFER_DONE; client must close this
185
186
    union {
187
        // if type == EVENT
188
        struct {
189
            OMX_EVENTTYPE event;
190
            OMX_U32 data1;
191
            OMX_U32 data2;
192
            OMX_U32 data3;
193
            OMX_U32 data4;
194
        } event_data;
195
196
        // if type == EMPTY_BUFFER_DONE
197
        struct {
198
            IOMX::buffer_id buffer;
199
        } buffer_data;
200
201
        // if type == FILL_BUFFER_DONE
202
        struct {
203
            IOMX::buffer_id buffer;
204
            OMX_U32 range_offset;
205
            OMX_U32 range_length;
206
            OMX_U32 flags;
207
            OMX_TICKS timestamp;
208
        } extended_buffer_data;
209
210
        // if type == FRAME_RENDERED
211
        struct {
212
            OMX_TICKS timestamp;
213
            OMX_S64 nanoTime;
214
        } render_data;
215
    } u;
216
};
217
218
class IOMXObserver : public IInterface {
219
public:
220
    DECLARE_META_INTERFACE(OMXObserver);
221
222
    // Handle (list of) messages.
223
    virtual void onMessages(const std::list<omx_message> &messages) = 0;
224
};
225
226
////////////////////////////////////////////////////////////////////////////////
227
228
class BnOMX : public BnInterface<IOMX> {
229
public:
230
    virtual status_t onTransact(
231
            uint32_t code, const Parcel &data, Parcel *reply,
232
            uint32_t flags = 0);
233
};
234
235
class BnOMXNode : public BnInterface<IOMXNode> {
236
public:
237
    virtual status_t onTransact(
238
            uint32_t code, const Parcel &data, Parcel *reply,
239
            uint32_t flags = 0);
240
241
protected:
242
    // check if the codec is secure.
243
0
    virtual bool isSecure() const {
244
0
        return false;
245
0
    }
246
};
247
248
class BnOMXObserver : public BnInterface<IOMXObserver> {
249
public:
250
    virtual status_t onTransact(
251
            uint32_t code, const Parcel &data, Parcel *reply,
252
            uint32_t flags = 0);
253
};
254
255
}  // namespace android
256
257
#endif  // ANDROID_IOMX_H_
/proc/self/cwd/frameworks/av/media/libstagefright/codecs/avcdec/SoftAVCDec.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2015 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
//#define LOG_NDEBUG 0
18
#define LOG_TAG "SoftAVCDec"
19
#include <utils/Log.h>
20
21
#include "ih264_typedefs.h"
22
#include "iv.h"
23
#include "ivd.h"
24
#include "ih264d.h"
25
#include "SoftAVCDec.h"
26
27
#include <media/stagefright/foundation/ADebug.h>
28
#include <media/stagefright/MediaDefs.h>
29
#include <OMX_VideoExt.h>
30
#include <inttypes.h>
31
32
namespace android {
33
34
#define componentName                   "video_decoder.avc"
35
#define codingType                      OMX_VIDEO_CodingAVC
36
2
#define CODEC_MIME_TYPE                 MEDIA_MIMETYPE_VIDEO_AVC
37
38
/** Function and structure definitions to keep code similar for each codec */
39
34
#define ivdec_api_function              ih264d_api_function
40
1
#define ivdext_create_ip_t              ih264d_create_ip_t
41
1
#define ivdext_create_op_t              ih264d_create_op_t
42
1
#define ivdext_delete_ip_t              ih264d_delete_ip_t
43
1
#define ivdext_delete_op_t              ih264d_delete_op_t
44
2
#define ivdext_ctl_set_num_cores_ip_t   ih264d_ctl_set_num_cores_ip_t
45
2
#define ivdext_ctl_set_num_cores_op_t   ih264d_ctl_set_num_cores_op_t
46
47
#define IVDEXT_CMD_CTL_SET_NUM_CORES    \
48
2
        (IVD_CONTROL_API_COMMAND_TYPE_T)IH264D_CMD_CTL_SET_NUM_CORES
49
50
static const CodecProfileLevel kProfileLevels[] = {
51
    { OMX_VIDEO_AVCProfileConstrainedBaseline, OMX_VIDEO_AVCLevel52 },
52
53
    { OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel52 },
54
55
    { OMX_VIDEO_AVCProfileMain,     OMX_VIDEO_AVCLevel52 },
56
57
    { OMX_VIDEO_AVCProfileConstrainedHigh,     OMX_VIDEO_AVCLevel52 },
58
59
    { OMX_VIDEO_AVCProfileHigh,     OMX_VIDEO_AVCLevel52 },
60
};
61
62
SoftAVC::SoftAVC(
63
        const char *name,
64
        const OMX_CALLBACKTYPE *callbacks,
65
        OMX_PTR appData,
66
        OMX_COMPONENTTYPE **component)
67
    : SoftVideoDecoderOMXComponent(
68
            name, componentName, codingType,
69
            kProfileLevels, ARRAY_SIZE(kProfileLevels),
70
            320 /* width */, 240 /* height */, callbacks,
71
            appData, component),
72
      mCodecCtx(NULL),
73
      mFlushOutBuffer(NULL),
74
      mOmxColorFormat(OMX_COLOR_FormatYUV420Planar),
75
      mIvColorFormat(IV_YUV_420P),
76
      mChangingResolution(false),
77
      mSignalledError(false),
78
      mStride(mWidth),
79
2
      mInputOffset(0){
80
2
    initPorts(
81
2
            1 /* numMinInputBuffers */, kNumBuffers, INPUT_BUF_SIZE,
82
2
            1 /* numMinOutputBuffers */, kNumBuffers, CODEC_MIME_TYPE);
83
2
84
2
    mTimeStart = mTimeEnd = systemTime();
85
2
86
2
    // If input dump is enabled, then open create an empty file
87
2
    GENERATE_FILE_NAMES();
88
2
    CREATE_DUMP_FILE(mInFile);
89
2
}
90
91
2
SoftAVC::~SoftAVC() {
92
2
    CHECK_EQ(deInitDecoder(), (status_t)OK);
93
2
}
94
95
55
static void *ivd_aligned_malloc(void *ctxt, WORD32 alignment, WORD32 size) {
96
55
    UNUSED(ctxt);
97
55
    return memalign(alignment, size);
98
55
}
99
100
55
static void ivd_aligned_free(void *ctxt, void *buf) {
101
55
    UNUSED(ctxt);
102
55
    free(buf);
103
55
    return;
104
55
}
105
106
1
static size_t GetCPUCoreCount() {
107
1
    long cpuCoreCount = 1;
108
1
#if defined(_SC_NPROCESSORS_ONLN)
109
1
    cpuCoreCount = sysconf(_SC_NPROCESSORS_ONLN);
110
#else
111
    // _SC_NPROC_ONLN must be defined...
112
    cpuCoreCount = sysconf(_SC_NPROC_ONLN);
113
#endif
114
1
    CHECK(cpuCoreCount >= 1);
115
1
    ALOGV("Number of CPU cores: %ld", cpuCoreCount);
116
1
    return (size_t)cpuCoreCount;
117
1
}
118
119
1
void SoftAVC::logVersion() {
120
1
    ivd_ctl_getversioninfo_ip_t s_ctl_ip;
121
1
    ivd_ctl_getversioninfo_op_t s_ctl_op;
122
1
    UWORD8 au1_buf[512];
123
1
    IV_API_CALL_STATUS_T status;
124
1
125
1
    s_ctl_ip.e_cmd = IVD_CMD_VIDEO_CTL;
126
1
    s_ctl_ip.e_sub_cmd = IVD_CMD_CTL_GETVERSION;
127
1
    s_ctl_ip.u4_size = sizeof(ivd_ctl_getversioninfo_ip_t);
128
1
    s_ctl_op.u4_size = sizeof(ivd_ctl_getversioninfo_op_t);
129
1
    s_ctl_ip.pv_version_buffer = au1_buf;
130
1
    s_ctl_ip.u4_version_buffer_size = sizeof(au1_buf);
131
1
132
1
    status =
133
1
        ivdec_api_function(mCodecCtx, (void *)&s_ctl_ip, (void *)&s_ctl_op);
134
1
135
1
    if (status != IV_SUCCESS) {
136
0
        ALOGE("Error in getting version number: 0x%x",
137
0
                s_ctl_op.u4_error_code);
138
1
    } else {
139
1
        ALOGV("Ittiam decoder version number: %s",
140
1
                (char *)s_ctl_ip.pv_version_buffer);
141
1
    }
142
1
    return;
143
1
}
144
145
1
status_t SoftAVC::setParams(size_t stride) {
146
1
    ivd_ctl_set_config_ip_t s_ctl_ip;
147
1
    ivd_ctl_set_config_op_t s_ctl_op;
148
1
    IV_API_CALL_STATUS_T status;
149
1
    s_ctl_ip.u4_disp_wd = (UWORD32)stride;
150
1
    s_ctl_ip.e_frm_skip_mode = IVD_SKIP_NONE;
151
1
152
1
    s_ctl_ip.e_frm_out_mode = IVD_DISPLAY_FRAME_OUT;
153
1
    s_ctl_ip.e_vid_dec_mode = IVD_DECODE_FRAME;
154
1
    s_ctl_ip.e_cmd = IVD_CMD_VIDEO_CTL;
155
1
    s_ctl_ip.e_sub_cmd = IVD_CMD_CTL_SETPARAMS;
156
1
    s_ctl_ip.u4_size = sizeof(ivd_ctl_set_config_ip_t);
157
1
    s_ctl_op.u4_size = sizeof(ivd_ctl_set_config_op_t);
158
1
159
1
    ALOGV("Set the run-time (dynamic) parameters stride = %zu", stride);
160
1
    status = ivdec_api_function(mCodecCtx, (void *)&s_ctl_ip, (void *)&s_ctl_op);
161
1
162
1
    if (status != IV_SUCCESS) {
163
0
        ALOGE("Error in setting the run-time parameters: 0x%x",
164
0
                s_ctl_op.u4_error_code);
165
0
166
0
        return UNKNOWN_ERROR;
167
0
    }
168
1
    return OK;
169
1
}
170
171
2
status_t SoftAVC::resetPlugin() {
172
2
    mIsInFlush = false;
173
2
    mReceivedEOS = false;
174
2
175
2
    memset(mTimeStamps, 0, sizeof(mTimeStamps));
176
2
    memset(mTimeStampsValid, 0, sizeof(mTimeStampsValid));
177
2
178
2
    /* Initialize both start and end times */
179
2
    mTimeStart = mTimeEnd = systemTime();
180
2
181
2
    return OK;
182
2
}
183
184
1
status_t SoftAVC::resetDecoder() {
185
1
    ivd_ctl_reset_ip_t s_ctl_ip;
186
1
    ivd_ctl_reset_op_t s_ctl_op;
187
1
    IV_API_CALL_STATUS_T status;
188
1
189
1
    s_ctl_ip.e_cmd = IVD_CMD_VIDEO_CTL;
190
1
    s_ctl_ip.e_sub_cmd = IVD_CMD_CTL_RESET;
191
1
    s_ctl_ip.u4_size = sizeof(ivd_ctl_reset_ip_t);
192
1
    s_ctl_op.u4_size = sizeof(ivd_ctl_reset_op_t);
193
1
194
1
    status = ivdec_api_function(mCodecCtx, (void *)&s_ctl_ip, (void *)&s_ctl_op);
195
1
    if (IV_SUCCESS != status) {
196
0
        ALOGE("Error in reset: 0x%x", s_ctl_op.u4_error_code);
197
0
        return UNKNOWN_ERROR;
198
0
    }
199
1
    mSignalledError = false;
200
1
201
1
    /* Set number of cores/threads to be used by the codec */
202
1
    setNumCores();
203
1
204
1
    mStride = 0;
205
1
    return OK;
206
1
}
207
208
2
status_t SoftAVC::setNumCores() {
209
2
    ivdext_ctl_set_num_cores_ip_t s_set_cores_ip;
210
2
    ivdext_ctl_set_num_cores_op_t s_set_cores_op;
211
2
    IV_API_CALL_STATUS_T status;
212
2
    s_set_cores_ip.e_cmd = IVD_CMD_VIDEO_CTL;
213
2
    s_set_cores_ip.e_sub_cmd = IVDEXT_CMD_CTL_SET_NUM_CORES;
214
2
    s_set_cores_ip.u4_num_cores = MIN(mNumCores, CODEC_MAX_NUM_CORES);
215
2
    s_set_cores_ip.u4_size = sizeof(ivdext_ctl_set_num_cores_ip_t);
216
2
    s_set_cores_op.u4_size = sizeof(ivdext_ctl_set_num_cores_op_t);
217
2
    status = ivdec_api_function(
218
2
            mCodecCtx, (void *)&s_set_cores_ip, (void *)&s_set_cores_op);
219
2
    if (IV_SUCCESS != status) {
220
0
        ALOGE("Error in setting number of cores: 0x%x",
221
0
                s_set_cores_op.u4_error_code);
222
0
        return UNKNOWN_ERROR;
223
0
    }
224
2
    return OK;
225
2
}
226
227
0
status_t SoftAVC::setFlushMode() {
228
0
    IV_API_CALL_STATUS_T status;
229
0
    ivd_ctl_flush_ip_t s_video_flush_ip;
230
0
    ivd_ctl_flush_op_t s_video_flush_op;
231
0
232
0
    s_video_flush_ip.e_cmd = IVD_CMD_VIDEO_CTL;
233
0
    s_video_flush_ip.e_sub_cmd = IVD_CMD_CTL_FLUSH;
234
0
    s_video_flush_ip.u4_size = sizeof(ivd_ctl_flush_ip_t);
235
0
    s_video_flush_op.u4_size = sizeof(ivd_ctl_flush_op_t);
236
0
237
0
    /* Set the decoder in Flush mode, subsequent decode() calls will flush */
238
0
    status = ivdec_api_function(
239
0
            mCodecCtx, (void *)&s_video_flush_ip, (void *)&s_video_flush_op);
240
0
241
0
    if (status != IV_SUCCESS) {
242
0
        ALOGE("Error in setting the decoder in flush mode: (%d) 0x%x", status,
243
0
                s_video_flush_op.u4_error_code);
244
0
        return UNKNOWN_ERROR;
245
0
    }
246
0
247
0
    mIsInFlush = true;
248
0
    return OK;
249
0
}
250
251
1
status_t SoftAVC::initDecoder() {
252
1
    IV_API_CALL_STATUS_T status;
253
1
254
1
    mNumCores = GetCPUCoreCount();
255
1
    mCodecCtx = NULL;
256
1
257
1
    mStride = outputBufferWidth();
258
1
259
1
    /* Initialize the decoder */
260
1
    {
261
1
        ivdext_create_ip_t s_create_ip;
262
1
        ivdext_create_op_t s_create_op;
263
1
264
1
        void *dec_fxns = (void *)ivdec_api_function;
265
1
266
1
        s_create_ip.s_ivd_create_ip_t.u4_size = sizeof(ivdext_create_ip_t);
267
1
        s_create_ip.s_ivd_create_ip_t.e_cmd = IVD_CMD_CREATE;
268
1
        s_create_ip.s_ivd_create_ip_t.u4_share_disp_buf = 0;
269
1
        s_create_op.s_ivd_create_op_t.u4_size = sizeof(ivdext_create_op_t);
270
1
        s_create_ip.s_ivd_create_ip_t.e_output_format = mIvColorFormat;
271
1
        s_create_ip.s_ivd_create_ip_t.pf_aligned_alloc = ivd_aligned_malloc;
272
1
        s_create_ip.s_ivd_create_ip_t.pf_aligned_free = ivd_aligned_free;
273
1
        s_create_ip.s_ivd_create_ip_t.pv_mem_ctxt = NULL;
274
1
275
1
        status = ivdec_api_function(mCodecCtx, (void *)&s_create_ip, (void *)&s_create_op);
276
1
277
1
        if (status != IV_SUCCESS) {
278
0
            ALOGE("Error in create: 0x%x",
279
0
                    s_create_op.s_ivd_create_op_t.u4_error_code);
280
0
            deInitDecoder();
281
0
            mCodecCtx = NULL;
282
0
            return UNKNOWN_ERROR;
283
0
        }
284
1
285
1
        mCodecCtx = (iv_obj_t*)s_create_op.s_ivd_create_op_t.pv_handle;
286
1
        mCodecCtx->pv_fxns = dec_fxns;
287
1
        mCodecCtx->u4_size = sizeof(iv_obj_t);
288
1
    }
289
1
290
1
    /* Reset the plugin state */
291
1
    resetPlugin();
292
1
293
1
    /* Set the run time (dynamic) parameters */
294
1
    setParams(mStride);
295
1
296
1
    /* Set number of cores/threads to be used by the codec */
297
1
    setNumCores();
298
1
299
1
    /* Get codec version */
300
1
    logVersion();
301
1
302
1
    mFlushNeeded = false;
303
1
    return OK;
304
1
}
305
306
2
status_t SoftAVC::deInitDecoder() {
307
2
    IV_API_CALL_STATUS_T status;
308
2
309
2
    if (mCodecCtx) {
310
1
        ivdext_delete_ip_t s_delete_ip;
311
1
        ivdext_delete_op_t s_delete_op;
312
1
313
1
        s_delete_ip.s_ivd_delete_ip_t.u4_size = sizeof(ivdext_delete_ip_t);
314
1
        s_delete_ip.s_ivd_delete_ip_t.e_cmd = IVD_CMD_DELETE;
315
1
316
1
        s_delete_op.s_ivd_delete_op_t.u4_size = sizeof(ivdext_delete_op_t);
317
1
318
1
        status = ivdec_api_function(mCodecCtx, (void *)&s_delete_ip, (void *)&s_delete_op);
319
1
        if (status != IV_SUCCESS) {
320
0
            ALOGE("Error in delete: 0x%x",
321
0
                    s_delete_op.s_ivd_delete_op_t.u4_error_code);
322
0
            return UNKNOWN_ERROR;
323
0
        }
324
2
    }
325
2
326
2
327
2
    mChangingResolution = false;
328
2
329
2
    return OK;
330
2
}
331
332
1
void SoftAVC::onReset() {
333
1
    SoftVideoDecoderOMXComponent::onReset();
334
1
335
1
    mSignalledError = false;
336
1
    mInputOffset = 0;
337
1
    resetDecoder();
338
1
    resetPlugin();
339
1
}
340
341
13
bool SoftAVC::getVUIParams() {
342
13
    IV_API_CALL_STATUS_T status;
343
13
    ih264d_ctl_get_vui_params_ip_t s_ctl_get_vui_params_ip;
344
13
    ih264d_ctl_get_vui_params_op_t s_ctl_get_vui_params_op;
345
13
346
13
    s_ctl_get_vui_params_ip.e_cmd = IVD_CMD_VIDEO_CTL;
347
13
    s_ctl_get_vui_params_ip.e_sub_cmd =
348
13
        (IVD_CONTROL_API_COMMAND_TYPE_T)IH264D_CMD_CTL_GET_VUI_PARAMS;
349
13
350
13
    s_ctl_get_vui_params_ip.u4_size =
351
13
        sizeof(ih264d_ctl_get_vui_params_ip_t);
352
13
353
13
    s_ctl_get_vui_params_op.u4_size = sizeof(ih264d_ctl_get_vui_params_op_t);
354
13
355
13
    status = ivdec_api_function(
356
13
            (iv_obj_t *)mCodecCtx, (void *)&s_ctl_get_vui_params_ip,
357
13
            (void *)&s_ctl_get_vui_params_op);
358
13
359
13
    if (status != IV_SUCCESS) {
360
0
        ALOGW("Error in getting VUI params: 0x%x",
361
0
                s_ctl_get_vui_params_op.u4_error_code);
362
0
        return false;
363
0
    }
364
13
365
13
    int32_t primaries = s_ctl_get_vui_params_op.u1_colour_primaries;
366
13
    int32_t transfer = s_ctl_get_vui_params_op.u1_tfr_chars;
367
13
    int32_t coeffs = s_ctl_get_vui_params_op.u1_matrix_coeffs;
368
13
    bool fullRange = s_ctl_get_vui_params_op.u1_video_full_range_flag;
369
13
370
13
    ColorAspects colorAspects;
371
13
    ColorUtils::convertIsoColorAspectsToCodecAspects(
372
13
            primaries, transfer, coeffs, fullRange, colorAspects);
373
13
374
13
    // Update color aspects if necessary.
375
13
    if (colorAspectsDiffer(colorAspects, mBitstreamColorAspects)) {
376
1
        mBitstreamColorAspects = colorAspects;
377
1
        status_t err = handleColorAspectsChange();
378
1
        CHECK(err == OK);
379
1
    }
380
13
    return true;
381
13
}
382
383
bool SoftAVC::setDecodeArgs(
384
        ivd_video_decode_ip_t *ps_dec_ip,
385
        ivd_video_decode_op_t *ps_dec_op,
386
        OMX_BUFFERHEADERTYPE *inHeader,
387
        OMX_BUFFERHEADERTYPE *outHeader,
388
13
        size_t timeStampIx) {
389
13
    size_t sizeY = outputBufferWidth() * outputBufferHeight();
390
13
    size_t sizeUV;
391
13
392
13
    ps_dec_ip->u4_size = sizeof(ivd_video_decode_ip_t);
393
13
    ps_dec_op->u4_size = sizeof(ivd_video_decode_op_t);
394
13
395
13
    ps_dec_ip->e_cmd = IVD_CMD_VIDEO_DECODE;
396
13
397
13
    /* When in flush and after EOS with zero byte input,
398
13
     * inHeader is set to zero. Hence check for non-null */
399
13
    if (inHeader) {
400
13
        ps_dec_ip->u4_ts = timeStampIx;
401
13
        ps_dec_ip->pv_stream_buffer =
402
13
            inHeader->pBuffer + inHeader->nOffset + mInputOffset;
403
13
        ps_dec_ip->u4_num_Bytes = inHeader->nFilledLen - mInputOffset;
404
13
    } else {
405
0
        ps_dec_ip->u4_ts = 0;
406
0
        ps_dec_ip->pv_stream_buffer = NULL;
407
0
        ps_dec_ip->u4_num_Bytes = 0;
408
0
    }
409
13
410
13
    sizeUV = sizeY / 4;
411
13
    ps_dec_ip->s_out_buffer.u4_min_out_buf_size[0] = sizeY;
412
13
    ps_dec_ip->s_out_buffer.u4_min_out_buf_size[1] = sizeUV;
413
13
    ps_dec_ip->s_out_buffer.u4_min_out_buf_size[2] = sizeUV;
414
13
415
13
    uint8_t *pBuf;
416
13
    if (outHeader) {
417
13
        if (outHeader->nAllocLen < sizeY + (sizeUV * 2)) {
418
0
            android_errorWriteLog(0x534e4554, "27833616");
419
0
            return false;
420
0
        }
421
13
        pBuf = outHeader->pBuffer;
422
13
    } else {
423
0
        // mFlushOutBuffer always has the right size.
424
0
        pBuf = mFlushOutBuffer;
425
0
    }
426
13
427
13
    ps_dec_ip->s_out_buffer.pu1_bufs[0] = pBuf;
428
13
    ps_dec_ip->s_out_buffer.pu1_bufs[1] = pBuf + sizeY;
429
13
    ps_dec_ip->s_out_buffer.pu1_bufs[2] = pBuf + sizeY + sizeUV;
430
13
    ps_dec_ip->s_out_buffer.u4_num_bufs = 3;
431
13
    return true;
432
13
}
433
0
void SoftAVC::onPortFlushCompleted(OMX_U32 portIndex) {
434
0
    /* Once the output buffers are flushed, ignore any buffers that are held in decoder */
435
0
    if (kOutputPortIndex == portIndex) {
436
0
        setFlushMode();
437
0
438
0
        /* Allocate a picture buffer to flushed data */
439
0
        uint32_t displayStride = outputBufferWidth();
440
0
        uint32_t displayHeight = outputBufferHeight();
441
0
442
0
        uint32_t bufferSize = displayStride * displayHeight * 3 / 2;
443
0
        mFlushOutBuffer = (uint8_t *)memalign(128, bufferSize);
444
0
        if (NULL == mFlushOutBuffer) {
445
0
            ALOGE("Could not allocate flushOutputBuffer of size %u", bufferSize);
446
0
            return;
447
0
        }
448
0
449
0
        while (true) {
450
0
            ivd_video_decode_ip_t s_dec_ip;
451
0
            ivd_video_decode_op_t s_dec_op;
452
0
            IV_API_CALL_STATUS_T status;
453
0
454
0
            setDecodeArgs(&s_dec_ip, &s_dec_op, NULL, NULL, 0);
455
0
456
0
            status = ivdec_api_function(mCodecCtx, (void *)&s_dec_ip, (void *)&s_dec_op);
457
0
            if (0 == s_dec_op.u4_output_present) {
458
0
                resetPlugin();
459
0
                break;
460
0
            }
461
0
        }
462
0
463
0
        if (mFlushOutBuffer) {
464
0
            free(mFlushOutBuffer);
465
0
            mFlushOutBuffer = NULL;
466
0
        }
467
0
    } else {
468
0
        mInputOffset = 0;
469
0
    }
470
0
}
471
472
29
void SoftAVC::onQueueFilled(OMX_U32 portIndex) {
473
29
    UNUSED(portIndex);
474
29
    OMX_BUFFERHEADERTYPE *inHeader = NULL;
475
29
    BufferInfo *inInfo = NULL;
476
29
477
29
    if (mSignalledError) {
478
0
        return;
479
0
    }
480
29
    if (mOutputPortSettingsChange != NONE) {
481
0
        return;
482
0
    }
483
29
484
29
    if (NULL == mCodecCtx) {
485
1
        if (OK != initDecoder()) {
486
0
            ALOGE("Failed to initialize decoder");
487
0
            notify(OMX_EventError, OMX_ErrorUnsupportedSetting, 0, NULL);
488
0
            mSignalledError = true;
489
0
            return;
490
0
        }
491
29
    }
492
29
    if (outputBufferWidth() != mStride) {
493
0
        /* Set the run-time (dynamic) parameters */
494
0
        mStride = outputBufferWidth();
495
0
        setParams(mStride);
496
0
    }
497
29
498
29
    List<BufferInfo *> &inQueue = getPortQueue(kInputPortIndex);
499
29
    List<BufferInfo *> &outQueue = getPortQueue(kOutputPortIndex);
500
29
501
42
    while (!outQueue.empty()) {
502
32
        BufferInfo *outInfo;
503
32
        OMX_BUFFERHEADERTYPE *outHeader;
504
32
        size_t timeStampIx = 0;
505
32
506
32
        if (!mIsInFlush && (NULL == inHeader)) {
507
32
            if (!inQueue.empty()) {
508
13
                inInfo = *inQueue.begin();
509
13
                inHeader = inInfo->mHeader;
510
13
                if (inHeader == NULL) {
511
0
                    inQueue.erase(inQueue.begin());
512
0
                    inInfo->mOwnedByUs = false;
513
0
                    continue;
514
0
                }
515
19
            } else {
516
19
                break;
517
19
            }
518
13
        }
519
13
520
13
        outInfo = *outQueue.begin();
521
13
        outHeader = outInfo->mHeader;
522
13
        outHeader->nFlags = 0;
523
13
        outHeader->nTimeStamp = 0;
524
13
        outHeader->nOffset = 0;
525
13
526
13
        if (inHeader != NULL) {
527
13
            if (inHeader->nFilledLen == 0) {
528
0
                inQueue.erase(inQueue.begin());
529
0
                inInfo->mOwnedByUs = false;
530
0
                notifyEmptyBufferDone(inHeader);
531
0
532
0
                if (!(inHeader->nFlags & OMX_BUFFERFLAG_EOS)) {
533
0
                    return;
534
0
                }
535
0
536
0
                mReceivedEOS = true;
537
0
                inHeader = NULL;
538
0
                setFlushMode();
539
13
            } else if (inHeader->nFlags & OMX_BUFFERFLAG_EOS) {
540
0
                mReceivedEOS = true;
541
0
            }
542
13
        }
543
13
544
13
        /* Get a free slot in timestamp array to hold input timestamp */
545
13
        {
546
13
            size_t i;
547
13
            timeStampIx = 0;
548
23
            for (i = 0; i < MAX_TIME_STAMPS; i++) {
549
23
                if (!mTimeStampsValid[i]) {
550
13
                    timeStampIx = i;
551
13
                    break;
552
13
                }
553
23
            }
554
13
            if (inHeader != NULL) {
555
13
                mTimeStampsValid[timeStampIx] = true;
556
13
                mTimeStamps[timeStampIx] = inHeader->nTimeStamp;
557
13
            }
558
13
        }
559
13
560
13
        {
561
13
            ivd_video_decode_ip_t s_dec_ip;
562
13
            ivd_video_decode_op_t s_dec_op;
563
13
            nsecs_t timeDelay, timeTaken;
564
13
565
13
            if (!setDecodeArgs(&s_dec_ip, &s_dec_op, inHeader, outHeader, timeStampIx)) {
566
0
                ALOGE("Decoder arg setup failed");
567
0
                notify(OMX_EventError, OMX_ErrorUndefined, 0, NULL);
568
0
                mSignalledError = true;
569
0
                return;
570
0
            }
571
13
            // If input dump is enabled, then write to file
572
13
            DUMP_TO_FILE(mInFile, s_dec_ip.pv_stream_buffer, s_dec_ip.u4_num_Bytes, mInputOffset);
573
13
574
13
            mTimeStart = systemTime();
575
13
            /* Compute time elapsed between end of previous decode()
576
13
             * to start of current decode() */
577
13
            timeDelay = mTimeStart - mTimeEnd;
578
13
579
13
            IV_API_CALL_STATUS_T status;
580
13
            status = ivdec_api_function(mCodecCtx, (void *)&s_dec_ip, (void *)&s_dec_op);
581
13
582
13
            bool unsupportedResolution =
583
13
                (IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED == (s_dec_op.u4_error_code & 0xFF));
584
13
585
13
            /* Check for unsupported dimensions */
586
13
            if (unsupportedResolution) {
587
0
                ALOGE("Unsupported resolution : %dx%d", mWidth, mHeight);
588
0
                notify(OMX_EventError, OMX_ErrorUnsupportedSetting, 0, NULL);
589
0
                mSignalledError = true;
590
0
                return;
591
0
            }
592
13
593
13
            bool allocationFailed = (IVD_MEM_ALLOC_FAILED == (s_dec_op.u4_error_code & 0xFF));
594
13
            if (allocationFailed) {
595
0
                ALOGE("Allocation failure in decoder");
596
0
                notify(OMX_EventError, OMX_ErrorUnsupportedSetting, 0, NULL);
597
0
                mSignalledError = true;
598
0
                return;
599
0
            }
600
13
601
13
            bool resChanged = (IVD_RES_CHANGED == (s_dec_op.u4_error_code & 0xFF));
602
13
603
13
            getVUIParams();
604
13
605
13
            mTimeEnd = systemTime();
606
13
            /* Compute time taken for decode() */
607
13
            timeTaken = mTimeEnd - mTimeStart;
608
13
609
13
            ALOGV("timeTaken=%6lldus delay=%6lldus numBytes=%6d",
610
13
                    (long long) (timeTaken / 1000ll), (long long) (timeDelay / 1000ll),
611
13
                   s_dec_op.u4_num_bytes_consumed);
612
13
            if (s_dec_op.u4_frame_decoded_flag && !mFlushNeeded) {
613
1
                mFlushNeeded = true;
614
1
            }
615
13
616
13
            if ((inHeader != NULL) && (1 != s_dec_op.u4_frame_decoded_flag)) {
617
2
                /* If the input did not contain picture data, then ignore
618
2
                 * the associated timestamp */
619
2
                mTimeStampsValid[timeStampIx] = false;
620
2
            }
621
13
622
13
            // If the decoder is in the changing resolution mode and there is no output present,
623
13
            // that means the switching is done and it's ready to reset the decoder and the plugin.
624
13
            if (mChangingResolution && !s_dec_op.u4_output_present) {
625
0
                mChangingResolution = false;
626
0
                resetDecoder();
627
0
                resetPlugin();
628
0
                mStride = outputBufferWidth();
629
0
                setParams(mStride);
630
0
                continue;
631
0
            }
632
13
633
13
            if (resChanged) {
634
0
                mChangingResolution = true;
635
0
                if (mFlushNeeded) {
636
0
                    setFlushMode();
637
0
                }
638
0
                continue;
639
0
            }
640
13
641
13
            // Combine the resolution change and coloraspects change in one PortSettingChange event
642
13
            // if necessary.
643
13
            if ((0 < s_dec_op.u4_pic_wd) && (0 < s_dec_op.u4_pic_ht)) {
644
13
                uint32_t width = s_dec_op.u4_pic_wd;
645
13
                uint32_t height = s_dec_op.u4_pic_ht;
646
13
                bool portWillReset = false;
647
13
                handlePortSettingsChange(&portWillReset, width, height);
648
13
                if (portWillReset) {
649
0
                    resetDecoder();
650
0
                    resetPlugin();
651
0
                    return;
652
0
                }
653
0
            } else if (mUpdateColorAspects) {
654
0
                notify(OMX_EventPortSettingsChanged, kOutputPortIndex,
655
0
                    kDescribeColorAspectsIndex, NULL);
656
0
                mUpdateColorAspects = false;
657
0
                return;
658
0
            }
659
13
660
13
            if (s_dec_op.u4_output_present) {
661
9
                outHeader->nFilledLen = (outputBufferWidth() * outputBufferHeight() * 3) / 2;
662
9
663
9
                outHeader->nTimeStamp = mTimeStamps[s_dec_op.u4_ts];
664
9
                mTimeStampsValid[s_dec_op.u4_ts] = false;
665
9
666
9
                outInfo->mOwnedByUs = false;
667
9
                outQueue.erase(outQueue.begin());
668
9
                outInfo = NULL;
669
9
                notifyFillBufferDone(outHeader);
670
9
                outHeader = NULL;
671
9
            } else if (mIsInFlush) {
672
0
                /* If in flush mode and no output is returned by the codec,
673
0
                 * then come out of flush mode */
674
0
                mIsInFlush = false;
675
0
676
0
                /* If EOS was recieved on input port and there is no output
677
0
                 * from the codec, then signal EOS on output port */
678
0
                if (mReceivedEOS) {
679
0
                    outHeader->nFilledLen = 0;
680
0
                    outHeader->nFlags |= OMX_BUFFERFLAG_EOS;
681
0
682
0
                    outInfo->mOwnedByUs = false;
683
0
                    outQueue.erase(outQueue.begin());
684
0
                    outInfo = NULL;
685
0
                    notifyFillBufferDone(outHeader);
686
0
                    outHeader = NULL;
687
0
                    resetPlugin();
688
0
                }
689
0
            }
690
13
            mInputOffset += s_dec_op.u4_num_bytes_consumed;
691
13
        }
692
13
        // If more than 4 bytes are remaining in input, then do not release it
693
13
        if (inHeader != NULL && ((inHeader->nFilledLen - mInputOffset) <= 4)) {
694
13
            inInfo->mOwnedByUs = false;
695
13
            inQueue.erase(inQueue.begin());
696
13
            inInfo = NULL;
697
13
            notifyEmptyBufferDone(inHeader);
698
13
            inHeader = NULL;
699
13
            mInputOffset = 0;
700
13
701
13
            /* If input EOS is seen and decoder is not in flush mode,
702
13
             * set the decoder in flush mode.
703
13
             * There can be a case where EOS is sent along with last picture data
704
13
             * In that case, only after decoding that input data, decoder has to be
705
13
             * put in flush. This case is handled here  */
706
13
707
13
            if (mReceivedEOS && !mIsInFlush) {
708
0
                setFlushMode();
709
0
            }
710
13
        }
711
13
    }
712
29
}
713
714
7
int SoftAVC::getColorAspectPreference() {
715
7
    return kPreferBitstream;
716
7
}
717
718
}  // namespace android
719
720
android::SoftOMXComponent *createSoftOMXComponent(
721
        const char *name, const OMX_CALLBACKTYPE *callbacks, OMX_PTR appData,
722
2
        OMX_COMPONENTTYPE **component) {
723
2
    return new android::SoftAVC(name, callbacks, appData, component);
724
2
}
/proc/self/cwd/frameworks/av/media/libstagefright/codecs/avcdec/SoftAVCDec.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2015 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef SOFT_H264_DEC_H_
18
19
#define SOFT_H264_DEC_H_
20
21
#include <media/stagefright/omx/SoftVideoDecoderOMXComponent.h>
22
#include <sys/time.h>
23
24
namespace android {
25
26
/** Number of entries in the time-stamp array */
27
23
#define MAX_TIME_STAMPS 64
28
29
/** Maximum number of cores supported by the codec */
30
#define CODEC_MAX_NUM_CORES 4
31
32
#define CODEC_MAX_WIDTH     1920
33
34
#define CODEC_MAX_HEIGHT    1088
35
36
/** Input buffer size */
37
2
#define INPUT_BUF_SIZE (1024 * 1024)
38
39
2
#define MIN(a, b) ((a) < (b)) ? (a) : (b)
40
41
/** Used to remove warnings about unused parameters */
42
139
#define UNUSED(x) ((void)(x))
43
44
struct SoftAVC : public SoftVideoDecoderOMXComponent {
45
    SoftAVC(const char *name, const OMX_CALLBACKTYPE *callbacks,
46
            OMX_PTR appData, OMX_COMPONENTTYPE **component);
47
48
protected:
49
    virtual ~SoftAVC();
50
51
    virtual void onQueueFilled(OMX_U32 portIndex);
52
    virtual void onPortFlushCompleted(OMX_U32 portIndex);
53
    virtual void onReset();
54
    virtual int getColorAspectPreference();
55
private:
56
    // Number of input and output buffers
57
    enum {
58
        kNumBuffers = 8
59
    };
60
61
    iv_obj_t *mCodecCtx;         // Codec context
62
63
    size_t mNumCores;            // Number of cores to be uesd by the codec
64
65
    nsecs_t mTimeStart;   // Time at the start of decode()
66
    nsecs_t mTimeEnd;     // Time at the end of decode()
67
68
    // Internal buffer to be used to flush out the buffers from decoder
69
    uint8_t *mFlushOutBuffer;
70
71
    // Status of entries in the timestamp array
72
    bool mTimeStampsValid[MAX_TIME_STAMPS];
73
74
    // Timestamp array - Since codec does not take 64 bit timestamps,
75
    // they are maintained in the plugin
76
    OMX_S64 mTimeStamps[MAX_TIME_STAMPS];
77
78
#ifdef FILE_DUMP_ENABLE
79
    char mInFile[200];
80
#endif /* FILE_DUMP_ENABLE */
81
82
    OMX_COLOR_FORMATTYPE mOmxColorFormat;    // OMX Color format
83
    IV_COLOR_FORMAT_T mIvColorFormat;        // Ittiam Color format
84
85
    bool mIsInFlush;        // codec is flush mode
86
    bool mReceivedEOS;      // EOS is receieved on input port
87
88
    // The input stream has changed to a different resolution, which is still supported by the
89
    // codec. So the codec is switching to decode the new resolution.
90
    bool mChangingResolution;
91
    bool mFlushNeeded;
92
    bool mSignalledError;
93
    size_t mStride;
94
    size_t mInputOffset;
95
96
    status_t initDecoder();
97
    status_t deInitDecoder();
98
    status_t setFlushMode();
99
    status_t setParams(size_t stride);
100
    void logVersion();
101
    status_t setNumCores();
102
    status_t resetDecoder();
103
    status_t resetPlugin();
104
105
106
    bool setDecodeArgs(
107
            ivd_video_decode_ip_t *ps_dec_ip,
108
            ivd_video_decode_op_t *ps_dec_op,
109
            OMX_BUFFERHEADERTYPE *inHeader,
110
            OMX_BUFFERHEADERTYPE *outHeader,
111
            size_t timeStampIx);
112
113
    bool getVUIParams();
114
115
    DISALLOW_EVIL_CONSTRUCTORS(SoftAVC);
116
};
117
118
#ifdef FILE_DUMP_ENABLE
119
120
#define INPUT_DUMP_PATH     "/sdcard/media/avcd_input"
121
#define INPUT_DUMP_EXT      "h264"
122
123
#define GENERATE_FILE_NAMES() {                         \
124
    strcpy(mInFile, "");                                \
125
    sprintf(mInFile, "%s_%lld.%s", INPUT_DUMP_PATH,     \
126
            (long long) mTimeStart,                     \
127
            INPUT_DUMP_EXT);                            \
128
}
129
130
#define CREATE_DUMP_FILE(m_filename) {                  \
131
    FILE *fp = fopen(m_filename, "wb");                 \
132
    if (fp != NULL) {                                   \
133
        fclose(fp);                                     \
134
    } else {                                            \
135
        ALOGD("Could not open file %s", m_filename);    \
136
    }                                                   \
137
}
138
#define DUMP_TO_FILE(m_filename, m_buf, m_size, m_offset)\
139
{                                                       \
140
    FILE *fp = fopen(m_filename, "ab");                 \
141
    if (fp != NULL && m_buf != NULL && m_offset == 0) { \
142
        int i;                                          \
143
        i = fwrite(m_buf, 1, m_size, fp);               \
144
        ALOGD("fwrite ret %d to write %d", i, m_size);  \
145
        if (i != (int) m_size) {                        \
146
            ALOGD("Error in fwrite, returned %d", i);   \
147
            perror("Error in write to file");           \
148
        }                                               \
149
    } else if (fp == NULL) {                            \
150
        ALOGD("Could not write to file %s", m_filename);\
151
    }                                                   \
152
    if (fp) {                                           \
153
        fclose(fp);                                     \
154
    }                                                   \
155
}
156
#else /* FILE_DUMP_ENABLE */
157
#define INPUT_DUMP_PATH
158
#define INPUT_DUMP_EXT
159
#define OUTPUT_DUMP_PATH
160
#define OUTPUT_DUMP_EXT
161
#define GENERATE_FILE_NAMES()
162
#define CREATE_DUMP_FILE(m_filename)
163
#define DUMP_TO_FILE(m_filename, m_buf, m_size, m_offset)
164
#endif /* FILE_DUMP_ENABLE */
165
166
} // namespace android
167
168
#endif  // SOFT_H264_DEC_H_
/proc/self/cwd/frameworks/av/media/libstagefright/include/media/stagefright/foundation/AData.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2016 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef STAGEFRIGHT_FOUNDATION_A_DATA_H_
18
#define STAGEFRIGHT_FOUNDATION_A_DATA_H_
19
20
#include <memory> // for std::shared_ptr, weak_ptr and unique_ptr
21
#include <type_traits> // for std::aligned_union
22
23
#include <utils/StrongPointer.h> // for android::sp and wp
24
25
#include <media/stagefright/foundation/TypeTraits.h>
26
#include <media/stagefright/foundation/Flagged.h>
27
28
#undef HIDE
29
#define HIDE __attribute__((visibility("hidden")))
30
31
namespace android {
32
33
/**
34
 * AData is a flexible union type that supports non-POD members. It supports arbitrary types as long
35
 * as they are either moveable or copyable.
36
 *
37
 * Internally, AData is using AUnion - a structure providing the union support. AUnion should not
38
 * be used by generic code as it is very unsafe - it opens type aliasing errors where an object of
39
 * one type can be easily accessed as an object of another type. AData prevents this.
40
 *
41
 * AData allows a custom type flagger to be used for future extensions (e.g. allowing automatic
42
 * type conversion). A strict and a relaxed flagger are provided as internal types.
43
 *
44
 * Use as follows:
45
 *
46
 * AData<int, float>::Basic data; // strict type support
47
 * int i = 1;
48
 * float f = 7.0f;
49
 *
50
 * data.set(5);
51
 * EXPECT_TRUE(data.find(&i));
52
 * EXPECT_FALSE(data.find(&f));
53
 * EXPECT_EQ(i, 5);
54
 *
55
 * data.set(6.0f);
56
 * EXPECT_FALSE(data.find(&i));
57
 * EXPECT_TRUE(data.find(&f));
58
 * EXPECT_EQ(f, 6.0f);
59
 *
60
 * AData<int, sp<RefBase>>::RelaxedBasic objdata; // relaxed type support
61
 * sp<ABuffer> buf = new ABuffer(16), buf2;
62
 * sp<RefBase> obj;
63
 *
64
 * objdata.set(buf);
65
 * EXPECT_TRUE(objdata.find(&buf2));
66
 * EXPECT_EQ(buf, buf2);
67
 * EXPECT_FALSE(objdata.find(&i));
68
 * EXPECT_TRUE(objdata.find(&obj));
69
 * EXPECT_TRUE(obj == buf);
70
 *
71
 * obj = buf;
72
 * objdata.set(obj); // storing as sp<RefBase>
73
 * EXPECT_FALSE(objdata.find(&buf2));  // not stored as ABuffer(!)
74
 * EXPECT_TRUE(objdata.find(&obj));
75
 */
76
77
/// \cond Internal
78
79
/**
80
 * Helper class to call constructor and destructor for a specific type in AUnion.
81
 * This class is needed as member function specialization is not allowed for a
82
 * templated class.
83
 */
84
struct HIDE _AUnion_impl {
85
    /**
86
     * Calls placement constuctor for type T with arbitrary arguments for a storage at an address.
87
     * Storage MUST be large enough to contain T.
88
     * Also clears the slack space after type T. \todo This is not technically needed, so we may
89
     * choose to do this just for debugging.
90
     *
91
     * \param totalSize size of the storage
92
     * \param addr      pointer to where object T should be constructed
93
     * \param args      arbitrary arguments for constructor
94
     */
95
    template<typename T, typename ...Args>
96
    inline static void emplace(size_t totalSize, T *addr, Args&&... args) {
97
        new(addr)T(std::forward<Args>(args)...);
98
        // clear slack space - this is not technically required
99
        constexpr size_t size = sizeof(T);
100
        memset(reinterpret_cast<uint8_t*>(addr) + size, 0, totalSize - size);
101
    }
102
103
    /**
104
     * Calls destuctor for an object of type T located at a specific address.
105
     *
106
     * \note we do not clear the storage in this case as the storage should not be used
107
     * until another object is placed there, at which case the storage will be cleared.
108
     *
109
     * \param addr    pointer to where object T is stored
110
     */
111
    template<typename T>
112
    inline static void del(T *addr) {
113
        addr->~T();
114
    }
115
};
116
117
/** Constructor specialization for void type */
118
template<>
119
0
HIDE inline void _AUnion_impl::emplace<void>(size_t totalSize, void *addr) {
120
0
    memset(addr, 0, totalSize);
121
0
}
122
123
/** Destructor specialization for void type */
124
template<>
125
0
HIDE inline void _AUnion_impl::del<void>(void *) {
126
0
}
127
128
/// \endcond
129
130
/**
131
 * A templated union class that can contain specific types of data, and provides
132
 * constructors, destructor and access methods strictly for those types.
133
 *
134
 * \note This class is VERY UNSAFE compared to a union, but it allows non-POD unions.
135
 * In particular care must be taken that methods are called in a careful order to
136
 * prevent accessing objects of one type as another type. This class provides no
137
 * facilities to help with this ordering. This is meant to be wrapped by safer
138
 * utility classes that do that.
139
 *
140
 * \param Ts types stored in this union.
141
 */
142
template<typename ...Ts>
143
struct AUnion {
144
private:
145
    using _type = typename std::aligned_union<0, Ts...>::type; ///< storage type
146
    _type mValue;                                              ///< storage
147
148
public:
149
    /**
150
     * Constructs an object of type T with arbitrary arguments in this union. After this call,
151
     * this union will contain this object.
152
     *
153
     * This method MUST be called only when either 1) no object or 2) a void object (equivalent to
154
     * no object) is contained in this union.
155
     *
156
     * \param T     type of object to be constructed. This must be one of the template parameters of
157
     *              the union class with the same cv-qualification, or void.
158
     * \param args  arbitrary arguments for the constructor
159
     */
160
    template<
161
            typename T, typename ...Args,
162
            typename=typename std::enable_if<is_one_of<T, void, Ts...>::value>::type>
163
    inline void emplace(Args&&... args) {
164
        _AUnion_impl::emplace(
165
                sizeof(_type), reinterpret_cast<T*>(&mValue), std::forward<Args>(args)...);
166
    }
167
168
    /**
169
     * Destructs an object of type T in this union. After this call, this union will contain no
170
     * object.
171
     *
172
     * This method MUST be called only when this union contains an object of type T.
173
     *
174
     * \param T     type of object to be destructed. This must be one of the template parameters of
175
     *              the union class with the same cv-qualification, or void.
176
     */
177
    template<
178
            typename T,
179
            typename=typename std::enable_if<is_one_of<T, void, Ts...>::value>::type>
180
    inline void del() {
181
        _AUnion_impl::del(reinterpret_cast<T*>(&mValue));
182
    }
183
184
    /**
185
     * Returns a const reference to the object of type T in this union.
186
     *
187
     * This method MUST be called only when this union contains an object of type T.
188
     *
189
     * \param T     type of object to be returned. This must be one of the template parameters of
190
     *              the union class with the same cv-qualification.
191
     */
192
    template<
193
            typename T,
194
            typename=typename std::enable_if<is_one_of<T, Ts...>::value>::type>
195
    inline const T &get() const {
196
        return *reinterpret_cast<const T*>(&mValue);
197
    }
198
199
    /**
200
     * Returns a reference to the object of type T in this union.
201
     *
202
     * This method MUST be called only when this union contains an object of type T.
203
     *
204
     * \param T     type of object to be returned. This must be one of the template parameters of
205
     *              the union class with the same cv-qualification.
206
     */
207
    template<typename T>
208
    inline T &get() {
209
        return *reinterpret_cast<T*>(&mValue);
210
    }
211
};
212
213
/**
214
 * Helper utility class that copies an object of type T to a destination.
215
 *
216
 * T must be copy assignable or copy constructible.
217
 *
218
 * It provides:
219
 *
220
 * void assign(T*, const U&) // for copiable types - this leaves the source unchanged, hence const.
221
 *
222
 * \param T type of object to assign to
223
 */
224
template<
225
        typename T,
226
        bool=std::is_copy_assignable<T>::value>
227
struct HIDE _AData_copier {
228
    static_assert(std::is_copy_assignable<T>::value, "T must be copy assignable here");
229
230
    /**
231
     * Copies src to data without modifying data.
232
     *
233
     * \param data pointer to destination
234
     * \param src source object
235
     */
236
    inline static void assign(T *data, const T &src) {
237
        *data = src;
238
    }
239
240
    template<typename U>
241
    using enable_if_T_is_same_as = typename std::enable_if<std::is_same<U, T>::value>::type;
242
243
    /**
244
     * Downcast specializations for sp<>, shared_ptr<> and weak_ptr<>
245
     */
246
    template<typename Tp, typename U, typename=enable_if_T_is_same_as<sp<Tp>>>
247
    inline static void assign(sp<Tp> *data, const sp<U> &src) {
248
        *data = static_cast<Tp*>(src.get());
249
    }
250
251
    template<typename Tp, typename U, typename=enable_if_T_is_same_as<wp<Tp>>>
252
    inline static void assign(wp<Tp> *data, const wp<U> &src) {
253
        sp<U> __tmp = src.promote();
254
        *data = static_cast<Tp*>(__tmp.get());
255
    }
256
257
    template<typename Tp, typename U, typename=enable_if_T_is_same_as<sp<Tp>>>
258
    inline static void assign(sp<Tp> *data, sp<U> &&src) {
259
        sp<U> __tmp = std::move(src); // move src out as get cannot
260
        *data = static_cast<Tp*>(__tmp.get());
261
    }
262
263
    template<typename Tp, typename U, typename=enable_if_T_is_same_as<std::shared_ptr<Tp>>>
264
    inline static void assign(std::shared_ptr<Tp> *data, const std::shared_ptr<U> &src) {
265
        *data = std::static_pointer_cast<Tp>(src);
266
    }
267
268
    template<typename Tp, typename U, typename=enable_if_T_is_same_as<std::shared_ptr<Tp>>>
269
    inline static void assign(std::shared_ptr<Tp> *data, std::shared_ptr<U> &&src) {
270
        std::shared_ptr<U> __tmp = std::move(src); // move src out as static_pointer_cast cannot
271
        *data = std::static_pointer_cast<Tp>(__tmp);
272
    }
273
274
    template<typename Tp, typename U, typename=enable_if_T_is_same_as<std::weak_ptr<Tp>>>
275
    inline static void assign(std::weak_ptr<Tp> *data, const std::weak_ptr<U> &src) {
276
        *data = std::static_pointer_cast<Tp>(src.lock());
277
    }
278
279
    // shared_ptrs are implicitly convertible to weak_ptrs but not vice versa, but picking the
280
    // first compatible type in Ts requires having shared_ptr types before weak_ptr types, so that
281
    // they are stored as shared_ptrs.
282
    /**
283
     * Provide sensible error message if encountering shared_ptr/weak_ptr ambiguity. This method
284
     * is not enough to detect this, only if someone is trying to find the shared_ptr.
285
     */
286
    template<typename Tp, typename U>
287
    inline static void assign(std::shared_ptr<Tp> *, const std::weak_ptr<U> &) {
288
        static_assert(std::is_same<Tp, void>::value,
289
                      "shared/weak pointer ambiguity. move shared ptr types before weak_ptrs");
290
    }
291
};
292
293
/**
294
 * Template specialization for non copy assignable, but copy constructible types.
295
 *
296
 * \todo Test this. No basic classes are copy constructible but not assignable.
297
 *
298
 */
299
template<typename T>
300
struct HIDE _AData_copier<T, false> {
301
    static_assert(!std::is_copy_assignable<T>::value, "T must not be copy assignable here");
302
    static_assert(std::is_copy_constructible<T>::value, "T must be copy constructible here");
303
304
    inline static void copy(T *data, const T &src) {
305
        data->~T();
306
        new(data)T(src);
307
    }
308
};
309
310
/**
311
 * Helper utility class that moves an object of type T to a destination.
312
 *
313
 * T must be move assignable or move constructible.
314
 *
315
 * It provides multiple methods:
316
 *
317
 * void assign(T*, T&&)
318
 *
319
 * \param T type of object to assign
320
 */
321
template<
322
        typename T,
323
        bool=std::is_move_assignable<T>::value>
324
struct HIDE _AData_mover {
325
    static_assert(std::is_move_assignable<T>::value, "T must be move assignable here");
326
327
    /**
328
     * Moves src to data while likely modifying it.
329
     *
330
     * \param data pointer to destination
331
     * \param src source object
332
     */
333
    inline static void assign(T *data, T &&src) {
334
        *data = std::move(src);
335
    }
336
337
    template<typename U>
338
    using enable_if_T_is_same_as = typename std::enable_if<std::is_same<U, T>::value>::type;
339
340
    /**
341
     * Downcast specializations for sp<>, shared_ptr<> and weak_ptr<>
342
     */
343
    template<typename Tp, typename U, typename=enable_if_T_is_same_as<sp<Tp>>>
344
    inline static void assign(sp<Tp> *data, sp<U> &&src) {
345
        sp<U> __tmp = std::move(src); // move src out as get cannot
346
        *data = static_cast<Tp*>(__tmp.get());
347
    }
348
349
    template<typename Tp, typename U, typename=enable_if_T_is_same_as<std::shared_ptr<Tp>>>
350
    inline static void assign(std::shared_ptr<Tp> *data, std::shared_ptr<U> &&src) {
351
        std::shared_ptr<U> __tmp = std::move(src); // move src out as static_pointer_cast cannot
352
        *data = std::static_pointer_cast<Tp>(__tmp);
353
    }
354
355
    template<typename Tp, typename Td, typename U, typename Ud,
356
            typename=enable_if_T_is_same_as<std::unique_ptr<Tp, Td>>>
357
    inline static void assign(std::unique_ptr<Tp, Td> *data, std::unique_ptr<U, Ud> &&src) {
358
        *data = std::unique_ptr<Tp, Td>(static_cast<Tp*>(src.release()));
359
    }
360
361
    // shared_ptrs are implicitly convertible to weak_ptrs but not vice versa, but picking the
362
    // first compatible type in Ts requires having shared_ptr types before weak_ptr types, so that
363
    // they are stored as shared_ptrs.
364
    /**
365
     * Provide sensible error message if encountering shared_ptr/weak_ptr ambiguity. This method
366
     * is not enough to detect this, only if someone is trying to remove the shared_ptr.
367
     */
368
    template<typename Tp, typename U>
369
    inline static void assign(std::shared_ptr<Tp> *, std::weak_ptr<U> &&) {
370
        static_assert(std::is_same<Tp, void>::value,
371
                      "shared/weak pointer ambiguity. move shared ptr types before weak_ptrs");
372
    }
373
374
    // unique_ptrs are implicitly convertible to shared_ptrs but not vice versa, but picking the
375
    // first compatible type in Ts requires having unique_ptrs types before shared_ptrs types, so
376
    // that they are stored as unique_ptrs.
377
    /**
378
     * Provide sensible error message if encountering shared_ptr/unique_ptr ambiguity. This method
379
     * is not enough to detect this, only if someone is trying to remove the unique_ptr.
380
     */
381
    template<typename Tp, typename U>
382
    inline static void assign(std::unique_ptr<Tp> *, std::shared_ptr<U> &&) {
383
        static_assert(std::is_same<Tp, void>::value,
384
                      "unique/shared pointer ambiguity. move unique ptr types before shared_ptrs");
385
    }
386
};
387
388
/**
389
 * Template specialization for non move assignable, but move constructible types.
390
 *
391
 * \todo Test this. No basic classes are move constructible but not assignable.
392
 *
393
 */
394
template<typename T>
395
struct HIDE _AData_mover<T, false> {
396
    static_assert(!std::is_move_assignable<T>::value, "T must not be move assignable here");
397
    static_assert(std::is_move_constructible<T>::value, "T must be move constructible here");
398
399
    inline static void assign(T *data, T &&src) {
400
        data->~T();
401
        new(data)T(std::move(src));
402
    }
403
};
404
405
/**
406
 * Helper template that deletes an object of a specific type (member) in an AUnion.
407
 *
408
 * \param Flagger type flagger class (see AData)
409
 * \param U AUnion object in which the member should be deleted
410
 * \param Ts types to consider for the member
411
 */
412
template<typename Flagger, typename U, typename ...Ts>
413
struct HIDE _AData_deleter;
414
415
/**
416
 * Template specialization when there are still types to consider (T and rest)
417
 */
418
template<typename Flagger, typename U, typename T, typename ...Ts>
419
struct HIDE _AData_deleter<Flagger, U, T, Ts...> {
420
    static bool del(typename Flagger::type flags, U &data) {
421
        if (Flagger::canDeleteAs(flags, Flagger::flagFor((T*)0))) {
422
            data.template del<T>();
423
            return true;
424
        }
425
        return _AData_deleter<Flagger, U, Ts...>::del(flags, data);
426
    }
427
};
428
429
/**
430
 * Template specialization when there are no more types to consider.
431
 */
432
template<typename Flagger, typename U>
433
struct HIDE _AData_deleter<Flagger, U> {
434
    inline static bool del(typename Flagger::type, U &) {
435
        return false;
436
    }
437
};
438
439
/**
440
 * Helper template that copy assigns an object of a specific type (member) in an
441
 * AUnion.
442
 *
443
 * \param Flagger type flagger class (see AData)
444
 * \param U AUnion object in which the member should be copy assigned
445
 * \param Ts types to consider for the member
446
 */
447
template<typename Flagger, typename U, typename ...Ts>
448
struct HIDE _AData_copy_assigner;
449
450
/**
451
 * Template specialization when there are still types to consider (T and rest)
452
 */
453
template<typename Flagger, typename U, typename T, typename ...Ts>
454
struct HIDE _AData_copy_assigner<Flagger, U, T, Ts...> {
455
    static bool assign(typename Flagger::type flags, U &dst, const U &src) {
456
        static_assert(std::is_copy_constructible<T>::value, "T must be copy constructible");
457
        // if we can delete as, we can also assign as
458
        if (Flagger::canDeleteAs(flags, Flagger::flagFor((T*)0))) {
459
            dst.template emplace<T>(src.template get<T>());
460
            return true;
461
        }
462
        return _AData_copy_assigner<Flagger, U, Ts...>::assign(flags, dst, src);
463
    }
464
};
465
466
/**
467
 * Template specialization when there are no more types to consider.
468
 */
469
template<typename Flagger, typename U>
470
struct HIDE _AData_copy_assigner<Flagger, U> {
471
    inline static bool assign(typename Flagger::type, U &, const U &) {
472
        return false;
473
    }
474
};
475
476
/**
477
 * Helper template that move assigns an object of a specific type (member) in an
478
 * AUnion.
479
 *
480
 * \param Flagger type flagger class (see AData)
481
 * \param U AUnion object in which the member should be copy assigned
482
 * \param Ts types to consider for the member
483
 */
484
template<typename Flagger, typename U, typename ...Ts>
485
struct HIDE _AData_move_assigner;
486
487
/**
488
 * Template specialization when there are still types to consider (T and rest)
489
 */
490
template<typename Flagger, typename U, typename T, typename ...Ts>
491
struct HIDE _AData_move_assigner<Flagger, U, T, Ts...> {
492
    template<typename V = T>
493
    static typename std::enable_if<std::is_move_constructible<V>::value, bool>::type
494
    assign(typename Flagger::type flags, U &dst, U &src) {
495
        // if we can delete as, we can also assign as
496
        if (Flagger::canDeleteAs(flags, Flagger::flagFor((T*)0))) {
497
            dst.template emplace<T>(std::move(src.template get<T>()));
498
            return true;
499
        }
500
        return _AData_move_assigner<Flagger, U, Ts...>::assign(flags, dst, src);
501
    }
502
503
    // Fall back to copy construction if T is not move constructible
504
    template<typename V = T>
505
    static typename std::enable_if<!std::is_move_constructible<V>::value, bool>::type
506
    assign(typename Flagger::type flags, U &dst, U &src) {
507
        static_assert(std::is_copy_constructible<T>::value, "T must be copy constructible");
508
        // if we can delete as, we can also assign as
509
        if (Flagger::canDeleteAs(flags, Flagger::flagFor((T*)0))) {
510
            dst.template emplace<T>(src.template get<T>());
511
            return true;
512
        }
513
        return _AData_move_assigner<Flagger, U, Ts...>::assign(flags, dst, src);
514
    }
515
};
516
517
/**
518
 * Template specialization when there are no more types to consider.
519
 */
520
template<typename Flagger, typename U>
521
struct HIDE _AData_move_assigner<Flagger, U> {
522
    inline static bool assign(typename Flagger::type, U &, U &) {
523
        return false;
524
    }
525
};
526
527
/**
528
 * Container that can store an arbitrary object of a set of specified types.
529
 *
530
 * This struct is an outer class that contains various inner classes based on desired type
531
 * strictness. The following inner classes are supported:
532
 *
533
 * AData<types...>::Basic   - strict type support using uint32_t flag.
534
 *
535
 * AData<types...>::Strict<Flag> - strict type support using custom flag.
536
 * AData<types...>::Relaxed<Flag, MaxSize, Align>
537
 *                          - relaxed type support with compatible (usually derived) class support
538
 *                            for pointer types with added size checking for minimal additional
539
 *                            safety.
540
 *
541
 * AData<types...>::RelaxedBasic - strict type support using uint32_t flag.
542
 *
543
 * AData<types...>::Custom<flagger> - custom type support (flaggers determine the supported types
544
 *                                    and the base type to use for each)
545
 *
546
 */
547
template<typename ...Ts>
548
struct AData {
549
private:
550
    static_assert(are_unique<Ts...>::value, "types must be unique");
551
552
    static constexpr size_t num_types = sizeof...(Ts); ///< number of types to support
553
554
public:
555
    /**
556
     * Default (strict) type flagger provided.
557
     *
558
     * The default flagger simply returns the index of the type within Ts, or 0 for void.
559
     *
560
     * Type flaggers return a flag for a supported type.
561
     *
562
     * They must provide:
563
     *
564
     * - a flagFor(T*) method for supported types _and_ for T=void. T=void is used to mark that no
565
     *   object is stored in the container. For this, an arbitrary unique value may be returned.
566
     * - a mask field that contains the flag mask.
567
     * - a canDeleteAs(Flag, Flag) flag comparison method that checks if a type of a flag can be
568
     *   deleted as another type.
569
     *
570
     * \param Flag the underlying unsigned integral to use for the flags.
571
     */
572
    template<typename Flag>
573
    struct flagger {
574
    private:
575
        static_assert(std::is_unsigned<Flag>::value, "Flag must be unsigned");
576
        static_assert(std::is_integral<Flag>::value, "Flag must be an integral type");
577
578
        static constexpr Flag count = num_types + 1;
579
580
    public:
581
        typedef Flag type; ///< flag type
582
583
        static constexpr Flag mask = _Flagged_helper::minMask<Flag>(count); ///< flag mask
584
585
        /**
586
         * Return the stored type for T. This is itself.
587
         */
588
        template<typename T>
589
        struct store {
590
            typedef T as_type; ///< the base type that T is stored as
591
        };
592
593
        /**
594
         * Constexpr method that returns if two flags are compatible for deletion.
595
         *
596
         * \param objectFlag flag for object to be deleted
597
         * \param deleteFlag flag for type that object is to be deleted as
598
         */
599
        static constexpr bool canDeleteAs(Flag objectFlag, Flag deleteFlag) {
600
            // default flagger requires strict type equality
601
            return objectFlag == deleteFlag;
602
        }
603
604
        /**
605
         * Constexpr method that returns the flag to use for a given type.
606
         *
607
         * Function overload for void*.
608
         */
609
        static constexpr Flag flagFor(void*) {
610
            return 0u;
611
        }
612
613
        /**
614
         * Constexpr method that returns the flag to use for a given supported type (T).
615
         */
616
        template<typename T, typename=typename std::enable_if<is_one_of<T, Ts...>::value>::type>
617
        static constexpr Flag flagFor(T*) {
618
            return find_first<T, Ts...>::index;
619
        }
620
    };
621
622
    /**
623
     * Relaxed flagger returns the index of the type within Ts. However, for pointers T* it returns
624
     * the first type in Ts that T* can be converted into (this is normally a base type, but also
625
     * works for sp<>, shared_ptr<> or unique_ptr<>). For a bit more strictness, the flag also
626
     * contains the size of the class to avoid finding objects that were stored as a different
627
     * derived class of the same base class.
628
     *
629
     * Flag is basically the index of the (base) type in Ts multiplied by the max size stored plus
630
     * the size of the type (divided by alignment) for derived pointer types.
631
     *
632
     * \param MaxSize max supported size for derived class pointers
633
     * \param Align alignment to assume for derived class pointers
634
     */
635
    template<typename Flag, size_t MaxSize=1024, size_t Align=4>
636
    struct relaxed_flagger {
637
    private:
638
        static_assert(std::is_unsigned<Flag>::value, "Flag must be unsigned");
639
        static_assert(std::is_integral<Flag>::value, "Flag must be an integral type");
640
641
        static constexpr Flag count = num_types + 1;
642
        static_assert(std::numeric_limits<Flag>::max() / count > (MaxSize / Align),
643
                      "not enough bits to fit into flag");
644
645
        static constexpr Flag max_size_stored = MaxSize / Align + 1;
646
647
        // T can be converted if it's size is <= MaxSize and it can be converted to one of the Ts
648
        template<typename T, size_t size>
649
        using enable_if_can_be_converted = typename std::enable_if<
650
                (size / Align < max_size_stored
651
                        && find_first_convertible_to<T, Ts...>::index)>::type;
652
653
654
        template<typename W, typename T, typename=enable_if_can_be_converted<W, sizeof(T)>>
655
        static constexpr Flag relaxedFlagFor(W*, T*) {
656
            return find_first_convertible_to<W, Ts...>::index * max_size_stored
657
                    + (is_one_of<W, Ts...>::value ? 0 : (sizeof(T) / Align));
658
        }
659
660
    public:
661
        typedef Flag type; ///< flag type
662
663
        static constexpr Flag mask =
664
            _Flagged_helper::minMask<Flag>(count * max_size_stored); ///< flag mask
665
666
        /**
667
         * Constexpr method that returns if two flags are compatible for deletion.
668
         *
669
         * \param objectFlag flag for object to be deleted
670
         * \param deleteFlag flag for type that object is to be deleted as
671
         */
672
        static constexpr bool canDeleteAs(Flag objectFlag, Flag deleteFlag) {
673
            // can delete if objects have the same base type
674
            return
675
                objectFlag / max_size_stored == deleteFlag / max_size_stored &&
676
                (deleteFlag % max_size_stored) == 0;
677
        }
678
679
        /**
680
         * Constexpr method that returns the flag to use for a given type.
681
         *
682
         * Function overload for void*.
683
         */
684
        static constexpr Flag flagFor(void*) {
685
            return 0u;
686
        }
687
688
        /**
689
         * Constexpr method that returns the flag to use for a given supported type (T).
690
         *
691
         * This is a member method to enable both overloading as well as template specialization.
692
         */
693
        template<typename T, typename=typename std::enable_if<is_one_of<T, Ts...>::value>::type>
694
        static constexpr Flag flagFor(T*) {
695
            return find_first<T, Ts...>::index * max_size_stored;
696
        }
697
698
        /**
699
         * For precaution, we only consider converting pointers to their base classes.
700
         */
701
702
        /**
703
         * Template specialization for derived class pointers and managed pointers.
704
         */
705
        template<typename T>
706
        static constexpr Flag flagFor(T**p) { return relaxedFlagFor(p, (T*)0); }
707
        template<typename T>
708
        static constexpr Flag flagFor(std::shared_ptr<T>*p) { return relaxedFlagFor(p, (T*)0); }
709
        template<typename T>
710
        static constexpr Flag flagFor(std::unique_ptr<T>*p) { return relaxedFlagFor(p, (T*)0); }
711
        template<typename T>
712
        static constexpr Flag flagFor(std::weak_ptr<T>*p) { return relaxedFlagFor(p, (T*)0); }
713
        template<typename T>
714
        static constexpr Flag flagFor(sp<T>*p) { return relaxedFlagFor(p, (T*)0); }
715
        template<typename T>
716
        static constexpr Flag flagFor(wp<T>*p) { return relaxedFlagFor(p, (T*)0); }
717
718
        /**
719
         * Type support template that provodes the stored type for T.
720
         * This is itself if it is one of Ts, or the first type in Ts that T is convertible to.
721
         *
722
         * NOTE: This template may provide a base class for an unsupported type. Support is
723
         * determined by flagFor().
724
         */
725
        template<typename T>
726
        struct store {
727
            typedef typename std::conditional<
728
                    is_one_of<T, Ts...>::value,
729
                    T,
730
                    typename find_first_convertible_to<T, Ts...>::type>::type as_type;
731
        };
732
    };
733
734
    /**
735
     * Implementation of AData.
736
     */
737
    template<typename Flagger>
738
    struct Custom : protected Flagged<AUnion<Ts...>, typename Flagger::type, Flagger::mask> {
739
        using data_t = AUnion<Ts...>;
740
        using base_t = Flagged<AUnion<Ts...>, typename Flagger::type, Flagger::mask>;
741
742
        /**
743
         * Constructor. Initializes this to a container that does not contain any object.
744
         */
745
        Custom() : base_t(Flagger::flagFor((void*)0)) { }
746
747
        /**
748
         * Copy assignment operator.
749
         */
750
        Custom& operator=(const Custom &o) {
751
            if (&o != this) {
752
                if (this->used() && !this->clear()) {
753
                    __builtin_trap();
754
                }
755
                if (o.used()) {
756
                    if (_AData_copy_assigner<Flagger, data_t, Ts...>::assign(
757
                            o.flags(), this->get(), o.get())) {
758
                        this->setFlags(o.flags());
759
                    } else {
760
                        __builtin_trap();
761
                    }
762
                }
763
            }
764
            return *this;
765
        }
766
767
        /**
768
         * Copy constructor.
769
         */
770
        Custom(const Custom &o) : Custom() {
771
            *this = o;
772
        }
773
774
        /**
775
         * Move assignment operator.
776
         */
777
        Custom& operator=(Custom &&o) noexcept {
778
            if (&o != this) {
779
                if (this->used() && !this->clear()) {
780
                    __builtin_trap();
781
                }
782
                if (o.used()) {
783
                    if (_AData_move_assigner<Flagger, data_t, Ts...>::assign(
784
                            o.flags(), this->get(), o.get())) {
785
                        this->setFlags(o.flags());
786
                        o.clear();
787
                    } else {
788
                        __builtin_trap();
789
                    }
790
                }
791
            }
792
            return *this;
793
        }
794
795
        /**
796
         * Move constructor.
797
         */
798
        Custom(Custom &&o) noexcept : Custom() {
799
            *this = std::move(o);
800
        }
801
802
        /**
803
         * Removes the contained object, if any.
804
         */
805
        ~Custom() {
806
            if (!this->clear()) {
807
                __builtin_trap();
808
                // std::cerr << "could not delete data of type " << this->flags() << std::endl;
809
            }
810
        }
811
812
        /**
813
         * Returns whether there is any object contained.
814
         */
815
        inline bool used() const {
816
            return this->flags() != Flagger::flagFor((void*)0);
817
        }
818
819
        /**
820
         * Removes the contained object, if any. Returns true if there are no objects contained,
821
         * or false on any error (this is highly unexpected).
822
         */
823
        bool clear() {
824
            if (this->used()) {
825
                if (_AData_deleter<Flagger, data_t, Ts...>::del(this->flags(), this->get())) {
826
                    this->setFlags(Flagger::flagFor((void*)0));
827
                    return true;
828
                }
829
                return false;
830
            }
831
            return true;
832
        }
833
834
        template<typename T>
835
        using is_supported_by_flagger =
836
            typename std::enable_if<Flagger::flagFor((T*)0) != Flagger::flagFor((void*)0)>::type;
837
838
        /**
839
         * Checks if there is a copiable object of type T in this container. If there is, it copies
840
         * that object into the provided address and returns true. Otherwise, it does nothing and
841
         * returns false.
842
         *
843
         * This method normally requires a flag equality between the stored and retrieved types.
844
         * However, it also allows retrieving the stored object as the stored type
845
         * (usually base type).
846
         *
847
         * \param T type of object to sought
848
         * \param data address at which the object should be retrieved
849
         *
850
         * \return true if the object was retrieved. false if it was not.
851
         */
852
        template<
853
                typename T,
854
                typename=is_supported_by_flagger<T>>
855
        bool find(T *data) const {
856
            using B = typename Flagger::template store<T>::as_type;
857
            if (this->flags() == Flagger::flagFor((T*)0) ||
858
                Flagger::canDeleteAs(this->flags(), Flagger::flagFor((T*)0))) {
859
                _AData_copier<T>::assign(data, this->get().template get<B>());
860
                return true;
861
            }
862
            return false;
863
        }
864
865
        /**
866
         * Checks if there is an object of type T in this container. If there is, it moves that
867
         * object into the provided address and returns true. Otherwise, it does nothing and returns
868
         * false.
869
         *
870
         * This method normally requires a flag equality between the stored and retrieved types.
871
         * However, it also allows retrieving the stored object as the stored type
872
         * (usually base type).
873
         *
874
         * \param T type of object to sought
875
         * \param data address at which the object should be retrieved.
876
         *
877
         * \return true if the object was retrieved. false if it was not.
878
         */
879
        template<
880
                typename T,
881
                typename=is_supported_by_flagger<T>>
882
        bool remove(T *data) {
883
            using B = typename Flagger::template store<T>::as_type;
884
            if (this->flags() == Flagger::flagFor((T*)0) ||
885
                Flagger::canDeleteAs(this->flags(), Flagger::flagFor((T*)0))) {
886
                _AData_mover<T>::assign(data, std::move(this->get().template get<B>()));
887
                return true;
888
            }
889
            return false;
890
        }
891
892
        /**
893
         * Stores an object into this container by copying. If it was successful, returns true.
894
         * Otherwise, (e.g. it could not destroy the already stored object) it returns false. This
895
         * latter would be highly unexpected.
896
         *
897
         * \param T type of object to store
898
         * \param data object to store
899
         *
900
         * \return true if the object was stored. false if it was not.
901
         */
902
        template<
903
                typename T,
904
                typename=is_supported_by_flagger<T>,
905
                typename=typename std::enable_if<
906
                        std::is_copy_constructible<T>::value ||
907
                        (std::is_default_constructible<T>::value &&
908
                                std::is_copy_assignable<T>::value)>::type>
909
        bool set(const T &data) {
910
            using B = typename Flagger::template store<T>::as_type;
911
912
            // if already contains an object of this type, simply assign
913
            if (this->flags() == Flagger::flagFor((T*)0) && std::is_same<T, B>::value) {
914
                _AData_copier<B>::assign(&this->get().template get<B>(), data);
915
                return true;
916
            } else if (this->used()) {
917
                // destroy previous object
918
                if (!this->clear()) {
919
                    return false;
920
                }
921
            }
922
            this->get().template emplace<B>(data);
923
            this->setFlags(Flagger::flagFor((T *)0));
924
            return true;
925
        }
926
927
        /**
928
         * Moves an object into this container. If it was successful, returns true. Otherwise,
929
         * (e.g. it could not destroy the already stored object) it returns false. This latter
930
         * would be highly unexpected.
931
         *
932
         * \param T type of object to store
933
         * \param data object to store
934
         *
935
         * \return true if the object was stored. false if it was not.
936
         */
937
        template<
938
                typename T,
939
                typename=is_supported_by_flagger<T>>
940
        bool set(T &&data) {
941
            using B = typename Flagger::template store<T>::as_type;
942
943
            // if already contains an object of this type, simply assign
944
            if (this->flags() == Flagger::flagFor((T*)0) && std::is_same<T, B>::value) {
945
                _AData_mover<B>::assign(&this->get().template get<B>(), std::forward<T&&>(data));
946
                return true;
947
            } else if (this->used()) {
948
                // destroy previous object
949
                if (!this->clear()) {
950
                    return false;
951
                }
952
            }
953
            this->get().template emplace<B>(std::forward<T&&>(data));
954
            this->setFlags(Flagger::flagFor((T *)0));
955
            return true;
956
        }
957
    };
958
959
    /**
960
     * Basic AData using the default type flagger and requested flag type.
961
     *
962
     * \param Flag desired flag type to use. Must be an unsigned and std::integral type.
963
     */
964
    template<typename Flag>
965
    using Strict = Custom<flagger<Flag>>;
966
967
    /**
968
     * Basic AData using the default type flagger and uint32_t flag.
969
     */
970
    using Basic = Strict<uint32_t>;
971
972
    /**
973
     * AData using the relaxed type flagger for max size and requested flag type.
974
     *
975
     * \param Flag desired flag type to use. Must be an unsigned and std::integral type.
976
     */
977
    template<typename Flag, size_t MaxSize = 1024, size_t Align = 4>
978
    using Relaxed = Custom<relaxed_flagger<Flag, MaxSize, Align>>;
979
980
    /**
981
     * Basic AData using the relaxed type flagger and uint32_t flag.
982
     */
983
    using RelaxedBasic = Relaxed<uint32_t>;
984
};
985
986
}  // namespace android
987
988
#endif  // STAGEFRIGHT_FOUNDATION_A_DATA_H_
989
/proc/self/cwd/frameworks/av/media/libstagefright/include/media/stagefright/foundation/ADebug.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2010 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef A_DEBUG_H_
18
19
#define A_DEBUG_H_
20
21
#include <string.h>
22
23
#include <media/stagefright/foundation/ABase.h>
24
#include <media/stagefright/foundation/AString.h>
25
#include <utils/Log.h>
26
27
namespace android {
28
29
0
inline static const char *asString(status_t i, const char *def = "??") {
30
0
    switch (i) {
31
0
        case NO_ERROR:              return "NO_ERROR";
32
0
        case UNKNOWN_ERROR:         return "UNKNOWN_ERROR";
33
0
        case NO_MEMORY:             return "NO_MEMORY";
34
0
        case INVALID_OPERATION:     return "INVALID_OPERATION";
35
0
        case BAD_VALUE:             return "BAD_VALUE";
36
0
        case BAD_TYPE:              return "BAD_TYPE";
37
0
        case NAME_NOT_FOUND:        return "NAME_NOT_FOUND";
38
0
        case PERMISSION_DENIED:     return "PERMISSION_DENIED";
39
0
        case NO_INIT:               return "NO_INIT";
40
0
        case ALREADY_EXISTS:        return "ALREADY_EXISTS";
41
0
        case DEAD_OBJECT:           return "DEAD_OBJECT";
42
0
        case FAILED_TRANSACTION:    return "FAILED_TRANSACTION";
43
0
        case BAD_INDEX:             return "BAD_INDEX";
44
0
        case NOT_ENOUGH_DATA:       return "NOT_ENOUGH_DATA";
45
0
        case WOULD_BLOCK:           return "WOULD_BLOCK";
46
0
        case TIMED_OUT:             return "TIMED_OUT";
47
0
        case UNKNOWN_TRANSACTION:   return "UNKNOWN_TRANSACTION";
48
0
        case FDS_NOT_ALLOWED:       return "FDS_NOT_ALLOWED";
49
0
        default:                    return def;
50
0
    }
51
0
}
52
53
#define LITERAL_TO_STRING_INTERNAL(x)    #x
54
#define LITERAL_TO_STRING(x) LITERAL_TO_STRING_INTERNAL(x)
55
56
#ifdef CHECK
57
#undef CHECK
58
#endif
59
#define CHECK(condition)                                \
60
2
    LOG_ALWAYS_FATAL_IF(                                \
61
2
            !(condition),                               \
62
2
            "%s",                                       \
63
2
            __FILE__ ":" LITERAL_TO_STRING(__LINE__)    \
64
2
            " CHECK(" #condition ") failed.")
65
66
#ifdef CHECK_OP
67
#undef CHECK_OP
68
#endif
69
70
#define CHECK_OP(x,y,suffix,op)                                         \
71
2
    do {                                                                \
72
2
        const auto &a = x;                                              \
73
2
        const auto &b = y;                                              \
74
2
        if (!(a op b)) {                                                \
75
0
            AString ___full =                                           \
76
0
                __FILE__ ":" LITERAL_TO_STRING(__LINE__)                \
77
0
                    " CHECK_" #suffix "( " #x "," #y ") failed: ";      \
78
0
            ___full.append(a);                                          \
79
0
            ___full.append(" vs. ");                                    \
80
0
            ___full.append(b);                                          \
81
0
            LOG_ALWAYS_FATAL("%s", ___full.c_str());                    \
82
0
        }                                                               \
83
2
    } while (false)
84
85
#ifdef CHECK_EQ
86
#undef CHECK_EQ
87
#undef CHECK_NE
88
#undef CHECK_LE
89
#undef CHECK_LT
90
#undef CHECK_GE
91
#undef CHECK_GT
92
#endif
93
94
2
#define CHECK_EQ(x,y)   CHECK_OP(x,y,EQ,==)
95
#define CHECK_NE(x,y)   CHECK_OP(x,y,NE,!=)
96
#define CHECK_LE(x,y)   CHECK_OP(x,y,LE,<=)
97
#define CHECK_LT(x,y)   CHECK_OP(x,y,LT,<)
98
#define CHECK_GE(x,y)   CHECK_OP(x,y,GE,>=)
99
#define CHECK_GT(x,y)   CHECK_OP(x,y,GT,>)
100
101
#define TRESPASS(...) \
102
        LOG_ALWAYS_FATAL(                                       \
103
            __FILE__ ":" LITERAL_TO_STRING(__LINE__)            \
104
                " Should not be here. " __VA_ARGS__);
105
106
#ifdef NDEBUG
107
#define CHECK_DBG CHECK
108
#define CHECK_EQ_DBG CHECK_EQ
109
#define CHECK_NE_DBG CHECK_NE
110
#define CHECK_LE_DBG CHECK_LE
111
#define CHECK_LT_DBG CHECK_LT
112
#define CHECK_GE_DBG CHECK_GE
113
#define CHECK_GT_DBG CHECK_GT
114
#define TRESPASS_DBG TRESPASS
115
#else
116
#define CHECK_DBG(condition)
117
#define CHECK_EQ_DBG(x,y)
118
#define CHECK_NE_DBG(x,y)
119
#define CHECK_LE_DBG(x,y)
120
#define CHECK_LT_DBG(x,y)
121
#define CHECK_GE_DBG(x,y)
122
#define CHECK_GT_DBG(x,y)
123
#define TRESPASS_DBG(...)
124
#endif
125
126
struct ADebug {
127
    enum Level {
128
        kDebugNone,             // no debug
129
        kDebugLifeCycle,        // lifecycle events: creation/deletion
130
        kDebugState,            // commands and events
131
        kDebugConfig,           // configuration
132
        kDebugInternalState,    // internal state changes
133
        kDebugAll,              // all
134
        kDebugMax = kDebugAll,
135
136
    };
137
138
    // parse the property or string to get a long-type level for a component name
139
    // string format is:
140
    // <level>[:<glob>][,<level>[:<glob>]...]
141
    // - <level> is 0-5 corresponding to ADebug::Level
142
    // - <glob> is used to match component name case insensitively, if omitted, it
143
    //   matches all components
144
    // - string is read left-to-right, and the last matching level is returned, or
145
    //   the def if no terms matched
146
    static long GetLevelFromSettingsString(
147
            const char *name, const char *value, long def);
148
    static long GetLevelFromProperty(
149
            const char *name, const char *value, long def);
150
151
    // same for ADebug::Level - performs clamping to valid debug ranges
152
    static Level GetDebugLevelFromProperty(
153
            const char *name, const char *propertyName, Level def = kDebugNone);
154
155
    // remove redundant segments of a codec name, and return a newly allocated
156
    // string suitable for debugging
157
    static char *GetDebugName(const char *name);
158
159
    inline static bool isExperimentEnabled(
160
0
            const char *name __unused /* nonnull */, bool allow __unused = true) {
161
0
#ifdef ENABLE_STAGEFRIGHT_EXPERIMENTS
162
0
        if (!strcmp(name, "legacy-adaptive")) {
163
0
            return getExperimentFlag(allow, name, 2, 1); // every other day
164
0
        } else if (!strcmp(name, "legacy-setsurface")) {
165
0
            return getExperimentFlag(allow, name, 3, 1); // every third day
166
0
        } else {
167
0
            ALOGE("unknown experiment '%s' (disabled)", name);
168
0
        }
169
0
#endif
170
0
        return false;
171
0
    }
172
173
private:
174
    // pass in allow, so we can print in the log if the experiment is disabled
175
    static bool getExperimentFlag(
176
            bool allow, const char *name, uint64_t modulo, uint64_t limit,
177
            uint64_t plus = 0, uint64_t timeDivisor = 24 * 60 * 60 /* 1 day */);
178
};
179
180
}  // namespace android
181
182
#endif  // A_DEBUG_H_
183
/proc/self/cwd/frameworks/av/media/libstagefright/include/media/stagefright/foundation/AHandler.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2010 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef A_HANDLER_H_
18
19
#define A_HANDLER_H_
20
21
#include <media/stagefright/foundation/ALooper.h>
22
#include <utils/KeyedVector.h>
23
#include <utils/RefBase.h>
24
25
namespace android {
26
27
struct AMessage;
28
29
struct AHandler : public RefBase {
30
    AHandler()
31
        : mID(0),
32
          mVerboseStats(false),
33
0
          mMessageCounter(0) {
34
0
    }
35
36
0
    ALooper::handler_id id() const {
37
0
        return mID;
38
0
    }
39
40
0
    sp<ALooper> looper() const {
41
0
        return mLooper.promote();
42
0
    }
43
44
0
    wp<ALooper> getLooper() const {
45
0
        return mLooper;
46
0
    }
47
48
0
    wp<AHandler> getHandler() const {
49
0
        // allow getting a weak reference to a const handler
50
0
        return const_cast<AHandler *>(this);
51
0
    }
52
53
protected:
54
    virtual void onMessageReceived(const sp<AMessage> &msg) = 0;
55
56
private:
57
    friend struct AMessage;      // deliverMessage()
58
    friend struct ALooperRoster; // setID()
59
60
    ALooper::handler_id mID;
61
    wp<ALooper> mLooper;
62
63
0
    inline void setID(ALooper::handler_id id, const wp<ALooper> &looper) {
64
0
        mID = id;
65
0
        mLooper = looper;
66
0
    }
67
68
    bool mVerboseStats;
69
    uint32_t mMessageCounter;
70
    KeyedVector<uint32_t, uint32_t> mMessages;
71
72
    void deliverMessage(const sp<AMessage> &msg);
73
74
    DISALLOW_EVIL_CONSTRUCTORS(AHandler);
75
};
76
77
}  // namespace android
78
79
#endif  // A_HANDLER_H_
/proc/self/cwd/frameworks/av/media/libstagefright/include/media/stagefright/foundation/ALooper.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2010 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef A_LOOPER_H_
18
19
#define A_LOOPER_H_
20
21
#include <media/stagefright/foundation/ABase.h>
22
#include <media/stagefright/foundation/AString.h>
23
#include <utils/Errors.h>
24
#include <utils/KeyedVector.h>
25
#include <utils/List.h>
26
#include <utils/RefBase.h>
27
#include <utils/threads.h>
28
29
namespace android {
30
31
struct AHandler;
32
struct AMessage;
33
struct AReplyToken;
34
35
struct ALooper : public RefBase {
36
    typedef int32_t event_id;
37
    typedef int32_t handler_id;
38
39
    ALooper();
40
41
    // Takes effect in a subsequent call to start().
42
    void setName(const char *name);
43
44
    handler_id registerHandler(const sp<AHandler> &handler);
45
    void unregisterHandler(handler_id handlerID);
46
47
    status_t start(
48
            bool runOnCallingThread = false,
49
            bool canCallJava = false,
50
            int32_t priority = PRIORITY_DEFAULT
51
            );
52
53
    status_t stop();
54
55
    static int64_t GetNowUs();
56
57
0
    const char *getName() const {
58
0
        return mName.c_str();
59
0
    }
60
61
protected:
62
    virtual ~ALooper();
63
64
private:
65
    friend struct AMessage;       // post()
66
67
    struct Event {
68
        int64_t mWhenUs;
69
        sp<AMessage> mMessage;
70
    };
71
72
    Mutex mLock;
73
    Condition mQueueChangedCondition;
74
75
    AString mName;
76
77
    List<Event> mEventQueue;
78
79
    struct LooperThread;
80
    sp<LooperThread> mThread;
81
    bool mRunningLocally;
82
83
    // use a separate lock for reply handling, as it is always on another thread
84
    // use a central lock, however, to avoid creating a mutex for each reply
85
    Mutex mRepliesLock;
86
    Condition mRepliesCondition;
87
88
    // START --- methods used only by AMessage
89
90
    // posts a message on this looper with the given timeout
91
    void post(const sp<AMessage> &msg, int64_t delayUs);
92
93
    // creates a reply token to be used with this looper
94
    sp<AReplyToken> createReplyToken();
95
    // waits for a response for the reply token.  If status is OK, the response
96
    // is stored into the supplied variable.  Otherwise, it is unchanged.
97
    status_t awaitResponse(const sp<AReplyToken> &replyToken, sp<AMessage> *response);
98
    // posts a reply for a reply token.  If the reply could be successfully posted,
99
    // it returns OK. Otherwise, it returns an error value.
100
    status_t postReply(const sp<AReplyToken> &replyToken, const sp<AMessage> &msg);
101
102
    // END --- methods used only by AMessage
103
104
    bool loop();
105
106
    DISALLOW_EVIL_CONSTRUCTORS(ALooper);
107
};
108
109
} // namespace android
110
111
#endif  // A_LOOPER_H_
/proc/self/cwd/frameworks/av/media/libstagefright/include/media/stagefright/foundation/AMessage.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2010 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef A_MESSAGE_H_
18
19
#define A_MESSAGE_H_
20
21
#include <media/stagefright/foundation/ABase.h>
22
#include <media/stagefright/foundation/AData.h>
23
#include <media/stagefright/foundation/ALooper.h>
24
#include <utils/KeyedVector.h>
25
#include <utils/RefBase.h>
26
27
namespace android {
28
29
struct ABuffer;
30
struct AHandler;
31
struct AString;
32
class Parcel;
33
34
struct AReplyToken : public RefBase {
35
    explicit AReplyToken(const sp<ALooper> &looper)
36
        : mLooper(looper),
37
0
          mReplied(false) {
38
0
    }
39
40
private:
41
    friend struct AMessage;
42
    friend struct ALooper;
43
    wp<ALooper> mLooper;
44
    sp<AMessage> mReply;
45
    bool mReplied;
46
47
0
    sp<ALooper> getLooper() const {
48
0
        return mLooper.promote();
49
0
    }
50
    // if reply is not set, returns false; otherwise, it retrieves the reply and returns true
51
0
    bool retrieveReply(sp<AMessage> *reply) {
52
0
        if (mReplied) {
53
0
            *reply = mReply;
54
0
            mReply.clear();
55
0
        }
56
0
        return mReplied;
57
0
    }
58
    // sets the reply for this token. returns OK or error
59
    status_t setReply(const sp<AMessage> &reply);
60
};
61
62
struct AMessage : public RefBase {
63
    AMessage();
64
    AMessage(uint32_t what, const sp<const AHandler> &handler);
65
66
    // Construct an AMessage from a parcel.
67
    // nestingAllowed determines how many levels AMessage can be nested inside
68
    // AMessage. The default value here is arbitrarily set to 255.
69
    // FromParcel() returns NULL on error, which occurs when the input parcel
70
    // contains
71
    // - an AMessage nested deeper than maxNestingLevel; or
72
    // - an item whose type is not recognized by this function.
73
    // Types currently recognized by this function are:
74
    //   Item types      set/find function suffixes
75
    //   ==========================================
76
    //     int32_t                Int32
77
    //     int64_t                Int64
78
    //     size_t                 Size
79
    //     float                  Float
80
    //     double                 Double
81
    //     AString                String
82
    //     AMessage               Message
83
    static sp<AMessage> FromParcel(const Parcel &parcel,
84
                                   size_t maxNestingLevel = 255);
85
86
    // Write this AMessage to a parcel.
87
    // All items in the AMessage must have types that are recognized by
88
    // FromParcel(); otherwise, TRESPASS error will occur.
89
    void writeToParcel(Parcel *parcel) const;
90
91
    void setWhat(uint32_t what);
92
    uint32_t what() const;
93
94
    void setTarget(const sp<const AHandler> &handler);
95
96
    void clear();
97
98
    void setInt32(const char *name, int32_t value);
99
    void setInt64(const char *name, int64_t value);
100
    void setSize(const char *name, size_t value);
101
    void setFloat(const char *name, float value);
102
    void setDouble(const char *name, double value);
103
    void setPointer(const char *name, void *value);
104
    void setString(const char *name, const char *s, ssize_t len = -1);
105
    void setString(const char *name, const AString &s);
106
    void setObject(const char *name, const sp<RefBase> &obj);
107
    void setBuffer(const char *name, const sp<ABuffer> &buffer);
108
    void setMessage(const char *name, const sp<AMessage> &obj);
109
110
    void setRect(
111
            const char *name,
112
            int32_t left, int32_t top, int32_t right, int32_t bottom);
113
114
    bool contains(const char *name) const;
115
116
    bool findInt32(const char *name, int32_t *value) const;
117
    bool findInt64(const char *name, int64_t *value) const;
118
    bool findSize(const char *name, size_t *value) const;
119
    bool findFloat(const char *name, float *value) const;
120
    bool findDouble(const char *name, double *value) const;
121
    bool findPointer(const char *name, void **value) const;
122
    bool findString(const char *name, AString *value) const;
123
    bool findObject(const char *name, sp<RefBase> *obj) const;
124
    bool findBuffer(const char *name, sp<ABuffer> *buffer) const;
125
    bool findMessage(const char *name, sp<AMessage> *obj) const;
126
127
    // finds signed integer types cast to int64_t
128
    bool findAsInt64(const char *name, int64_t *value) const;
129
130
    // finds any numeric type cast to a float
131
    bool findAsFloat(const char *name, float *value) const;
132
133
    bool findRect(
134
            const char *name,
135
            int32_t *left, int32_t *top, int32_t *right, int32_t *bottom) const;
136
137
    status_t post(int64_t delayUs = 0);
138
139
    // Posts the message to its target and waits for a response (or error)
140
    // before returning.
141
    status_t postAndAwaitResponse(sp<AMessage> *response);
142
143
    // If this returns true, the sender of this message is synchronously
144
    // awaiting a response and the reply token is consumed from the message
145
    // and stored into replyID. The reply token must be used to send the response
146
    // using "postReply" below.
147
    bool senderAwaitsResponse(sp<AReplyToken> *replyID);
148
149
    // Posts the message as a response to a reply token.  A reply token can
150
    // only be used once. Returns OK if the response could be posted; otherwise,
151
    // an error.
152
    status_t postReply(const sp<AReplyToken> &replyID);
153
154
    // Performs a deep-copy of "this", contained messages are in turn "dup'ed".
155
    // Warning: RefBase items, i.e. "objects" are _not_ copied but only have
156
    // their refcount incremented.
157
    sp<AMessage> dup() const;
158
159
    // Adds all items from other into this.
160
    void extend(const sp<AMessage> &other);
161
162
    // Performs a shallow or deep comparison of |this| and |other| and returns
163
    // an AMessage with the differences.
164
    // Warning: RefBase items, i.e. "objects" are _not_ copied but only have
165
    // their refcount incremented.
166
    // This is true for AMessages that have no corresponding AMessage equivalent in |other|.
167
    // (E.g. there is no such key or the type is different.) On the other hand, changes in
168
    // the AMessage (or AMessages if deep is |false|) are returned in new objects.
169
    sp<AMessage> changesFrom(const sp<const AMessage> &other, bool deep = false) const;
170
171
    AString debugString(int32_t indent = 0) const;
172
173
    enum Type {
174
        kTypeInt32,
175
        kTypeInt64,
176
        kTypeSize,
177
        kTypeFloat,
178
        kTypeDouble,
179
        kTypePointer,
180
        kTypeString,
181
        kTypeObject,
182
        kTypeMessage,
183
        kTypeRect,
184
        kTypeBuffer,
185
    };
186
187
    struct Rect {
188
        int32_t mLeft, mTop, mRight, mBottom;
189
    };
190
191
    size_t countEntries() const;
192
    const char *getEntryNameAt(size_t index, Type *type) const;
193
194
    /**
195
     * Retrieves the item at a specific index.
196
     */
197
    typedef AData<
198
        int32_t, int64_t, size_t, float, double, Rect, AString,
199
        void *, sp<AMessage>, sp<ABuffer>, sp<RefBase>>::Basic ItemData;
200
201
    /**
202
     * Finds an item by name. This can be used if the type is unknown.
203
     *
204
     * \param name name of the item
205
     * Returns an empty item if no item is present with that name.
206
     */
207
    ItemData findItem(const char *name) const;
208
209
    /**
210
     * Sets an item of arbitrary type. Does nothing if the item value is empty.
211
     *
212
     * \param name name of the item
213
     * \param item value of the item
214
     */
215
    void setItem(const char *name, const ItemData &item);
216
217
    ItemData getEntryAt(size_t index) const;
218
219
    /**
220
     * Finds an entry by name and returns its index.
221
     *
222
     * \retval countEntries() if the entry is not found.
223
     */
224
    size_t findEntryByName(const char *name) const;
225
226
    /**
227
     * Sets the name of an entry based on index.
228
     *
229
     * \param index index of the entry
230
     * \param name (new) name of the entry
231
     *
232
     * \retval OK the name was set successfully
233
     * \retval BAD_INDEX invalid index
234
     * \retval BAD_VALUE name is invalid (null)
235
     * \retval ALREADY_EXISTS name is already used by another entry
236
     */
237
    status_t setEntryNameAt(size_t index, const char *name);
238
239
    /**
240
     * Sets the item of an entry based on index.
241
     *
242
     * \param index index of the entry
243
     * \param item new item of the entry
244
     *
245
     * \retval OK the item was set successfully
246
     * \retval BAD_INDEX invalid index
247
     * \retval BAD_VALUE item is invalid (null)
248
     * \retval BAD_TYPE type is unsupported (should not happen)
249
     */
250
    status_t setEntryAt(size_t index, const ItemData &item);
251
252
    /**
253
     * Removes an entry based on index.
254
     *
255
     * \param index index of the entry
256
     *
257
     * \retval OK the entry was removed successfully
258
     * \retval BAD_INDEX invalid index
259
     */
260
    status_t removeEntryAt(size_t index);
261
262
protected:
263
    virtual ~AMessage();
264
265
private:
266
    friend struct ALooper; // deliver()
267
268
    uint32_t mWhat;
269
270
    // used only for debugging
271
    ALooper::handler_id mTarget;
272
273
    wp<AHandler> mHandler;
274
    wp<ALooper> mLooper;
275
276
    struct Item {
277
        union {
278
            int32_t int32Value;
279
            int64_t int64Value;
280
            size_t sizeValue;
281
            float floatValue;
282
            double doubleValue;
283
            void *ptrValue;
284
            RefBase *refValue;
285
            AString *stringValue;
286
            Rect rectValue;
287
        } u;
288
        const char *mName;
289
        size_t      mNameLength;
290
        Type mType;
291
        void setName(const char *name, size_t len);
292
    };
293
294
    enum {
295
        kMaxNumItems = 64
296
    };
297
    Item mItems[kMaxNumItems];
298
    size_t mNumItems;
299
300
    Item *allocateItem(const char *name);
301
    void freeItemValue(Item *item);
302
    const Item *findItem(const char *name, Type type) const;
303
304
    void setObjectInternal(
305
            const char *name, const sp<RefBase> &obj, Type type);
306
307
    size_t findItemIndex(const char *name, size_t len) const;
308
309
    void deliver();
310
311
    DISALLOW_EVIL_CONSTRUCTORS(AMessage);
312
};
313
314
}  // namespace android
315
316
#endif  // A_MESSAGE_H_
/proc/self/cwd/frameworks/av/media/libstagefright/include/media/stagefright/foundation/AString.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2010 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef A_STRING_H_
18
19
#define A_STRING_H_
20
21
#include <utils/Errors.h>
22
#include <sys/types.h>
23
24
namespace android {
25
26
class String8;
27
class Parcel;
28
29
struct AString {
30
    AString();
31
    AString(const char *s);  // NOLINT, implicit conversion
32
    AString(const char *s, size_t size);
33
    AString(const String8 &from);  // NOLINT, implicit conversion
34
    AString(const AString &from);
35
    AString(const AString &from, size_t offset, size_t n);
36
    ~AString();
37
38
    AString &operator=(const AString &from);
39
    void setTo(const char *s);
40
    void setTo(const char *s, size_t size);
41
    void setTo(const AString &from, size_t offset, size_t n);
42
43
    size_t size() const;
44
    const char *c_str() const;
45
46
    bool empty() const;
47
48
    void clear();
49
    void trim();
50
    void erase(size_t start, size_t n);
51
52
0
    void append(char c) { append(&c, 1); }
53
    void append(const char *s);
54
    void append(const char *s, size_t size);
55
    void append(const AString &from);
56
    void append(const AString &from, size_t offset, size_t n);
57
    void append(int x);
58
    void append(unsigned x);
59
    void append(long x);
60
    void append(unsigned long x);
61
    void append(long long x);
62
    void append(unsigned long long x);
63
    void append(float x);
64
    void append(double x);
65
    void append(void *x);
66
67
    void insert(const AString &from, size_t insertionPos);
68
    void insert(const char *from, size_t size, size_t insertionPos);
69
70
    ssize_t find(const char *substring, size_t start = 0) const;
71
72
    size_t hash() const;
73
74
    bool operator==(const AString &other) const;
75
0
    bool operator!=(const AString &other) const {
76
0
        return !operator==(other);
77
0
    }
78
    bool operator<(const AString &other) const;
79
    bool operator>(const AString &other) const;
80
81
    int compare(const AString &other) const;
82
    int compareIgnoreCase(const AString &other) const;
83
84
    bool equalsIgnoreCase(const AString &other) const;
85
    bool startsWith(const char *prefix) const;
86
    bool endsWith(const char *suffix) const;
87
    bool startsWithIgnoreCase(const char *prefix) const;
88
    bool endsWithIgnoreCase(const char *suffix) const;
89
90
    void tolower();
91
92
    static AString FromParcel(const Parcel &parcel);
93
    status_t writeToParcel(Parcel *parcel) const;
94
95
private:
96
    constexpr static const char *kEmptyString = "";
97
98
    char *mData;
99
    size_t mSize;
100
    size_t mAllocSize;
101
102
    void makeMutable();
103
};
104
105
AString AStringPrintf(const char *format, ...);
106
107
}  // namespace android
108
109
#endif  // A_STRING_H_
110
/proc/self/cwd/frameworks/av/media/libstagefright/include/media/stagefright/foundation/ColorUtils.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2016 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef COLOR_UTILS_H_
18
19
#define COLOR_UTILS_H_
20
21
#include <stdint.h>
22
23
#define STRINGIFY_ENUMS
24
25
#include <media/stagefright/foundation/AMessage.h>
26
27
#include <media/hardware/VideoAPI.h>
28
#include <system/graphics.h>
29
30
namespace android {
31
32
struct ColorUtils {
33
    /*
34
     * Media-platform color constants. MediaCodec uses (an extended version of) platform-defined
35
     * constants that are derived from HAL_DATASPACE, since these are directly exposed to the user.
36
     * We extend the values to maintain the richer set of information defined inside media
37
     * containers and bitstreams that are not supported by the platform. We also expect vendors
38
     * to extend some of these values with vendor-specific values. These are separated into a
39
     * vendor-extension section so they won't collide with future platform values.
40
     */
41
42
    /**
43
     * graphic.h constants changed in Android 8.0 after ColorStandard values were already public
44
     * in Android 7.0. We will not deal with the break in graphic.h here, but list the public
45
     * Android SDK MediaFormat values here.
46
     */
47
    enum ColorStandard : uint32_t {
48
        kColorStandardUnspecified =          0,
49
        kColorStandardBT709 =                1,
50
        kColorStandardBT601_625 =            2,
51
        kColorStandardBT601_625_Unadjusted = 3, // not in SDK
52
        kColorStandardBT601_525 =            4,
53
        kColorStandardBT601_525_Unadjusted = 5, // not in SDK
54
        kColorStandardBT2020 =               6,
55
        kColorStandardBT2020Constant =       7, // not in SDK
56
        kColorStandardBT470M =               8, // not in SDK
57
        kColorStandardFilm =                 9, // not in SDK
58
        kColorStandardDCI_P3 =               10, // not in SDK, new in Android 8.0
59
60
        /* This marks a section of color-standard values that are not supported by graphics HAL,
61
           but track defined color primaries-matrix coefficient combinations in media.
62
           These are stable for a given release. */
63
        kColorStandardExtendedStart = 64,
64
65
        /* This marks a section of color-standard values that are not supported by graphics HAL
66
           nor using media defined color primaries or matrix coefficients. These may differ per
67
           device. */
68
        kColorStandardVendorStart = 0x10000,
69
    };
70
71
    enum ColorTransfer : uint32_t  {
72
        kColorTransferUnspecified = 0,
73
        kColorTransferLinear =      1,
74
        kColorTransferSRGB =        2,
75
        kColorTransferSMPTE_170M =  3, // not in SDK
76
        kColorTransferGamma22 =     4, // not in SDK
77
        kColorTransferGamma28 =     5, // not in SDK
78
        kColorTransferST2084 =      6,
79
        kColorTransferHLG =         7,
80
        kColorTransferGamma26 =     8, // not in SDK, new in Android 8.0
81
82
        /* This marks a section of color-transfer values that are not supported by graphics HAL,
83
           but track media-defined color-transfer. These are stable for a given release. */
84
        kColorTransferExtendedStart = 32,
85
86
        /* This marks a section of color-transfer values that are not supported by graphics HAL
87
           nor defined by media. These may differ per device. */
88
        kColorTransferVendorStart = 0x10000,
89
    };
90
91
    enum ColorRange : uint32_t  {
92
        kColorRangeUnspecified = 0,
93
        kColorRangeFull =        1,
94
        kColorRangeLimited =     2,
95
96
        /* This marks a section of color-transfer values that are not supported by graphics HAL,
97
           but track media-defined color-transfer. These are stable for a given release. */
98
        kColorRangeExtendedStart = 8,
99
100
        /* This marks a section of color-transfer values that are not supported by graphics HAL
101
           nor defined by media. These may differ per device. */
102
        kColorRangeVendorStart = 0x10000,
103
    };
104
105
    /*
106
     * Static utilities for codec support
107
     */
108
109
    // using int32_t for media range/standard/transfers to denote extended ranges
110
    // wrap methods change invalid aspects to the Unspecified value
111
    static int32_t wrapColorAspectsIntoColorStandard(
112
            ColorAspects::Primaries primaries, ColorAspects::MatrixCoeffs coeffs);
113
    static int32_t wrapColorAspectsIntoColorRange(ColorAspects::Range range);
114
    static int32_t wrapColorAspectsIntoColorTransfer(ColorAspects::Transfer transfer);
115
116
    // unwrap methods change invalid aspects to the Other value
117
    static status_t unwrapColorAspectsFromColorRange(
118
            int32_t range, ColorAspects::Range *aspect);
119
    static status_t unwrapColorAspectsFromColorTransfer(
120
            int32_t transfer, ColorAspects::Transfer *aspect);
121
    static status_t unwrapColorAspectsFromColorStandard(
122
            int32_t standard,
123
            ColorAspects::Primaries *primaries, ColorAspects::MatrixCoeffs *coeffs);
124
125
    static status_t convertPlatformColorAspectsToCodecAspects(
126
            int32_t range, int32_t standard, int32_t transfer, ColorAspects &aspects);
127
    static status_t convertCodecColorAspectsToPlatformAspects(
128
            const ColorAspects &aspects, int32_t *range, int32_t *standard, int32_t *transfer);
129
130
    // converts Other values to Unspecified
131
    static void convertCodecColorAspectsToIsoAspects(
132
            const ColorAspects &aspects,
133
            int32_t *primaries, int32_t *transfer, int32_t *coeffs, bool *fullRange);
134
    // converts unsupported values to Other
135
    static void convertIsoColorAspectsToCodecAspects(
136
            int32_t primaries, int32_t transfer, int32_t coeffs, bool fullRange,
137
            ColorAspects &aspects);
138
139
    // unpack a uint32_t to a full ColorAspects struct
140
    static ColorAspects unpackToColorAspects(uint32_t packed);
141
142
    // pack a full ColorAspects struct into a uint32_t
143
    static uint32_t packToU32(const ColorAspects &aspects);
144
145
    // updates Unspecified color aspects to their defaults based on the video size
146
    static void setDefaultCodecColorAspectsIfNeeded(
147
            ColorAspects &aspects, int32_t width, int32_t height);
148
149
    // it returns the closest dataSpace for given color |aspects|. if |mayExpand| is true, it allows
150
    // returning a larger dataSpace that contains the color space given by |aspects|, and is better
151
    // suited to blending. This requires implicit color space conversion on part of the device.
152
    static android_dataspace getDataSpaceForColorAspects(ColorAspects &aspects, bool mayExpand);
153
154
    // converts |dataSpace| to a V0 enum, and returns true if dataSpace is an aspect-only value
155
    static bool convertDataSpaceToV0(android_dataspace &dataSpace);
156
157
    // compares |aspect| to |orig|. Returns |true| if any aspects have changed, except if they
158
    // changed to Unspecified value. It also sets the changed values to Unspecified in |aspect|.
159
    static bool checkIfAspectsChangedAndUnspecifyThem(
160
            ColorAspects &aspects, const ColorAspects &orig, bool usePlatformAspects = false);
161
162
    // finds color config in format, defaulting them to 0.
163
    static void getColorConfigFromFormat(
164
            const sp<AMessage> &format, int *range, int *standard, int *transfer);
165
166
    // copies existing color config from |source| to |target|.
167
    static void copyColorConfig(const sp<AMessage> &source, sp<AMessage> &target);
168
169
    // finds color config in format as ColorAspects, defaulting them to 0.
170
    static void getColorAspectsFromFormat(const sp<AMessage> &format, ColorAspects &aspects);
171
172
    // writes |aspects| into format. iff |force| is false, Unspecified values are not
173
    // written.
174
    static void setColorAspectsIntoFormat(
175
            const ColorAspects &aspects, sp<AMessage> &format, bool force = false);
176
177
    // finds HDR metadata in format as HDRStaticInfo, defaulting them to 0.
178
    // Return |true| if could find HDR metadata in format. Otherwise, return |false|.
179
    static bool getHDRStaticInfoFromFormat(const sp<AMessage> &format, HDRStaticInfo *info);
180
181
    // writes |info| into format.
182
    static void setHDRStaticInfoIntoFormat(const HDRStaticInfo &info, sp<AMessage> &format);
183
};
184
185
0
inline static const char *asString(android::ColorUtils::ColorStandard i, const char *def = "??") {
186
0
    using namespace android;
187
0
    switch (i) {
188
0
        case ColorUtils::kColorStandardUnspecified:          return "Unspecified";
189
0
        case ColorUtils::kColorStandardBT709:                return "BT709";
190
0
        case ColorUtils::kColorStandardBT601_625:            return "BT601_625";
191
0
        case ColorUtils::kColorStandardBT601_625_Unadjusted: return "BT601_625_Unadjusted";
192
0
        case ColorUtils::kColorStandardBT601_525:            return "BT601_525";
193
0
        case ColorUtils::kColorStandardBT601_525_Unadjusted: return "BT601_525_Unadjusted";
194
0
        case ColorUtils::kColorStandardBT2020:               return "BT2020";
195
0
        case ColorUtils::kColorStandardBT2020Constant:       return "BT2020Constant";
196
0
        case ColorUtils::kColorStandardBT470M:               return "BT470M";
197
0
        case ColorUtils::kColorStandardFilm:                 return "Film";
198
0
        case ColorUtils::kColorStandardDCI_P3:               return "DCI_P3";
199
0
        default:                                             return def;
200
0
    }
201
0
}
202
203
0
inline static const char *asString(android::ColorUtils::ColorTransfer i, const char *def = "??") {
204
0
    using namespace android;
205
0
    switch (i) {
206
0
        case ColorUtils::kColorTransferUnspecified: return "Unspecified";
207
0
        case ColorUtils::kColorTransferLinear:      return "Linear";
208
0
        case ColorUtils::kColorTransferSRGB:        return "SRGB";
209
0
        case ColorUtils::kColorTransferSMPTE_170M:  return "SMPTE_170M";
210
0
        case ColorUtils::kColorTransferGamma22:     return "Gamma22";
211
0
        case ColorUtils::kColorTransferGamma28:     return "Gamma28";
212
0
        case ColorUtils::kColorTransferST2084:      return "ST2084";
213
0
        case ColorUtils::kColorTransferHLG:         return "HLG";
214
0
        case ColorUtils::kColorTransferGamma26:     return "Gamma26";
215
0
        default:                                    return def;
216
0
    }
217
0
}
218
219
0
inline static const char *asString(android::ColorUtils::ColorRange i, const char *def = "??") {
220
0
    using namespace android;
221
0
    switch (i) {
222
0
        case ColorUtils::kColorRangeUnspecified: return "Unspecified";
223
0
        case ColorUtils::kColorRangeFull:        return "Full";
224
0
        case ColorUtils::kColorRangeLimited:     return "Limited";
225
0
        default:                                 return def;
226
0
    }
227
0
}
228
229
}  // namespace android
230
231
#endif  // COLOR_UTILS_H_
232
/proc/self/cwd/frameworks/av/media/libstagefright/include/media/stagefright/foundation/Flagged.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2016 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef STAGEFRIGHT_FOUNDATION_FLAGGED_H_
18
#define STAGEFRIGHT_FOUNDATION_FLAGGED_H_
19
20
#include <media/stagefright/foundation/TypeTraits.h>
21
22
namespace android {
23
24
/**
25
 * Flagged<T, Flag> is basically a specialized std::pair<Flag, T> that automatically optimizes out
26
 * the flag if the wrapped type T is already flagged and we can combine the outer and inner flags.
27
 *
28
 * Flags can be queried/manipulated via flags() an setFlags(Flags). The wrapped value can be
29
 * accessed via get(). This template is meant to be inherited by other utility/wrapper classes
30
 * that need to store integral information along with the value.
31
 *
32
 * Users must specify the used bits (MASK) in the flags. Flag getters and setters will enforce this
33
 * mask. _Flagged_helper::minMask<Flag> is provided to easily calculate a mask for a max value.
34
 *
35
 * E.g. adding a safe flag can be achieved like this:
36
 *
37
 *
38
 * enum SafeFlags : uint32_t {
39
 *   kUnsafe,
40
 *   kSafe,
41
 *   kSafeMask = _Flagged_helper::minMask(kSafe),
42
 * };
43
 * typedef Flagged<int32_t, SafeFlags, kSafeMask> safeInt32;
44
 *
45
 * safeInt32 a;
46
 * a.setFlags(kSafe);
47
 * a.get() = 15;
48
 * EXPECT_EQ(a.flags(), kSafe);
49
 * EXPECT_EQ(a.get(), 15);
50
 *
51
 *
52
 * Flagged also supports lazy or calculated wrapping of already flagged types. Lazy wrapping is
53
 * provided automatically (flags are automatically shared if possible, e.g. mask is shifted
54
 * automatically to not overlap with used bits of the wrapped type's flags, and fall back to
55
 * unshared version of the template.):
56
 *
57
 * enum OriginFlags : uint32_t {
58
 *   kUnknown,
59
 *   kConst,
60
 *   kCalculated,
61
 *   kComponent,
62
 *   kApplication,
63
 *   kFile,
64
 *   kBinder,
65
 *   kOriginMask = _Flagged_helper::minMask(kBinder),
66
 * };
67
 * typedef Flagged<safeInt32, OriginFlags, kOriginMask>
68
 *          trackedSafeInt32;
69
 *
70
 * static_assert(sizeof(trackedSafeInt32) == sizeof(safeInt32), "");
71
 *
72
 * trackedSafeInt32 b(kConst, kSafe, 1);
73
 * EXPECT_EQ(b.flags(), kConst);
74
 * EXPECT_EQ(b.get().flags(), kSafe);
75
 * EXPECT_EQ(b.get().get(), 1);
76
 * b.setFlags(kCalculated);
77
 * b.get().setFlags(overflow ? kUnsafe : kSafe);
78
 *
79
 * One can also choose to share some flag-bits with the wrapped class:
80
 *
81
 * enum ValidatedFlags : uint32_t {
82
 *   kUnsafeV = kUnsafe,
83
 *   kSafeV = kSafe,
84
 *   kValidated = kSafe | 2,
85
 *   kSharedMaskV = kSafeMask,
86
 *   kValidatedMask = _Flagged_helper::minMask(kValidated),
87
 * };
88
 * typedef Flagged<safeInt32, ValidatedFlags, kValidatedMask, kSharedMaskV> validatedInt32;
89
 *
90
 * validatedInt32 v(kUnsafeV, kSafe, 10);
91
 * EXPECT_EQ(v.flags(), kUnsafeV);
92
 * EXPECT_EQ(v.get().flags(), kUnsafe);  // !kUnsafeV overrides kSafe
93
 * EXPECT_EQ(v.get().get(), 10);
94
 * v.setFlags(kValidated);
95
 * EXPECT_EQ(v.flags(), kValidated);
96
 * EXPECT_EQ(v.get().flags(), kSafe);
97
 * v.get().setFlags(kUnsafe);
98
 * EXPECT_EQ(v.flags(), 2);  // NOTE: sharing masks with enums allows strange situations to occur
99
 */
100
101
/**
102
 * Helper class for Flagged support. Encapsulates common utilities used by all
103
 * templated classes.
104
 */
105
struct _Flagged_helper {
106
    /**
107
     * Calculates the value with a given number of top-most bits set.
108
     *
109
     * This method may be called with a signed flag.
110
     *
111
     * \param num number of bits to set. This must be between 0 and the number of bits in Flag.
112
     *
113
     * \return the value where only the given number of top-most bits are set.
114
     */
115
    template<typename Flag>
116
    static constexpr Flag topBits(int num) {
117
        return Flag(num > 0 ?
118
                    ~((Flag(1) << (sizeof(Flag) * 8 - is_signed_integral<Flag>::value - num)) - 1) :
119
                    0);
120
    }
121
122
    /**
123
     * Calculates the minimum mask required to cover a value. Used with the maximum enum value for
124
     * an unsigned flag.
125
     *
126
     * \param maxValue maximum value to cover
127
     * \param shift DO NO USE. used internally
128
     *
129
     * \return mask that can be used that covers the maximum value.
130
     */
131
    template<typename Flag>
132
    static constexpr Flag minMask(Flag maxValue, int shift=sizeof(Flag) * 4) {
133
        static_assert(is_unsigned_integral<Flag>::value,
134
                      "this method only makes sense for unsigned flags");
135
        return shift ? minMask<Flag>(Flag(maxValue | (maxValue >> shift)), shift >> 1) : maxValue;
136
    }
137
138
    /**
139
     * Returns a value left-shifted by an argument as a potential constexpr.
140
     *
141
     * This method helps around the C-language limitation, when left-shift of a negative value with
142
     * even 0 cannot be a constexpr.
143
     *
144
     * \param value value to shift
145
     * \param shift amount of shift
146
     * \returns the shifted value as an integral type
147
     */
148
    template<typename Flag, typename IntFlag = typename underlying_integral_type<Flag>::type>
149
    static constexpr IntFlag lshift(Flag value, int shift) {
150
        return shift ? value << shift : value;
151
    }
152
153
private:
154
155
    /**
156
     * Determines whether mask can be combined with base-mask for a given left shift.
157
     *
158
     * \param mask desired mask
159
     * \param baseMask mask used by T or 0 if T is not flagged by Flag
160
     * \param sharedMask desired shared mask (if this is non-0, this must be mask & baseMask)
161
     * \param shift desired left shift to be used for mask
162
     * \param baseShift left shift used by T or 0 if T is not flagged by Flag
163
     * \param effectiveMask effective mask used by T or 0 if T is not flagged by Flag
164
     *
165
     * \return bool whether mask can be combined with baseMask using the desired values.
166
     */
167
    template<typename Flag, typename IntFlag=typename underlying_integral_type<Flag>::type>
168
    static constexpr bool canCombine(
169
            Flag mask, IntFlag baseMask, Flag sharedMask, int shift,
170
            int baseShift, IntFlag effectiveMask) {
171
        return
172
            // verify that shift is valid and mask can be shifted
173
            shift >= 0 && (mask & topBits<Flag>(shift)) == 0 &&
174
175
            // verify that base mask is part of effective mask (sanity check on arguments)
176
            (baseMask & ~(effectiveMask >> baseShift)) == 0 &&
177
178
            // if sharing masks, shift must be the base's shift.
179
            // verify that shared mask is the overlap of base mask and mask
180
            (sharedMask ?
181
                    ((sharedMask ^ (baseMask & mask)) == 0 &&
182
                     shift == baseShift) :
183
184
185
            // otherwise, verify that there is no overlap between mask and base's effective mask
186
                    (mask & (effectiveMask >> shift)) == 0);
187
    }
188
189
190
    /**
191
     * Calculates the minimum (left) shift required to combine a mask with the mask of an
192
     * underlying type (T, also flagged by Flag).
193
     *
194
     * \param mask desired mask
195
     * \param baseMask mask used by T or 0 if T is not flagged by Flag
196
     * \param sharedMask desired shared mask (if this is non-0, this must be mask & baseMask)
197
     * \param baseShift left shift used by T
198
     * \param effectiveMask effective mask used by T
199
     *
200
     * \return a non-negative minimum left shift value if mask can be combined with baseMask,
201
     *         or -1 if the masks cannot be combined. -2 if the input is invalid.
202
     */
203
    template<typename Flag,
204
             typename IntFlag = typename underlying_integral_type<Flag>::type>
205
    static constexpr int getShift(
206
            Flag mask, IntFlag baseMask, Flag sharedMask, int baseShift, IntFlag effectiveMask) {
207
        return
208
            // baseMask must be part of the effective mask
209
            (baseMask & ~(effectiveMask >> baseShift)) ? -2 :
210
211
            // if sharing masks, shift must be base's shift. verify that shared mask is part of
212
            // base mask and mask, and that desired mask still fits with base's shift value
213
            sharedMask ?
214
                    (canCombine(mask, baseMask, sharedMask, baseShift /* shift */,
215
                                baseShift, effectiveMask) ? baseShift : -1) :
216
217
            // otherwise, see if 0-shift works
218
            ((mask & effectiveMask) == 0) ? 0 :
219
220
            // otherwise, verify that mask can be shifted up
221
            ((mask & topBits<Flag>(1)) || (mask < 0)) ? -1 :
222
223
            incShift(getShift(Flag(mask << 1), baseMask /* unused */, sharedMask /* 0 */,
224
                              baseShift /* unused */, effectiveMask));
225
    }
226
227
    /**
228
     * Helper method that increments a non-negative (shift) value.
229
     *
230
     * This method is used to make it easier to create a constexpr for getShift.
231
     *
232
     * \param shift (shift) value to increment
233
     *
234
     * \return original shift if it was negative; otherwise, the shift incremented by one.
235
     */
236
0
    static constexpr int incShift(int shift) {
237
0
        return shift + (shift >= 0);
238
0
    }
239
240
#ifdef FRIEND_TEST
241
    FRIEND_TEST(FlaggedTest, _Flagged_helper_Test);
242
#endif
243
244
public:
245
    /**
246
     * Base class for all Flagged<T, Flag> classes.
247
     *
248
     * \note flagged types do not have a member variable for the mask used by the type. As such,
249
     * they should be be cast to this base class.
250
     *
251
     * \todo can we replace this base class check with a static member check to remove possibility
252
     * of cast?
253
     */
254
    template<typename Flag>
255
    struct base {};
256
257
    /**
258
     * Type support utility that retrieves the mask of a class (T) if it is a type flagged by
259
     * Flag (e.g. Flagged<T, Flag>).
260
     *
261
     * \note This retrieves 0 if T is a flagged class, that is not flagged by Flag or an equivalent
262
     * underlying type.
263
     *
264
     * Generic implementation for a non-flagged class.
265
     */
266
    template<
267
        typename T, typename Flag,
268
        bool=std::is_base_of<base<typename underlying_integral_type<Flag>::type>, T>::value>
269
    struct mask_of {
270
        using IntFlag = typename underlying_integral_type<Flag>::type;
271
        static constexpr IntFlag value = Flag(0); ///< mask of a potentially flagged class
272
        static constexpr int shift = 0; ///<left shift of flags in a potentially flagged class
273
        static constexpr IntFlag effective_value = IntFlag(0); ///<effective mask of flagged class
274
    };
275
276
    /**
277
     * Type support utility that calculates the minimum (left) shift required to combine a mask
278
     * with the mask of an underlying type T also flagged by Flag.
279
     *
280
     * \note if T is not flagged, not flagged by Flag, or the masks cannot be combined due to
281
     * incorrect sharing or the flags not having enough bits, the minimum is -1.
282
     *
283
     * \param MASK desired mask
284
     * \param SHARED_MASK desired shared mask (if this is non-0, T must be an type flagged by
285
     *        Flag with a mask that has exactly these bits common with MASK)
286
     */
287
    template<typename T, typename Flag, Flag MASK, Flag SHARED_MASK>
288
    struct min_shift {
289
        /// minimum (left) shift required, or -1 if masks cannot be combined
290
        static constexpr int value =
291
            getShift(MASK, mask_of<T, Flag>::value, SHARED_MASK,
292
                     mask_of<T, Flag>::shift, mask_of<T, Flag>::effective_value);
293
    };
294
295
    /**
296
     * Type support utility that calculates whether the flags of T can be combined with MASK.
297
     *
298
     * \param MASK desired mask
299
     * \param SHARED_MASK desired shared mask (if this is non-0, T MUST be an type flagged by
300
     *        Flag with a mask that has exactly these bits common with MASK)
301
     */
302
    template<
303
            typename T, typename Flag, Flag MASK,
304
            Flag SHARED_MASK=Flag(0),
305
            int SHIFT=min_shift<T, Flag, MASK, SHARED_MASK>::value>
306
    struct can_combine {
307
        using IntFlag = typename underlying_integral_type<Flag>::type;
308
        /// true if this mask can be combined with T's existing flag. false otherwise.
309
        static constexpr bool value =
310
                std::is_base_of<base<IntFlag>, T>::value
311
                        && canCombine(MASK, mask_of<T, Flag>::value, SHARED_MASK, SHIFT,
312
                                      mask_of<T, Flag>::shift, mask_of<T, Flag>::effective_value);
313
    };
314
};
315
316
/**
317
 * Template specialization for the case when T is flagged by Flag or a compatible type.
318
 */
319
template<typename T, typename Flag>
320
struct _Flagged_helper::mask_of<T, Flag, true> {
321
    using IntType = typename underlying_integral_type<Flag>::type;
322
    static constexpr IntType value = T::sFlagMask;
323
    static constexpr int shift = T::sFlagShift;
324
    static constexpr IntType effective_value = T::sEffectiveMask;
325
};
326
327
/**
328
 * Main Flagged template that adds flags to an object of another type (in essence, creates a pair)
329
 *
330
 * Flag must be an integral type (enums are allowed).
331
 *
332
 * \note We could make SHARED_MASK be a boolean as it must be either 0 or MASK & base's mask, but we
333
 * want it to be spelled out for safety.
334
 *
335
 * \param T type of object wrapped
336
 * \param Flag type of flag
337
 * \param MASK mask for the bits used in flag (before any shift)
338
 * \param SHARED_MASK optional mask to be shared with T (if this is not zero, SHIFT must be 0, and
339
 *        it must equal to MASK & T's mask)
340
 * \param SHIFT optional left shift for MASK to combine with T's mask (or -1, if masks should not
341
 *        be combined.)
342
 */
343
template<
344
        typename T, typename Flag, Flag MASK, Flag SHARED_MASK=(Flag)0,
345
        int SHIFT=_Flagged_helper::min_shift<T, Flag, MASK, SHARED_MASK>::value,
346
        typename IntFlag=typename underlying_integral_type<Flag>::type,
347
        bool=_Flagged_helper::can_combine<T, IntFlag, MASK, SHARED_MASK, SHIFT>::value>
348
class Flagged : public _Flagged_helper::base<IntFlag> {
349
    static_assert(SHARED_MASK == 0,
350
                  "shared mask can only be used with common flag types "
351
                  "and must be part of mask and mask of base type");
352
    static_assert((_Flagged_helper::topBits<Flag>(SHIFT) & MASK) == 0, "SHIFT overflows MASK");
353
354
    static constexpr Flag sFlagMask = MASK;  ///< the mask
355
    static constexpr int sFlagShift = SHIFT > 0 ? SHIFT : 0; ///< the left shift applied to flags
356
357
    friend struct _Flagged_helper;
358
#ifdef FRIEND_TEST
359
    static constexpr bool sFlagCombined = false;
360
    FRIEND_TEST(FlaggedTest, _Flagged_helper_Test);
361
#endif
362
363
    T       mValue; ///< wrapped value
364
    IntFlag mFlags; ///< flags
365
366
protected:
367
    /// The effective combined mask used by this class and any wrapped classes if the flags are
368
    /// combined.
369
    static constexpr IntFlag sEffectiveMask = _Flagged_helper::lshift(MASK, sFlagShift);
370
371
    /**
372
     * Helper method used by subsequent flagged wrappers to query flags. Returns the
373
     * flags for a particular mask and left shift.
374
     *
375
     * \param mask bitmask to use
376
     * \param shift left shifts to use
377
     *
378
     * \return the requested flags
379
     */
380
    inline constexpr IntFlag getFlagsHelper(IntFlag mask, int shift) const {
381
        return (mFlags >> shift) & mask;
382
    }
383
384
    /**
385
     * Helper method used by subsequent flagged wrappers to apply combined flags. Sets the flags
386
     * in the bitmask using a particulare left shift.
387
     *
388
     * \param mask bitmask to use
389
     * \param shift left shifts to use
390
     * \param flags flags to update (any flags within the bitmask are updated to their value in this
391
     *        argument)
392
     */
393
    inline void setFlagsHelper(IntFlag mask, int shift, IntFlag flags) {
394
        mFlags = Flag((mFlags & ~(mask << shift)) | ((flags & mask) << shift));
395
    }
396
397
public:
398
    /**
399
     * Wrapper around base class constructor. These take the flags as their first
400
     * argument and pass the rest of the arguments to the base class constructor.
401
     *
402
     * \param flags initial flags
403
     */
404
    template<typename ...Args>
405
    constexpr Flagged(Flag flags, Args... args)
406
        : mValue(std::forward<Args>(args)...),
407
          mFlags(Flag(_Flagged_helper::lshift(flags & sFlagMask, sFlagShift))) { }
408
409
    /** Gets the wrapped value as const. */
410
    inline constexpr const T &get() const { return mValue; }
411
412
    /** Gets the wrapped value. */
413
    inline T &get() { return mValue; }
414
415
    /** Gets the flags. */
416
    constexpr Flag flags() const {
417
        return Flag(getFlagsHelper(sFlagMask, sFlagShift));
418
    }
419
420
    /** Sets the flags. */
421
    void setFlags(Flag flags) {
422
        setFlagsHelper(sFlagMask, sFlagShift, flags);
423
    }
424
};
425
426
/*
427
 * TRICKY: we cannot implement the specialization as:
428
 *
429
 * class Flagged : base<Flag> {
430
 *    T value;
431
 * };
432
 *
433
 * Because T also inherits from base<Flag> and this runs into a compiler bug where
434
 * sizeof(Flagged) > sizeof(T).
435
 *
436
 * Instead, we must inherit directly from the wrapped class
437
 *
438
 */
439
#if 0
440
template<
441
        typename T, typename Flag, Flag MASK, Flag SHARED_MASK, int SHIFT>
442
class Flagged<T, Flag, MASK, SHARED_MASK, SHIFT, true> : public _Flagged_helper::base<Flag> {
443
private:
444
    T mValue;
445
};
446
#else
447
/**
448
 * Specialization for the case when T is derived from Flagged<U, Flag> and flags can be combined.
449
 */
450
template<
451
        typename T, typename Flag, Flag MASK, Flag SHARED_MASK, int SHIFT, typename IntFlag>
452
class Flagged<T, Flag, MASK, SHARED_MASK, SHIFT, IntFlag, true> : private T {
453
    static_assert(is_integral_or_enum<Flag>::value, "flag must be integer or enum");
454
455
    static_assert(SHARED_MASK == 0 || SHIFT == 0, "cannot overlap masks when using SHIFT");
456
    static_assert((SHARED_MASK & ~MASK) == 0, "shared mask must be part of the mask");
457
    static_assert((SHARED_MASK & ~T::sEffectiveMask) == 0,
458
                  "shared mask must be part of the base mask");
459
    static_assert(SHARED_MASK == 0 || (~SHARED_MASK & (MASK & T::sEffectiveMask)) == 0,
460
                  "mask and base mask can only overlap in shared mask");
461
462
    static constexpr Flag sFlagMask = MASK;  ///< the mask
463
    static constexpr int sFlagShift = SHIFT;  ///< the left shift applied to the flags
464
465
#ifdef FRIEND_TEST
466
    const static bool sFlagCombined = true;
467
    FRIEND_TEST(FlaggedTest, _Flagged_helper_Test);
468
#endif
469
470
protected:
471
    /// The effective combined mask used by this class and any wrapped classes if the flags are
472
    /// combined.
473
    static constexpr IntFlag sEffectiveMask = Flag((MASK << SHIFT) | T::sEffectiveMask);
474
    friend struct _Flagged_helper;
475
476
public:
477
    /**
478
     * Wrapper around base class constructor. These take the flags as their first
479
     * argument and pass the rest of the arguments to the base class constructor.
480
     *
481
     * \param flags initial flags
482
     */
483
    template<typename ...Args>
484
    constexpr Flagged(Flag flags, Args... args)
485
        : T(std::forward<Args>(args)...) {
486
        // we construct the base class first and apply the flags afterwards as
487
        // base class may not have a constructor that takes flags even if it is derived from
488
        // Flagged<U, Flag>
489
        setFlags(flags);
490
    }
491
492
    /** Gets the wrapped value as const. */
493
    inline constexpr T &get() const { return *this; }
494
495
    /** Gets the wrapped value. */
496
    inline T &get() { return *this; }
497
498
    /** Gets the flags. */
499
    Flag constexpr flags() const {
500
        return Flag(this->getFlagsHelper(sFlagMask, sFlagShift));
501
    }
502
503
    /** Sets the flags. */
504
    void setFlags(Flag flags) {
505
        this->setFlagsHelper(sFlagMask, sFlagShift, flags);
506
    }
507
};
508
#endif
509
510
}  // namespace android
511
512
#endif  // STAGEFRIGHT_FOUNDATION_FLAGGED_H_
513
/proc/self/cwd/frameworks/av/media/libstagefright/omx/include/media/stagefright/omx/SoftOMXComponent.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2011 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef SOFT_OMX_COMPONENT_H_
18
19
#define SOFT_OMX_COMPONENT_H_
20
21
#include <media/stagefright/foundation/ABase.h>
22
#include <media/stagefright/foundation/AString.h>
23
#include <utils/RefBase.h>
24
25
#include <OMX_Component.h>
26
27
namespace android {
28
29
struct SoftOMXComponent : public RefBase {
30
    SoftOMXComponent(
31
            const char *name,
32
            const OMX_CALLBACKTYPE *callbacks,
33
            OMX_PTR appData,
34
            OMX_COMPONENTTYPE **component);
35
36
    virtual OMX_ERRORTYPE initCheck() const;
37
38
    void setLibHandle(void *libHandle);
39
    void *libHandle() const;
40
41
0
    virtual void prepareForDestruction() {}
42
43
protected:
44
    virtual ~SoftOMXComponent();
45
46
    const char *name() const;
47
48
    void notify(
49
            OMX_EVENTTYPE event,
50
            OMX_U32 data1, OMX_U32 data2, OMX_PTR data);
51
52
    void notifyEmptyBufferDone(OMX_BUFFERHEADERTYPE *header);
53
    void notifyFillBufferDone(OMX_BUFFERHEADERTYPE *header);
54
55
    virtual OMX_ERRORTYPE sendCommand(
56
            OMX_COMMANDTYPE cmd, OMX_U32 param, OMX_PTR data);
57
58
    virtual OMX_ERRORTYPE getParameter(
59
            OMX_INDEXTYPE index, OMX_PTR params);
60
61
    virtual OMX_ERRORTYPE setParameter(
62
            OMX_INDEXTYPE index, const OMX_PTR params);
63
64
    virtual OMX_ERRORTYPE getConfig(
65
            OMX_INDEXTYPE index, OMX_PTR params);
66
67
    virtual OMX_ERRORTYPE setConfig(
68
            OMX_INDEXTYPE index, const OMX_PTR params);
69
70
    virtual OMX_ERRORTYPE getExtensionIndex(
71
            const char *name, OMX_INDEXTYPE *index);
72
73
    virtual OMX_ERRORTYPE useBuffer(
74
            OMX_BUFFERHEADERTYPE **buffer,
75
            OMX_U32 portIndex,
76
            OMX_PTR appPrivate,
77
            OMX_U32 size,
78
            OMX_U8 *ptr);
79
80
    virtual OMX_ERRORTYPE allocateBuffer(
81
            OMX_BUFFERHEADERTYPE **buffer,
82
            OMX_U32 portIndex,
83
            OMX_PTR appPrivate,
84
            OMX_U32 size);
85
86
    virtual OMX_ERRORTYPE freeBuffer(
87
            OMX_U32 portIndex,
88
            OMX_BUFFERHEADERTYPE *buffer);
89
90
    virtual OMX_ERRORTYPE emptyThisBuffer(
91
            OMX_BUFFERHEADERTYPE *buffer);
92
93
    virtual OMX_ERRORTYPE fillThisBuffer(
94
            OMX_BUFFERHEADERTYPE *buffer);
95
96
    virtual OMX_ERRORTYPE getState(OMX_STATETYPE *state);
97
98
private:
99
    AString mName;
100
    const OMX_CALLBACKTYPE *mCallbacks;
101
    OMX_COMPONENTTYPE *mComponent;
102
103
    void *mLibHandle;
104
105
    static OMX_ERRORTYPE SendCommandWrapper(
106
            OMX_HANDLETYPE component,
107
            OMX_COMMANDTYPE cmd,
108
            OMX_U32 param,
109
            OMX_PTR data);
110
111
    static OMX_ERRORTYPE GetParameterWrapper(
112
            OMX_HANDLETYPE component,
113
            OMX_INDEXTYPE index,
114
            OMX_PTR params);
115
116
    static OMX_ERRORTYPE SetParameterWrapper(
117
            OMX_HANDLETYPE component,
118
            OMX_INDEXTYPE index,
119
            OMX_PTR params);
120
121
    static OMX_ERRORTYPE GetConfigWrapper(
122
            OMX_HANDLETYPE component,
123
            OMX_INDEXTYPE index,
124
            OMX_PTR params);
125
126
    static OMX_ERRORTYPE SetConfigWrapper(
127
            OMX_HANDLETYPE component,
128
            OMX_INDEXTYPE index,
129
            OMX_PTR params);
130
131
    static OMX_ERRORTYPE GetExtensionIndexWrapper(
132
            OMX_HANDLETYPE component,
133
            OMX_STRING name,
134
            OMX_INDEXTYPE *index);
135
136
    static OMX_ERRORTYPE UseBufferWrapper(
137
            OMX_HANDLETYPE component,
138
            OMX_BUFFERHEADERTYPE **buffer,
139
            OMX_U32 portIndex,
140
            OMX_PTR appPrivate,
141
            OMX_U32 size,
142
            OMX_U8 *ptr);
143
144
    static OMX_ERRORTYPE AllocateBufferWrapper(
145
            OMX_HANDLETYPE component,
146
            OMX_BUFFERHEADERTYPE **buffer,
147
            OMX_U32 portIndex,
148
            OMX_PTR appPrivate,
149
            OMX_U32 size);
150
151
    static OMX_ERRORTYPE FreeBufferWrapper(
152
            OMX_HANDLETYPE component,
153
            OMX_U32 portIndex,
154
            OMX_BUFFERHEADERTYPE *buffer);
155
156
    static OMX_ERRORTYPE EmptyThisBufferWrapper(
157
            OMX_HANDLETYPE component,
158
            OMX_BUFFERHEADERTYPE *buffer);
159
160
    static OMX_ERRORTYPE FillThisBufferWrapper(
161
            OMX_HANDLETYPE component,
162
            OMX_BUFFERHEADERTYPE *buffer);
163
164
    static OMX_ERRORTYPE GetStateWrapper(
165
            OMX_HANDLETYPE component,
166
            OMX_STATETYPE *state);
167
168
    DISALLOW_EVIL_CONSTRUCTORS(SoftOMXComponent);
169
};
170
171
template<typename T>
172
bool isValidOMXParam(T *a) {
173
  static_assert(offsetof(typeof(*a), nSize) == 0, "nSize not at offset 0");
174
  static_assert(std::is_same< decltype(a->nSize), OMX_U32>::value, "nSize has wrong type");
175
  static_assert(offsetof(typeof(*a), nVersion) == 4, "nVersion not at offset 4");
176
  static_assert(std::is_same< decltype(a->nVersion), OMX_VERSIONTYPE>::value,
177
          "nVersion has wrong type");
178
179
  if (a->nSize < sizeof(*a)) {
180
      ALOGE("b/27207275: need %zu, got %u", sizeof(*a), a->nSize);
181
      android_errorWriteLog(0x534e4554, "27207275");
182
      return false;
183
  }
184
  return true;
185
}
186
187
}  // namespace android
188
189
#endif  // SOFT_OMX_COMPONENT_H_
/proc/self/cwd/frameworks/native/headers/media_plugin/media/hardware/OMXPluginBase.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2009 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef OMX_PLUGIN_BASE_H_
18
19
#define OMX_PLUGIN_BASE_H_
20
21
#include <sys/types.h>
22
23
#include <OMX_Component.h>
24
25
#include <utils/String8.h>
26
#include <utils/Vector.h>
27
28
namespace android {
29
30
struct OMXPluginBase {
31
0
    OMXPluginBase() {}
32
0
    virtual ~OMXPluginBase() {}
33
34
    virtual OMX_ERRORTYPE makeComponentInstance(
35
            const char *name,
36
            const OMX_CALLBACKTYPE *callbacks,
37
            OMX_PTR appData,
38
            OMX_COMPONENTTYPE **component) = 0;
39
40
    virtual OMX_ERRORTYPE destroyComponentInstance(
41
            OMX_COMPONENTTYPE *component) = 0;
42
43
    virtual OMX_ERRORTYPE enumerateComponents(
44
            OMX_STRING name,
45
            size_t size,
46
            OMX_U32 index) = 0;
47
48
    virtual OMX_ERRORTYPE getRolesOfComponent(
49
            const char *name,
50
            Vector<String8> *roles) = 0;
51
52
private:
53
    OMXPluginBase(const OMXPluginBase &);
54
    OMXPluginBase &operator=(const OMXPluginBase &);
55
};
56
57
}  // namespace android
58
59
#endif  // OMX_PLUGIN_BASE_H_
/proc/self/cwd/frameworks/native/headers/media_plugin/media/hardware/VideoAPI.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2016 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef VIDEO_API_H_
18
19
#define VIDEO_API_H_
20
21
namespace android {
22
23
/**
24
 * Structure describing a media image (frame)
25
 * Currently only supporting YUV
26
 * @deprecated. Use MediaImage2 instead
27
 */
28
struct MediaImage {
29
    enum Type {
30
        MEDIA_IMAGE_TYPE_UNKNOWN = 0,
31
        MEDIA_IMAGE_TYPE_YUV,
32
    };
33
34
    enum PlaneIndex {
35
        Y = 0,
36
        U,
37
        V,
38
        MAX_NUM_PLANES
39
    };
40
41
    Type mType;
42
    uint32_t mNumPlanes;              // number of planes
43
    uint32_t mWidth;                  // width of largest plane (unpadded, as in nFrameWidth)
44
    uint32_t mHeight;                 // height of largest plane (unpadded, as in nFrameHeight)
45
    uint32_t mBitDepth;               // useable bit depth
46
    struct PlaneInfo {
47
        uint32_t mOffset;             // offset of first pixel of the plane in bytes
48
                                      // from buffer offset
49
        uint32_t mColInc;             // column increment in bytes
50
        uint32_t mRowInc;             // row increment in bytes
51
        uint32_t mHorizSubsampling;   // subsampling compared to the largest plane
52
        uint32_t mVertSubsampling;    // subsampling compared to the largest plane
53
    };
54
    PlaneInfo mPlane[MAX_NUM_PLANES];
55
};
56
57
/**
58
 * Structure describing a media image (frame)
59
 */
60
struct __attribute__ ((__packed__)) MediaImage2 {
61
    enum Type : uint32_t {
62
        MEDIA_IMAGE_TYPE_UNKNOWN = 0,
63
        MEDIA_IMAGE_TYPE_YUV,
64
        MEDIA_IMAGE_TYPE_YUVA,
65
        MEDIA_IMAGE_TYPE_RGB,
66
        MEDIA_IMAGE_TYPE_RGBA,
67
        MEDIA_IMAGE_TYPE_Y,
68
    };
69
70
    enum PlaneIndex : uint32_t {
71
        Y = 0,
72
        U = 1,
73
        V = 2,
74
        R = 0,
75
        G = 1,
76
        B = 2,
77
        A = 3,
78
        MAX_NUM_PLANES = 4,
79
    };
80
81
    Type mType;
82
    uint32_t mNumPlanes;              // number of planes
83
    uint32_t mWidth;                  // width of largest plane (unpadded, as in nFrameWidth)
84
    uint32_t mHeight;                 // height of largest plane (unpadded, as in nFrameHeight)
85
    uint32_t mBitDepth;               // useable bit depth (always MSB)
86
    uint32_t mBitDepthAllocated;      // bits per component (must be 8 or 16)
87
88
    struct __attribute__ ((__packed__)) PlaneInfo {
89
        uint32_t mOffset;             // offset of first pixel of the plane in bytes
90
                                      // from buffer offset
91
        int32_t mColInc;              // column increment in bytes
92
        int32_t mRowInc;              // row increment in bytes
93
        uint32_t mHorizSubsampling;   // subsampling compared to the largest plane
94
        uint32_t mVertSubsampling;    // subsampling compared to the largest plane
95
    };
96
    PlaneInfo mPlane[MAX_NUM_PLANES];
97
98
    void initFromV1(const MediaImage&); // for internal use only
99
};
100
101
static_assert(sizeof(MediaImage2::PlaneInfo) == 20, "wrong struct size");
102
static_assert(sizeof(MediaImage2) == 104, "wrong struct size");
103
104
/**
105
 * Aspects of color.
106
 */
107
108
// NOTE: this structure is expected to grow in the future if new color aspects are
109
// added to codec bitstreams. OMX component should not require a specific nSize
110
// though could verify that nSize is at least the size of the structure at the
111
// time of implementation. All new fields will be added at the end of the structure
112
// ensuring backward compatibility.
113
struct __attribute__ ((__packed__, aligned(alignof(uint32_t)))) ColorAspects {
114
    // this is in sync with the range values in graphics.h
115
    enum Range : uint32_t {
116
        RangeUnspecified,
117
        RangeFull,
118
        RangeLimited,
119
        RangeOther = 0xff,
120
    };
121
122
    enum Primaries : uint32_t {
123
        PrimariesUnspecified,
124
        PrimariesBT709_5,       // Rec.ITU-R BT.709-5 or equivalent
125
        PrimariesBT470_6M,      // Rec.ITU-R BT.470-6 System M or equivalent
126
        PrimariesBT601_6_625,   // Rec.ITU-R BT.601-6 625 or equivalent
127
        PrimariesBT601_6_525,   // Rec.ITU-R BT.601-6 525 or equivalent
128
        PrimariesGenericFilm,   // Generic Film
129
        PrimariesBT2020,        // Rec.ITU-R BT.2020 or equivalent
130
        PrimariesOther = 0xff,
131
    };
132
133
    // this partially in sync with the transfer values in graphics.h prior to the transfers
134
    // unlikely to be required by Android section
135
    enum Transfer : uint32_t {
136
        TransferUnspecified,
137
        TransferLinear,         // Linear transfer characteristics
138
        TransferSRGB,           // sRGB or equivalent
139
        TransferSMPTE170M,      // SMPTE 170M or equivalent (e.g. BT.601/709/2020)
140
        TransferGamma22,        // Assumed display gamma 2.2
141
        TransferGamma28,        // Assumed display gamma 2.8
142
        TransferST2084,         // SMPTE ST 2084 for 10/12/14/16 bit systems
143
        TransferHLG,            // ARIB STD-B67 hybrid-log-gamma
144
145
        // transfers unlikely to be required by Android
146
        TransferSMPTE240M = 0x40, // SMPTE 240M
147
        TransferXvYCC,          // IEC 61966-2-4
148
        TransferBT1361,         // Rec.ITU-R BT.1361 extended gamut
149
        TransferST428,          // SMPTE ST 428-1
150
        TransferOther = 0xff,
151
    };
152
153
    enum MatrixCoeffs : uint32_t {
154
        MatrixUnspecified,
155
        MatrixBT709_5,          // Rec.ITU-R BT.709-5 or equivalent
156
        MatrixBT470_6M,         // KR=0.30, KB=0.11 or equivalent
157
        MatrixBT601_6,          // Rec.ITU-R BT.601-6 625 or equivalent
158
        MatrixSMPTE240M,        // SMPTE 240M or equivalent
159
        MatrixBT2020,           // Rec.ITU-R BT.2020 non-constant luminance
160
        MatrixBT2020Constant,   // Rec.ITU-R BT.2020 constant luminance
161
        MatrixOther = 0xff,
162
    };
163
164
    // this is in sync with the standard values in graphics.h
165
    enum Standard : uint32_t {
166
        StandardUnspecified,
167
        StandardBT709,                  // PrimariesBT709_5 and MatrixBT709_5
168
        StandardBT601_625,              // PrimariesBT601_6_625 and MatrixBT601_6
169
        StandardBT601_625_Unadjusted,   // PrimariesBT601_6_625 and KR=0.222, KB=0.071
170
        StandardBT601_525,              // PrimariesBT601_6_525 and MatrixBT601_6
171
        StandardBT601_525_Unadjusted,   // PrimariesBT601_6_525 and MatrixSMPTE240M
172
        StandardBT2020,                 // PrimariesBT2020 and MatrixBT2020
173
        StandardBT2020Constant,         // PrimariesBT2020 and MatrixBT2020Constant
174
        StandardBT470M,                 // PrimariesBT470_6M and MatrixBT470_6M
175
        StandardFilm,                   // PrimariesGenericFilm and KR=0.253, KB=0.068
176
        StandardOther = 0xff,
177
    };
178
179
    Range mRange;                // IN/OUT
180
    Primaries mPrimaries;        // IN/OUT
181
    Transfer mTransfer;          // IN/OUT
182
    MatrixCoeffs mMatrixCoeffs;  // IN/OUT
183
};
184
185
static_assert(sizeof(ColorAspects) == 16, "wrong struct size");
186
187
/**
188
 * HDR Metadata.
189
 */
190
191
// HDR Static Metadata Descriptor as defined by CTA-861-3.
192
struct __attribute__ ((__packed__)) HDRStaticInfo {
193
    // Static_Metadata_Descriptor_ID
194
    enum ID : uint8_t {
195
        kType1 = 0, // Static Metadata Type 1
196
    } mID;
197
198
    struct __attribute__ ((__packed__)) Primaries1 {
199
        // values are in units of 0.00002
200
        uint16_t x;
201
        uint16_t y;
202
    };
203
204
    // Static Metadata Descriptor Type 1
205
    struct __attribute__ ((__packed__)) Type1 {
206
        Primaries1 mR; // display primary 0
207
        Primaries1 mG; // display primary 1
208
        Primaries1 mB; // display primary 2
209
        Primaries1 mW; // white point
210
        uint16_t mMaxDisplayLuminance; // in cd/m^2
211
        uint16_t mMinDisplayLuminance; // in 0.0001 cd/m^2
212
        uint16_t mMaxContentLightLevel; // in cd/m^2
213
        uint16_t mMaxFrameAverageLightLevel; // in cd/m^2
214
    };
215
216
    union {
217
         Type1 sType1;
218
    };
219
};
220
221
static_assert(sizeof(HDRStaticInfo::Primaries1) == 4, "wrong struct size");
222
static_assert(sizeof(HDRStaticInfo::Type1) == 24, "wrong struct size");
223
static_assert(sizeof(HDRStaticInfo) == 25, "wrong struct size");
224
225
#ifdef STRINGIFY_ENUMS
226
227
0
inline static const char *asString(MediaImage::Type i, const char *def = "??") {
228
0
    switch (i) {
229
0
        case MediaImage::MEDIA_IMAGE_TYPE_UNKNOWN: return "Unknown";
230
0
        case MediaImage::MEDIA_IMAGE_TYPE_YUV:     return "YUV";
231
0
        default:                                   return def;
232
0
    }
233
0
}
234
235
0
inline static const char *asString(MediaImage::PlaneIndex i, const char *def = "??") {
236
0
    switch (i) {
237
0
        case MediaImage::Y: return "Y";
238
0
        case MediaImage::U: return "U";
239
0
        case MediaImage::V: return "V";
240
0
        default:            return def;
241
0
    }
242
0
}
243
244
0
inline static const char *asString(MediaImage2::Type i, const char *def = "??") {
245
0
    switch (i) {
246
0
        case MediaImage2::MEDIA_IMAGE_TYPE_UNKNOWN: return "Unknown";
247
0
        case MediaImage2::MEDIA_IMAGE_TYPE_YUV:     return "YUV";
248
0
        case MediaImage2::MEDIA_IMAGE_TYPE_YUVA:    return "YUVA";
249
0
        case MediaImage2::MEDIA_IMAGE_TYPE_RGB:     return "RGB";
250
0
        case MediaImage2::MEDIA_IMAGE_TYPE_RGBA:    return "RGBA";
251
0
        case MediaImage2::MEDIA_IMAGE_TYPE_Y:       return "Y";
252
0
        default:                                    return def;
253
0
    }
254
0
}
255
256
inline static char asChar2(
257
0
        MediaImage2::PlaneIndex i, MediaImage2::Type j, char def = '?') {
258
0
    const char *planes = asString(j, NULL);
259
0
    // handle unknown values
260
0
    if (j == MediaImage2::MEDIA_IMAGE_TYPE_UNKNOWN || planes == NULL || i >= strlen(planes)) {
261
0
        return def;
262
0
    }
263
0
    return planes[i];
264
0
}
265
266
0
inline static const char *asString(ColorAspects::Range i, const char *def = "??") {
267
0
    switch (i) {
268
0
        case ColorAspects::RangeUnspecified: return "Unspecified";
269
0
        case ColorAspects::RangeFull:        return "Full";
270
0
        case ColorAspects::RangeLimited:     return "Limited";
271
0
        case ColorAspects::RangeOther:       return "Other";
272
0
        default:                             return def;
273
0
    }
274
0
}
275
276
0
inline static const char *asString(ColorAspects::Primaries i, const char *def = "??") {
277
0
    switch (i) {
278
0
        case ColorAspects::PrimariesUnspecified: return "Unspecified";
279
0
        case ColorAspects::PrimariesBT709_5:     return "BT709_5";
280
0
        case ColorAspects::PrimariesBT470_6M:    return "BT470_6M";
281
0
        case ColorAspects::PrimariesBT601_6_625: return "BT601_6_625";
282
0
        case ColorAspects::PrimariesBT601_6_525: return "BT601_6_525";
283
0
        case ColorAspects::PrimariesGenericFilm: return "GenericFilm";
284
0
        case ColorAspects::PrimariesBT2020:      return "BT2020";
285
0
        case ColorAspects::PrimariesOther:       return "Other";
286
0
        default:                                 return def;
287
0
    }
288
0
}
289
290
0
inline static const char *asString(ColorAspects::Transfer i, const char *def = "??") {
291
0
    switch (i) {
292
0
        case ColorAspects::TransferUnspecified: return "Unspecified";
293
0
        case ColorAspects::TransferLinear:      return "Linear";
294
0
        case ColorAspects::TransferSRGB:        return "SRGB";
295
0
        case ColorAspects::TransferSMPTE170M:   return "SMPTE170M";
296
0
        case ColorAspects::TransferGamma22:     return "Gamma22";
297
0
        case ColorAspects::TransferGamma28:     return "Gamma28";
298
0
        case ColorAspects::TransferST2084:      return "ST2084";
299
0
        case ColorAspects::TransferHLG:         return "HLG";
300
0
        case ColorAspects::TransferSMPTE240M:   return "SMPTE240M";
301
0
        case ColorAspects::TransferXvYCC:       return "XvYCC";
302
0
        case ColorAspects::TransferBT1361:      return "BT1361";
303
0
        case ColorAspects::TransferST428:       return "ST428";
304
0
        case ColorAspects::TransferOther:       return "Other";
305
0
        default:                                return def;
306
0
    }
307
0
}
308
309
0
inline static const char *asString(ColorAspects::MatrixCoeffs i, const char *def = "??") {
310
0
    switch (i) {
311
0
        case ColorAspects::MatrixUnspecified:    return "Unspecified";
312
0
        case ColorAspects::MatrixBT709_5:        return "BT709_5";
313
0
        case ColorAspects::MatrixBT470_6M:       return "BT470_6M";
314
0
        case ColorAspects::MatrixBT601_6:        return "BT601_6";
315
0
        case ColorAspects::MatrixSMPTE240M:      return "SMPTE240M";
316
0
        case ColorAspects::MatrixBT2020:         return "BT2020";
317
0
        case ColorAspects::MatrixBT2020Constant: return "BT2020Constant";
318
0
        case ColorAspects::MatrixOther:          return "Other";
319
0
        default:                                 return def;
320
0
    }
321
0
}
322
323
0
inline static const char *asString(ColorAspects::Standard i, const char *def = "??") {
324
0
    switch (i) {
325
0
        case ColorAspects::StandardUnspecified:          return "Unspecified";
326
0
        case ColorAspects::StandardBT709:                return "BT709";
327
0
        case ColorAspects::StandardBT601_625:            return "BT601_625";
328
0
        case ColorAspects::StandardBT601_625_Unadjusted: return "BT601_625_Unadjusted";
329
0
        case ColorAspects::StandardBT601_525:            return "BT601_525";
330
0
        case ColorAspects::StandardBT601_525_Unadjusted: return "BT601_525_Unadjusted";
331
0
        case ColorAspects::StandardBT2020:               return "BT2020";
332
0
        case ColorAspects::StandardBT2020Constant:       return "BT2020Constant";
333
0
        case ColorAspects::StandardBT470M:               return "BT470M";
334
0
        case ColorAspects::StandardFilm:                 return "Film";
335
0
        case ColorAspects::StandardOther:                return "Other";
336
0
        default:                                         return def;
337
0
    }
338
0
}
339
340
#endif
341
342
}  // namespace android
343
344
#endif  // VIDEO_API_H_
/proc/self/cwd/frameworks/native/headers/media_plugin/media/openmax/OMX_Core.h
Line
Count
Source
1
/* ------------------------------------------------------------------
2
 * Copyright (C) 1998-2009 PacketVideo
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13
 * express or implied.
14
 * See the License for the specific language governing permissions
15
 * and limitations under the License.
16
 * -------------------------------------------------------------------
17
 */
18
/*
19
 * Copyright (c) 2008 The Khronos Group Inc.
20
 *
21
 * Permission is hereby granted, free of charge, to any person obtaining
22
 * a copy of this software and associated documentation files (the
23
 * "Software"), to deal in the Software without restriction, including
24
 * without limitation the rights to use, copy, modify, merge, publish,
25
 * distribute, sublicense, and/or sell copies of the Software, and to
26
 * permit persons to whom the Software is furnished to do so, subject
27
 * to the following conditions:
28
 * The above copyright notice and this permission notice shall be included
29
 * in all copies or substantial portions of the Software.
30
 *
31
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
32
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
34
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
35
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
36
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
37
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38
 *
39
 */
40
41
/** OMX_Core.h - OpenMax IL version 1.1.2
42
 *  The OMX_Core header file contains the definitions used by both the
43
 *  application and the component to access common items.
44
 */
45
46
#ifndef OMX_Core_h
47
#define OMX_Core_h
48
49
#ifdef __cplusplus
50
extern "C" {
51
#endif /* __cplusplus */
52
53
54
/* Each OMX header shall include all required header files to allow the
55
 *  header to compile without errors.  The includes below are required
56
 *  for this header file to compile successfully
57
 */
58
59
#include <OMX_Index.h>
60
61
62
/** The OMX_COMMANDTYPE enumeration is used to specify the action in the
63
 *  OMX_SendCommand macro.
64
 *  @ingroup core
65
 */
66
typedef enum OMX_COMMANDTYPE
67
{
68
    OMX_CommandStateSet,    /**< Change the component state */
69
    OMX_CommandFlush,       /**< Flush the data queue(s) of a component */
70
    OMX_CommandPortDisable, /**< Disable a port on a component. */
71
    OMX_CommandPortEnable,  /**< Enable a port on a component. */
72
    OMX_CommandMarkBuffer,  /**< Mark a component/buffer for observation */
73
    OMX_CommandKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
74
    OMX_CommandVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
75
    OMX_CommandMax = 0X7FFFFFFF
76
} OMX_COMMANDTYPE;
77
78
79
80
/** The OMX_STATETYPE enumeration is used to indicate or change the component
81
 *  state.  This enumeration reflects the current state of the component when
82
 *  used with the OMX_GetState macro or becomes the parameter in a state change
83
 *  command when used with the OMX_SendCommand macro.
84
 *
85
 *  The component will be in the Loaded state after the component is initially
86
 *  loaded into memory.  In the Loaded state, the component is not allowed to
87
 *  allocate or hold resources other than to build it's internal parameter
88
 *  and configuration tables.  The application will send one or more
89
 *  SetParameters/GetParameters and SetConfig/GetConfig commands to the
90
 *  component and the component will record each of these parameter and
91
 *  configuration changes for use later.  When the application sends the
92
 *  Idle command, the component will acquire the resources needed for the
93
 *  specified configuration and will transition to the idle state if the
94
 *  allocation is successful.  If the component cannot successfully
95
 *  transition to the idle state for any reason, the state of the component
96
 *  shall be fully rolled back to the Loaded state (e.g. all allocated
97
 *  resources shall be released).  When the component receives the command
98
 *  to go to the Executing state, it shall begin processing buffers by
99
 *  sending all input buffers it holds to the application.  While
100
 *  the component is in the Idle state, the application may also send the
101
 *  Pause command.  If the component receives the pause command while in the
102
 *  Idle state, the component shall send all input buffers it holds to the
103
 *  application, but shall not begin processing buffers.  This will allow the
104
 *  application to prefill buffers.
105
 *
106
 *  @ingroup comp
107
 */
108
109
typedef enum OMX_STATETYPE
110
{
111
    OMX_StateInvalid,      /**< component has detected that it's internal data
112
                                structures are corrupted to the point that
113
                                it cannot determine it's state properly */
114
    OMX_StateLoaded,      /**< component has been loaded but has not completed
115
                                initialization.  The OMX_SetParameter macro
116
                                and the OMX_GetParameter macro are the only
117
                                valid macros allowed to be sent to the
118
                                component in this state. */
119
    OMX_StateIdle,        /**< component initialization has been completed
120
                                successfully and the component is ready to
121
                                to start. */
122
    OMX_StateExecuting,   /**< component has accepted the start command and
123
                                is processing data (if data is available) */
124
    OMX_StatePause,       /**< component has received pause command */
125
    OMX_StateWaitForResources, /**< component is waiting for resources, either after
126
                                preemption or before it gets the resources requested.
127
                                See specification for complete details. */
128
    OMX_StateKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
129
    OMX_StateVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
130
    OMX_StateMax = 0X7FFFFFFF
131
} OMX_STATETYPE;
132
133
/** The OMX_ERRORTYPE enumeration defines the standard OMX Errors.  These
134
 *  errors should cover most of the common failure cases.  However,
135
 *  vendors are free to add additional error messages of their own as
136
 *  long as they follow these rules:
137
 *  1.  Vendor error messages shall be in the range of 0x90000000 to
138
 *      0x9000FFFF.
139
 *  2.  Vendor error messages shall be defined in a header file provided
140
 *      with the component.  No error messages are allowed that are
141
 *      not defined.
142
 */
143
typedef enum OMX_ERRORTYPE
144
{
145
  OMX_ErrorNone = 0,
146
147
  /** There were insufficient resources to perform the requested operation */
148
  OMX_ErrorInsufficientResources = (OMX_S32) 0x80001000,
149
150
  /** There was an error, but the cause of the error could not be determined */
151
  OMX_ErrorUndefined = (OMX_S32) 0x80001001,
152
153
  /** The component name string was not valid */
154
  OMX_ErrorInvalidComponentName = (OMX_S32) 0x80001002,
155
156
  /** No component with the specified name string was found */
157
  OMX_ErrorComponentNotFound = (OMX_S32) 0x80001003,
158
159
  /** The component specified did not have a "OMX_ComponentInit" or
160
      "OMX_ComponentDeInit entry point */
161
  OMX_ErrorInvalidComponent = (OMX_S32) 0x80001004,
162
163
  /** One or more parameters were not valid */
164
  OMX_ErrorBadParameter = (OMX_S32) 0x80001005,
165
166
  /** The requested function is not implemented */
167
  OMX_ErrorNotImplemented = (OMX_S32) 0x80001006,
168
169
  /** The buffer was emptied before the next buffer was ready */
170
  OMX_ErrorUnderflow = (OMX_S32) 0x80001007,
171
172
  /** The buffer was not available when it was needed */
173
  OMX_ErrorOverflow = (OMX_S32) 0x80001008,
174
175
  /** The hardware failed to respond as expected */
176
  OMX_ErrorHardware = (OMX_S32) 0x80001009,
177
178
  /** The component is in the state OMX_StateInvalid */
179
  OMX_ErrorInvalidState = (OMX_S32) 0x8000100A,
180
181
  /** Stream is found to be corrupt */
182
  OMX_ErrorStreamCorrupt = (OMX_S32) 0x8000100B,
183
184
  /** Ports being connected are not compatible */
185
  OMX_ErrorPortsNotCompatible = (OMX_S32) 0x8000100C,
186
187
  /** Resources allocated to an idle component have been
188
      lost resulting in the component returning to the loaded state */
189
  OMX_ErrorResourcesLost = (OMX_S32) 0x8000100D,
190
191
  /** No more indicies can be enumerated */
192
  OMX_ErrorNoMore = (OMX_S32) 0x8000100E,
193
194
  /** The component detected a version mismatch */
195
  OMX_ErrorVersionMismatch = (OMX_S32) 0x8000100F,
196
197
  /** The component is not ready to return data at this time */
198
  OMX_ErrorNotReady = (OMX_S32) 0x80001010,
199
200
  /** There was a timeout that occurred */
201
  OMX_ErrorTimeout = (OMX_S32) 0x80001011,
202
203
  /** This error occurs when trying to transition into the state you are already in */
204
  OMX_ErrorSameState = (OMX_S32) 0x80001012,
205
206
  /** Resources allocated to an executing or paused component have been
207
      preempted, causing the component to return to the idle state */
208
  OMX_ErrorResourcesPreempted = (OMX_S32) 0x80001013,
209
210
  /** A non-supplier port sends this error to the IL client (via the EventHandler callback)
211
      during the allocation of buffers (on a transition from the LOADED to the IDLE state or
212
      on a port restart) when it deems that it has waited an unusually long time for the supplier
213
      to send it an allocated buffer via a UseBuffer call. */
214
  OMX_ErrorPortUnresponsiveDuringAllocation = (OMX_S32) 0x80001014,
215
216
  /** A non-supplier port sends this error to the IL client (via the EventHandler callback)
217
      during the deallocation of buffers (on a transition from the IDLE to LOADED state or
218
      on a port stop) when it deems that it has waited an unusually long time for the supplier
219
      to request the deallocation of a buffer header via a FreeBuffer call. */
220
  OMX_ErrorPortUnresponsiveDuringDeallocation = (OMX_S32) 0x80001015,
221
222
  /** A supplier port sends this error to the IL client (via the EventHandler callback)
223
      during the stopping of a port (either on a transition from the IDLE to LOADED
224
      state or a port stop) when it deems that it has waited an unusually long time for
225
      the non-supplier to return a buffer via an EmptyThisBuffer or FillThisBuffer call. */
226
  OMX_ErrorPortUnresponsiveDuringStop = (OMX_S32) 0x80001016,
227
228
  /** Attempting a state transtion that is not allowed */
229
  OMX_ErrorIncorrectStateTransition = (OMX_S32) 0x80001017,
230
231
  /* Attempting a command that is not allowed during the present state. */
232
  OMX_ErrorIncorrectStateOperation = (OMX_S32) 0x80001018,
233
234
  /** The values encapsulated in the parameter or config structure are not supported. */
235
  OMX_ErrorUnsupportedSetting = (OMX_S32) 0x80001019,
236
237
  /** The parameter or config indicated by the given index is not supported. */
238
  OMX_ErrorUnsupportedIndex = (OMX_S32) 0x8000101A,
239
240
  /** The port index supplied is incorrect. */
241
  OMX_ErrorBadPortIndex = (OMX_S32) 0x8000101B,
242
243
  /** The port has lost one or more of its buffers and it thus unpopulated. */
244
  OMX_ErrorPortUnpopulated = (OMX_S32) 0x8000101C,
245
246
  /** Component suspended due to temporary loss of resources */
247
  OMX_ErrorComponentSuspended = (OMX_S32) 0x8000101D,
248
249
  /** Component suspended due to an inability to acquire dynamic resources */
250
  OMX_ErrorDynamicResourcesUnavailable = (OMX_S32) 0x8000101E,
251
252
  /** When the macroblock error reporting is enabled the component returns new error
253
  for every frame that has errors */
254
  OMX_ErrorMbErrorsInFrame = (OMX_S32) 0x8000101F,
255
256
  /** A component reports this error when it cannot parse or determine the format of an input stream. */
257
  OMX_ErrorFormatNotDetected = (OMX_S32) 0x80001020,
258
259
  /** The content open operation failed. */
260
  OMX_ErrorContentPipeOpenFailed = (OMX_S32) 0x80001021,
261
262
  /** The content creation operation failed. */
263
  OMX_ErrorContentPipeCreationFailed = (OMX_S32) 0x80001022,
264
265
  /** Separate table information is being used */
266
  OMX_ErrorSeperateTablesUsed = (OMX_S32) 0x80001023,
267
268
  /** Tunneling is unsupported by the component*/
269
  OMX_ErrorTunnelingUnsupported = (OMX_S32) 0x80001024,
270
271
  OMX_ErrorKhronosExtensions = (OMX_S32)0x8F000000, /**< Reserved region for introducing Khronos Standard Extensions */
272
  OMX_ErrorVendorStartUnused = (OMX_S32)0x90000000, /**< Reserved region for introducing Vendor Extensions */
273
  OMX_ErrorMax = 0x7FFFFFFF
274
} OMX_ERRORTYPE;
275
276
/** @ingroup core */
277
typedef OMX_ERRORTYPE (* OMX_COMPONENTINITTYPE)(OMX_IN  OMX_HANDLETYPE hComponent);
278
279
/** @ingroup core */
280
typedef struct OMX_COMPONENTREGISTERTYPE
281
{
282
  const char          * pName;       /* Component name, 128 byte limit (including '\0') applies */
283
  OMX_COMPONENTINITTYPE pInitialize; /* Component instance initialization function */
284
} OMX_COMPONENTREGISTERTYPE;
285
286
/** @ingroup core */
287
extern OMX_COMPONENTREGISTERTYPE OMX_ComponentRegistered[];
288
289
/** @ingroup rpm */
290
typedef struct OMX_PRIORITYMGMTTYPE {
291
 OMX_U32 nSize;             /**< size of the structure in bytes */
292
 OMX_VERSIONTYPE nVersion;  /**< OMX specification version information */
293
 OMX_U32 nGroupPriority;            /**< Priority of the component group */
294
 OMX_U32 nGroupID;                  /**< ID of the component group */
295
} OMX_PRIORITYMGMTTYPE;
296
297
/* Component name and Role names are limited to 128 characters including the terminating '\0'. */
298
#define OMX_MAX_STRINGNAME_SIZE 128
299
300
/** @ingroup comp */
301
typedef struct OMX_PARAM_COMPONENTROLETYPE {
302
    OMX_U32 nSize;              /**< size of the structure in bytes */
303
    OMX_VERSIONTYPE nVersion;   /**< OMX specification version information */
304
    OMX_U8 cRole[OMX_MAX_STRINGNAME_SIZE];  /**< name of standard component which defines component role */
305
} OMX_PARAM_COMPONENTROLETYPE;
306
307
/** End of Stream Buffer Flag:
308
  *
309
  * A component sets EOS when it has no more data to emit on a particular
310
  * output port. Thus an output port shall set EOS on the last buffer it
311
  * emits. A component's determination of when an output port should
312
  * cease sending data is implemenation specific.
313
  * @ingroup buf
314
  */
315
316
13
#define OMX_BUFFERFLAG_EOS 0x00000001
317
318
/** Start Time Buffer Flag:
319
 *
320
 * The source of a stream (e.g. a demux component) sets the STARTTIME
321
 * flag on the buffer that contains the starting timestamp for the
322
 * stream. The starting timestamp corresponds to the first data that
323
 * should be displayed at startup or after a seek.
324
 * The first timestamp of the stream is not necessarily the start time.
325
 * For instance, in the case of a seek to a particular video frame,
326
 * the target frame may be an interframe. Thus the first buffer of
327
 * the stream will be the intra-frame preceding the target frame and
328
 * the starttime will occur with the target frame (with any other
329
 * required frames required to reconstruct the target intervening).
330
 *
331
 * The STARTTIME flag is directly associated with the buffer's
332
 * timestamp ' thus its association to buffer data and its
333
 * propagation is identical to the timestamp's.
334
 *
335
 * When a Sync Component client receives a buffer with the
336
 * STARTTIME flag it shall perform a SetConfig on its sync port
337
 * using OMX_ConfigTimeClientStartTime and passing the buffer's
338
 * timestamp.
339
 *
340
 * @ingroup buf
341
 */
342
343
#define OMX_BUFFERFLAG_STARTTIME 0x00000002
344
345
346
347
/** Decode Only Buffer Flag:
348
 *
349
 * The source of a stream (e.g. a demux component) sets the DECODEONLY
350
 * flag on any buffer that should shall be decoded but should not be
351
 * displayed. This flag is used, for instance, when a source seeks to
352
 * a target interframe that requires the decode of frames preceding the
353
 * target to facilitate the target's reconstruction. In this case the
354
 * source would emit the frames preceding the target downstream
355
 * but mark them as decode only.
356
 *
357
 * The DECODEONLY is associated with buffer data and propagated in a
358
 * manner identical to the buffer timestamp.
359
 *
360
 * A component that renders data should ignore all buffers with
361
 * the DECODEONLY flag set.
362
 *
363
 * @ingroup buf
364
 */
365
366
#define OMX_BUFFERFLAG_DECODEONLY 0x00000004
367
368
369
/* Data Corrupt Flag: This flag is set when the IL client believes the data in the associated buffer is corrupt
370
 * @ingroup buf
371
 */
372
373
#define OMX_BUFFERFLAG_DATACORRUPT 0x00000008
374
375
/* End of Frame: The buffer contains exactly one end of frame and no data
376
 *  occurs after the end of frame. This flag is an optional hint. The absence
377
 *  of this flag does not imply the absence of an end of frame within the buffer.
378
 * @ingroup buf
379
*/
380
#define OMX_BUFFERFLAG_ENDOFFRAME 0x00000010
381
382
/* Sync Frame Flag: This flag is set when the buffer content contains a coded sync frame '
383
 *  a frame that has no dependency on any other frame information
384
 *  @ingroup buf
385
 */
386
#define OMX_BUFFERFLAG_SYNCFRAME 0x00000020
387
388
/* Extra data present flag: there is extra data appended to the data stream
389
 * residing in the buffer
390
 * @ingroup buf
391
 */
392
#define OMX_BUFFERFLAG_EXTRADATA 0x00000040
393
394
/** Codec Config Buffer Flag:
395
* OMX_BUFFERFLAG_CODECCONFIG is an optional flag that is set by an
396
* output port when all bytes in the buffer form part or all of a set of
397
* codec specific configuration data.  Examples include SPS/PPS nal units
398
* for OMX_VIDEO_CodingAVC or AudioSpecificConfig data for
399
* OMX_AUDIO_CodingAAC.  Any component that for a given stream sets
400
* OMX_BUFFERFLAG_CODECCONFIG shall not mix codec configuration bytes
401
* with frame data in the same buffer, and shall send all buffers
402
* containing codec configuration bytes before any buffers containing
403
* frame data that those configurations bytes describe.
404
* If the stream format for a particular codec has a frame specific
405
* header at the start of each frame, for example OMX_AUDIO_CodingMP3 or
406
* OMX_AUDIO_CodingAAC in ADTS mode, then these shall be presented as
407
* normal without setting OMX_BUFFERFLAG_CODECCONFIG.
408
 * @ingroup buf
409
 */
410
#define OMX_BUFFERFLAG_CODECCONFIG 0x00000080
411
412
413
414
/** @ingroup buf */
415
typedef struct OMX_BUFFERHEADERTYPE
416
{
417
    OMX_U32 nSize;              /**< size of the structure in bytes */
418
    OMX_VERSIONTYPE nVersion;   /**< OMX specification version information */
419
    OMX_U8* pBuffer;            /**< Pointer to actual block of memory
420
                                     that is acting as the buffer */
421
    OMX_U32 nAllocLen;          /**< size of the buffer allocated, in bytes */
422
    OMX_U32 nFilledLen;         /**< number of bytes currently in the
423
                                     buffer */
424
    OMX_U32 nOffset;            /**< start offset of valid data in bytes from
425
                                     the start of the buffer */
426
    OMX_PTR pAppPrivate;        /**< pointer to any data the application
427
                                     wants to associate with this buffer */
428
    OMX_PTR pPlatformPrivate;   /**< pointer to any data the platform
429
                                     wants to associate with this buffer */
430
    OMX_PTR pInputPortPrivate;  /**< pointer to any data the input port
431
                                     wants to associate with this buffer */
432
    OMX_PTR pOutputPortPrivate; /**< pointer to any data the output port
433
                                     wants to associate with this buffer */
434
    OMX_HANDLETYPE hMarkTargetComponent; /**< The component that will generate a
435
                                              mark event upon processing this buffer. */
436
    OMX_PTR pMarkData;          /**< Application specific data associated with
437
                                     the mark sent on a mark event to disambiguate
438
                                     this mark from others. */
439
    OMX_U32 nTickCount;         /**< Optional entry that the component and
440
                                     application can update with a tick count
441
                                     when they access the component.  This
442
                                     value should be in microseconds.  Since
443
                                     this is a value relative to an arbitrary
444
                                     starting point, this value cannot be used
445
                                     to determine absolute time.  This is an
446
                                     optional entry and not all components
447
                                     will update it.*/
448
 OMX_TICKS nTimeStamp;          /**< Timestamp corresponding to the sample
449
                                     starting at the first logical sample
450
                                     boundary in the buffer. Timestamps of
451
                                     successive samples within the buffer may
452
                                     be inferred by adding the duration of the
453
                                     of the preceding buffer to the timestamp
454
                                     of the preceding buffer.*/
455
  OMX_U32     nFlags;           /**< buffer specific flags */
456
  OMX_U32 nOutputPortIndex;     /**< The index of the output port (if any) using
457
                                     this buffer */
458
  OMX_U32 nInputPortIndex;      /**< The index of the input port (if any) using
459
                                     this buffer */
460
} OMX_BUFFERHEADERTYPE;
461
462
/** The OMX_EXTRADATATYPE enumeration is used to define the
463
 * possible extra data payload types.
464
 * NB: this enum is binary backwards compatible with the previous
465
 * OMX_EXTRADATA_QUANT define.  This should be replaced with
466
 * OMX_ExtraDataQuantization.
467
 */
468
typedef enum OMX_EXTRADATATYPE
469
{
470
   OMX_ExtraDataNone = 0,                       /**< Indicates that no more extra data sections follow */
471
   OMX_ExtraDataQuantization,                   /**< The data payload contains quantization data */
472
   OMX_ExtraDataKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
473
   OMX_ExtraDataVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
474
   OMX_ExtraDataMax = 0x7FFFFFFF
475
} OMX_EXTRADATATYPE;
476
477
478
typedef struct OMX_OTHER_EXTRADATATYPE  {
479
    OMX_U32 nSize;
480
    OMX_VERSIONTYPE nVersion;
481
    OMX_U32 nPortIndex;
482
    OMX_EXTRADATATYPE eType;       /* Extra Data type */
483
    OMX_U32 nDataSize;   /* Size of the supporting data to follow */
484
    OMX_U8  data[1];     /* Supporting data hint  */
485
} OMX_OTHER_EXTRADATATYPE;
486
487
/** @ingroup comp */
488
typedef struct OMX_PORT_PARAM_TYPE {
489
    OMX_U32 nSize;              /**< size of the structure in bytes */
490
    OMX_VERSIONTYPE nVersion;   /**< OMX specification version information */
491
    OMX_U32 nPorts;             /**< The number of ports for this component */
492
    OMX_U32 nStartPortNumber;   /** first port number for this type of port */
493
} OMX_PORT_PARAM_TYPE;
494
495
/** @ingroup comp */
496
typedef enum OMX_EVENTTYPE
497
{
498
    OMX_EventCmdComplete,         /**< component has sucessfully completed a command */
499
    OMX_EventError,               /**< component has detected an error condition */
500
    OMX_EventMark,                /**< component has detected a buffer mark */
501
    OMX_EventPortSettingsChanged, /**< component is reported a port settings change */
502
    OMX_EventBufferFlag,          /**< component has detected an EOS */
503
    OMX_EventResourcesAcquired,   /**< component has been granted resources and is
504
                                       automatically starting the state change from
505
                                       OMX_StateWaitForResources to OMX_StateIdle. */
506
    OMX_EventComponentResumed,     /**< Component resumed due to reacquisition of resources */
507
    OMX_EventDynamicResourcesAvailable, /**< Component has acquired previously unavailable dynamic resources */
508
    OMX_EventPortFormatDetected,      /**< Component has detected a supported format. */
509
    OMX_EventKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
510
    OMX_EventVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
511
512
    /** Event when tunneled decoder has rendered an output or reached EOS
513
     *  nData1 must contain the number of timestamps returned
514
     *  pEventData must point to an array of the OMX_VIDEO_RENDEREVENTTYPE structs containing the
515
     *  render-timestamps of each frame. Component may batch rendered timestamps using this event,
516
     *  but must signal the event no more than 40ms after the first frame in the batch. The frames
517
     *  must be ordered by system timestamp inside and across batches.
518
     *
519
     *  The component shall signal the render-timestamp of the very first frame (as well as the
520
     *  first frame after each flush) unbatched (with nData1 set to 1) within 5 msec.
521
     *
522
     *  If component is doing frame-rate conversion, it must signal the render time of each
523
     *  converted frame, and must interpolate media timestamps for in-between frames.
524
     *
525
     *  When the component reached EOS, it must signal an EOS timestamp using the same mechanism.
526
     *  This is in addition to the timestamp of the last rendered frame, and should follow that
527
     *  frame.
528
     */
529
    OMX_EventOutputRendered = 0x7F000001,
530
531
    /** For framework internal use only: event sent by OMXNodeInstance when it receives a graphic
532
     *  input buffer with a new dataspace for encoding. |arg1| will contain the dataspace. |arg2|
533
     *  will contain the ColorAspects requested by the component (or framework defaults) using
534
     *  the following bitfield layout:
535
     *
536
     *       +----------+-------------+----------------+------------+
537
     *       |   Range  |  Primaries  |  MatrixCoeffs  |  Transfer  |
538
     *       +----------+-------------+----------------+------------+
539
     *  bits:  31....24   23.......16   15...........8   7........0
540
     *
541
     *  TODO: We would really need to tie this to an output buffer, but OMX does not provide a
542
     *  fool-proof way to do that for video encoders.
543
     */
544
    OMX_EventDataSpaceChanged,
545
    OMX_EventMax = 0x7FFFFFFF
546
} OMX_EVENTTYPE;
547
548
typedef struct OMX_CALLBACKTYPE
549
{
550
    /** The EventHandler method is used to notify the application when an
551
        event of interest occurs.  Events are defined in the OMX_EVENTTYPE
552
        enumeration.  Please see that enumeration for details of what will
553
        be returned for each type of event. Callbacks should not return
554
        an error to the component, so if an error occurs, the application
555
        shall handle it internally.  This is a blocking call.
556
557
        The application should return from this call within 5 msec to avoid
558
        blocking the component for an excessively long period of time.
559
560
        @param hComponent
561
            handle of the component to access.  This is the component
562
            handle returned by the call to the GetHandle function.
563
        @param pAppData
564
            pointer to an application defined value that was provided in the
565
            pAppData parameter to the OMX_GetHandle method for the component.
566
            This application defined value is provided so that the application
567
            can have a component specific context when receiving the callback.
568
        @param eEvent
569
            Event that the component wants to notify the application about.
570
        @param nData1
571
            nData will be the OMX_ERRORTYPE for an error event and will be
572
            an OMX_COMMANDTYPE for a command complete event and OMX_INDEXTYPE for a OMX_PortSettingsChanged event.
573
         @param nData2
574
            nData2 will hold further information related to the event. Can be OMX_STATETYPE for
575
            a OMX_CommandStateSet command or port index for a OMX_PortSettingsChanged event.
576
            Default value is 0 if not used. )
577
        @param pEventData
578
            Pointer to additional event-specific data (see spec for meaning).
579
      */
580
581
   OMX_ERRORTYPE (*EventHandler)(
582
        OMX_IN OMX_HANDLETYPE hComponent,
583
        OMX_IN OMX_PTR pAppData,
584
        OMX_IN OMX_EVENTTYPE eEvent,
585
        OMX_IN OMX_U32 nData1,
586
        OMX_IN OMX_U32 nData2,
587
        OMX_IN OMX_PTR pEventData);
588
589
    /** The EmptyBufferDone method is used to return emptied buffers from an
590
        input port back to the application for reuse.  This is a blocking call
591
        so the application should not attempt to refill the buffers during this
592
        call, but should queue them and refill them in another thread.  There
593
        is no error return, so the application shall handle any errors generated
594
        internally.
595
596
        The application should return from this call within 5 msec.
597
598
        @param hComponent
599
            handle of the component to access.  This is the component
600
            handle returned by the call to the GetHandle function.
601
        @param pAppData
602
            pointer to an application defined value that was provided in the
603
            pAppData parameter to the OMX_GetHandle method for the component.
604
            This application defined value is provided so that the application
605
            can have a component specific context when receiving the callback.
606
        @param pBuffer
607
            pointer to an OMX_BUFFERHEADERTYPE structure allocated with UseBuffer
608
            or AllocateBuffer indicating the buffer that was emptied.
609
        @ingroup buf
610
     */
611
    OMX_ERRORTYPE (*EmptyBufferDone)(
612
        OMX_IN OMX_HANDLETYPE hComponent,
613
        OMX_IN OMX_PTR pAppData,
614
        OMX_IN OMX_BUFFERHEADERTYPE* pBuffer);
615
616
    /** The FillBufferDone method is used to return filled buffers from an
617
        output port back to the application for emptying and then reuse.
618
        This is a blocking call so the application should not attempt to
619
        empty the buffers during this call, but should queue the buffers
620
        and empty them in another thread.  There is no error return, so
621
        the application shall handle any errors generated internally.  The
622
        application shall also update the buffer header to indicate the
623
        number of bytes placed into the buffer.
624
625
        The application should return from this call within 5 msec.
626
627
        @param hComponent
628
            handle of the component to access.  This is the component
629
            handle returned by the call to the GetHandle function.
630
        @param pAppData
631
            pointer to an application defined value that was provided in the
632
            pAppData parameter to the OMX_GetHandle method for the component.
633
            This application defined value is provided so that the application
634
            can have a component specific context when receiving the callback.
635
        @param pBuffer
636
            pointer to an OMX_BUFFERHEADERTYPE structure allocated with UseBuffer
637
            or AllocateBuffer indicating the buffer that was filled.
638
        @ingroup buf
639
     */
640
    OMX_ERRORTYPE (*FillBufferDone)(
641
        OMX_OUT OMX_HANDLETYPE hComponent,
642
        OMX_OUT OMX_PTR pAppData,
643
        OMX_OUT OMX_BUFFERHEADERTYPE* pBuffer);
644
645
} OMX_CALLBACKTYPE;
646
647
/** The OMX_BUFFERSUPPLIERTYPE enumeration is used to dictate port supplier
648
    preference when tunneling between two ports.
649
    @ingroup tun buf
650
*/
651
typedef enum OMX_BUFFERSUPPLIERTYPE
652
{
653
    OMX_BufferSupplyUnspecified = 0x0, /**< port supplying the buffers is unspecified,
654
                                              or don't care */
655
    OMX_BufferSupplyInput,             /**< input port supplies the buffers */
656
    OMX_BufferSupplyOutput,            /**< output port supplies the buffers */
657
    OMX_BufferSupplyKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
658
    OMX_BufferSupplyVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
659
    OMX_BufferSupplyMax = 0x7FFFFFFF
660
} OMX_BUFFERSUPPLIERTYPE;
661
662
663
/** buffer supplier parameter
664
 * @ingroup tun
665
 */
666
typedef struct OMX_PARAM_BUFFERSUPPLIERTYPE {
667
    OMX_U32 nSize; /**< size of the structure in bytes */
668
    OMX_VERSIONTYPE nVersion; /**< OMX specification version information */
669
    OMX_U32 nPortIndex; /**< port that this structure applies to */
670
    OMX_BUFFERSUPPLIERTYPE eBufferSupplier; /**< buffer supplier */
671
} OMX_PARAM_BUFFERSUPPLIERTYPE;
672
673
674
/**< indicates that buffers received by an input port of a tunnel
675
     may not modify the data in the buffers
676
     @ingroup tun
677
 */
678
#define OMX_PORTTUNNELFLAG_READONLY 0x00000001
679
680
681
/** The OMX_TUNNELSETUPTYPE structure is used to pass data from an output
682
    port to an input port as part the two ComponentTunnelRequest calls
683
    resulting from a OMX_SetupTunnel call from the IL Client.
684
    @ingroup tun
685
 */
686
typedef struct OMX_TUNNELSETUPTYPE
687
{
688
    OMX_U32 nTunnelFlags;             /**< bit flags for tunneling */
689
    OMX_BUFFERSUPPLIERTYPE eSupplier; /**< supplier preference */
690
} OMX_TUNNELSETUPTYPE;
691
692
/* OMX Component headers is included to enable the core to use
693
   macros for functions into the component for OMX release 1.0.
694
   Developers should not access any structures or data from within
695
   the component header directly */
696
/* TO BE REMOVED - #include <OMX_Component.h> */
697
698
/** GetComponentVersion will return information about the component.
699
    This is a blocking call.  This macro will go directly from the
700
    application to the component (via a core macro).  The
701
    component will return from this call within 5 msec.
702
    @param [in] hComponent
703
        handle of component to execute the command
704
    @param [out] pComponentName
705
        pointer to an empty string of length 128 bytes.  The component
706
        will write its name into this string.  The name will be
707
        terminated by a single zero byte.  The name of a component will
708
        be 127 bytes or less to leave room for the trailing zero byte.
709
        An example of a valid component name is "OMX.ABC.ChannelMixer\0".
710
    @param [out] pComponentVersion
711
        pointer to an OMX Version structure that the component will fill
712
        in.  The component will fill in a value that indicates the
713
        component version.  NOTE: the component version is NOT the same
714
        as the OMX Specification version (found in all structures).  The
715
        component version is defined by the vendor of the component and
716
        its value is entirely up to the component vendor.
717
    @param [out] pSpecVersion
718
        pointer to an OMX Version structure that the component will fill
719
        in.  The SpecVersion is the version of the specification that the
720
        component was built against.  Please note that this value may or
721
        may not match the structure's version.  For example, if the
722
        component was built against the 2.0 specification, but the
723
        application (which creates the structure is built against the
724
        1.0 specification the versions would be different.
725
    @param [out] pComponentUUID
726
        pointer to the UUID of the component which will be filled in by
727
        the component.  The UUID is a unique identifier that is set at
728
        RUN time for the component and is unique to each instantion of
729
        the component.
730
    @return OMX_ERRORTYPE
731
        If the command successfully executes, the return code will be
732
        OMX_ErrorNone.  Otherwise the appropriate OMX error will be returned.
733
    @ingroup comp
734
 */
735
#define OMX_GetComponentVersion(                            \
736
        hComponent,                                         \
737
        pComponentName,                                     \
738
        pComponentVersion,                                  \
739
        pSpecVersion,                                       \
740
        pComponentUUID)                                     \
741
    ((OMX_COMPONENTTYPE*)(hComponent))->GetComponentVersion(\
742
        hComponent,                                         \
743
        pComponentName,                                     \
744
        pComponentVersion,                                  \
745
        pSpecVersion,                                       \
746
        pComponentUUID)                 /* Macro End */
747
748
749
/** Send a command to the component.  This call is a non-blocking call.
750
    The component should check the parameters and then queue the command
751
    to the component thread to be executed.  The component thread shall
752
    send the EventHandler() callback at the conclusion of the command.
753
    This macro will go directly from the application to the component (via
754
    a core macro).  The component will return from this call within 5 msec.
755
756
    When the command is "OMX_CommandStateSet" the component will queue a
757
    state transition to the new state idenfied in nParam.
758
759
    The component shall transition from executing to loaded state within 500 msec.
760
761
    When the command is "OMX_CommandFlush", to flush a port's buffer queues,
762
    the command will force the component to return all buffers NOT CURRENTLY
763
    BEING PROCESSED to the application, in the order in which the buffers
764
    were received.
765
766
    The component shall finish flusing each port within 5 msec.
767
768
    When the command is "OMX_CommandPortDisable" or
769
    "OMX_CommandPortEnable", the component's port (given by the value of
770
    nParam) will be stopped or restarted.
771
772
    The component shall finish disabling/reenabling each port within 5 msec.
773
774
    When the command "OMX_CommandMarkBuffer" is used to mark a buffer, the
775
    pCmdData will point to a OMX_MARKTYPE structure containing the component
776
    handle of the component to examine the buffer chain for the mark.  nParam1
777
    contains the index of the port on which the buffer mark is applied.
778
779
    Specification text for more details.
780
781
    @param [in] hComponent
782
        handle of component to execute the command
783
    @param [in] Cmd
784
        Command for the component to execute
785
    @param [in] nParam
786
        Parameter for the command to be executed.  When Cmd has the value
787
        OMX_CommandStateSet, value is a member of OMX_STATETYPE.  When Cmd has
788
        the value OMX_CommandFlush, value of nParam indicates which port(s)
789
        to flush. -1 is used to flush all ports a single port index will
790
        only flush that port.  When Cmd has the value "OMX_CommandPortDisable"
791
        or "OMX_CommandPortEnable", the component's port is given by
792
        the value of nParam.  When Cmd has the value "OMX_CommandMarkBuffer"
793
        the components pot is given by the value of nParam.
794
    @param [in] pCmdData
795
        Parameter pointing to the OMX_MARKTYPE structure when Cmd has the value
796
        "OMX_CommandMarkBuffer".
797
    @return OMX_ERRORTYPE
798
        If the command successfully executes, the return code will be
799
        OMX_ErrorNone.  Otherwise the appropriate OMX error will be returned.
800
    @ingroup comp
801
 */
802
#define OMX_SendCommand(                                    \
803
         hComponent,                                        \
804
         Cmd,                                               \
805
         nParam,                                            \
806
         pCmdData)                                          \
807
     ((OMX_COMPONENTTYPE*)(hComponent))->SendCommand(       \
808
         hComponent,                                        \
809
         Cmd,                                               \
810
         nParam,                                            \
811
         pCmdData)                          /* Macro End */
812
813
814
/** The OMX_GetParameter macro will get one of the current parameter
815
    settings from the component.  This macro cannot only be invoked when
816
    the component is in the OMX_StateInvalid state.  The nParamIndex
817
    parameter is used to indicate which structure is being requested from
818
    the component.  The application shall allocate the correct structure
819
    and shall fill in the structure size and version information before
820
    invoking this macro.  When the parameter applies to a port, the
821
    caller shall fill in the appropriate nPortIndex value indicating the
822
    port on which the parameter applies. If the component has not had
823
    any settings changed, then the component should return a set of
824
    valid DEFAULT  parameters for the component.  This is a blocking
825
    call.
826
827
    The component should return from this call within 20 msec.
828
829
    @param [in] hComponent
830
        Handle of the component to be accessed.  This is the component
831
        handle returned by the call to the OMX_GetHandle function.
832
    @param [in] nParamIndex
833
        Index of the structure to be filled.  This value is from the
834
        OMX_INDEXTYPE enumeration.
835
    @param [in,out] pComponentParameterStructure
836
        Pointer to application allocated structure to be filled by the
837
        component.
838
    @return OMX_ERRORTYPE
839
        If the command successfully executes, the return code will be
840
        OMX_ErrorNone.  Otherwise the appropriate OMX error will be returned.
841
    @ingroup comp
842
 */
843
#define OMX_GetParameter(                                   \
844
        hComponent,                                         \
845
        nParamIndex,                                        \
846
        pComponentParameterStructure)                       \
847
    ((OMX_COMPONENTTYPE*)(hComponent))->GetParameter(       \
848
        hComponent,                                         \
849
        nParamIndex,                                        \
850
        pComponentParameterStructure)    /* Macro End */
851
852
853
/** The OMX_SetParameter macro will send an initialization parameter
854
    structure to a component.  Each structure shall be sent one at a time,
855
    in a separate invocation of the macro.  This macro can only be
856
    invoked when the component is in the OMX_StateLoaded state, or the
857
    port is disabled (when the parameter applies to a port). The
858
    nParamIndex parameter is used to indicate which structure is being
859
    passed to the component.  The application shall allocate the
860
    correct structure and shall fill in the structure size and version
861
    information (as well as the actual data) before invoking this macro.
862
    The application is free to dispose of this structure after the call
863
    as the component is required to copy any data it shall retain.  This
864
    is a blocking call.
865
866
    The component should return from this call within 20 msec.
867
868
    @param [in] hComponent
869
        Handle of the component to be accessed.  This is the component
870
        handle returned by the call to the OMX_GetHandle function.
871
    @param [in] nIndex
872
        Index of the structure to be sent.  This value is from the
873
        OMX_INDEXTYPE enumeration.
874
    @param [in] pComponentParameterStructure
875
        pointer to application allocated structure to be used for
876
        initialization by the component.
877
    @return OMX_ERRORTYPE
878
        If the command successfully executes, the return code will be
879
        OMX_ErrorNone.  Otherwise the appropriate OMX error will be returned.
880
    @ingroup comp
881
 */
882
#define OMX_SetParameter(                                   \
883
        hComponent,                                         \
884
        nParamIndex,                                        \
885
        pComponentParameterStructure)                       \
886
    ((OMX_COMPONENTTYPE*)(hComponent))->SetParameter(       \
887
        hComponent,                                         \
888
        nParamIndex,                                        \
889
        pComponentParameterStructure)    /* Macro End */
890
891
892
/** The OMX_GetConfig macro will get one of the configuration structures
893
    from a component.  This macro can be invoked anytime after the
894
    component has been loaded.  The nParamIndex call parameter is used to
895
    indicate which structure is being requested from the component.  The
896
    application shall allocate the correct structure and shall fill in the
897
    structure size and version information before invoking this macro.
898
    If the component has not had this configuration parameter sent before,
899
    then the component should return a set of valid DEFAULT values for the
900
    component.  This is a blocking call.
901
902
    The component should return from this call within 5 msec.
903
904
    @param [in] hComponent
905
        Handle of the component to be accessed.  This is the component
906
        handle returned by the call to the OMX_GetHandle function.
907
    @param [in] nIndex
908
        Index of the structure to be filled.  This value is from the
909
        OMX_INDEXTYPE enumeration.
910
    @param [in,out] pComponentConfigStructure
911
        pointer to application allocated structure to be filled by the
912
        component.
913
    @return OMX_ERRORTYPE
914
        If the command successfully executes, the return code will be
915
        OMX_ErrorNone.  Otherwise the appropriate OMX error will be returned.
916
    @ingroup comp
917
*/
918
#define OMX_GetConfig(                                      \
919
        hComponent,                                         \
920
        nConfigIndex,                                       \
921
        pComponentConfigStructure)                          \
922
    ((OMX_COMPONENTTYPE*)(hComponent))->GetConfig(          \
923
        hComponent,                                         \
924
        nConfigIndex,                                       \
925
        pComponentConfigStructure)       /* Macro End */
926
927
928
/** The OMX_SetConfig macro will send one of the configuration
929
    structures to a component.  Each structure shall be sent one at a time,
930
    each in a separate invocation of the macro.  This macro can be invoked
931
    anytime after the component has been loaded.  The application shall
932
    allocate the correct structure and shall fill in the structure size
933
    and version information (as well as the actual data) before invoking
934
    this macro.  The application is free to dispose of this structure after
935
    the call as the component is required to copy any data it shall retain.
936
    This is a blocking call.
937
938
    The component should return from this call within 5 msec.
939
940
    @param [in] hComponent
941
        Handle of the component to be accessed.  This is the component
942
        handle returned by the call to the OMX_GetHandle function.
943
    @param [in] nConfigIndex
944
        Index of the structure to be sent.  This value is from the
945
        OMX_INDEXTYPE enumeration above.
946
    @param [in] pComponentConfigStructure
947
        pointer to application allocated structure to be used for
948
        initialization by the component.
949
    @return OMX_ERRORTYPE
950
        If the command successfully executes, the return code will be
951
        OMX_ErrorNone.  Otherwise the appropriate OMX error will be returned.
952
    @ingroup comp
953
 */
954
#define OMX_SetConfig(                                      \
955
        hComponent,                                         \
956
        nConfigIndex,                                       \
957
        pComponentConfigStructure)                          \
958
    ((OMX_COMPONENTTYPE*)(hComponent))->SetConfig(          \
959
        hComponent,                                         \
960
        nConfigIndex,                                       \
961
        pComponentConfigStructure)       /* Macro End */
962
963
964
/** The OMX_GetExtensionIndex macro will invoke a component to translate
965
    a vendor specific configuration or parameter string into an OMX
966
    structure index.  There is no requirement for the vendor to support
967
    this command for the indexes already found in the OMX_INDEXTYPE
968
    enumeration (this is done to save space in small components).  The
969
    component shall support all vendor supplied extension indexes not found
970
    in the master OMX_INDEXTYPE enumeration.  This is a blocking call.
971
972
    The component should return from this call within 5 msec.
973
974
    @param [in] hComponent
975
        Handle of the component to be accessed.  This is the component
976
        handle returned by the call to the GetHandle function.
977
    @param [in] cParameterName
978
        OMX_STRING that shall be less than 128 characters long including
979
        the trailing null byte.  This is the string that will get
980
        translated by the component into a configuration index.
981
    @param [out] pIndexType
982
        a pointer to a OMX_INDEXTYPE to receive the index value.
983
    @return OMX_ERRORTYPE
984
        If the command successfully executes, the return code will be
985
        OMX_ErrorNone.  Otherwise the appropriate OMX error will be returned.
986
    @ingroup comp
987
 */
988
#define OMX_GetExtensionIndex(                              \
989
        hComponent,                                         \
990
        cParameterName,                                     \
991
        pIndexType)                                         \
992
    ((OMX_COMPONENTTYPE*)(hComponent))->GetExtensionIndex(  \
993
        hComponent,                                         \
994
        cParameterName,                                     \
995
        pIndexType)                     /* Macro End */
996
997
998
/** The OMX_GetState macro will invoke the component to get the current
999
    state of the component and place the state value into the location
1000
    pointed to by pState.
1001
1002
    The component should return from this call within 5 msec.
1003
1004
    @param [in] hComponent
1005
        Handle of the component to be accessed.  This is the component
1006
        handle returned by the call to the OMX_GetHandle function.
1007
    @param [out] pState
1008
        pointer to the location to receive the state.  The value returned
1009
        is one of the OMX_STATETYPE members
1010
    @return OMX_ERRORTYPE
1011
        If the command successfully executes, the return code will be
1012
        OMX_ErrorNone.  Otherwise the appropriate OMX error will be returned.
1013
    @ingroup comp
1014
 */
1015
#define OMX_GetState(                                       \
1016
        hComponent,                                         \
1017
        pState)                                             \
1018
    ((OMX_COMPONENTTYPE*)(hComponent))->GetState(           \
1019
        hComponent,                                         \
1020
        pState)                         /* Macro End */
1021
1022
1023
/** The OMX_UseBuffer macro will request that the component use
1024
    a buffer (and allocate its own buffer header) already allocated
1025
    by another component, or by the IL Client. This is a blocking
1026
    call.
1027
1028
    The component should return from this call within 20 msec.
1029
1030
    @param [in] hComponent
1031
        Handle of the component to be accessed.  This is the component
1032
        handle returned by the call to the OMX_GetHandle function.
1033
    @param [out] ppBuffer
1034
        pointer to an OMX_BUFFERHEADERTYPE structure used to receive the
1035
        pointer to the buffer header
1036
    @return OMX_ERRORTYPE
1037
        If the command successfully executes, the return code will be
1038
        OMX_ErrorNone.  Otherwise the appropriate OMX error will be returned.
1039
    @ingroup comp buf
1040
 */
1041
1042
#define OMX_UseBuffer(                                      \
1043
           hComponent,                                      \
1044
           ppBufferHdr,                                     \
1045
           nPortIndex,                                      \
1046
           pAppPrivate,                                     \
1047
           nSizeBytes,                                      \
1048
           pBuffer)                                         \
1049
    ((OMX_COMPONENTTYPE*)(hComponent))->UseBuffer(          \
1050
           hComponent,                                      \
1051
           ppBufferHdr,                                     \
1052
           nPortIndex,                                      \
1053
           pAppPrivate,                                     \
1054
           nSizeBytes,                                      \
1055
           pBuffer)
1056
1057
1058
/** The OMX_AllocateBuffer macro will request that the component allocate
1059
    a new buffer and buffer header.  The component will allocate the
1060
    buffer and the buffer header and return a pointer to the buffer
1061
    header.  This is a blocking call.
1062
1063
    The component should return from this call within 5 msec.
1064
1065
    @param [in] hComponent
1066
        Handle of the component to be accessed.  This is the component
1067
        handle returned by the call to the OMX_GetHandle function.
1068
    @param [out] ppBuffer
1069
        pointer to an OMX_BUFFERHEADERTYPE structure used to receive
1070
        the pointer to the buffer header
1071
    @param [in] nPortIndex
1072
        nPortIndex is used to select the port on the component the buffer will
1073
        be used with.  The port can be found by using the nPortIndex
1074
        value as an index into the Port Definition array of the component.
1075
    @param [in] pAppPrivate
1076
        pAppPrivate is used to initialize the pAppPrivate member of the
1077
        buffer header structure.
1078
    @param [in] nSizeBytes
1079
        size of the buffer to allocate.  Used when bAllocateNew is true.
1080
    @return OMX_ERRORTYPE
1081
        If the command successfully executes, the return code will be
1082
        OMX_ErrorNone.  Otherwise the appropriate OMX error will be returned.
1083
    @ingroup comp buf
1084
 */
1085
#define OMX_AllocateBuffer(                                 \
1086
        hComponent,                                         \
1087
        ppBuffer,                                           \
1088
        nPortIndex,                                         \
1089
        pAppPrivate,                                        \
1090
        nSizeBytes)                                         \
1091
    ((OMX_COMPONENTTYPE*)(hComponent))->AllocateBuffer(     \
1092
        hComponent,                                         \
1093
        ppBuffer,                                           \
1094
        nPortIndex,                                         \
1095
        pAppPrivate,                                        \
1096
        nSizeBytes)                     /* Macro End */
1097
1098
1099
/** The OMX_FreeBuffer macro will release a buffer header from the component
1100
    which was allocated using either OMX_AllocateBuffer or OMX_UseBuffer. If
1101
    the component allocated the buffer (see the OMX_UseBuffer macro) then
1102
    the component shall free the buffer and buffer header. This is a
1103
    blocking call.
1104
1105
    The component should return from this call within 20 msec.
1106
1107
    @param [in] hComponent
1108
        Handle of the component to be accessed.  This is the component
1109
        handle returned by the call to the OMX_GetHandle function.
1110
    @param [in] nPortIndex
1111
        nPortIndex is used to select the port on the component the buffer will
1112
        be used with.
1113
    @param [in] pBuffer
1114
        pointer to an OMX_BUFFERHEADERTYPE structure allocated with UseBuffer
1115
        or AllocateBuffer.
1116
    @return OMX_ERRORTYPE
1117
        If the command successfully executes, the return code will be
1118
        OMX_ErrorNone.  Otherwise the appropriate OMX error will be returned.
1119
    @ingroup comp buf
1120
 */
1121
#define OMX_FreeBuffer(                                     \
1122
        hComponent,                                         \
1123
        nPortIndex,                                         \
1124
        pBuffer)                                            \
1125
    ((OMX_COMPONENTTYPE*)(hComponent))->FreeBuffer(         \
1126
        hComponent,                                         \
1127
        nPortIndex,                                         \
1128
        pBuffer)                        /* Macro End */
1129
1130
1131
/** The OMX_EmptyThisBuffer macro will send a buffer full of data to an
1132
    input port of a component.  The buffer will be emptied by the component
1133
    and returned to the application via the EmptyBufferDone call back.
1134
    This is a non-blocking call in that the component will record the buffer
1135
    and return immediately and then empty the buffer, later, at the proper
1136
    time.  As expected, this macro may be invoked only while the component
1137
    is in the OMX_StateExecuting.  If nPortIndex does not specify an input
1138
    port, the component shall return an error.
1139
1140
    The component should return from this call within 5 msec.
1141
1142
    @param [in] hComponent
1143
        Handle of the component to be accessed.  This is the component
1144
        handle returned by the call to the OMX_GetHandle function.
1145
    @param [in] pBuffer
1146
        pointer to an OMX_BUFFERHEADERTYPE structure allocated with UseBuffer
1147
        or AllocateBuffer.
1148
    @return OMX_ERRORTYPE
1149
        If the command successfully executes, the return code will be
1150
        OMX_ErrorNone.  Otherwise the appropriate OMX error will be returned.
1151
    @ingroup comp buf
1152
 */
1153
#define OMX_EmptyThisBuffer(                                \
1154
        hComponent,                                         \
1155
        pBuffer)                                            \
1156
    ((OMX_COMPONENTTYPE*)(hComponent))->EmptyThisBuffer(    \
1157
        hComponent,                                         \
1158
        pBuffer)                        /* Macro End */
1159
1160
1161
/** The OMX_FillThisBuffer macro will send an empty buffer to an
1162
    output port of a component.  The buffer will be filled by the component
1163
    and returned to the application via the FillBufferDone call back.
1164
    This is a non-blocking call in that the component will record the buffer
1165
    and return immediately and then fill the buffer, later, at the proper
1166
    time.  As expected, this macro may be invoked only while the component
1167
    is in the OMX_ExecutingState.  If nPortIndex does not specify an output
1168
    port, the component shall return an error.
1169
1170
    The component should return from this call within 5 msec.
1171
1172
    @param [in] hComponent
1173
        Handle of the component to be accessed.  This is the component
1174
        handle returned by the call to the OMX_GetHandle function.
1175
    @param [in] pBuffer
1176
        pointer to an OMX_BUFFERHEADERTYPE structure allocated with UseBuffer
1177
        or AllocateBuffer.
1178
    @return OMX_ERRORTYPE
1179
        If the command successfully executes, the return code will be
1180
        OMX_ErrorNone.  Otherwise the appropriate OMX error will be returned.
1181
    @ingroup comp buf
1182
 */
1183
#define OMX_FillThisBuffer(                                 \
1184
        hComponent,                                         \
1185
        pBuffer)                                            \
1186
    ((OMX_COMPONENTTYPE*)(hComponent))->FillThisBuffer(     \
1187
        hComponent,                                         \
1188
        pBuffer)                        /* Macro End */
1189
1190
1191
1192
/** The OMX_UseEGLImage macro will request that the component use
1193
    a EGLImage provided by EGL (and allocate its own buffer header)
1194
    This is a blocking call.
1195
1196
    The component should return from this call within 20 msec.
1197
1198
    @param [in] hComponent
1199
        Handle of the component to be accessed.  This is the component
1200
        handle returned by the call to the OMX_GetHandle function.
1201
    @param [out] ppBuffer
1202
        pointer to an OMX_BUFFERHEADERTYPE structure used to receive the
1203
        pointer to the buffer header.  Note that the memory location used
1204
        for this buffer is NOT visible to the IL Client.
1205
    @param [in] nPortIndex
1206
        nPortIndex is used to select the port on the component the buffer will
1207
        be used with.  The port can be found by using the nPortIndex
1208
        value as an index into the Port Definition array of the component.
1209
    @param [in] pAppPrivate
1210
        pAppPrivate is used to initialize the pAppPrivate member of the
1211
        buffer header structure.
1212
    @param [in] eglImage
1213
        eglImage contains the handle of the EGLImage to use as a buffer on the
1214
        specified port.  The component is expected to validate properties of
1215
        the EGLImage against the configuration of the port to ensure the component
1216
        can use the EGLImage as a buffer.
1217
    @return OMX_ERRORTYPE
1218
        If the command successfully executes, the return code will be
1219
        OMX_ErrorNone.  Otherwise the appropriate OMX error will be returned.
1220
    @ingroup comp buf
1221
 */
1222
#define OMX_UseEGLImage(                                    \
1223
           hComponent,                                      \
1224
           ppBufferHdr,                                     \
1225
           nPortIndex,                                      \
1226
           pAppPrivate,                                     \
1227
           eglImage)                                        \
1228
    ((OMX_COMPONENTTYPE*)(hComponent))->UseEGLImage(        \
1229
           hComponent,                                      \
1230
           ppBufferHdr,                                     \
1231
           nPortIndex,                                      \
1232
           pAppPrivate,                                     \
1233
           eglImage)
1234
1235
/** The OMX_Init method is used to initialize the OMX core.  It shall be the
1236
    first call made into OMX and it should only be executed one time without
1237
    an interviening OMX_Deinit call.
1238
1239
    The core should return from this call within 20 msec.
1240
1241
    @return OMX_ERRORTYPE
1242
        If the command successfully executes, the return code will be
1243
        OMX_ErrorNone.  Otherwise the appropriate OMX error will be returned.
1244
    @ingroup core
1245
 */
1246
OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_Init(void);
1247
1248
1249
/** The OMX_Deinit method is used to deinitialize the OMX core.  It shall be
1250
    the last call made into OMX. In the event that the core determines that
1251
    thare are components loaded when this call is made, the core may return
1252
    with an error rather than try to unload the components.
1253
1254
    The core should return from this call within 20 msec.
1255
1256
    @return OMX_ERRORTYPE
1257
        If the command successfully executes, the return code will be
1258
        OMX_ErrorNone.  Otherwise the appropriate OMX error will be returned.
1259
    @ingroup core
1260
 */
1261
OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_Deinit(void);
1262
1263
1264
/** The OMX_ComponentNameEnum method will enumerate through all the names of
1265
    recognised valid components in the system. This function is provided
1266
    as a means to detect all the components in the system run-time. There is
1267
    no strict ordering to the enumeration order of component names, although
1268
    each name will only be enumerated once.  If the OMX core supports run-time
1269
    installation of new components, it is only requried to detect newly
1270
    installed components when the first call to enumerate component names
1271
    is made (i.e. when nIndex is 0x0).
1272
1273
    The core should return from this call in 20 msec.
1274
1275
    @param [out] cComponentName
1276
        pointer to a null terminated string with the component name.  The
1277
        names of the components are strings less than 127 bytes in length
1278
        plus the trailing null for a maximum size of 128 bytes.  An example
1279
        of a valid component name is "OMX.TI.AUDIO.DSP.MIXER\0".  Names are
1280
        assigned by the vendor, but shall start with "OMX." and then have
1281
        the Vendor designation next.
1282
    @param [in] nNameLength
1283
        number of characters in the cComponentName string.  With all
1284
        component name strings restricted to less than 128 characters
1285
        (including the trailing null) it is recomended that the caller
1286
        provide a input string for the cComponentName of 128 characters.
1287
    @param [in] nIndex
1288
        number containing the enumeration index for the component.
1289
        Multiple calls to OMX_ComponentNameEnum with increasing values
1290
        of nIndex will enumerate through the component names in the
1291
        system until OMX_ErrorNoMore is returned.  The value of nIndex
1292
        is 0 to (N-1), where N is the number of valid installed components
1293
        in the system.
1294
    @return OMX_ERRORTYPE
1295
        If the command successfully executes, the return code will be
1296
        OMX_ErrorNone.  When the value of nIndex exceeds the number of
1297
        components in the system minus 1, OMX_ErrorNoMore will be
1298
        returned. Otherwise the appropriate OMX error will be returned.
1299
    @ingroup core
1300
 */
1301
OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_ComponentNameEnum(
1302
    OMX_OUT OMX_STRING cComponentName,
1303
    OMX_IN  OMX_U32 nNameLength,
1304
    OMX_IN  OMX_U32 nIndex);
1305
1306
1307
/** The OMX_GetHandle method will locate the component specified by the
1308
    component name given, load that component into memory and then invoke
1309
    the component's methods to create an instance of the component.
1310
1311
    The core should return from this call within 20 msec.
1312
1313
    @param [out] pHandle
1314
        pointer to an OMX_HANDLETYPE pointer to be filled in by this method.
1315
    @param [in] cComponentName
1316
        pointer to a null terminated string with the component name.  The
1317
        names of the components are strings less than 127 bytes in length
1318
        plus the trailing null for a maximum size of 128 bytes.  An example
1319
        of a valid component name is "OMX.TI.AUDIO.DSP.MIXER\0".  Names are
1320
        assigned by the vendor, but shall start with "OMX." and then have
1321
        the Vendor designation next.
1322
    @param [in] pAppData
1323
        pointer to an application defined value that will be returned
1324
        during callbacks so that the application can identify the source
1325
        of the callback.
1326
    @param [in] pCallBacks
1327
        pointer to a OMX_CALLBACKTYPE structure that will be passed to the
1328
        component to initialize it with.
1329
    @return OMX_ERRORTYPE
1330
        If the command successfully executes, the return code will be
1331
        OMX_ErrorNone.  Otherwise the appropriate OMX error will be returned.
1332
    @ingroup core
1333
 */
1334
OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_GetHandle(
1335
    OMX_OUT OMX_HANDLETYPE* pHandle,
1336
    OMX_IN  OMX_STRING cComponentName,
1337
    OMX_IN  OMX_PTR pAppData,
1338
    OMX_IN  OMX_CALLBACKTYPE* pCallBacks);
1339
1340
1341
/** The OMX_FreeHandle method will free a handle allocated by the OMX_GetHandle
1342
    method.  If the component reference count goes to zero, the component will
1343
    be unloaded from memory.
1344
1345
    The core should return from this call within 20 msec when the component is
1346
    in the OMX_StateLoaded state.
1347
1348
    @param [in] hComponent
1349
        Handle of the component to be accessed.  This is the component
1350
        handle returned by the call to the GetHandle function.
1351
    @return OMX_ERRORTYPE
1352
        If the command successfully executes, the return code will be
1353
        OMX_ErrorNone.  Otherwise the appropriate OMX error will be returned.
1354
    @ingroup core
1355
 */
1356
OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_FreeHandle(
1357
    OMX_IN  OMX_HANDLETYPE hComponent);
1358
1359
1360
1361
/** The OMX_SetupTunnel method will handle the necessary calls to the components
1362
    to setup the specified tunnel the two components.  NOTE: This is
1363
    an actual method (not a #define macro).  This method will make calls into
1364
    the component ComponentTunnelRequest method to do the actual tunnel
1365
    connection.
1366
1367
    The ComponentTunnelRequest method on both components will be called.
1368
    This method shall not be called unless the component is in the
1369
    OMX_StateLoaded state except when the ports used for the tunnel are
1370
    disabled. In this case, the component may be in the OMX_StateExecuting,
1371
    OMX_StatePause, or OMX_StateIdle states.
1372
1373
    The core should return from this call within 20 msec.
1374
1375
    @param [in] hOutput
1376
        Handle of the component to be accessed.  Also this is the handle
1377
        of the component whose port, specified in the nPortOutput parameter
1378
        will be used the source for the tunnel. This is the component handle
1379
        returned by the call to the OMX_GetHandle function.  There is a
1380
        requirement that hOutput be the source for the data when
1381
        tunelling (i.e. nPortOutput is an output port).  If 0x0, the component
1382
        specified in hInput will have it's port specified in nPortInput
1383
        setup for communication with the application / IL client.
1384
    @param [in] nPortOutput
1385
        nPortOutput is used to select the source port on component to be
1386
        used in the tunnel.
1387
    @param [in] hInput
1388
        This is the component to setup the tunnel with. This is the handle
1389
        of the component whose port, specified in the nPortInput parameter
1390
        will be used the destination for the tunnel. This is the component handle
1391
        returned by the call to the OMX_GetHandle function.  There is a
1392
        requirement that hInput be the destination for the data when
1393
        tunelling (i.e. nPortInut is an input port).   If 0x0, the component
1394
        specified in hOutput will have it's port specified in nPortPOutput
1395
        setup for communication with the application / IL client.
1396
    @param [in] nPortInput
1397
        nPortInput is used to select the destination port on component to be
1398
        used in the tunnel.
1399
    @return OMX_ERRORTYPE
1400
        If the command successfully executes, the return code will be
1401
        OMX_ErrorNone.  Otherwise the appropriate OMX error will be returned.
1402
        When OMX_ErrorNotImplemented is returned, one or both components is
1403
        a non-interop component and does not support tunneling.
1404
1405
        On failure, the ports of both components are setup for communication
1406
        with the application / IL Client.
1407
    @ingroup core tun
1408
 */
1409
OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_SetupTunnel(
1410
    OMX_IN  OMX_HANDLETYPE hOutput,
1411
    OMX_IN  OMX_U32 nPortOutput,
1412
    OMX_IN  OMX_HANDLETYPE hInput,
1413
    OMX_IN  OMX_U32 nPortInput);
1414
1415
/** @ingroup cp */
1416
OMX_API OMX_ERRORTYPE   OMX_GetContentPipe(
1417
    OMX_OUT OMX_HANDLETYPE *hPipe,
1418
    OMX_IN OMX_STRING szURI);
1419
1420
/** The OMX_GetComponentsOfRole method will return the number of components that support the given
1421
    role and (if the compNames field is non-NULL) the names of those components. The call will fail if
1422
    an insufficiently sized array of names is supplied. To ensure the array is sufficiently sized the
1423
    client should:
1424
        * first call this function with the compNames field NULL to determine the number of component names
1425
        * second call this function with the compNames field pointing to an array of names allocated
1426
          according to the number returned by the first call.
1427
1428
    The core should return from this call within 5 msec.
1429
1430
    @param [in] role
1431
        This is generic standard component name consisting only of component class
1432
        name and the type within that class (e.g. 'audio_decoder.aac').
1433
    @param [inout] pNumComps
1434
        This is used both as input and output.
1435
1436
        If compNames is NULL, the input is ignored and the output specifies how many components support
1437
        the given role.
1438
1439
        If compNames is not NULL, on input it bounds the size of the input structure and
1440
        on output, it specifies the number of components string names listed within the compNames parameter.
1441
    @param [inout] compNames
1442
        If NULL this field is ignored. If non-NULL this points to an array of 128-byte strings which accepts
1443
        a list of the names of all physical components that implement the specified standard component name.
1444
        Each name is NULL terminated. numComps indicates the number of names.
1445
    @ingroup core
1446
 */
1447
OMX_API OMX_ERRORTYPE OMX_GetComponentsOfRole (
1448
    OMX_IN      OMX_STRING role,
1449
    OMX_INOUT   OMX_U32 *pNumComps,
1450
    OMX_INOUT   OMX_U8  **compNames);
1451
1452
/** The OMX_GetRolesOfComponent method will return the number of roles supported by the given
1453
    component and (if the roles field is non-NULL) the names of those roles. The call will fail if
1454
    an insufficiently sized array of names is supplied. To ensure the array is sufficiently sized the
1455
    client should:
1456
        * first call this function with the roles field NULL to determine the number of role names
1457
        * second call this function with the roles field pointing to an array of names allocated
1458
          according to the number returned by the first call.
1459
1460
    The core should return from this call within 5 msec.
1461
1462
    @param [in] compName
1463
        This is the name of the component being queried about.
1464
    @param [inout] pNumRoles
1465
        This is used both as input and output.
1466
1467
        If roles is NULL, the input is ignored and the output specifies how many roles the component supports.
1468
1469
        If compNames is not NULL, on input it bounds the size of the input structure and
1470
        on output, it specifies the number of roles string names listed within the roles parameter.
1471
    @param [out] roles
1472
        If NULL this field is ignored. If non-NULL this points to an array of 128-byte strings
1473
        which accepts a list of the names of all standard components roles implemented on the
1474
        specified component name. numComps indicates the number of names.
1475
    @ingroup core
1476
 */
1477
OMX_API OMX_ERRORTYPE OMX_GetRolesOfComponent (
1478
    OMX_IN      OMX_STRING compName,
1479
    OMX_INOUT   OMX_U32 *pNumRoles,
1480
    OMX_OUT     OMX_U8 **roles);
1481
1482
#ifdef __cplusplus
1483
}
1484
#endif /* __cplusplus */
1485
1486
#endif
1487
/* File EOF */
1488
/proc/self/cwd/frameworks/native/libs/binder/include/binder/Binder.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2008 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef ANDROID_BINDER_H
18
#define ANDROID_BINDER_H
19
20
#include <atomic>
21
#include <stdint.h>
22
#include <binder/IBinder.h>
23
24
// ---------------------------------------------------------------------------
25
namespace android {
26
27
class BBinder : public IBinder
28
{
29
public:
30
                        BBinder();
31
32
    virtual const String16& getInterfaceDescriptor() const;
33
    virtual bool        isBinderAlive() const;
34
    virtual status_t    pingBinder();
35
    virtual status_t    dump(int fd, const Vector<String16>& args);
36
37
    // NOLINTNEXTLINE(google-default-arguments)
38
    virtual status_t    transact(   uint32_t code,
39
                                    const Parcel& data,
40
                                    Parcel* reply,
41
                                    uint32_t flags = 0);
42
43
    // NOLINTNEXTLINE(google-default-arguments)
44
    virtual status_t    linkToDeath(const sp<DeathRecipient>& recipient,
45
                                    void* cookie = nullptr,
46
                                    uint32_t flags = 0);
47
48
    // NOLINTNEXTLINE(google-default-arguments)
49
    virtual status_t    unlinkToDeath(  const wp<DeathRecipient>& recipient,
50
                                        void* cookie = nullptr,
51
                                        uint32_t flags = 0,
52
                                        wp<DeathRecipient>* outRecipient = nullptr);
53
54
    virtual void        attachObject(   const void* objectID,
55
                                        void* object,
56
                                        void* cleanupCookie,
57
                                        object_cleanup_func func);
58
    virtual void*       findObject(const void* objectID) const;
59
    virtual void        detachObject(const void* objectID);
60
61
    virtual BBinder*    localBinder();
62
63
protected:
64
    virtual             ~BBinder();
65
66
    // NOLINTNEXTLINE(google-default-arguments)
67
    virtual status_t    onTransact( uint32_t code,
68
                                    const Parcel& data,
69
                                    Parcel* reply,
70
                                    uint32_t flags = 0);
71
72
private:
73
                        BBinder(const BBinder& o);
74
            BBinder&    operator=(const BBinder& o);
75
76
    class Extras;
77
78
    std::atomic<Extras*> mExtras;
79
            void*       mReserved0;
80
};
81
82
// ---------------------------------------------------------------------------
83
84
class BpRefBase : public virtual RefBase
85
{
86
protected:
87
    explicit                BpRefBase(const sp<IBinder>& o);
88
    virtual                 ~BpRefBase();
89
    virtual void            onFirstRef();
90
    virtual void            onLastStrongRef(const void* id);
91
    virtual bool            onIncStrongAttempted(uint32_t flags, const void* id);
92
93
0
    inline  IBinder*        remote()                { return mRemote; }
94
0
    inline  IBinder*        remote() const          { return mRemote; }
95
96
private:
97
                            BpRefBase(const BpRefBase& o);
98
    BpRefBase&              operator=(const BpRefBase& o);
99
100
    IBinder* const          mRemote;
101
    RefBase::weakref_type*  mRefs;
102
    std::atomic<int32_t>    mState;
103
};
104
105
}; // namespace android
106
107
// ---------------------------------------------------------------------------
108
109
#endif // ANDROID_BINDER_H
/proc/self/cwd/frameworks/native/libs/binder/include/binder/Parcel.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2005 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef ANDROID_PARCEL_H
18
#define ANDROID_PARCEL_H
19
20
#include <string>
21
#include <vector>
22
23
#include <android-base/unique_fd.h>
24
#include <cutils/native_handle.h>
25
#include <utils/Errors.h>
26
#include <utils/RefBase.h>
27
#include <utils/String16.h>
28
#include <utils/Vector.h>
29
#include <utils/Flattenable.h>
30
#include <linux/android/binder.h>
31
32
#include <binder/IInterface.h>
33
#include <binder/Parcelable.h>
34
#include <binder/Map.h>
35
36
// ---------------------------------------------------------------------------
37
namespace android {
38
39
template <typename T> class Flattenable;
40
template <typename T> class LightFlattenable;
41
class IBinder;
42
class IPCThreadState;
43
class ProcessState;
44
class String8;
45
class TextOutput;
46
47
namespace binder {
48
class Value;
49
};
50
51
class Parcel {
52
    friend class IPCThreadState;
53
public:
54
    class ReadableBlob;
55
    class WritableBlob;
56
57
                        Parcel();
58
                        ~Parcel();
59
    
60
    const uint8_t*      data() const;
61
    size_t              dataSize() const;
62
    size_t              dataAvail() const;
63
    size_t              dataPosition() const;
64
    size_t              dataCapacity() const;
65
66
    status_t            setDataSize(size_t size);
67
    void                setDataPosition(size_t pos) const;
68
    status_t            setDataCapacity(size_t size);
69
    
70
    status_t            setData(const uint8_t* buffer, size_t len);
71
72
    status_t            appendFrom(const Parcel *parcel,
73
                                   size_t start, size_t len);
74
75
    int                 compareData(const Parcel& other);
76
77
    bool                allowFds() const;
78
    bool                pushAllowFds(bool allowFds);
79
    void                restoreAllowFds(bool lastValue);
80
81
    bool                hasFileDescriptors() const;
82
83
    // Writes the RPC header.
84
    status_t            writeInterfaceToken(const String16& interface);
85
86
    // Parses the RPC header, returning true if the interface name
87
    // in the header matches the expected interface from the caller.
88
    //
89
    // Additionally, enforceInterface does part of the work of
90
    // propagating the StrictMode policy mask, populating the current
91
    // IPCThreadState, which as an optimization may optionally be
92
    // passed in.
93
    bool                enforceInterface(const String16& interface,
94
                                         IPCThreadState* threadState = nullptr) const;
95
    bool                checkInterface(IBinder*) const;
96
97
    void                freeData();
98
99
private:
100
    const binder_size_t* objects() const;
101
102
public:
103
    size_t              objectsCount() const;
104
    
105
    status_t            errorCheck() const;
106
    void                setError(status_t err);
107
    
108
    status_t            write(const void* data, size_t len);
109
    void*               writeInplace(size_t len);
110
    status_t            writeUnpadded(const void* data, size_t len);
111
    status_t            writeInt32(int32_t val);
112
    status_t            writeUint32(uint32_t val);
113
    status_t            writeInt64(int64_t val);
114
    status_t            writeUint64(uint64_t val);
115
    status_t            writeFloat(float val);
116
    status_t            writeDouble(double val);
117
    status_t            writeCString(const char* str);
118
    status_t            writeString8(const String8& str);
119
    status_t            writeString16(const String16& str);
120
    status_t            writeString16(const std::unique_ptr<String16>& str);
121
    status_t            writeString16(const char16_t* str, size_t len);
122
    status_t            writeStrongBinder(const sp<IBinder>& val);
123
    status_t            writeWeakBinder(const wp<IBinder>& val);
124
    status_t            writeInt32Array(size_t len, const int32_t *val);
125
    status_t            writeByteArray(size_t len, const uint8_t *val);
126
    status_t            writeBool(bool val);
127
    status_t            writeChar(char16_t val);
128
    status_t            writeByte(int8_t val);
129
130
    // Take a UTF8 encoded string, convert to UTF16, write it to the parcel.
131
    status_t            writeUtf8AsUtf16(const std::string& str);
132
    status_t            writeUtf8AsUtf16(const std::unique_ptr<std::string>& str);
133
134
    status_t            writeByteVector(const std::unique_ptr<std::vector<int8_t>>& val);
135
    status_t            writeByteVector(const std::vector<int8_t>& val);
136
    status_t            writeByteVector(const std::unique_ptr<std::vector<uint8_t>>& val);
137
    status_t            writeByteVector(const std::vector<uint8_t>& val);
138
    status_t            writeInt32Vector(const std::unique_ptr<std::vector<int32_t>>& val);
139
    status_t            writeInt32Vector(const std::vector<int32_t>& val);
140
    status_t            writeInt64Vector(const std::unique_ptr<std::vector<int64_t>>& val);
141
    status_t            writeInt64Vector(const std::vector<int64_t>& val);
142
    status_t            writeFloatVector(const std::unique_ptr<std::vector<float>>& val);
143
    status_t            writeFloatVector(const std::vector<float>& val);
144
    status_t            writeDoubleVector(const std::unique_ptr<std::vector<double>>& val);
145
    status_t            writeDoubleVector(const std::vector<double>& val);
146
    status_t            writeBoolVector(const std::unique_ptr<std::vector<bool>>& val);
147
    status_t            writeBoolVector(const std::vector<bool>& val);
148
    status_t            writeCharVector(const std::unique_ptr<std::vector<char16_t>>& val);
149
    status_t            writeCharVector(const std::vector<char16_t>& val);
150
    status_t            writeString16Vector(
151
                            const std::unique_ptr<std::vector<std::unique_ptr<String16>>>& val);
152
    status_t            writeString16Vector(const std::vector<String16>& val);
153
    status_t            writeUtf8VectorAsUtf16Vector(
154
                            const std::unique_ptr<std::vector<std::unique_ptr<std::string>>>& val);
155
    status_t            writeUtf8VectorAsUtf16Vector(const std::vector<std::string>& val);
156
157
    status_t            writeStrongBinderVector(const std::unique_ptr<std::vector<sp<IBinder>>>& val);
158
    status_t            writeStrongBinderVector(const std::vector<sp<IBinder>>& val);
159
160
    template<typename T>
161
    status_t            writeParcelableVector(const std::unique_ptr<std::vector<std::unique_ptr<T>>>& val);
162
    template<typename T>
163
    status_t            writeParcelableVector(const std::shared_ptr<std::vector<std::unique_ptr<T>>>& val);
164
    template<typename T>
165
    status_t            writeParcelableVector(const std::vector<T>& val);
166
167
    template<typename T>
168
    status_t            writeNullableParcelable(const std::unique_ptr<T>& parcelable);
169
170
    status_t            writeParcelable(const Parcelable& parcelable);
171
172
    status_t            writeValue(const binder::Value& value);
173
174
    template<typename T>
175
    status_t            write(const Flattenable<T>& val);
176
177
    template<typename T>
178
    status_t            write(const LightFlattenable<T>& val);
179
180
    template<typename T>
181
    status_t            writeVectorSize(const std::vector<T>& val);
182
    template<typename T>
183
    status_t            writeVectorSize(const std::unique_ptr<std::vector<T>>& val);
184
185
    status_t            writeMap(const binder::Map& map);
186
    status_t            writeNullableMap(const std::unique_ptr<binder::Map>& map);
187
188
    // Place a native_handle into the parcel (the native_handle's file-
189
    // descriptors are dup'ed, so it is safe to delete the native_handle
190
    // when this function returns).
191
    // Doesn't take ownership of the native_handle.
192
    status_t            writeNativeHandle(const native_handle* handle);
193
194
    // Place a file descriptor into the parcel.  The given fd must remain
195
    // valid for the lifetime of the parcel.
196
    // The Parcel does not take ownership of the given fd unless you ask it to.
197
    status_t            writeFileDescriptor(int fd, bool takeOwnership = false);
198
199
    // Place a file descriptor into the parcel.  A dup of the fd is made, which
200
    // will be closed once the parcel is destroyed.
201
    status_t            writeDupFileDescriptor(int fd);
202
203
    // Place a Java "parcel file descriptor" into the parcel.  The given fd must remain
204
    // valid for the lifetime of the parcel.
205
    // The Parcel does not take ownership of the given fd unless you ask it to.
206
    status_t            writeParcelFileDescriptor(int fd, bool takeOwnership = false);
207
208
    // Place a Java "parcel file descriptor" into the parcel.  A dup of the fd is made, which will
209
    // be closed once the parcel is destroyed.
210
    status_t            writeDupParcelFileDescriptor(int fd);
211
212
    // Place a file descriptor into the parcel.  This will not affect the
213
    // semantics of the smart file descriptor. A new descriptor will be
214
    // created, and will be closed when the parcel is destroyed.
215
    status_t            writeUniqueFileDescriptor(
216
                            const base::unique_fd& fd);
217
218
    // Place a vector of file desciptors into the parcel. Each descriptor is
219
    // dup'd as in writeDupFileDescriptor
220
    status_t            writeUniqueFileDescriptorVector(
221
                            const std::unique_ptr<std::vector<base::unique_fd>>& val);
222
    status_t            writeUniqueFileDescriptorVector(
223
                            const std::vector<base::unique_fd>& val);
224
225
    // Writes a blob to the parcel.
226
    // If the blob is small, then it is stored in-place, otherwise it is
227
    // transferred by way of an anonymous shared memory region.  Prefer sending
228
    // immutable blobs if possible since they may be subsequently transferred between
229
    // processes without further copying whereas mutable blobs always need to be copied.
230
    // The caller should call release() on the blob after writing its contents.
231
    status_t            writeBlob(size_t len, bool mutableCopy, WritableBlob* outBlob);
232
233
    // Write an existing immutable blob file descriptor to the parcel.
234
    // This allows the client to send the same blob to multiple processes
235
    // as long as it keeps a dup of the blob file descriptor handy for later.
236
    status_t            writeDupImmutableBlobFileDescriptor(int fd);
237
238
    status_t            writeObject(const flat_binder_object& val, bool nullMetaData);
239
240
    // Like Parcel.java's writeNoException().  Just writes a zero int32.
241
    // Currently the native implementation doesn't do any of the StrictMode
242
    // stack gathering and serialization that the Java implementation does.
243
    status_t            writeNoException();
244
245
    void                remove(size_t start, size_t amt);
246
    
247
    status_t            read(void* outData, size_t len) const;
248
    const void*         readInplace(size_t len) const;
249
    int32_t             readInt32() const;
250
    status_t            readInt32(int32_t *pArg) const;
251
    uint32_t            readUint32() const;
252
    status_t            readUint32(uint32_t *pArg) const;
253
    int64_t             readInt64() const;
254
    status_t            readInt64(int64_t *pArg) const;
255
    uint64_t            readUint64() const;
256
    status_t            readUint64(uint64_t *pArg) const;
257
    float               readFloat() const;
258
    status_t            readFloat(float *pArg) const;
259
    double              readDouble() const;
260
    status_t            readDouble(double *pArg) const;
261
    intptr_t            readIntPtr() const;
262
    status_t            readIntPtr(intptr_t *pArg) const;
263
    bool                readBool() const;
264
    status_t            readBool(bool *pArg) const;
265
    char16_t            readChar() const;
266
    status_t            readChar(char16_t *pArg) const;
267
    int8_t              readByte() const;
268
    status_t            readByte(int8_t *pArg) const;
269
270
    // Read a UTF16 encoded string, convert to UTF8
271
    status_t            readUtf8FromUtf16(std::string* str) const;
272
    status_t            readUtf8FromUtf16(std::unique_ptr<std::string>* str) const;
273
274
    const char*         readCString() const;
275
    String8             readString8() const;
276
    status_t            readString8(String8* pArg) const;
277
    String16            readString16() const;
278
    status_t            readString16(String16* pArg) const;
279
    status_t            readString16(std::unique_ptr<String16>* pArg) const;
280
    const char16_t*     readString16Inplace(size_t* outLen) const;
281
    sp<IBinder>         readStrongBinder() const;
282
    status_t            readStrongBinder(sp<IBinder>* val) const;
283
    status_t            readNullableStrongBinder(sp<IBinder>* val) const;
284
    wp<IBinder>         readWeakBinder() const;
285
286
    template<typename T>
287
    status_t            readParcelableVector(
288
                            std::unique_ptr<std::vector<std::unique_ptr<T>>>* val) const;
289
    template<typename T>
290
    status_t            readParcelableVector(std::vector<T>* val) const;
291
292
    status_t            readParcelable(Parcelable* parcelable) const;
293
294
    template<typename T>
295
    status_t            readParcelable(std::unique_ptr<T>* parcelable) const;
296
297
    status_t            readValue(binder::Value* value) const;
298
299
    template<typename T>
300
    status_t            readStrongBinder(sp<T>* val) const;
301
302
    template<typename T>
303
    status_t            readNullableStrongBinder(sp<T>* val) const;
304
305
    status_t            readStrongBinderVector(std::unique_ptr<std::vector<sp<IBinder>>>* val) const;
306
    status_t            readStrongBinderVector(std::vector<sp<IBinder>>* val) const;
307
308
    status_t            readByteVector(std::unique_ptr<std::vector<int8_t>>* val) const;
309
    status_t            readByteVector(std::vector<int8_t>* val) const;
310
    status_t            readByteVector(std::unique_ptr<std::vector<uint8_t>>* val) const;
311
    status_t            readByteVector(std::vector<uint8_t>* val) const;
312
    status_t            readInt32Vector(std::unique_ptr<std::vector<int32_t>>* val) const;
313
    status_t            readInt32Vector(std::vector<int32_t>* val) const;
314
    status_t            readInt64Vector(std::unique_ptr<std::vector<int64_t>>* val) const;
315
    status_t            readInt64Vector(std::vector<int64_t>* val) const;
316
    status_t            readFloatVector(std::unique_ptr<std::vector<float>>* val) const;
317
    status_t            readFloatVector(std::vector<float>* val) const;
318
    status_t            readDoubleVector(std::unique_ptr<std::vector<double>>* val) const;
319
    status_t            readDoubleVector(std::vector<double>* val) const;
320
    status_t            readBoolVector(std::unique_ptr<std::vector<bool>>* val) const;
321
    status_t            readBoolVector(std::vector<bool>* val) const;
322
    status_t            readCharVector(std::unique_ptr<std::vector<char16_t>>* val) const;
323
    status_t            readCharVector(std::vector<char16_t>* val) const;
324
    status_t            readString16Vector(
325
                            std::unique_ptr<std::vector<std::unique_ptr<String16>>>* val) const;
326
    status_t            readString16Vector(std::vector<String16>* val) const;
327
    status_t            readUtf8VectorFromUtf16Vector(
328
                            std::unique_ptr<std::vector<std::unique_ptr<std::string>>>* val) const;
329
    status_t            readUtf8VectorFromUtf16Vector(std::vector<std::string>* val) const;
330
331
    template<typename T>
332
    status_t            read(Flattenable<T>& val) const;
333
334
    template<typename T>
335
    status_t            read(LightFlattenable<T>& val) const;
336
337
    template<typename T>
338
    status_t            resizeOutVector(std::vector<T>* val) const;
339
    template<typename T>
340
    status_t            resizeOutVector(std::unique_ptr<std::vector<T>>* val) const;
341
342
    status_t            readMap(binder::Map* map)const;
343
    status_t            readNullableMap(std::unique_ptr<binder::Map>* map) const;
344
345
    // Like Parcel.java's readExceptionCode().  Reads the first int32
346
    // off of a Parcel's header, returning 0 or the negative error
347
    // code on exceptions, but also deals with skipping over rich
348
    // response headers.  Callers should use this to read & parse the
349
    // response headers rather than doing it by hand.
350
    int32_t             readExceptionCode() const;
351
352
    // Retrieve native_handle from the parcel. This returns a copy of the
353
    // parcel's native_handle (the caller takes ownership). The caller
354
    // must free the native_handle with native_handle_close() and 
355
    // native_handle_delete().
356
    native_handle*     readNativeHandle() const;
357
358
    
359
    // Retrieve a file descriptor from the parcel.  This returns the raw fd
360
    // in the parcel, which you do not own -- use dup() to get your own copy.
361
    int                 readFileDescriptor() const;
362
363
    // Retrieve a Java "parcel file descriptor" from the parcel.  This returns the raw fd
364
    // in the parcel, which you do not own -- use dup() to get your own copy.
365
    int                 readParcelFileDescriptor() const;
366
367
    // Retrieve a smart file descriptor from the parcel.
368
    status_t            readUniqueFileDescriptor(
369
                            base::unique_fd* val) const;
370
371
    // Retrieve a Java "parcel file descriptor" from the parcel.
372
    status_t            readUniqueParcelFileDescriptor(base::unique_fd* val) const;
373
374
375
    // Retrieve a vector of smart file descriptors from the parcel.
376
    status_t            readUniqueFileDescriptorVector(
377
                            std::unique_ptr<std::vector<base::unique_fd>>* val) const;
378
    status_t            readUniqueFileDescriptorVector(
379
                            std::vector<base::unique_fd>* val) const;
380
381
    // Reads a blob from the parcel.
382
    // The caller should call release() on the blob after reading its contents.
383
    status_t            readBlob(size_t len, ReadableBlob* outBlob) const;
384
385
    const flat_binder_object* readObject(bool nullMetaData) const;
386
387
    // Explicitly close all file descriptors in the parcel.
388
    void                closeFileDescriptors();
389
390
    // Debugging: get metrics on current allocations.
391
    static size_t       getGlobalAllocSize();
392
    static size_t       getGlobalAllocCount();
393
394
private:
395
    typedef void        (*release_func)(Parcel* parcel,
396
                                        const uint8_t* data, size_t dataSize,
397
                                        const binder_size_t* objects, size_t objectsSize,
398
                                        void* cookie);
399
                        
400
    uintptr_t           ipcData() const;
401
    size_t              ipcDataSize() const;
402
    uintptr_t           ipcObjects() const;
403
    size_t              ipcObjectsCount() const;
404
    void                ipcSetDataReference(const uint8_t* data, size_t dataSize,
405
                                            const binder_size_t* objects, size_t objectsCount,
406
                                            release_func relFunc, void* relCookie);
407
    
408
public:
409
    void                print(TextOutput& to, uint32_t flags = 0) const;
410
411
private:
412
                        Parcel(const Parcel& o);
413
    Parcel&             operator=(const Parcel& o);
414
    
415
    status_t            finishWrite(size_t len);
416
    void                releaseObjects();
417
    void                acquireObjects();
418
    status_t            growData(size_t len);
419
    status_t            restartWrite(size_t desired);
420
    status_t            continueWrite(size_t desired);
421
    status_t            writePointer(uintptr_t val);
422
    status_t            readPointer(uintptr_t *pArg) const;
423
    uintptr_t           readPointer() const;
424
    void                freeDataNoInit();
425
    void                initState();
426
    void                scanForFds() const;
427
    status_t            validateReadData(size_t len) const;
428
                        
429
    template<class T>
430
    status_t            readAligned(T *pArg) const;
431
432
    template<class T>   T readAligned() const;
433
434
    template<class T>
435
    status_t            writeAligned(T val);
436
437
    status_t            writeRawNullableParcelable(const Parcelable*
438
                                                   parcelable);
439
440
    template<typename T, typename U>
441
    status_t            unsafeReadTypedVector(std::vector<T>* val,
442
                                              status_t(Parcel::*read_func)(U*) const) const;
443
    template<typename T>
444
    status_t            readNullableTypedVector(std::unique_ptr<std::vector<T>>* val,
445
                                                status_t(Parcel::*read_func)(T*) const) const;
446
    template<typename T>
447
    status_t            readTypedVector(std::vector<T>* val,
448
                                        status_t(Parcel::*read_func)(T*) const) const;
449
    template<typename T, typename U>
450
    status_t            unsafeWriteTypedVector(const std::vector<T>& val,
451
                                               status_t(Parcel::*write_func)(U));
452
    template<typename T>
453
    status_t            writeNullableTypedVector(const std::unique_ptr<std::vector<T>>& val,
454
                                                 status_t(Parcel::*write_func)(const T&));
455
    template<typename T>
456
    status_t            writeNullableTypedVector(const std::unique_ptr<std::vector<T>>& val,
457
                                                 status_t(Parcel::*write_func)(T));
458
    template<typename T>
459
    status_t            writeTypedVector(const std::vector<T>& val,
460
                                         status_t(Parcel::*write_func)(const T&));
461
    template<typename T>
462
    status_t            writeTypedVector(const std::vector<T>& val,
463
                                         status_t(Parcel::*write_func)(T));
464
465
    status_t            mError;
466
    uint8_t*            mData;
467
    size_t              mDataSize;
468
    size_t              mDataCapacity;
469
    mutable size_t      mDataPos;
470
    binder_size_t*      mObjects;
471
    size_t              mObjectsSize;
472
    size_t              mObjectsCapacity;
473
    mutable size_t      mNextObjectHint;
474
    mutable bool        mObjectsSorted;
475
476
    mutable bool        mFdsKnown;
477
    mutable bool        mHasFds;
478
    bool                mAllowFds;
479
480
    release_func        mOwner;
481
    void*               mOwnerCookie;
482
483
    class Blob {
484
    public:
485
        Blob();
486
        ~Blob();
487
488
        void clear();
489
        void release();
490
0
        inline size_t size() const { return mSize; }
491
0
        inline int fd() const { return mFd; }
492
0
        inline bool isMutable() const { return mMutable; }
493
494
    protected:
495
        void init(int fd, void* data, size_t size, bool isMutable);
496
497
        int mFd; // owned by parcel so not closed when released
498
        void* mData;
499
        size_t mSize;
500
        bool mMutable;
501
    };
502
503
    #if defined(__clang__)
504
    #pragma clang diagnostic push
505
    #pragma clang diagnostic ignored "-Wweak-vtables"
506
    #endif
507
508
    // FlattenableHelperInterface and FlattenableHelper avoid generating a vtable entry in objects
509
    // following Flattenable template/protocol.
510
    class FlattenableHelperInterface {
511
    protected:
512
0
        ~FlattenableHelperInterface() { }
513
    public:
514
        virtual size_t getFlattenedSize() const = 0;
515
        virtual size_t getFdCount() const = 0;
516
        virtual status_t flatten(void* buffer, size_t size, int* fds, size_t count) const = 0;
517
        virtual status_t unflatten(void const* buffer, size_t size, int const* fds, size_t count) = 0;
518
    };
519
520
    #if defined(__clang__)
521
    #pragma clang diagnostic pop
522
    #endif
523
524
    // Concrete implementation of FlattenableHelperInterface that delegates virtual calls to the
525
    // specified class T implementing the Flattenable protocol. It "virtualizes" a compile-time
526
    // protocol.
527
    template<typename T>
528
    class FlattenableHelper : public FlattenableHelperInterface {
529
        friend class Parcel;
530
        const Flattenable<T>& val;
531
        explicit FlattenableHelper(const Flattenable<T>& _val) : val(_val) { }
532
533
    protected:
534
        ~FlattenableHelper() = default;
535
    public:
536
        virtual size_t getFlattenedSize() const {
537
            return val.getFlattenedSize();
538
        }
539
        virtual size_t getFdCount() const {
540
            return val.getFdCount();
541
        }
542
        virtual status_t flatten(void* buffer, size_t size, int* fds, size_t count) const {
543
            return val.flatten(buffer, size, fds, count);
544
        }
545
        virtual status_t unflatten(void const* buffer, size_t size, int const* fds, size_t count) {
546
            return const_cast<Flattenable<T>&>(val).unflatten(buffer, size, fds, count);
547
        }
548
    };
549
    status_t write(const FlattenableHelperInterface& val);
550
    status_t read(FlattenableHelperInterface& val) const;
551
552
public:
553
    class ReadableBlob : public Blob {
554
        friend class Parcel;
555
    public:
556
0
        inline const void* data() const { return mData; }
557
0
        inline void* mutableData() { return isMutable() ? mData : nullptr; }
558
    };
559
560
    class WritableBlob : public Blob {
561
        friend class Parcel;
562
    public:
563
0
        inline void* data() { return mData; }
564
    };
565
566
private:
567
    size_t mOpenAshmemSize;
568
569
public:
570
    // TODO: Remove once ABI can be changed.
571
    size_t getBlobAshmemSize() const;
572
    size_t getOpenAshmemSize() const;
573
};
574
575
// ---------------------------------------------------------------------------
576
577
template<typename T>
578
status_t Parcel::write(const Flattenable<T>& val) {
579
    const FlattenableHelper<T> helper(val);
580
    return write(helper);
581
}
582
583
template<typename T>
584
status_t Parcel::write(const LightFlattenable<T>& val) {
585
    size_t size(val.getFlattenedSize());
586
    if (!val.isFixedSize()) {
587
        if (size > INT32_MAX) {
588
            return BAD_VALUE;
589
        }
590
        status_t err = writeInt32(static_cast<int32_t>(size));
591
        if (err != NO_ERROR) {
592
            return err;
593
        }
594
    }
595
    if (size) {
596
        void* buffer = writeInplace(size);
597
        if (buffer == nullptr)
598
            return NO_MEMORY;
599
        return val.flatten(buffer, size);
600
    }
601
    return NO_ERROR;
602
}
603
604
template<typename T>
605
status_t Parcel::read(Flattenable<T>& val) const {
606
    FlattenableHelper<T> helper(val);
607
    return read(helper);
608
}
609
610
template<typename T>
611
status_t Parcel::read(LightFlattenable<T>& val) const {
612
    size_t size;
613
    if (val.isFixedSize()) {
614
        size = val.getFlattenedSize();
615
    } else {
616
        int32_t s;
617
        status_t err = readInt32(&s);
618
        if (err != NO_ERROR) {
619
            return err;
620
        }
621
        size = static_cast<size_t>(s);
622
    }
623
    if (size) {
624
        void const* buffer = readInplace(size);
625
        return buffer == nullptr ? NO_MEMORY :
626
                val.unflatten(buffer, size);
627
    }
628
    return NO_ERROR;
629
}
630
631
template<typename T>
632
status_t Parcel::writeVectorSize(const std::vector<T>& val) {
633
    if (val.size() > INT32_MAX) {
634
        return BAD_VALUE;
635
    }
636
    return writeInt32(static_cast<int32_t>(val.size()));
637
}
638
639
template<typename T>
640
status_t Parcel::writeVectorSize(const std::unique_ptr<std::vector<T>>& val) {
641
    if (!val) {
642
        return writeInt32(-1);
643
    }
644
645
    return writeVectorSize(*val);
646
}
647
648
template<typename T>
649
status_t Parcel::resizeOutVector(std::vector<T>* val) const {
650
    int32_t size;
651
    status_t err = readInt32(&size);
652
    if (err != NO_ERROR) {
653
        return err;
654
    }
655
656
    if (size < 0) {
657
        return UNEXPECTED_NULL;
658
    }
659
    val->resize(size_t(size));
660
    return OK;
661
}
662
663
template<typename T>
664
status_t Parcel::resizeOutVector(std::unique_ptr<std::vector<T>>* val) const {
665
    int32_t size;
666
    status_t err = readInt32(&size);
667
    if (err != NO_ERROR) {
668
        return err;
669
    }
670
671
    val->reset();
672
    if (size >= 0) {
673
        val->reset(new std::vector<T>(size_t(size)));
674
    }
675
676
    return OK;
677
}
678
679
template<typename T>
680
status_t Parcel::readStrongBinder(sp<T>* val) const {
681
    sp<IBinder> tmp;
682
    status_t ret = readStrongBinder(&tmp);
683
684
    if (ret == OK) {
685
        *val = interface_cast<T>(tmp);
686
687
        if (val->get() == nullptr) {
688
            return UNKNOWN_ERROR;
689
        }
690
    }
691
692
    return ret;
693
}
694
695
template<typename T>
696
status_t Parcel::readNullableStrongBinder(sp<T>* val) const {
697
    sp<IBinder> tmp;
698
    status_t ret = readNullableStrongBinder(&tmp);
699
700
    if (ret == OK) {
701
        *val = interface_cast<T>(tmp);
702
703
        if (val->get() == nullptr && tmp.get() != nullptr) {
704
            ret = UNKNOWN_ERROR;
705
        }
706
    }
707
708
    return ret;
709
}
710
711
template<typename T, typename U>
712
status_t Parcel::unsafeReadTypedVector(
713
        std::vector<T>* val,
714
        status_t(Parcel::*read_func)(U*) const) const {
715
    int32_t size;
716
    status_t status = this->readInt32(&size);
717
718
    if (status != OK) {
719
        return status;
720
    }
721
722
    if (size < 0) {
723
        return UNEXPECTED_NULL;
724
    }
725
726
    if (val->max_size() < static_cast<size_t>(size)) {
727
        return NO_MEMORY;
728
    }
729
730
    val->resize(static_cast<size_t>(size));
731
732
    if (val->size() < static_cast<size_t>(size)) {
733
        return NO_MEMORY;
734
    }
735
736
    for (auto& v: *val) {
737
        status = (this->*read_func)(&v);
738
739
        if (status != OK) {
740
            return status;
741
        }
742
    }
743
744
    return OK;
745
}
746
747
template<typename T>
748
status_t Parcel::readTypedVector(std::vector<T>* val,
749
                                 status_t(Parcel::*read_func)(T*) const) const {
750
    return unsafeReadTypedVector(val, read_func);
751
}
752
753
template<typename T>
754
status_t Parcel::readNullableTypedVector(std::unique_ptr<std::vector<T>>* val,
755
                                         status_t(Parcel::*read_func)(T*) const) const {
756
    const size_t start = dataPosition();
757
    int32_t size;
758
    status_t status = readInt32(&size);
759
    val->reset();
760
761
    if (status != OK || size < 0) {
762
        return status;
763
    }
764
765
    setDataPosition(start);
766
    val->reset(new std::vector<T>());
767
768
    status = unsafeReadTypedVector(val->get(), read_func);
769
770
    if (status != OK) {
771
        val->reset();
772
    }
773
774
    return status;
775
}
776
777
template<typename T, typename U>
778
status_t Parcel::unsafeWriteTypedVector(const std::vector<T>& val,
779
                                        status_t(Parcel::*write_func)(U)) {
780
    if (val.size() > std::numeric_limits<int32_t>::max()) {
781
        return BAD_VALUE;
782
    }
783
784
    status_t status = this->writeInt32(static_cast<int32_t>(val.size()));
785
786
    if (status != OK) {
787
        return status;
788
    }
789
790
    for (const auto& item : val) {
791
        status = (this->*write_func)(item);
792
793
        if (status != OK) {
794
            return status;
795
        }
796
    }
797
798
    return OK;
799
}
800
801
template<typename T>
802
status_t Parcel::writeTypedVector(const std::vector<T>& val,
803
                                  status_t(Parcel::*write_func)(const T&)) {
804
    return unsafeWriteTypedVector(val, write_func);
805
}
806
807
template<typename T>
808
status_t Parcel::writeTypedVector(const std::vector<T>& val,
809
                                  status_t(Parcel::*write_func)(T)) {
810
    return unsafeWriteTypedVector(val, write_func);
811
}
812
813
template<typename T>
814
status_t Parcel::writeNullableTypedVector(const std::unique_ptr<std::vector<T>>& val,
815
                                          status_t(Parcel::*write_func)(const T&)) {
816
    if (val.get() == nullptr) {
817
        return this->writeInt32(-1);
818
    }
819
820
    return unsafeWriteTypedVector(*val, write_func);
821
}
822
823
template<typename T>
824
status_t Parcel::writeNullableTypedVector(const std::unique_ptr<std::vector<T>>& val,
825
                                          status_t(Parcel::*write_func)(T)) {
826
    if (val.get() == nullptr) {
827
        return this->writeInt32(-1);
828
    }
829
830
    return unsafeWriteTypedVector(*val, write_func);
831
}
832
833
template<typename T>
834
status_t Parcel::readParcelableVector(std::vector<T>* val) const {
835
    return unsafeReadTypedVector<T, Parcelable>(val, &Parcel::readParcelable);
836
}
837
838
template<typename T>
839
status_t Parcel::readParcelableVector(std::unique_ptr<std::vector<std::unique_ptr<T>>>* val) const {
840
    const size_t start = dataPosition();
841
    int32_t size;
842
    status_t status = readInt32(&size);
843
    val->reset();
844
845
    if (status != OK || size < 0) {
846
        return status;
847
    }
848
849
    setDataPosition(start);
850
    val->reset(new std::vector<std::unique_ptr<T>>());
851
852
    status = unsafeReadTypedVector(val->get(), &Parcel::readParcelable<T>);
853
854
    if (status != OK) {
855
        val->reset();
856
    }
857
858
    return status;
859
}
860
861
template<typename T>
862
status_t Parcel::readParcelable(std::unique_ptr<T>* parcelable) const {
863
    const size_t start = dataPosition();
864
    int32_t present;
865
    status_t status = readInt32(&present);
866
    parcelable->reset();
867
868
    if (status != OK || !present) {
869
        return status;
870
    }
871
872
    setDataPosition(start);
873
    parcelable->reset(new T());
874
875
    status = readParcelable(parcelable->get());
876
877
    if (status != OK) {
878
        parcelable->reset();
879
    }
880
881
    return status;
882
}
883
884
template<typename T>
885
status_t Parcel::writeNullableParcelable(const std::unique_ptr<T>& parcelable) {
886
    return writeRawNullableParcelable(parcelable.get());
887
}
888
889
template<typename T>
890
status_t Parcel::writeParcelableVector(const std::vector<T>& val) {
891
    return unsafeWriteTypedVector<T,const Parcelable&>(val, &Parcel::writeParcelable);
892
}
893
894
template<typename T>
895
status_t Parcel::writeParcelableVector(const std::unique_ptr<std::vector<std::unique_ptr<T>>>& val) {
896
    if (val.get() == nullptr) {
897
        return this->writeInt32(-1);
898
    }
899
900
    return unsafeWriteTypedVector(*val, &Parcel::writeNullableParcelable<T>);
901
}
902
903
template<typename T>
904
status_t Parcel::writeParcelableVector(const std::shared_ptr<std::vector<std::unique_ptr<T>>>& val) {
905
    if (val.get() == nullptr) {
906
        return this->writeInt32(-1);
907
    }
908
909
    return unsafeWriteTypedVector(*val, &Parcel::writeNullableParcelable<T>);
910
}
911
912
// ---------------------------------------------------------------------------
913
914
inline TextOutput& operator<<(TextOutput& to, const Parcel& parcel)
915
0
{
916
0
    parcel.print(to);
917
0
    return to;
918
0
}
919
920
// ---------------------------------------------------------------------------
921
922
// Generic acquire and release of objects.
923
void acquire_object(const sp<ProcessState>& proc,
924
                    const flat_binder_object& obj, const void* who);
925
void release_object(const sp<ProcessState>& proc,
926
                    const flat_binder_object& obj, const void* who);
927
928
void flatten_binder(const sp<ProcessState>& proc,
929
                    const sp<IBinder>& binder, flat_binder_object* out);
930
void flatten_binder(const sp<ProcessState>& proc,
931
                    const wp<IBinder>& binder, flat_binder_object* out);
932
status_t unflatten_binder(const sp<ProcessState>& proc,
933
                          const flat_binder_object& flat, sp<IBinder>* out);
934
status_t unflatten_binder(const sp<ProcessState>& proc,
935
                          const flat_binder_object& flat, wp<IBinder>* out);
936
937
}; // namespace android
938
939
// ---------------------------------------------------------------------------
940
941
#endif // ANDROID_PARCEL_H
/proc/self/cwd/out/soong/.intermediates/hardware/interfaces/graphics/common/1.0/android.hardware.graphics.common@1.0_genc++_headers/gen/android/hardware/graphics/common/1.0/types.h
Line
Count
Source (jump to first uncovered line)
1
#ifndef HIDL_GENERATED_ANDROID_HARDWARE_GRAPHICS_COMMON_V1_0_TYPES_H
2
#define HIDL_GENERATED_ANDROID_HARDWARE_GRAPHICS_COMMON_V1_0_TYPES_H
3
4
#include <hidl/HidlSupport.h>
5
#include <hidl/MQDescriptor.h>
6
#include <utils/NativeHandle.h>
7
#include <utils/misc.h>
8
9
namespace android {
10
namespace hardware {
11
namespace graphics {
12
namespace common {
13
namespace V1_0 {
14
15
// Forward declaration for forward reference support:
16
enum class PixelFormat : int32_t;
17
enum class BufferUsage : uint64_t;
18
enum class Transform : int32_t;
19
enum class Dataspace : int32_t;
20
enum class ColorMode : int32_t;
21
enum class ColorTransform : int32_t;
22
enum class Hdr : int32_t;
23
24
/**
25
 * Common enumeration and structure definitions for all graphics HALs.
26
 * 
27
 * 
28
 * Pixel formats for graphics buffers.
29
 */
30
enum class PixelFormat : int32_t {
31
    /**
32
     * 32-bit format that has 8-bit R, G, B, and A components, in that order,
33
     * from the lowest memory address to the highest memory address.
34
     * 
35
     * The component values are unsigned normalized to the range [0, 1], whose
36
     * interpretation is defined by the dataspace.
37
     */
38
    RGBA_8888 = 1 /* 0x1 */,
39
    /**
40
     * 32-bit format that has 8-bit R, G, B, and unused components, in that
41
     * order, from the lowest memory address to the highest memory address.
42
     * 
43
     * The component values are unsigned normalized to the range [0, 1], whose
44
     * interpretation is defined by the dataspace.
45
     */
46
    RGBX_8888 = 2 /* 0x2 */,
47
    /**
48
     * 24-bit format that has 8-bit R, G, and B components, in that order,
49
     * from the lowest memory address to the highest memory address.
50
     * 
51
     * The component values are unsigned normalized to the range [0, 1], whose
52
     * interpretation is defined by the dataspace.
53
     */
54
    RGB_888 = 3 /* 0x3 */,
55
    /**
56
     * 16-bit packed format that has 5-bit R, 6-bit G, and 5-bit B components,
57
     * in that order, from the most-sigfinicant bits to the least-significant
58
     * bits.
59
     * 
60
     * The component values are unsigned normalized to the range [0, 1], whose
61
     * interpretation is defined by the dataspace.
62
     */
63
    RGB_565 = 4 /* 0x4 */,
64
    /**
65
     * 32-bit format that has 8-bit B, G, R, and A components, in that order,
66
     * from the lowest memory address to the highest memory address.
67
     * 
68
     * The component values are unsigned normalized to the range [0, 1], whose
69
     * interpretation is defined by the dataspace.
70
     */
71
    BGRA_8888 = 5 /* 0x5 */,
72
    /**
73
     * Legacy formats deprecated in favor of YCBCR_420_888.
74
     */
75
    YCBCR_422_SP = 16 /* 0x10 */,
76
    YCRCB_420_SP = 17 /* 0x11 */,
77
    YCBCR_422_I = 20 /* 0x14 */,
78
    /**
79
     * 64-bit format that has 16-bit R, G, B, and A components, in that order,
80
     * from the lowest memory address to the highest memory address.
81
     * 
82
     * The component values are signed floats, whose interpretation is defined
83
     * by the dataspace.
84
     */
85
    RGBA_FP16 = 22 /* 0x16 */,
86
    /**
87
     * RAW16 is a single-channel, 16-bit, little endian format, typically
88
     * representing raw Bayer-pattern images from an image sensor, with minimal
89
     * processing.
90
     * 
91
     * The exact pixel layout of the data in the buffer is sensor-dependent, and
92
     * needs to be queried from the camera device.
93
     * 
94
     * Generally, not all 16 bits are used; more common values are 10 or 12
95
     * bits. If not all bits are used, the lower-order bits are filled first.
96
     * All parameters to interpret the raw data (black and white points,
97
     * color space, etc) must be queried from the camera device.
98
     * 
99
     * This format assumes
100
     * - an even width
101
     * - an even height
102
     * - a horizontal stride multiple of 16 pixels
103
     * - a vertical stride equal to the height
104
     * - strides are specified in pixels, not in bytes
105
     * 
106
     *   size = stride * height * 2
107
     * 
108
     * This format must be accepted by the allocator when used with the
109
     * following usage flags:
110
     * 
111
     *    - BufferUsage::CAMERA_*
112
     *    - BufferUsage::CPU_*
113
     *    - BufferUsage::RENDERSCRIPT
114
     * 
115
     * The mapping of the dataspace to buffer contents for RAW16 is as
116
     * follows:
117
     * 
118
     *  Dataspace value               | Buffer contents
119
     * -------------------------------+-----------------------------------------
120
     *  Dataspace::ARBITRARY          | Raw image sensor data, layout is as
121
     *                                | defined above.
122
     *  Dataspace::DEPTH              | Unprocessed implementation-dependent raw
123
     *                                | depth measurements, opaque with 16 bit
124
     *                                | samples.
125
     *  Other                         | Unsupported
126
     */
127
    RAW16 = 32 /* 0x20 */,
128
    /**
129
     * BLOB is used to carry task-specific data which does not have a standard
130
     * image structure. The details of the format are left to the two
131
     * endpoints.
132
     * 
133
     * A typical use case is for transporting JPEG-compressed images from the
134
     * Camera HAL to the framework or to applications.
135
     * 
136
     * Buffers of this format must have a height of 1, and width equal to their
137
     * size in bytes.
138
     * 
139
     * The mapping of the dataspace to buffer contents for BLOB is as
140
     * follows:
141
     * 
142
     *  Dataspace value               | Buffer contents
143
     * -------------------------------+-----------------------------------------
144
     *  Dataspace::JFIF               | An encoded JPEG image
145
     *  Dataspace::DEPTH              | An android_depth_points buffer
146
     *  Dataspace::SENSOR             | Sensor event data.
147
     *  Other                         | Unsupported
148
     */
149
    BLOB = 33 /* 0x21 */,
150
    /**
151
     * A format indicating that the choice of format is entirely up to the
152
     * allocator.
153
     * 
154
     * The allocator should examine the usage bits passed in when allocating a
155
     * buffer with this format, and it should derive the pixel format from
156
     * those usage flags. This format must never be used with any of the
157
     * BufferUsage::CPU_* usage flags.
158
     * 
159
     * Even when the internally chosen format has an alpha component, the
160
     * clients must assume the alpha vlaue to be 1.0.
161
     * 
162
     * The interpretation of the component values is defined by the dataspace.
163
     */
164
    IMPLEMENTATION_DEFINED = 34 /* 0x22 */,
165
    /**
166
     * This format allows platforms to use an efficient YCbCr/YCrCb 4:2:0
167
     * buffer layout, while still describing the general format in a
168
     * layout-independent manner. While called YCbCr, it can be used to
169
     * describe formats with either chromatic ordering, as well as
170
     * whole planar or semiplanar layouts.
171
     * 
172
     * This format must be accepted by the allocator when BufferUsage::CPU_*
173
     * are set.
174
     * 
175
     * Buffers with this format must be locked with IMapper::lockYCbCr.
176
     * Locking with IMapper::lock must return an error.
177
     * 
178
     * The interpretation of the component values is defined by the dataspace.
179
     */
180
    YCBCR_420_888 = 35 /* 0x23 */,
181
    /**
182
     * RAW_OPAQUE is a format for unprocessed raw image buffers coming from an
183
     * image sensor. The actual structure of buffers of this format is
184
     * implementation-dependent.
185
     * 
186
     * This format must be accepted by the allocator when used with the
187
     * following usage flags:
188
     * 
189
     *    - BufferUsage::CAMERA_*
190
     *    - BufferUsage::CPU_*
191
     *    - BufferUsage::RENDERSCRIPT
192
     * 
193
     * The mapping of the dataspace to buffer contents for RAW_OPAQUE is as
194
     * follows:
195
     * 
196
     *  Dataspace value               | Buffer contents
197
     * -------------------------------+-----------------------------------------
198
     *  Dataspace::ARBITRARY          | Raw image sensor data.
199
     *  Other                         | Unsupported
200
     */
201
    RAW_OPAQUE = 36 /* 0x24 */,
202
    /**
203
     * RAW10 is a single-channel, 10-bit per pixel, densely packed in each row,
204
     * unprocessed format, usually representing raw Bayer-pattern images coming from
205
     * an image sensor.
206
     * 
207
     * In an image buffer with this format, starting from the first pixel of each
208
     * row, each 4 consecutive pixels are packed into 5 bytes (40 bits). Each one
209
     * of the first 4 bytes contains the top 8 bits of each pixel, The fifth byte
210
     * contains the 2 least significant bits of the 4 pixels, the exact layout data
211
     * for each 4 consecutive pixels is illustrated below (Pi[j] stands for the jth
212
     * bit of the ith pixel):
213
     * 
214
     *          bit 7                                     bit 0
215
     *          =====|=====|=====|=====|=====|=====|=====|=====|
216
     * Byte 0: |P0[9]|P0[8]|P0[7]|P0[6]|P0[5]|P0[4]|P0[3]|P0[2]|
217
     *         |-----|-----|-----|-----|-----|-----|-----|-----|
218
     * Byte 1: |P1[9]|P1[8]|P1[7]|P1[6]|P1[5]|P1[4]|P1[3]|P1[2]|
219
     *         |-----|-----|-----|-----|-----|-----|-----|-----|
220
     * Byte 2: |P2[9]|P2[8]|P2[7]|P2[6]|P2[5]|P2[4]|P2[3]|P2[2]|
221
     *         |-----|-----|-----|-----|-----|-----|-----|-----|
222
     * Byte 3: |P3[9]|P3[8]|P3[7]|P3[6]|P3[5]|P3[4]|P3[3]|P3[2]|
223
     *         |-----|-----|-----|-----|-----|-----|-----|-----|
224
     * Byte 4: |P3[1]|P3[0]|P2[1]|P2[0]|P1[1]|P1[0]|P0[1]|P0[0]|
225
     *          ===============================================
226
     * 
227
     * This format assumes
228
     * - a width multiple of 4 pixels
229
     * - an even height
230
     * - a vertical stride equal to the height
231
     * - strides are specified in bytes, not in pixels
232
     * 
233
     *   size = stride * height
234
     * 
235
     * When stride is equal to width * (10 / 8), there will be no padding bytes at
236
     * the end of each row, the entire image data is densely packed. When stride is
237
     * larger than width * (10 / 8), padding bytes will be present at the end of each
238
     * row (including the last row).
239
     * 
240
     * This format must be accepted by the allocator when used with the
241
     * following usage flags:
242
     * 
243
     *    - BufferUsage::CAMERA_*
244
     *    - BufferUsage::CPU_*
245
     *    - BufferUsage::RENDERSCRIPT
246
     * 
247
     * The mapping of the dataspace to buffer contents for RAW10 is as
248
     * follows:
249
     * 
250
     *  Dataspace value               | Buffer contents
251
     * -------------------------------+-----------------------------------------
252
     *  Dataspace::ARBITRARY          | Raw image sensor data.
253
     *  Other                         | Unsupported
254
     */
255
    RAW10 = 37 /* 0x25 */,
256
    /**
257
     * RAW12 is a single-channel, 12-bit per pixel, densely packed in each row,
258
     * unprocessed format, usually representing raw Bayer-pattern images coming from
259
     * an image sensor.
260
     * 
261
     * In an image buffer with this format, starting from the first pixel of each
262
     * row, each two consecutive pixels are packed into 3 bytes (24 bits). The first
263
     * and second byte contains the top 8 bits of first and second pixel. The third
264
     * byte contains the 4 least significant bits of the two pixels, the exact layout
265
     * data for each two consecutive pixels is illustrated below (Pi[j] stands for
266
     * the jth bit of the ith pixel):
267
     * 
268
     *           bit 7                                            bit 0
269
     *          ======|======|======|======|======|======|======|======|
270
     * Byte 0: |P0[11]|P0[10]|P0[ 9]|P0[ 8]|P0[ 7]|P0[ 6]|P0[ 5]|P0[ 4]|
271
     *         |------|------|------|------|------|------|------|------|
272
     * Byte 1: |P1[11]|P1[10]|P1[ 9]|P1[ 8]|P1[ 7]|P1[ 6]|P1[ 5]|P1[ 4]|
273
     *         |------|------|------|------|------|------|------|------|
274
     * Byte 2: |P1[ 3]|P1[ 2]|P1[ 1]|P1[ 0]|P0[ 3]|P0[ 2]|P0[ 1]|P0[ 0]|
275
     *          =======================================================
276
     * 
277
     * This format assumes:
278
     * - a width multiple of 4 pixels
279
     * - an even height
280
     * - a vertical stride equal to the height
281
     * - strides are specified in bytes, not in pixels
282
     * 
283
     *   size = stride * height
284
     * 
285
     * When stride is equal to width * (12 / 8), there will be no padding bytes at
286
     * the end of each row, the entire image data is densely packed. When stride is
287
     * larger than width * (12 / 8), padding bytes will be present at the end of
288
     * each row (including the last row).
289
     * 
290
     * This format must be accepted by the allocator when used with the
291
     * following usage flags:
292
     * 
293
     *    - BufferUsage::CAMERA_*
294
     *    - BufferUsage::CPU_*
295
     *    - BufferUsage::RENDERSCRIPT
296
     * 
297
     * The mapping of the dataspace to buffer contents for RAW12 is as
298
     * follows:
299
     * 
300
     *  Dataspace value               | Buffer contents
301
     * -------------------------------+-----------------------------------------
302
     *  Dataspace::ARBITRARY          | Raw image sensor data.
303
     *  Other                         | Unsupported
304
     */
305
    RAW12 = 38 /* 0x26 */,
306
    /**
307
     * 0x27 to 0x2A are reserved for flexible formats 
308
     * 
309
     * 32-bit packed format that has 2-bit A, 10-bit B, G, and R components,
310
     * in that order, from the most-sigfinicant bits to the least-significant
311
     * bits.
312
     * 
313
     * The component values are unsigned normalized to the range [0, 1], whose
314
     * interpretation is defined by the dataspace.
315
     */
316
    RGBA_1010102 = 43 /* 0x2B */,
317
    /**
318
     * 0x100 - 0x1FF
319
     * 
320
     * This range is reserved for vendor extensions. Formats in this range
321
     * must support BufferUsage::GPU_TEXTURE. Clients must assume they do not
322
     * have an alpha component.
323
     * 
324
     * 
325
     * Y8 is a YUV planar format comprised of a WxH Y plane, with each pixel
326
     * being represented by 8 bits. It is equivalent to just the Y plane from
327
     * YV12.
328
     * 
329
     * This format assumes
330
     * - an even width
331
     * - an even height
332
     * - a horizontal stride multiple of 16 pixels
333
     * - a vertical stride equal to the height
334
     * 
335
     *   size = stride * height
336
     * 
337
     * This format must be accepted by the allocator when used with the
338
     * following usage flags:
339
     * 
340
     *    - BufferUsage::CAMERA_*
341
     *    - BufferUsage::CPU_*
342
     * 
343
     * The component values are unsigned normalized to the range [0, 1], whose
344
     * interpretation is defined by the dataspace.
345
     */
346
    Y8 = 538982489 /* 0x20203859 */,
347
    /**
348
     * Y16 is a YUV planar format comprised of a WxH Y plane, with each pixel
349
     * being represented by 16 bits. It is just like Y8, but has double the
350
     * bits per pixel (little endian).
351
     * 
352
     * This format assumes
353
     * - an even width
354
     * - an even height
355
     * - a horizontal stride multiple of 16 pixels
356
     * - a vertical stride equal to the height
357
     * - strides are specified in pixels, not in bytes
358
     * 
359
     *   size = stride * height * 2
360
     * 
361
     * This format must be accepted by the allocator when used with the
362
     * following usage flags:
363
     * 
364
     *    - BufferUsage::CAMERA_*
365
     *    - BufferUsage::CPU_*
366
     * 
367
     * The component values are unsigned normalized to the range [0, 1], whose
368
     * interpretation is defined by the dataspace. When the dataspace is
369
     * Dataspace::DEPTH, each pixel is a distance value measured by a depth
370
     * camera, plus an associated confidence value.
371
     */
372
    Y16 = 540422489 /* 0x20363159 */,
373
    /**
374
     * YV12 is a 4:2:0 YCrCb planar format comprised of a WxH Y plane followed
375
     * by (W/2) x (H/2) Cr and Cb planes.
376
     * 
377
     * This format assumes
378
     * - an even width
379
     * - an even height
380
     * - a horizontal stride multiple of 16 pixels
381
     * - a vertical stride equal to the height
382
     * 
383
     *   y_size = stride * height
384
     *   c_stride = ALIGN(stride/2, 16)
385
     *   c_size = c_stride * height/2
386
     *   size = y_size + c_size * 2
387
     *   cr_offset = y_size
388
     *   cb_offset = y_size + c_size
389
     * 
390
     * This range is reserved for vendor extensions. Formats in this range
391
     * must support BufferUsage::GPU_TEXTURE. Clients must assume they do not
392
     * have an alpha component.
393
     * 
394
     * This format must be accepted by the allocator when used with the
395
     * following usage flags:
396
     * 
397
     *    - BufferUsage::CAMERA_*
398
     *    - BufferUsage::CPU_*
399
     *    - BufferUsage::GPU_TEXTURE
400
     * 
401
     * The component values are unsigned normalized to the range [0, 1], whose
402
     * interpretation is defined by the dataspace.
403
     */
404
    YV12 = 842094169 /* 0x32315659 */,
405
};
406
407
/**
408
 * Buffer usage definitions.
409
 */
410
enum class BufferUsage : uint64_t {
411
    /**
412
     * bit 0-3 is an enum  */
413
    CPU_READ_MASK = 15ull /* 0xfULL */,
414
    /**
415
     * buffer is never read by CPU  */
416
    CPU_READ_NEVER = 0ull,
417
    /**
418
     * buffer is rarely read by CPU  */
419
    CPU_READ_RARELY = 2ull,
420
    /**
421
     * buffer is often read by CPU  */
422
    CPU_READ_OFTEN = 3ull,
423
    /**
424
     * bit 4-7 is an enum  */
425
    CPU_WRITE_MASK = 240ull /* (0xfULL << 4) */,
426
    /**
427
     * buffer is never written by CPU  */
428
    CPU_WRITE_NEVER = 0ull /* (0 << 4) */,
429
    /**
430
     * buffer is rarely written by CPU  */
431
    CPU_WRITE_RARELY = 32ull /* (2 << 4) */,
432
    /**
433
     * buffer is often written by CPU  */
434
    CPU_WRITE_OFTEN = 48ull /* (3 << 4) */,
435
    /**
436
     * buffer is used as a GPU texture  */
437
    GPU_TEXTURE = 256ull /* (1ULL << 8) */,
438
    /**
439
     * buffer is used as a GPU render target  */
440
    GPU_RENDER_TARGET = 512ull /* (1ULL << 9) */,
441
    /**
442
     * bit 10 must be zero 
443
     * 
444
     * buffer is used as a composer HAL overlay layer  */
445
    COMPOSER_OVERLAY = 2048ull /* (1ULL << 11) */,
446
    /**
447
     * buffer is used as a composer HAL client target  */
448
    COMPOSER_CLIENT_TARGET = 4096ull /* (1ULL << 12) */,
449
    /**
450
     * bit 13 must be zero 
451
     * 
452
     * Buffer is allocated with hardware-level protection against copying the
453
     * contents (or information derived from the contents) into unprotected
454
     * memory.
455
     */
456
    PROTECTED = 16384ull /* (1ULL << 14) */,
457
    /**
458
     * buffer is used as a hwcomposer HAL cursor layer  */
459
    COMPOSER_CURSOR = 32768ull /* (1ULL << 15) */,
460
    /**
461
     * buffer is used as a video encoder input  */
462
    VIDEO_ENCODER = 65536ull /* (1ULL << 16) */,
463
    /**
464
     * buffer is used as a camera HAL output  */
465
    CAMERA_OUTPUT = 131072ull /* (1ULL << 17) */,
466
    /**
467
     * buffer is used as a camera HAL input  */
468
    CAMERA_INPUT = 262144ull /* (1ULL << 18) */,
469
    /**
470
     * bit 19 must be zero 
471
     * 
472
     * buffer is used as a renderscript allocation  */
473
    RENDERSCRIPT = 1048576ull /* (1ULL << 20) */,
474
    /**
475
     * bit 21 must be zero 
476
     * 
477
     * buffer is used as a video decoder output  */
478
    VIDEO_DECODER = 4194304ull /* (1ULL << 22) */,
479
    /**
480
     * buffer is used as a sensor direct report output  */
481
    SENSOR_DIRECT_DATA = 8388608ull /* (1ULL << 23) */,
482
    /**
483
     * buffer is used as as an OpenGL shader storage or uniform
484
     * buffer object
485
     */
486
    GPU_DATA_BUFFER = 16777216ull /* (1ULL << 24) */,
487
    /**
488
     * bits 25-27 must be zero and are reserved for future versions 
489
     * 
490
     * bits 28-31 are reserved for vendor extensions  */
491
    VENDOR_MASK = 4026531840ull /* (0xfULL << 28) */,
492
    /**
493
     * bits 32-47 must be zero and are reserved for future versions 
494
     * 
495
     * bits 48-63 are reserved for vendor extensions  */
496
    VENDOR_MASK_HI = 18446462598732840960ull /* (0xffffULL << 48) */,
497
};
498
499
/**
500
 * Transformation definitions
501
 */
502
enum class Transform : int32_t {
503
    /**
504
     * Horizontal flip. FLIP_H/FLIP_V is applied before ROT_90.
505
     */
506
    FLIP_H = 1 /* (1 << 0) */,
507
    /**
508
     * Vertical flip. FLIP_H/FLIP_V is applied before ROT_90.
509
     */
510
    FLIP_V = 2 /* (1 << 1) */,
511
    /**
512
     * 90 degree clockwise rotation. FLIP_H/FLIP_V is applied before ROT_90.
513
     */
514
    ROT_90 = 4 /* (1 << 2) */,
515
    /**
516
     * Commonly used combinations.
517
     */
518
    ROT_180 = 3 /* (FLIP_H | FLIP_V) */,
519
    ROT_270 = 7 /* ((FLIP_H | FLIP_V) | ROT_90) */,
520
};
521
522
/**
523
 * Dataspace Definitions
524
 * ======================
525
 * 
526
 * Dataspace is the definition of how pixel values should be interpreted.
527
 * 
528
 * For many formats, this is the colorspace of the image data, which includes
529
 * primaries (including white point) and the transfer characteristic function,
530
 * which describes both gamma curve and numeric range (within the bit depth).
531
 * 
532
 * Other dataspaces include depth measurement data from a depth camera.
533
 * 
534
 * A dataspace is comprised of a number of fields.
535
 * 
536
 * Version
537
 * --------
538
 * The top 2 bits represent the revision of the field specification. This is
539
 * currently always 0.
540
 * 
541
 * 
542
 * bits    31-30 29                      -                          0
543
 *        +-----+----------------------------------------------------+
544
 * fields | Rev |            Revision specific fields                |
545
 *        +-----+----------------------------------------------------+
546
 * 
547
 * Field layout for version = 0:
548
 * ----------------------------
549
 * 
550
 * A dataspace is comprised of the following fields:
551
 *      Standard
552
 *      Transfer function
553
 *      Range
554
 * 
555
 * bits    31-30 29-27 26 -  22 21 -  16 15             -           0
556
 *        +-----+-----+--------+--------+----------------------------+
557
 * fields |  0  |Range|Transfer|Standard|    Legacy and custom       |
558
 *        +-----+-----+--------+--------+----------------------------+
559
 *          VV    RRR   TTTTT    SSSSSS    LLLLLLLL       LLLLLLLL
560
 * 
561
 * If range, transfer and standard fields are all 0 (e.g. top 16 bits are
562
 * all zeroes), the bottom 16 bits contain either a legacy dataspace value,
563
 * or a custom value.
564
 */
565
enum class Dataspace : int32_t {
566
    /**
567
     * Default-assumption data space, when not explicitly specified.
568
     * 
569
     * It is safest to assume the buffer is an image with sRGB primaries and
570
     * encoding ranges, but the consumer and/or the producer of the data may
571
     * simply be using defaults. No automatic gamma transform should be
572
     * expected, except for a possible display gamma transform when drawn to a
573
     * screen.
574
     */
575
    UNKNOWN = 0 /* 0x0 */,
576
    /**
577
     * Arbitrary dataspace with manually defined characteristics.  Definition
578
     * for colorspaces or other meaning must be communicated separately.
579
     * 
580
     * This is used when specifying primaries, transfer characteristics,
581
     * etc. separately.
582
     * 
583
     * A typical use case is in video encoding parameters (e.g. for H.264),
584
     * where a colorspace can have separately defined primaries, transfer
585
     * characteristics, etc.
586
     */
587
    ARBITRARY = 1 /* 0x1 */,
588
    /**
589
     * Color-description aspects
590
     * 
591
     * The following aspects define various characteristics of the color
592
     * specification. These represent bitfields, so that a data space value
593
     * can specify each of them independently.
594
     */
595
    STANDARD_SHIFT = 16,
596
    /**
597
     * Standard aspect
598
     * 
599
     * Defines the chromaticity coordinates of the source primaries in terms of
600
     * the CIE 1931 definition of x and y specified in ISO 11664-1.
601
     */
602
    STANDARD_MASK = 4128768 /* (63 << STANDARD_SHIFT) */,
603
    /**
604
     * Chromacity coordinates are unknown or are determined by the application.
605
     * Implementations shall use the following suggested standards:
606
     * 
607
     * All YCbCr formats: BT709 if size is 720p or larger (since most video
608
     *                    content is letterboxed this corresponds to width is
609
     *                    1280 or greater, or height is 720 or greater).
610
     *                    BT601_625 if size is smaller than 720p or is JPEG.
611
     * All RGB formats:   BT709.
612
     * 
613
     * For all other formats standard is undefined, and implementations should use
614
     * an appropriate standard for the data represented.
615
     */
616
    STANDARD_UNSPECIFIED = 0 /* (0 << STANDARD_SHIFT) */,
617
    /**
618
     * Primaries:       x       y
619
     *  green           0.300   0.600
620
     *  blue            0.150   0.060
621
     *  red             0.640   0.330
622
     *  white (D65)     0.3127  0.3290
623
     * 
624
     * Use the unadjusted KR = 0.2126, KB = 0.0722 luminance interpretation
625
     * for RGB conversion.
626
     */
627
    STANDARD_BT709 = 65536 /* (1 << STANDARD_SHIFT) */,
628
    /**
629
     * Primaries:       x       y
630
     *  green           0.290   0.600
631
     *  blue            0.150   0.060
632
     *  red             0.640   0.330
633
     *  white (D65)     0.3127  0.3290
634
     * 
635
     *  KR = 0.299, KB = 0.114. This adjusts the luminance interpretation
636
     *  for RGB conversion from the one purely determined by the primaries
637
     *  to minimize the color shift into RGB space that uses BT.709
638
     *  primaries.
639
     */
640
    STANDARD_BT601_625 = 131072 /* (2 << STANDARD_SHIFT) */,
641
    /**
642
     * Primaries:       x       y
643
     *  green           0.290   0.600
644
     *  blue            0.150   0.060
645
     *  red             0.640   0.330
646
     *  white (D65)     0.3127  0.3290
647
     * 
648
     * Use the unadjusted KR = 0.222, KB = 0.071 luminance interpretation
649
     * for RGB conversion.
650
     */
651
    STANDARD_BT601_625_UNADJUSTED = 196608 /* (3 << STANDARD_SHIFT) */,
652
    /**
653
     * Primaries:       x       y
654
     *  green           0.310   0.595
655
     *  blue            0.155   0.070
656
     *  red             0.630   0.340
657
     *  white (D65)     0.3127  0.3290
658
     * 
659
     *  KR = 0.299, KB = 0.114. This adjusts the luminance interpretation
660
     *  for RGB conversion from the one purely determined by the primaries
661
     *  to minimize the color shift into RGB space that uses BT.709
662
     *  primaries.
663
     */
664
    STANDARD_BT601_525 = 262144 /* (4 << STANDARD_SHIFT) */,
665
    /**
666
     * Primaries:       x       y
667
     *  green           0.310   0.595
668
     *  blue            0.155   0.070
669
     *  red             0.630   0.340
670
     *  white (D65)     0.3127  0.3290
671
     * 
672
     * Use the unadjusted KR = 0.212, KB = 0.087 luminance interpretation
673
     * for RGB conversion (as in SMPTE 240M).
674
     */
675
    STANDARD_BT601_525_UNADJUSTED = 327680 /* (5 << STANDARD_SHIFT) */,
676
    /**
677
     * Primaries:       x       y
678
     *  green           0.170   0.797
679
     *  blue            0.131   0.046
680
     *  red             0.708   0.292
681
     *  white (D65)     0.3127  0.3290
682
     * 
683
     * Use the unadjusted KR = 0.2627, KB = 0.0593 luminance interpretation
684
     * for RGB conversion.
685
     */
686
    STANDARD_BT2020 = 393216 /* (6 << STANDARD_SHIFT) */,
687
    /**
688
     * Primaries:       x       y
689
     *  green           0.170   0.797
690
     *  blue            0.131   0.046
691
     *  red             0.708   0.292
692
     *  white (D65)     0.3127  0.3290
693
     * 
694
     * Use the unadjusted KR = 0.2627, KB = 0.0593 luminance interpretation
695
     * for RGB conversion using the linear domain.
696
     */
697
    STANDARD_BT2020_CONSTANT_LUMINANCE = 458752 /* (7 << STANDARD_SHIFT) */,
698
    /**
699
     * Primaries:       x      y
700
     *  green           0.21   0.71
701
     *  blue            0.14   0.08
702
     *  red             0.67   0.33
703
     *  white (C)       0.310  0.316
704
     * 
705
     * Use the unadjusted KR = 0.30, KB = 0.11 luminance interpretation
706
     * for RGB conversion.
707
     */
708
    STANDARD_BT470M = 524288 /* (8 << STANDARD_SHIFT) */,
709
    /**
710
     * Primaries:       x       y
711
     *  green           0.243   0.692
712
     *  blue            0.145   0.049
713
     *  red             0.681   0.319
714
     *  white (C)       0.310   0.316
715
     * 
716
     * Use the unadjusted KR = 0.254, KB = 0.068 luminance interpretation
717
     * for RGB conversion.
718
     */
719
    STANDARD_FILM = 589824 /* (9 << STANDARD_SHIFT) */,
720
    /**
721
     * SMPTE EG 432-1 and SMPTE RP 431-2. (DCI-P3)
722
     * Primaries:       x       y
723
     *  green           0.265   0.690
724
     *  blue            0.150   0.060
725
     *  red             0.680   0.320
726
     *  white (D65)     0.3127  0.3290
727
     */
728
    STANDARD_DCI_P3 = 655360 /* (10 << STANDARD_SHIFT) */,
729
    /**
730
     * Adobe RGB
731
     * Primaries:       x       y
732
     *  green           0.210   0.710
733
     *  blue            0.150   0.060
734
     *  red             0.640   0.330
735
     *  white (D65)     0.3127  0.3290
736
     */
737
    STANDARD_ADOBE_RGB = 720896 /* (11 << STANDARD_SHIFT) */,
738
    TRANSFER_SHIFT = 22,
739
    /**
740
     * Transfer aspect
741
     * 
742
     * Transfer characteristics are the opto-electronic transfer characteristic
743
     * at the source as a function of linear optical intensity (luminance).
744
     * 
745
     * For digital signals, E corresponds to the recorded value. Normally, the
746
     * transfer function is applied in RGB space to each of the R, G and B
747
     * components independently. This may result in color shift that can be
748
     * minized by applying the transfer function in Lab space only for the L
749
     * component. Implementation may apply the transfer function in RGB space
750
     * for all pixel formats if desired.
751
     */
752
    TRANSFER_MASK = 130023424 /* (31 << TRANSFER_SHIFT) */,
753
    /**
754
     * Transfer characteristics are unknown or are determined by the
755
     * application.
756
     * 
757
     * Implementations should use the following transfer functions:
758
     * 
759
     * For YCbCr formats: use TRANSFER_SMPTE_170M
760
     * For RGB formats: use TRANSFER_SRGB
761
     * 
762
     * For all other formats transfer function is undefined, and implementations
763
     * should use an appropriate standard for the data represented.
764
     */
765
    TRANSFER_UNSPECIFIED = 0 /* (0 << TRANSFER_SHIFT) */,
766
    /**
767
     * Transfer characteristic curve:
768
     *  E = L
769
     *      L - luminance of image 0 <= L <= 1 for conventional colorimetry
770
     *      E - corresponding electrical signal
771
     */
772
    TRANSFER_LINEAR = 4194304 /* (1 << TRANSFER_SHIFT) */,
773
    /**
774
     * Transfer characteristic curve:
775
     * 
776
     * E = 1.055 * L^(1/2.4) - 0.055  for 0.0031308 <= L <= 1
777
     *   = 12.92 * L                  for 0 <= L < 0.0031308
778
     *     L - luminance of image 0 <= L <= 1 for conventional colorimetry
779
     *     E - corresponding electrical signal
780
     */
781
    TRANSFER_SRGB = 8388608 /* (2 << TRANSFER_SHIFT) */,
782
    /**
783
     * BT.601 525, BT.601 625, BT.709, BT.2020
784
     * 
785
     * Transfer characteristic curve:
786
     *  E = 1.099 * L ^ 0.45 - 0.099  for 0.018 <= L <= 1
787
     *    = 4.500 * L                 for 0 <= L < 0.018
788
     *      L - luminance of image 0 <= L <= 1 for conventional colorimetry
789
     *      E - corresponding electrical signal
790
     */
791
    TRANSFER_SMPTE_170M = 12582912 /* (3 << TRANSFER_SHIFT) */,
792
    /**
793
     * Assumed display gamma 2.2.
794
     * 
795
     * Transfer characteristic curve:
796
     *  E = L ^ (1/2.2)
797
     *      L - luminance of image 0 <= L <= 1 for conventional colorimetry
798
     *      E - corresponding electrical signal
799
     */
800
    TRANSFER_GAMMA2_2 = 16777216 /* (4 << TRANSFER_SHIFT) */,
801
    /**
802
     *  display gamma 2.6.
803
     * 
804
     * Transfer characteristic curve:
805
     *  E = L ^ (1/2.6)
806
     *      L - luminance of image 0 <= L <= 1 for conventional colorimetry
807
     *      E - corresponding electrical signal
808
     */
809
    TRANSFER_GAMMA2_6 = 20971520 /* (5 << TRANSFER_SHIFT) */,
810
    /**
811
     *  display gamma 2.8.
812
     * 
813
     * Transfer characteristic curve:
814
     *  E = L ^ (1/2.8)
815
     *      L - luminance of image 0 <= L <= 1 for conventional colorimetry
816
     *      E - corresponding electrical signal
817
     */
818
    TRANSFER_GAMMA2_8 = 25165824 /* (6 << TRANSFER_SHIFT) */,
819
    /**
820
     * SMPTE ST 2084 (Dolby Perceptual Quantizer)
821
     * 
822
     * Transfer characteristic curve:
823
     *  E = ((c1 + c2 * L^n) / (1 + c3 * L^n)) ^ m
824
     *  c1 = c3 - c2 + 1 = 3424 / 4096 = 0.8359375
825
     *  c2 = 32 * 2413 / 4096 = 18.8515625
826
     *  c3 = 32 * 2392 / 4096 = 18.6875
827
     *  m = 128 * 2523 / 4096 = 78.84375
828
     *  n = 0.25 * 2610 / 4096 = 0.1593017578125
829
     *      L - luminance of image 0 <= L <= 1 for HDR colorimetry.
830
     *          L = 1 corresponds to 10000 cd/m2
831
     *      E - corresponding electrical signal
832
     */
833
    TRANSFER_ST2084 = 29360128 /* (7 << TRANSFER_SHIFT) */,
834
    /**
835
     * ARIB STD-B67 Hybrid Log Gamma
836
     * 
837
     * Transfer characteristic curve:
838
     *  E = r * L^0.5                 for 0 <= L <= 1
839
     *    = a * ln(L - b) + c         for 1 < L
840
     *  a = 0.17883277
841
     *  b = 0.28466892
842
     *  c = 0.55991073
843
     *  r = 0.5
844
     *      L - luminance of image 0 <= L for HDR colorimetry. L = 1 corresponds
845
     *          to reference white level of 100 cd/m2
846
     *      E - corresponding electrical signal
847
     */
848
    TRANSFER_HLG = 33554432 /* (8 << TRANSFER_SHIFT) */,
849
    RANGE_SHIFT = 27,
850
    /**
851
     * Range aspect
852
     * 
853
     * Defines the range of values corresponding to the unit range of 0-1.
854
     * This is defined for YCbCr only, but can be expanded to RGB space.
855
     */
856
    RANGE_MASK = 939524096 /* (7 << RANGE_SHIFT) */,
857
    /**
858
     * Range is unknown or are determined by the application.  Implementations
859
     * shall use the following suggested ranges:
860
     * 
861
     * All YCbCr formats: limited range.
862
     * All RGB or RGBA formats (including RAW and Bayer): full range.
863
     * All Y formats: full range
864
     * 
865
     * For all other formats range is undefined, and implementations should use
866
     * an appropriate range for the data represented.
867
     */
868
    RANGE_UNSPECIFIED = 0 /* (0 << RANGE_SHIFT) */,
869
    /**
870
     * Full range uses all values for Y, Cb and Cr from
871
     * 0 to 2^b-1, where b is the bit depth of the color format.
872
     */
873
    RANGE_FULL = 134217728 /* (1 << RANGE_SHIFT) */,
874
    /**
875
     * Limited range uses values 16/256*2^b to 235/256*2^b for Y, and
876
     * 1/16*2^b to 15/16*2^b for Cb, Cr, R, G and B, where b is the bit depth of
877
     * the color format.
878
     * 
879
     * E.g. For 8-bit-depth formats:
880
     * Luma (Y) samples should range from 16 to 235, inclusive
881
     * Chroma (Cb, Cr) samples should range from 16 to 240, inclusive
882
     * 
883
     * For 10-bit-depth formats:
884
     * Luma (Y) samples should range from 64 to 940, inclusive
885
     * Chroma (Cb, Cr) samples should range from 64 to 960, inclusive
886
     */
887
    RANGE_LIMITED = 268435456 /* (2 << RANGE_SHIFT) */,
888
    /**
889
     * Extended range is used for scRGB. Intended for use with
890
     * floating point pixel formats. [0.0 - 1.0] is the standard
891
     * sRGB space. Values outside the range 0.0 - 1.0 can encode
892
     * color outside the sRGB gamut.
893
     * Used to blend / merge multiple dataspaces on a single display.
894
     */
895
    RANGE_EXTENDED = 402653184 /* (3 << RANGE_SHIFT) */,
896
    /**
897
     * Legacy dataspaces
898
     * 
899
     * 
900
     * sRGB linear encoding:
901
     * 
902
     * The red, green, and blue components are stored in sRGB space, but
903
     * are linear, not gamma-encoded.
904
     * The RGB primaries and the white point are the same as BT.709.
905
     * 
906
     * The values are encoded using the full range ([0,255] for 8-bit) for all
907
     * components.
908
     */
909
    SRGB_LINEAR = 512 /* 0x200 */,
910
    V0_SRGB_LINEAR = 138477568 /* ((STANDARD_BT709 | TRANSFER_LINEAR) | RANGE_FULL) */,
911
    /**
912
     * scRGB linear encoding:
913
     * 
914
     * The red, green, and blue components are stored in extended sRGB space,
915
     * but are linear, not gamma-encoded.
916
     * The RGB primaries and the white point are the same as BT.709.
917
     * 
918
     * The values are floating point.
919
     * A pixel value of 1.0, 1.0, 1.0 corresponds to sRGB white (D65) at 80 nits.
920
     * Values beyond the range [0.0 - 1.0] would correspond to other colors
921
     * spaces and/or HDR content.
922
     */
923
    V0_SCRGB_LINEAR = 406913024 /* ((STANDARD_BT709 | TRANSFER_LINEAR) | RANGE_EXTENDED) */,
924
    /**
925
     * sRGB gamma encoding:
926
     * 
927
     * The red, green and blue components are stored in sRGB space, and
928
     * converted to linear space when read, using the SRGB transfer function
929
     * for each of the R, G and B components. When written, the inverse
930
     * transformation is performed.
931
     * 
932
     * The alpha component, if present, is always stored in linear space and
933
     * is left unmodified when read or written.
934
     * 
935
     * Use full range and BT.709 standard.
936
     */
937
    SRGB = 513 /* 0x201 */,
938
    V0_SRGB = 142671872 /* ((STANDARD_BT709 | TRANSFER_SRGB) | RANGE_FULL) */,
939
    /**
940
     * scRGB:
941
     * 
942
     * The red, green, and blue components are stored in extended sRGB space,
943
     * but are linear, not gamma-encoded.
944
     * The RGB primaries and the white point are the same as BT.709.
945
     * 
946
     * The values are floating point.
947
     * A pixel value of 1.0, 1.0, 1.0 corresponds to sRGB white (D65) at 80 nits.
948
     * Values beyond the range [0.0 - 1.0] would correspond to other colors
949
     * spaces and/or HDR content.
950
     */
951
    V0_SCRGB = 411107328 /* ((STANDARD_BT709 | TRANSFER_SRGB) | RANGE_EXTENDED) */,
952
    /**
953
     * YCbCr Colorspaces
954
     * -----------------
955
     * 
956
     * Primaries are given using (x,y) coordinates in the CIE 1931 definition
957
     * of x and y specified by ISO 11664-1.
958
     * 
959
     * Transfer characteristics are the opto-electronic transfer characteristic
960
     * at the source as a function of linear optical intensity (luminance).
961
     * 
962
     * 
963
     * JPEG File Interchange Format (JFIF)
964
     * 
965
     * Same model as BT.601-625, but all values (Y, Cb, Cr) range from 0 to 255
966
     * 
967
     * Use full range, BT.601 transfer and BT.601_625 standard.
968
     */
969
    JFIF = 257 /* 0x101 */,
970
    V0_JFIF = 146931712 /* ((STANDARD_BT601_625 | TRANSFER_SMPTE_170M) | RANGE_FULL) */,
971
    /**
972
     * ITU-R Recommendation 601 (BT.601) - 625-line
973
     * 
974
     * Standard-definition television, 625 Lines (PAL)
975
     * 
976
     * Use limited range, BT.601 transfer and BT.601_625 standard.
977
     */
978
    BT601_625 = 258 /* 0x102 */,
979
    V0_BT601_625 = 281149440 /* ((STANDARD_BT601_625 | TRANSFER_SMPTE_170M) | RANGE_LIMITED) */,
980
    /**
981
     * ITU-R Recommendation 601 (BT.601) - 525-line
982
     * 
983
     * Standard-definition television, 525 Lines (NTSC)
984
     * 
985
     * Use limited range, BT.601 transfer and BT.601_525 standard.
986
     */
987
    BT601_525 = 259 /* 0x103 */,
988
    V0_BT601_525 = 281280512 /* ((STANDARD_BT601_525 | TRANSFER_SMPTE_170M) | RANGE_LIMITED) */,
989
    /**
990
     * ITU-R Recommendation 709 (BT.709)
991
     * 
992
     * High-definition television
993
     * 
994
     * Use limited range, BT.709 transfer and BT.709 standard.
995
     */
996
    BT709 = 260 /* 0x104 */,
997
    V0_BT709 = 281083904 /* ((STANDARD_BT709 | TRANSFER_SMPTE_170M) | RANGE_LIMITED) */,
998
    /**
999
     * SMPTE EG 432-1 and SMPTE RP 431-2.
1000
     * 
1001
     * Digital Cinema DCI-P3
1002
     * 
1003
     * Use full range, linear transfer and D65 DCI-P3 standard
1004
     */
1005
    DCI_P3_LINEAR = 139067392 /* ((STANDARD_DCI_P3 | TRANSFER_LINEAR) | RANGE_FULL) */,
1006
    /**
1007
     * SMPTE EG 432-1 and SMPTE RP 431-2.
1008
     * 
1009
     * Digital Cinema DCI-P3
1010
     * 
1011
     * Use full range, gamma 2.6 transfer and D65 DCI-P3 standard
1012
     * Note: Application is responsible for gamma encoding the data as
1013
     * a 2.6 gamma encoding is not supported in HW.
1014
     */
1015
    DCI_P3 = 155844608 /* ((STANDARD_DCI_P3 | TRANSFER_GAMMA2_6) | RANGE_FULL) */,
1016
    /**
1017
     * Display P3
1018
     * 
1019
     * Display P3 uses same primaries and white-point as DCI-P3
1020
     * linear transfer function makes this the same as DCI_P3_LINEAR.
1021
     */
1022
    DISPLAY_P3_LINEAR = 139067392 /* ((STANDARD_DCI_P3 | TRANSFER_LINEAR) | RANGE_FULL) */,
1023
    /**
1024
     * Display P3
1025
     * 
1026
     * Use same primaries and white-point as DCI-P3
1027
     * but sRGB transfer function.
1028
     */
1029
    DISPLAY_P3 = 143261696 /* ((STANDARD_DCI_P3 | TRANSFER_SRGB) | RANGE_FULL) */,
1030
    /**
1031
     * Adobe RGB
1032
     * 
1033
     * Use full range, gamma 2.2 transfer and Adobe RGB primaries
1034
     * Note: Application is responsible for gamma encoding the data as
1035
     * a 2.2 gamma encoding is not supported in HW.
1036
     */
1037
    ADOBE_RGB = 151715840 /* ((STANDARD_ADOBE_RGB | TRANSFER_GAMMA2_2) | RANGE_FULL) */,
1038
    /**
1039
     * ITU-R Recommendation 2020 (BT.2020)
1040
     * 
1041
     * Ultra High-definition television
1042
     * 
1043
     * Use full range, linear transfer and BT2020 standard
1044
     */
1045
    BT2020_LINEAR = 138805248 /* ((STANDARD_BT2020 | TRANSFER_LINEAR) | RANGE_FULL) */,
1046
    /**
1047
     * ITU-R Recommendation 2020 (BT.2020)
1048
     * 
1049
     * Ultra High-definition television
1050
     * 
1051
     * Use full range, BT.709 transfer and BT2020 standard
1052
     */
1053
    BT2020 = 147193856 /* ((STANDARD_BT2020 | TRANSFER_SMPTE_170M) | RANGE_FULL) */,
1054
    /**
1055
     * ITU-R Recommendation 2020 (BT.2020)
1056
     * 
1057
     * Ultra High-definition television
1058
     * 
1059
     * Use full range, SMPTE 2084 (PQ) transfer and BT2020 standard
1060
     */
1061
    BT2020_PQ = 163971072 /* ((STANDARD_BT2020 | TRANSFER_ST2084) | RANGE_FULL) */,
1062
    /**
1063
     * Data spaces for non-color formats
1064
     * 
1065
     * 
1066
     * The buffer contains depth ranging measurements from a depth camera.
1067
     * This value is valid with formats:
1068
     *    HAL_PIXEL_FORMAT_Y16: 16-bit samples, consisting of a depth measurement
1069
     *       and an associated confidence value. The 3 MSBs of the sample make
1070
     *       up the confidence value, and the low 13 LSBs of the sample make up
1071
     *       the depth measurement.
1072
     *       For the confidence section, 0 means 100% confidence, 1 means 0%
1073
     *       confidence. The mapping to a linear float confidence value between
1074
     *       0.f and 1.f can be obtained with
1075
     *         float confidence = (((depthSample >> 13) - 1) & 0x7) / 7.0f;
1076
     *       The depth measurement can be extracted simply with
1077
     *         uint16_t range = (depthSample & 0x1FFF);
1078
     *    HAL_PIXEL_FORMAT_BLOB: A depth point cloud, as
1079
     *       a variable-length float (x,y,z, confidence) coordinate point list.
1080
     *       The point cloud will be represented with the android_depth_points
1081
     *       structure.
1082
     */
1083
    DEPTH = 4096 /* 0x1000 */,
1084
    /**
1085
     * The buffer contains sensor events from sensor direct report.
1086
     * This value is valid with formats:
1087
     *    HAL_PIXEL_FORMAT_BLOB: an array of sensor event structure that forms
1088
     *       a lock free queue. Format of sensor event structure is specified
1089
     *       in Sensors HAL.
1090
     */
1091
    SENSOR = 4097 /* 0x1001 */,
1092
};
1093
1094
/**
1095
 * Color modes that may be supported by a display.
1096
 * 
1097
 * Definitions:
1098
 * Rendering intent generally defines the goal in mapping a source (input)
1099
 * color to a destination device color for a given color mode.
1100
 * 
1101
 *  It is important to keep in mind three cases where mapping may be applied:
1102
 *  1. The source gamut is much smaller than the destination (display) gamut
1103
 *  2. The source gamut is much larger than the destination gamut (this will
1104
 *  ordinarily be handled using colorimetric rendering, below)
1105
 *  3. The source and destination gamuts are roughly equal, although not
1106
 *  completely overlapping
1107
 *  Also, a common requirement for mappings is that skin tones should be
1108
 *  preserved, or at least remain natural in appearance.
1109
 * 
1110
 *  Colorimetric Rendering Intent (All cases):
1111
 *  Colorimetric indicates that colors should be preserved. In the case
1112
 *  that the source gamut lies wholly within the destination gamut or is
1113
 *  about the same (#1, #3), this will simply mean that no manipulations
1114
 *  (no saturation boost, for example) are applied. In the case where some
1115
 *  source colors lie outside the destination gamut (#2, #3), those will
1116
 *  need to be mapped to colors that are within the destination gamut,
1117
 *  while the already in-gamut colors remain unchanged.
1118
 * 
1119
 *  Non-colorimetric transforms can take many forms. There are no hard
1120
 *  rules and it's left to the implementation to define.
1121
 *  Two common intents are described below.
1122
 * 
1123
 *  Stretched-Gamut Enhancement Intent (Source < Destination):
1124
 *  When the destination gamut is much larger than the source gamut (#1), the
1125
 *  source primaries may be redefined to reflect the full extent of the
1126
 *  destination space, or to reflect an intermediate gamut.
1127
 *  Skin-tone preservation would likely be applied. An example might be sRGB
1128
 *  input displayed on a DCI-P3 capable device, with skin-tone preservation.
1129
 * 
1130
 *  Within-Gamut Enhancement Intent (Source >= Destination):
1131
 *  When the device (destination) gamut is not larger than the source gamut
1132
 *  (#2 or #3), but the appearance of a larger gamut is desired, techniques
1133
 *  such as saturation boost may be applied to the source colors. Skin-tone
1134
 *  preservation may be applied. There is no unique method for within-gamut
1135
 *  enhancement; it would be defined within a flexible color mode.
1136
 * 
1137
 */
1138
enum class ColorMode : int32_t {
1139
    /**
1140
     * DEFAULT is the "native" gamut of the display.
1141
     * White Point: Vendor/OEM defined
1142
     * Panel Gamma: Vendor/OEM defined (typically 2.2)
1143
     * Rendering Intent: Vendor/OEM defined (typically 'enhanced')
1144
     */
1145
    NATIVE = 0,
1146
    /**
1147
     * STANDARD_BT601_625 corresponds with display
1148
     * settings that implement the ITU-R Recommendation BT.601
1149
     * or Rec 601. Using 625 line version
1150
     * Rendering Intent: Colorimetric
1151
     * Primaries:
1152
     *                  x       y
1153
     *  green           0.290   0.600
1154
     *  blue            0.150   0.060
1155
     *  red             0.640   0.330
1156
     *  white (D65)     0.3127  0.3290
1157
     * 
1158
     *  KR = 0.299, KB = 0.114. This adjusts the luminance interpretation
1159
     *  for RGB conversion from the one purely determined by the primaries
1160
     *  to minimize the color shift into RGB space that uses BT.709
1161
     *  primaries.
1162
     * 
1163
     * Gamma Correction (GC):
1164
     * 
1165
     *  if Vlinear < 0.018
1166
     *    Vnonlinear = 4.500 * Vlinear
1167
     *  else
1168
     *    Vnonlinear = 1.099 * (Vlinear)^(0.45) – 0.099
1169
     */
1170
    STANDARD_BT601_625 = 1,
1171
    /**
1172
     * Primaries:
1173
     *                  x       y
1174
     *  green           0.290   0.600
1175
     *  blue            0.150   0.060
1176
     *  red             0.640   0.330
1177
     *  white (D65)     0.3127  0.3290
1178
     * 
1179
     *  Use the unadjusted KR = 0.222, KB = 0.071 luminance interpretation
1180
     *  for RGB conversion.
1181
     * 
1182
     * Gamma Correction (GC):
1183
     * 
1184
     *  if Vlinear < 0.018
1185
     *    Vnonlinear = 4.500 * Vlinear
1186
     *  else
1187
     *    Vnonlinear = 1.099 * (Vlinear)^(0.45) – 0.099
1188
     */
1189
    STANDARD_BT601_625_UNADJUSTED = 2,
1190
    /**
1191
     * Primaries:
1192
     *                  x       y
1193
     *  green           0.310   0.595
1194
     *  blue            0.155   0.070
1195
     *  red             0.630   0.340
1196
     *  white (D65)     0.3127  0.3290
1197
     * 
1198
     *  KR = 0.299, KB = 0.114. This adjusts the luminance interpretation
1199
     *  for RGB conversion from the one purely determined by the primaries
1200
     *  to minimize the color shift into RGB space that uses BT.709
1201
     *  primaries.
1202
     * 
1203
     * Gamma Correction (GC):
1204
     * 
1205
     *  if Vlinear < 0.018
1206
     *    Vnonlinear = 4.500 * Vlinear
1207
     *  else
1208
     *    Vnonlinear = 1.099 * (Vlinear)^(0.45) – 0.099
1209
     */
1210
    STANDARD_BT601_525 = 3,
1211
    /**
1212
     * Primaries:
1213
     *                  x       y
1214
     *  green           0.310   0.595
1215
     *  blue            0.155   0.070
1216
     *  red             0.630   0.340
1217
     *  white (D65)     0.3127  0.3290
1218
     * 
1219
     *  Use the unadjusted KR = 0.212, KB = 0.087 luminance interpretation
1220
     *  for RGB conversion (as in SMPTE 240M).
1221
     * 
1222
     * Gamma Correction (GC):
1223
     * 
1224
     *  if Vlinear < 0.018
1225
     *    Vnonlinear = 4.500 * Vlinear
1226
     *  else
1227
     *    Vnonlinear = 1.099 * (Vlinear)^(0.45) – 0.099
1228
     */
1229
    STANDARD_BT601_525_UNADJUSTED = 4,
1230
    /**
1231
     * REC709 corresponds with display settings that implement
1232
     * the ITU-R Recommendation BT.709 / Rec. 709 for high-definition television.
1233
     * Rendering Intent: Colorimetric
1234
     * Primaries:
1235
     *                  x       y
1236
     *  green           0.300   0.600
1237
     *  blue            0.150   0.060
1238
     *  red             0.640   0.330
1239
     *  white (D65)     0.3127  0.3290
1240
     * 
1241
     * HDTV REC709 Inverse Gamma Correction (IGC): V represents normalized
1242
     * (with [0 to 1] range) value of R, G, or B.
1243
     * 
1244
     *  if Vnonlinear < 0.081
1245
     *    Vlinear = Vnonlinear / 4.5
1246
     *  else
1247
     *    Vlinear = ((Vnonlinear + 0.099) / 1.099) ^ (1/0.45)
1248
     * 
1249
     * HDTV REC709 Gamma Correction (GC):
1250
     * 
1251
     *  if Vlinear < 0.018
1252
     *    Vnonlinear = 4.5 * Vlinear
1253
     *  else
1254
     *    Vnonlinear = 1.099 * (Vlinear) ^ 0.45 – 0.099
1255
     */
1256
    STANDARD_BT709 = 5,
1257
    /**
1258
     * DCI_P3 corresponds with display settings that implement
1259
     * SMPTE EG 432-1 and SMPTE RP 431-2
1260
     * Rendering Intent: Colorimetric
1261
     * Primaries:
1262
     *                  x       y
1263
     *  green           0.265   0.690
1264
     *  blue            0.150   0.060
1265
     *  red             0.680   0.320
1266
     *  white (D65)     0.3127  0.3290
1267
     * 
1268
     * Gamma: 2.6
1269
     */
1270
    DCI_P3 = 6,
1271
    /**
1272
     * SRGB corresponds with display settings that implement
1273
     * the sRGB color space. Uses the same primaries as ITU-R Recommendation
1274
     * BT.709
1275
     * Rendering Intent: Colorimetric
1276
     * Primaries:
1277
     *                  x       y
1278
     *  green           0.300   0.600
1279
     *  blue            0.150   0.060
1280
     *  red             0.640   0.330
1281
     *  white (D65)     0.3127  0.3290
1282
     * 
1283
     * PC/Internet (sRGB) Inverse Gamma Correction (IGC):
1284
     * 
1285
     *  if Vnonlinear ≤ 0.03928
1286
     *    Vlinear = Vnonlinear / 12.92
1287
     *  else
1288
     *    Vlinear = ((Vnonlinear + 0.055)/1.055) ^ 2.4
1289
     * 
1290
     * PC/Internet (sRGB) Gamma Correction (GC):
1291
     * 
1292
     *  if Vlinear ≤ 0.0031308
1293
     *    Vnonlinear = 12.92 * Vlinear
1294
     *  else
1295
     *    Vnonlinear = 1.055 * (Vlinear)^(1/2.4) – 0.055
1296
     */
1297
    SRGB = 7,
1298
    /**
1299
     * ADOBE_RGB corresponds with the RGB color space developed
1300
     * by Adobe Systems, Inc. in 1998.
1301
     * Rendering Intent: Colorimetric
1302
     * Primaries:
1303
     *                  x       y
1304
     *  green           0.210   0.710
1305
     *  blue            0.150   0.060
1306
     *  red             0.640   0.330
1307
     *  white (D65)     0.3127  0.3290
1308
     * 
1309
     * Gamma: 2.2
1310
     */
1311
    ADOBE_RGB = 8,
1312
    /**
1313
     * DISPLAY_P3 is a color space that uses the DCI_P3 primaries,
1314
     * the D65 white point and the SRGB transfer functions.
1315
     * Rendering Intent: Colorimetric
1316
     * Primaries:
1317
     *                  x       y
1318
     *  green           0.265   0.690
1319
     *  blue            0.150   0.060
1320
     *  red             0.680   0.320
1321
     *  white (D65)     0.3127  0.3290
1322
     * 
1323
     * PC/Internet (sRGB) Gamma Correction (GC):
1324
     * 
1325
     *  if Vlinear ≤ 0.0030186
1326
     *    Vnonlinear = 12.92 * Vlinear
1327
     *  else
1328
     *    Vnonlinear = 1.055 * (Vlinear)^(1/2.4) – 0.055
1329
     * 
1330
     * Note: In most cases sRGB transfer function will be fine.
1331
     */
1332
    DISPLAY_P3 = 9,
1333
};
1334
1335
/**
1336
 * Color transforms that may be applied by hardware composer to the whole
1337
 * display.
1338
 */
1339
enum class ColorTransform : int32_t {
1340
    /**
1341
     * Applies no transform to the output color  */
1342
    IDENTITY = 0,
1343
    /**
1344
     * Applies an arbitrary transform defined by a 4x4 affine matrix  */
1345
    ARBITRARY_MATRIX = 1,
1346
    /**
1347
     * Applies a transform that inverts the value or luminance of the color, but
1348
     * does not modify hue or saturation  */
1349
    VALUE_INVERSE = 2,
1350
    /**
1351
     * Applies a transform that maps all colors to shades of gray  */
1352
    GRAYSCALE = 3,
1353
    /**
1354
     * Applies a transform which corrects for protanopic color blindness  */
1355
    CORRECT_PROTANOPIA = 4,
1356
    /**
1357
     * Applies a transform which corrects for deuteranopic color blindness  */
1358
    CORRECT_DEUTERANOPIA = 5,
1359
    /**
1360
     * Applies a transform which corrects for tritanopic color blindness  */
1361
    CORRECT_TRITANOPIA = 6,
1362
};
1363
1364
/**
1365
 * Supported HDR formats. Must be kept in sync with equivalents in Display.java.
1366
 */
1367
enum class Hdr : int32_t {
1368
    /**
1369
     * Device supports Dolby Vision HDR  */
1370
    DOLBY_VISION = 1,
1371
    /**
1372
     * Device supports HDR10  */
1373
    HDR10 = 2,
1374
    /**
1375
     * Device supports hybrid log-gamma HDR  */
1376
    HLG = 3,
1377
};
1378
1379
//
1380
// type declarations for package
1381
//
1382
1383
template<typename>
1384
static inline std::string toString(int32_t o);
1385
static inline std::string toString(::android::hardware::graphics::common::V1_0::PixelFormat o);
1386
1387
0
constexpr int32_t operator|(const ::android::hardware::graphics::common::V1_0::PixelFormat lhs, const ::android::hardware::graphics::common::V1_0::PixelFormat rhs) {
1388
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) | static_cast<int32_t>(rhs));
1389
0
}
1390
0
constexpr int32_t operator|(const int32_t lhs, const ::android::hardware::graphics::common::V1_0::PixelFormat rhs) {
1391
0
    return static_cast<int32_t>(lhs | static_cast<int32_t>(rhs));
1392
0
}
1393
0
constexpr int32_t operator|(const ::android::hardware::graphics::common::V1_0::PixelFormat lhs, const int32_t rhs) {
1394
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) | rhs);
1395
0
}
1396
0
constexpr int32_t operator&(const ::android::hardware::graphics::common::V1_0::PixelFormat lhs, const ::android::hardware::graphics::common::V1_0::PixelFormat rhs) {
1397
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) & static_cast<int32_t>(rhs));
1398
0
}
1399
0
constexpr int32_t operator&(const int32_t lhs, const ::android::hardware::graphics::common::V1_0::PixelFormat rhs) {
1400
0
    return static_cast<int32_t>(lhs & static_cast<int32_t>(rhs));
1401
0
}
1402
0
constexpr int32_t operator&(const ::android::hardware::graphics::common::V1_0::PixelFormat lhs, const int32_t rhs) {
1403
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) & rhs);
1404
0
}
1405
0
constexpr int32_t &operator|=(int32_t& v, const ::android::hardware::graphics::common::V1_0::PixelFormat e) {
1406
0
    v |= static_cast<int32_t>(e);
1407
0
    return v;
1408
0
}
1409
0
constexpr int32_t &operator&=(int32_t& v, const ::android::hardware::graphics::common::V1_0::PixelFormat e) {
1410
0
    v &= static_cast<int32_t>(e);
1411
0
    return v;
1412
0
}
1413
1414
template<typename>
1415
static inline std::string toString(uint64_t o);
1416
static inline std::string toString(::android::hardware::graphics::common::V1_0::BufferUsage o);
1417
1418
0
constexpr uint64_t operator|(const ::android::hardware::graphics::common::V1_0::BufferUsage lhs, const ::android::hardware::graphics::common::V1_0::BufferUsage rhs) {
1419
0
    return static_cast<uint64_t>(static_cast<uint64_t>(lhs) | static_cast<uint64_t>(rhs));
1420
0
}
1421
0
constexpr uint64_t operator|(const uint64_t lhs, const ::android::hardware::graphics::common::V1_0::BufferUsage rhs) {
1422
0
    return static_cast<uint64_t>(lhs | static_cast<uint64_t>(rhs));
1423
0
}
1424
0
constexpr uint64_t operator|(const ::android::hardware::graphics::common::V1_0::BufferUsage lhs, const uint64_t rhs) {
1425
0
    return static_cast<uint64_t>(static_cast<uint64_t>(lhs) | rhs);
1426
0
}
1427
0
constexpr uint64_t operator&(const ::android::hardware::graphics::common::V1_0::BufferUsage lhs, const ::android::hardware::graphics::common::V1_0::BufferUsage rhs) {
1428
0
    return static_cast<uint64_t>(static_cast<uint64_t>(lhs) & static_cast<uint64_t>(rhs));
1429
0
}
1430
0
constexpr uint64_t operator&(const uint64_t lhs, const ::android::hardware::graphics::common::V1_0::BufferUsage rhs) {
1431
0
    return static_cast<uint64_t>(lhs & static_cast<uint64_t>(rhs));
1432
0
}
1433
0
constexpr uint64_t operator&(const ::android::hardware::graphics::common::V1_0::BufferUsage lhs, const uint64_t rhs) {
1434
0
    return static_cast<uint64_t>(static_cast<uint64_t>(lhs) & rhs);
1435
0
}
1436
0
constexpr uint64_t &operator|=(uint64_t& v, const ::android::hardware::graphics::common::V1_0::BufferUsage e) {
1437
0
    v |= static_cast<uint64_t>(e);
1438
0
    return v;
1439
0
}
1440
0
constexpr uint64_t &operator&=(uint64_t& v, const ::android::hardware::graphics::common::V1_0::BufferUsage e) {
1441
0
    v &= static_cast<uint64_t>(e);
1442
0
    return v;
1443
0
}
1444
1445
template<typename>
1446
static inline std::string toString(int32_t o);
1447
static inline std::string toString(::android::hardware::graphics::common::V1_0::Transform o);
1448
1449
0
constexpr int32_t operator|(const ::android::hardware::graphics::common::V1_0::Transform lhs, const ::android::hardware::graphics::common::V1_0::Transform rhs) {
1450
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) | static_cast<int32_t>(rhs));
1451
0
}
1452
0
constexpr int32_t operator|(const int32_t lhs, const ::android::hardware::graphics::common::V1_0::Transform rhs) {
1453
0
    return static_cast<int32_t>(lhs | static_cast<int32_t>(rhs));
1454
0
}
1455
0
constexpr int32_t operator|(const ::android::hardware::graphics::common::V1_0::Transform lhs, const int32_t rhs) {
1456
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) | rhs);
1457
0
}
1458
0
constexpr int32_t operator&(const ::android::hardware::graphics::common::V1_0::Transform lhs, const ::android::hardware::graphics::common::V1_0::Transform rhs) {
1459
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) & static_cast<int32_t>(rhs));
1460
0
}
1461
0
constexpr int32_t operator&(const int32_t lhs, const ::android::hardware::graphics::common::V1_0::Transform rhs) {
1462
0
    return static_cast<int32_t>(lhs & static_cast<int32_t>(rhs));
1463
0
}
1464
0
constexpr int32_t operator&(const ::android::hardware::graphics::common::V1_0::Transform lhs, const int32_t rhs) {
1465
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) & rhs);
1466
0
}
1467
0
constexpr int32_t &operator|=(int32_t& v, const ::android::hardware::graphics::common::V1_0::Transform e) {
1468
0
    v |= static_cast<int32_t>(e);
1469
0
    return v;
1470
0
}
1471
0
constexpr int32_t &operator&=(int32_t& v, const ::android::hardware::graphics::common::V1_0::Transform e) {
1472
0
    v &= static_cast<int32_t>(e);
1473
0
    return v;
1474
0
}
1475
1476
template<typename>
1477
static inline std::string toString(int32_t o);
1478
static inline std::string toString(::android::hardware::graphics::common::V1_0::Dataspace o);
1479
1480
0
constexpr int32_t operator|(const ::android::hardware::graphics::common::V1_0::Dataspace lhs, const ::android::hardware::graphics::common::V1_0::Dataspace rhs) {
1481
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) | static_cast<int32_t>(rhs));
1482
0
}
1483
0
constexpr int32_t operator|(const int32_t lhs, const ::android::hardware::graphics::common::V1_0::Dataspace rhs) {
1484
0
    return static_cast<int32_t>(lhs | static_cast<int32_t>(rhs));
1485
0
}
1486
0
constexpr int32_t operator|(const ::android::hardware::graphics::common::V1_0::Dataspace lhs, const int32_t rhs) {
1487
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) | rhs);
1488
0
}
1489
0
constexpr int32_t operator&(const ::android::hardware::graphics::common::V1_0::Dataspace lhs, const ::android::hardware::graphics::common::V1_0::Dataspace rhs) {
1490
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) & static_cast<int32_t>(rhs));
1491
0
}
1492
0
constexpr int32_t operator&(const int32_t lhs, const ::android::hardware::graphics::common::V1_0::Dataspace rhs) {
1493
0
    return static_cast<int32_t>(lhs & static_cast<int32_t>(rhs));
1494
0
}
1495
0
constexpr int32_t operator&(const ::android::hardware::graphics::common::V1_0::Dataspace lhs, const int32_t rhs) {
1496
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) & rhs);
1497
0
}
1498
0
constexpr int32_t &operator|=(int32_t& v, const ::android::hardware::graphics::common::V1_0::Dataspace e) {
1499
0
    v |= static_cast<int32_t>(e);
1500
0
    return v;
1501
0
}
1502
0
constexpr int32_t &operator&=(int32_t& v, const ::android::hardware::graphics::common::V1_0::Dataspace e) {
1503
0
    v &= static_cast<int32_t>(e);
1504
0
    return v;
1505
0
}
1506
1507
template<typename>
1508
static inline std::string toString(int32_t o);
1509
static inline std::string toString(::android::hardware::graphics::common::V1_0::ColorMode o);
1510
1511
0
constexpr int32_t operator|(const ::android::hardware::graphics::common::V1_0::ColorMode lhs, const ::android::hardware::graphics::common::V1_0::ColorMode rhs) {
1512
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) | static_cast<int32_t>(rhs));
1513
0
}
1514
0
constexpr int32_t operator|(const int32_t lhs, const ::android::hardware::graphics::common::V1_0::ColorMode rhs) {
1515
0
    return static_cast<int32_t>(lhs | static_cast<int32_t>(rhs));
1516
0
}
1517
0
constexpr int32_t operator|(const ::android::hardware::graphics::common::V1_0::ColorMode lhs, const int32_t rhs) {
1518
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) | rhs);
1519
0
}
1520
0
constexpr int32_t operator&(const ::android::hardware::graphics::common::V1_0::ColorMode lhs, const ::android::hardware::graphics::common::V1_0::ColorMode rhs) {
1521
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) & static_cast<int32_t>(rhs));
1522
0
}
1523
0
constexpr int32_t operator&(const int32_t lhs, const ::android::hardware::graphics::common::V1_0::ColorMode rhs) {
1524
0
    return static_cast<int32_t>(lhs & static_cast<int32_t>(rhs));
1525
0
}
1526
0
constexpr int32_t operator&(const ::android::hardware::graphics::common::V1_0::ColorMode lhs, const int32_t rhs) {
1527
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) & rhs);
1528
0
}
1529
0
constexpr int32_t &operator|=(int32_t& v, const ::android::hardware::graphics::common::V1_0::ColorMode e) {
1530
0
    v |= static_cast<int32_t>(e);
1531
0
    return v;
1532
0
}
1533
0
constexpr int32_t &operator&=(int32_t& v, const ::android::hardware::graphics::common::V1_0::ColorMode e) {
1534
0
    v &= static_cast<int32_t>(e);
1535
0
    return v;
1536
0
}
1537
1538
template<typename>
1539
static inline std::string toString(int32_t o);
1540
static inline std::string toString(::android::hardware::graphics::common::V1_0::ColorTransform o);
1541
1542
0
constexpr int32_t operator|(const ::android::hardware::graphics::common::V1_0::ColorTransform lhs, const ::android::hardware::graphics::common::V1_0::ColorTransform rhs) {
1543
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) | static_cast<int32_t>(rhs));
1544
0
}
1545
0
constexpr int32_t operator|(const int32_t lhs, const ::android::hardware::graphics::common::V1_0::ColorTransform rhs) {
1546
0
    return static_cast<int32_t>(lhs | static_cast<int32_t>(rhs));
1547
0
}
1548
0
constexpr int32_t operator|(const ::android::hardware::graphics::common::V1_0::ColorTransform lhs, const int32_t rhs) {
1549
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) | rhs);
1550
0
}
1551
0
constexpr int32_t operator&(const ::android::hardware::graphics::common::V1_0::ColorTransform lhs, const ::android::hardware::graphics::common::V1_0::ColorTransform rhs) {
1552
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) & static_cast<int32_t>(rhs));
1553
0
}
1554
0
constexpr int32_t operator&(const int32_t lhs, const ::android::hardware::graphics::common::V1_0::ColorTransform rhs) {
1555
0
    return static_cast<int32_t>(lhs & static_cast<int32_t>(rhs));
1556
0
}
1557
0
constexpr int32_t operator&(const ::android::hardware::graphics::common::V1_0::ColorTransform lhs, const int32_t rhs) {
1558
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) & rhs);
1559
0
}
1560
0
constexpr int32_t &operator|=(int32_t& v, const ::android::hardware::graphics::common::V1_0::ColorTransform e) {
1561
0
    v |= static_cast<int32_t>(e);
1562
0
    return v;
1563
0
}
1564
0
constexpr int32_t &operator&=(int32_t& v, const ::android::hardware::graphics::common::V1_0::ColorTransform e) {
1565
0
    v &= static_cast<int32_t>(e);
1566
0
    return v;
1567
0
}
1568
1569
template<typename>
1570
static inline std::string toString(int32_t o);
1571
static inline std::string toString(::android::hardware::graphics::common::V1_0::Hdr o);
1572
1573
0
constexpr int32_t operator|(const ::android::hardware::graphics::common::V1_0::Hdr lhs, const ::android::hardware::graphics::common::V1_0::Hdr rhs) {
1574
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) | static_cast<int32_t>(rhs));
1575
0
}
1576
0
constexpr int32_t operator|(const int32_t lhs, const ::android::hardware::graphics::common::V1_0::Hdr rhs) {
1577
0
    return static_cast<int32_t>(lhs | static_cast<int32_t>(rhs));
1578
0
}
1579
0
constexpr int32_t operator|(const ::android::hardware::graphics::common::V1_0::Hdr lhs, const int32_t rhs) {
1580
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) | rhs);
1581
0
}
1582
0
constexpr int32_t operator&(const ::android::hardware::graphics::common::V1_0::Hdr lhs, const ::android::hardware::graphics::common::V1_0::Hdr rhs) {
1583
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) & static_cast<int32_t>(rhs));
1584
0
}
1585
0
constexpr int32_t operator&(const int32_t lhs, const ::android::hardware::graphics::common::V1_0::Hdr rhs) {
1586
0
    return static_cast<int32_t>(lhs & static_cast<int32_t>(rhs));
1587
0
}
1588
0
constexpr int32_t operator&(const ::android::hardware::graphics::common::V1_0::Hdr lhs, const int32_t rhs) {
1589
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) & rhs);
1590
0
}
1591
0
constexpr int32_t &operator|=(int32_t& v, const ::android::hardware::graphics::common::V1_0::Hdr e) {
1592
0
    v |= static_cast<int32_t>(e);
1593
0
    return v;
1594
0
}
1595
0
constexpr int32_t &operator&=(int32_t& v, const ::android::hardware::graphics::common::V1_0::Hdr e) {
1596
0
    v &= static_cast<int32_t>(e);
1597
0
    return v;
1598
0
}
1599
1600
//
1601
// type header definitions for package
1602
//
1603
1604
template<>
1605
0
inline std::string toString<::android::hardware::graphics::common::V1_0::PixelFormat>(int32_t o) {
1606
0
    using ::android::hardware::details::toHexString;
1607
0
    std::string os;
1608
0
    ::android::hardware::hidl_bitfield<::android::hardware::graphics::common::V1_0::PixelFormat> flipped = 0;
1609
0
    bool first = true;
1610
0
    if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::RGBA_8888) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::PixelFormat::RGBA_8888)) {
1611
0
        os += (first ? "" : " | ");
1612
0
        os += "RGBA_8888";
1613
0
        first = false;
1614
0
        flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::RGBA_8888;
1615
0
    }
1616
0
    if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::RGBX_8888) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::PixelFormat::RGBX_8888)) {
1617
0
        os += (first ? "" : " | ");
1618
0
        os += "RGBX_8888";
1619
0
        first = false;
1620
0
        flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::RGBX_8888;
1621
0
    }
1622
0
    if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::RGB_888) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::PixelFormat::RGB_888)) {
1623
0
        os += (first ? "" : " | ");
1624
0
        os += "RGB_888";
1625
0
        first = false;
1626
0
        flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::RGB_888;
1627
0
    }
1628
0
    if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::RGB_565) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::PixelFormat::RGB_565)) {
1629
0
        os += (first ? "" : " | ");
1630
0
        os += "RGB_565";
1631
0
        first = false;
1632
0
        flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::RGB_565;
1633
0
    }
1634
0
    if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::BGRA_8888) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::PixelFormat::BGRA_8888)) {
1635
0
        os += (first ? "" : " | ");
1636
0
        os += "BGRA_8888";
1637
0
        first = false;
1638
0
        flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::BGRA_8888;
1639
0
    }
1640
0
    if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::YCBCR_422_SP) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::PixelFormat::YCBCR_422_SP)) {
1641
0
        os += (first ? "" : " | ");
1642
0
        os += "YCBCR_422_SP";
1643
0
        first = false;
1644
0
        flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::YCBCR_422_SP;
1645
0
    }
1646
0
    if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::YCRCB_420_SP) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::PixelFormat::YCRCB_420_SP)) {
1647
0
        os += (first ? "" : " | ");
1648
0
        os += "YCRCB_420_SP";
1649
0
        first = false;
1650
0
        flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::YCRCB_420_SP;
1651
0
    }
1652
0
    if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::YCBCR_422_I) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::PixelFormat::YCBCR_422_I)) {
1653
0
        os += (first ? "" : " | ");
1654
0
        os += "YCBCR_422_I";
1655
0
        first = false;
1656
0
        flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::YCBCR_422_I;
1657
0
    }
1658
0
    if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::RGBA_FP16) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::PixelFormat::RGBA_FP16)) {
1659
0
        os += (first ? "" : " | ");
1660
0
        os += "RGBA_FP16";
1661
0
        first = false;
1662
0
        flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::RGBA_FP16;
1663
0
    }
1664
0
    if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::RAW16) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::PixelFormat::RAW16)) {
1665
0
        os += (first ? "" : " | ");
1666
0
        os += "RAW16";
1667
0
        first = false;
1668
0
        flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::RAW16;
1669
0
    }
1670
0
    if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::BLOB) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::PixelFormat::BLOB)) {
1671
0
        os += (first ? "" : " | ");
1672
0
        os += "BLOB";
1673
0
        first = false;
1674
0
        flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::BLOB;
1675
0
    }
1676
0
    if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::IMPLEMENTATION_DEFINED) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::PixelFormat::IMPLEMENTATION_DEFINED)) {
1677
0
        os += (first ? "" : " | ");
1678
0
        os += "IMPLEMENTATION_DEFINED";
1679
0
        first = false;
1680
0
        flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::IMPLEMENTATION_DEFINED;
1681
0
    }
1682
0
    if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::YCBCR_420_888) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::PixelFormat::YCBCR_420_888)) {
1683
0
        os += (first ? "" : " | ");
1684
0
        os += "YCBCR_420_888";
1685
0
        first = false;
1686
0
        flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::YCBCR_420_888;
1687
0
    }
1688
0
    if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::RAW_OPAQUE) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::PixelFormat::RAW_OPAQUE)) {
1689
0
        os += (first ? "" : " | ");
1690
0
        os += "RAW_OPAQUE";
1691
0
        first = false;
1692
0
        flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::RAW_OPAQUE;
1693
0
    }
1694
0
    if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::RAW10) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::PixelFormat::RAW10)) {
1695
0
        os += (first ? "" : " | ");
1696
0
        os += "RAW10";
1697
0
        first = false;
1698
0
        flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::RAW10;
1699
0
    }
1700
0
    if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::RAW12) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::PixelFormat::RAW12)) {
1701
0
        os += (first ? "" : " | ");
1702
0
        os += "RAW12";
1703
0
        first = false;
1704
0
        flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::RAW12;
1705
0
    }
1706
0
    if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::RGBA_1010102) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::PixelFormat::RGBA_1010102)) {
1707
0
        os += (first ? "" : " | ");
1708
0
        os += "RGBA_1010102";
1709
0
        first = false;
1710
0
        flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::RGBA_1010102;
1711
0
    }
1712
0
    if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::Y8) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::PixelFormat::Y8)) {
1713
0
        os += (first ? "" : " | ");
1714
0
        os += "Y8";
1715
0
        first = false;
1716
0
        flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::Y8;
1717
0
    }
1718
0
    if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::Y16) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::PixelFormat::Y16)) {
1719
0
        os += (first ? "" : " | ");
1720
0
        os += "Y16";
1721
0
        first = false;
1722
0
        flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::Y16;
1723
0
    }
1724
0
    if ((o & ::android::hardware::graphics::common::V1_0::PixelFormat::YV12) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::PixelFormat::YV12)) {
1725
0
        os += (first ? "" : " | ");
1726
0
        os += "YV12";
1727
0
        first = false;
1728
0
        flipped |= ::android::hardware::graphics::common::V1_0::PixelFormat::YV12;
1729
0
    }
1730
0
    if (o != flipped) {
1731
0
        os += (first ? "" : " | ");
1732
0
        os += toHexString(o & (~flipped));
1733
0
    }os += " (";
1734
0
    os += toHexString(o);
1735
0
    os += ")";
1736
0
    return os;
1737
0
}
1738
1739
0
static inline std::string toString(::android::hardware::graphics::common::V1_0::PixelFormat o) {
1740
0
    using ::android::hardware::details::toHexString;
1741
0
    if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::RGBA_8888) {
1742
0
        return "RGBA_8888";
1743
0
    }
1744
0
    if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::RGBX_8888) {
1745
0
        return "RGBX_8888";
1746
0
    }
1747
0
    if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::RGB_888) {
1748
0
        return "RGB_888";
1749
0
    }
1750
0
    if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::RGB_565) {
1751
0
        return "RGB_565";
1752
0
    }
1753
0
    if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::BGRA_8888) {
1754
0
        return "BGRA_8888";
1755
0
    }
1756
0
    if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::YCBCR_422_SP) {
1757
0
        return "YCBCR_422_SP";
1758
0
    }
1759
0
    if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::YCRCB_420_SP) {
1760
0
        return "YCRCB_420_SP";
1761
0
    }
1762
0
    if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::YCBCR_422_I) {
1763
0
        return "YCBCR_422_I";
1764
0
    }
1765
0
    if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::RGBA_FP16) {
1766
0
        return "RGBA_FP16";
1767
0
    }
1768
0
    if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::RAW16) {
1769
0
        return "RAW16";
1770
0
    }
1771
0
    if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::BLOB) {
1772
0
        return "BLOB";
1773
0
    }
1774
0
    if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::IMPLEMENTATION_DEFINED) {
1775
0
        return "IMPLEMENTATION_DEFINED";
1776
0
    }
1777
0
    if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::YCBCR_420_888) {
1778
0
        return "YCBCR_420_888";
1779
0
    }
1780
0
    if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::RAW_OPAQUE) {
1781
0
        return "RAW_OPAQUE";
1782
0
    }
1783
0
    if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::RAW10) {
1784
0
        return "RAW10";
1785
0
    }
1786
0
    if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::RAW12) {
1787
0
        return "RAW12";
1788
0
    }
1789
0
    if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::RGBA_1010102) {
1790
0
        return "RGBA_1010102";
1791
0
    }
1792
0
    if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::Y8) {
1793
0
        return "Y8";
1794
0
    }
1795
0
    if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::Y16) {
1796
0
        return "Y16";
1797
0
    }
1798
0
    if (o == ::android::hardware::graphics::common::V1_0::PixelFormat::YV12) {
1799
0
        return "YV12";
1800
0
    }
1801
0
    std::string os;
1802
0
    os += toHexString(static_cast<int32_t>(o));
1803
0
    return os;
1804
0
}
1805
1806
template<>
1807
0
inline std::string toString<::android::hardware::graphics::common::V1_0::BufferUsage>(uint64_t o) {
1808
0
    using ::android::hardware::details::toHexString;
1809
0
    std::string os;
1810
0
    ::android::hardware::hidl_bitfield<::android::hardware::graphics::common::V1_0::BufferUsage> flipped = 0;
1811
0
    bool first = true;
1812
0
    if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_MASK) == static_cast<uint64_t>(::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_MASK)) {
1813
0
        os += (first ? "" : " | ");
1814
0
        os += "CPU_READ_MASK";
1815
0
        first = false;
1816
0
        flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_MASK;
1817
0
    }
1818
0
    if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_NEVER) == static_cast<uint64_t>(::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_NEVER)) {
1819
0
        os += (first ? "" : " | ");
1820
0
        os += "CPU_READ_NEVER";
1821
0
        first = false;
1822
0
        flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_NEVER;
1823
0
    }
1824
0
    if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_RARELY) == static_cast<uint64_t>(::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_RARELY)) {
1825
0
        os += (first ? "" : " | ");
1826
0
        os += "CPU_READ_RARELY";
1827
0
        first = false;
1828
0
        flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_RARELY;
1829
0
    }
1830
0
    if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_OFTEN) == static_cast<uint64_t>(::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_OFTEN)) {
1831
0
        os += (first ? "" : " | ");
1832
0
        os += "CPU_READ_OFTEN";
1833
0
        first = false;
1834
0
        flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_OFTEN;
1835
0
    }
1836
0
    if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_MASK) == static_cast<uint64_t>(::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_MASK)) {
1837
0
        os += (first ? "" : " | ");
1838
0
        os += "CPU_WRITE_MASK";
1839
0
        first = false;
1840
0
        flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_MASK;
1841
0
    }
1842
0
    if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_NEVER) == static_cast<uint64_t>(::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_NEVER)) {
1843
0
        os += (first ? "" : " | ");
1844
0
        os += "CPU_WRITE_NEVER";
1845
0
        first = false;
1846
0
        flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_NEVER;
1847
0
    }
1848
0
    if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_RARELY) == static_cast<uint64_t>(::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_RARELY)) {
1849
0
        os += (first ? "" : " | ");
1850
0
        os += "CPU_WRITE_RARELY";
1851
0
        first = false;
1852
0
        flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_RARELY;
1853
0
    }
1854
0
    if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_OFTEN) == static_cast<uint64_t>(::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_OFTEN)) {
1855
0
        os += (first ? "" : " | ");
1856
0
        os += "CPU_WRITE_OFTEN";
1857
0
        first = false;
1858
0
        flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_OFTEN;
1859
0
    }
1860
0
    if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::GPU_TEXTURE) == static_cast<uint64_t>(::android::hardware::graphics::common::V1_0::BufferUsage::GPU_TEXTURE)) {
1861
0
        os += (first ? "" : " | ");
1862
0
        os += "GPU_TEXTURE";
1863
0
        first = false;
1864
0
        flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::GPU_TEXTURE;
1865
0
    }
1866
0
    if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::GPU_RENDER_TARGET) == static_cast<uint64_t>(::android::hardware::graphics::common::V1_0::BufferUsage::GPU_RENDER_TARGET)) {
1867
0
        os += (first ? "" : " | ");
1868
0
        os += "GPU_RENDER_TARGET";
1869
0
        first = false;
1870
0
        flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::GPU_RENDER_TARGET;
1871
0
    }
1872
0
    if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::COMPOSER_OVERLAY) == static_cast<uint64_t>(::android::hardware::graphics::common::V1_0::BufferUsage::COMPOSER_OVERLAY)) {
1873
0
        os += (first ? "" : " | ");
1874
0
        os += "COMPOSER_OVERLAY";
1875
0
        first = false;
1876
0
        flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::COMPOSER_OVERLAY;
1877
0
    }
1878
0
    if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::COMPOSER_CLIENT_TARGET) == static_cast<uint64_t>(::android::hardware::graphics::common::V1_0::BufferUsage::COMPOSER_CLIENT_TARGET)) {
1879
0
        os += (first ? "" : " | ");
1880
0
        os += "COMPOSER_CLIENT_TARGET";
1881
0
        first = false;
1882
0
        flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::COMPOSER_CLIENT_TARGET;
1883
0
    }
1884
0
    if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::PROTECTED) == static_cast<uint64_t>(::android::hardware::graphics::common::V1_0::BufferUsage::PROTECTED)) {
1885
0
        os += (first ? "" : " | ");
1886
0
        os += "PROTECTED";
1887
0
        first = false;
1888
0
        flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::PROTECTED;
1889
0
    }
1890
0
    if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::COMPOSER_CURSOR) == static_cast<uint64_t>(::android::hardware::graphics::common::V1_0::BufferUsage::COMPOSER_CURSOR)) {
1891
0
        os += (first ? "" : " | ");
1892
0
        os += "COMPOSER_CURSOR";
1893
0
        first = false;
1894
0
        flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::COMPOSER_CURSOR;
1895
0
    }
1896
0
    if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::VIDEO_ENCODER) == static_cast<uint64_t>(::android::hardware::graphics::common::V1_0::BufferUsage::VIDEO_ENCODER)) {
1897
0
        os += (first ? "" : " | ");
1898
0
        os += "VIDEO_ENCODER";
1899
0
        first = false;
1900
0
        flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::VIDEO_ENCODER;
1901
0
    }
1902
0
    if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::CAMERA_OUTPUT) == static_cast<uint64_t>(::android::hardware::graphics::common::V1_0::BufferUsage::CAMERA_OUTPUT)) {
1903
0
        os += (first ? "" : " | ");
1904
0
        os += "CAMERA_OUTPUT";
1905
0
        first = false;
1906
0
        flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::CAMERA_OUTPUT;
1907
0
    }
1908
0
    if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::CAMERA_INPUT) == static_cast<uint64_t>(::android::hardware::graphics::common::V1_0::BufferUsage::CAMERA_INPUT)) {
1909
0
        os += (first ? "" : " | ");
1910
0
        os += "CAMERA_INPUT";
1911
0
        first = false;
1912
0
        flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::CAMERA_INPUT;
1913
0
    }
1914
0
    if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::RENDERSCRIPT) == static_cast<uint64_t>(::android::hardware::graphics::common::V1_0::BufferUsage::RENDERSCRIPT)) {
1915
0
        os += (first ? "" : " | ");
1916
0
        os += "RENDERSCRIPT";
1917
0
        first = false;
1918
0
        flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::RENDERSCRIPT;
1919
0
    }
1920
0
    if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::VIDEO_DECODER) == static_cast<uint64_t>(::android::hardware::graphics::common::V1_0::BufferUsage::VIDEO_DECODER)) {
1921
0
        os += (first ? "" : " | ");
1922
0
        os += "VIDEO_DECODER";
1923
0
        first = false;
1924
0
        flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::VIDEO_DECODER;
1925
0
    }
1926
0
    if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::SENSOR_DIRECT_DATA) == static_cast<uint64_t>(::android::hardware::graphics::common::V1_0::BufferUsage::SENSOR_DIRECT_DATA)) {
1927
0
        os += (first ? "" : " | ");
1928
0
        os += "SENSOR_DIRECT_DATA";
1929
0
        first = false;
1930
0
        flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::SENSOR_DIRECT_DATA;
1931
0
    }
1932
0
    if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::GPU_DATA_BUFFER) == static_cast<uint64_t>(::android::hardware::graphics::common::V1_0::BufferUsage::GPU_DATA_BUFFER)) {
1933
0
        os += (first ? "" : " | ");
1934
0
        os += "GPU_DATA_BUFFER";
1935
0
        first = false;
1936
0
        flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::GPU_DATA_BUFFER;
1937
0
    }
1938
0
    if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::VENDOR_MASK) == static_cast<uint64_t>(::android::hardware::graphics::common::V1_0::BufferUsage::VENDOR_MASK)) {
1939
0
        os += (first ? "" : " | ");
1940
0
        os += "VENDOR_MASK";
1941
0
        first = false;
1942
0
        flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::VENDOR_MASK;
1943
0
    }
1944
0
    if ((o & ::android::hardware::graphics::common::V1_0::BufferUsage::VENDOR_MASK_HI) == static_cast<uint64_t>(::android::hardware::graphics::common::V1_0::BufferUsage::VENDOR_MASK_HI)) {
1945
0
        os += (first ? "" : " | ");
1946
0
        os += "VENDOR_MASK_HI";
1947
0
        first = false;
1948
0
        flipped |= ::android::hardware::graphics::common::V1_0::BufferUsage::VENDOR_MASK_HI;
1949
0
    }
1950
0
    if (o != flipped) {
1951
0
        os += (first ? "" : " | ");
1952
0
        os += toHexString(o & (~flipped));
1953
0
    }os += " (";
1954
0
    os += toHexString(o);
1955
0
    os += ")";
1956
0
    return os;
1957
0
}
1958
1959
0
static inline std::string toString(::android::hardware::graphics::common::V1_0::BufferUsage o) {
1960
0
    using ::android::hardware::details::toHexString;
1961
0
    if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_MASK) {
1962
0
        return "CPU_READ_MASK";
1963
0
    }
1964
0
    if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_NEVER) {
1965
0
        return "CPU_READ_NEVER";
1966
0
    }
1967
0
    if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_RARELY) {
1968
0
        return "CPU_READ_RARELY";
1969
0
    }
1970
0
    if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_OFTEN) {
1971
0
        return "CPU_READ_OFTEN";
1972
0
    }
1973
0
    if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_MASK) {
1974
0
        return "CPU_WRITE_MASK";
1975
0
    }
1976
0
    if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_NEVER) {
1977
0
        return "CPU_WRITE_NEVER";
1978
0
    }
1979
0
    if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_RARELY) {
1980
0
        return "CPU_WRITE_RARELY";
1981
0
    }
1982
0
    if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_OFTEN) {
1983
0
        return "CPU_WRITE_OFTEN";
1984
0
    }
1985
0
    if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::GPU_TEXTURE) {
1986
0
        return "GPU_TEXTURE";
1987
0
    }
1988
0
    if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::GPU_RENDER_TARGET) {
1989
0
        return "GPU_RENDER_TARGET";
1990
0
    }
1991
0
    if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::COMPOSER_OVERLAY) {
1992
0
        return "COMPOSER_OVERLAY";
1993
0
    }
1994
0
    if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::COMPOSER_CLIENT_TARGET) {
1995
0
        return "COMPOSER_CLIENT_TARGET";
1996
0
    }
1997
0
    if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::PROTECTED) {
1998
0
        return "PROTECTED";
1999
0
    }
2000
0
    if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::COMPOSER_CURSOR) {
2001
0
        return "COMPOSER_CURSOR";
2002
0
    }
2003
0
    if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::VIDEO_ENCODER) {
2004
0
        return "VIDEO_ENCODER";
2005
0
    }
2006
0
    if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::CAMERA_OUTPUT) {
2007
0
        return "CAMERA_OUTPUT";
2008
0
    }
2009
0
    if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::CAMERA_INPUT) {
2010
0
        return "CAMERA_INPUT";
2011
0
    }
2012
0
    if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::RENDERSCRIPT) {
2013
0
        return "RENDERSCRIPT";
2014
0
    }
2015
0
    if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::VIDEO_DECODER) {
2016
0
        return "VIDEO_DECODER";
2017
0
    }
2018
0
    if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::SENSOR_DIRECT_DATA) {
2019
0
        return "SENSOR_DIRECT_DATA";
2020
0
    }
2021
0
    if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::GPU_DATA_BUFFER) {
2022
0
        return "GPU_DATA_BUFFER";
2023
0
    }
2024
0
    if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::VENDOR_MASK) {
2025
0
        return "VENDOR_MASK";
2026
0
    }
2027
0
    if (o == ::android::hardware::graphics::common::V1_0::BufferUsage::VENDOR_MASK_HI) {
2028
0
        return "VENDOR_MASK_HI";
2029
0
    }
2030
0
    std::string os;
2031
0
    os += toHexString(static_cast<uint64_t>(o));
2032
0
    return os;
2033
0
}
2034
2035
template<>
2036
0
inline std::string toString<::android::hardware::graphics::common::V1_0::Transform>(int32_t o) {
2037
0
    using ::android::hardware::details::toHexString;
2038
0
    std::string os;
2039
0
    ::android::hardware::hidl_bitfield<::android::hardware::graphics::common::V1_0::Transform> flipped = 0;
2040
0
    bool first = true;
2041
0
    if ((o & ::android::hardware::graphics::common::V1_0::Transform::FLIP_H) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Transform::FLIP_H)) {
2042
0
        os += (first ? "" : " | ");
2043
0
        os += "FLIP_H";
2044
0
        first = false;
2045
0
        flipped |= ::android::hardware::graphics::common::V1_0::Transform::FLIP_H;
2046
0
    }
2047
0
    if ((o & ::android::hardware::graphics::common::V1_0::Transform::FLIP_V) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Transform::FLIP_V)) {
2048
0
        os += (first ? "" : " | ");
2049
0
        os += "FLIP_V";
2050
0
        first = false;
2051
0
        flipped |= ::android::hardware::graphics::common::V1_0::Transform::FLIP_V;
2052
0
    }
2053
0
    if ((o & ::android::hardware::graphics::common::V1_0::Transform::ROT_90) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Transform::ROT_90)) {
2054
0
        os += (first ? "" : " | ");
2055
0
        os += "ROT_90";
2056
0
        first = false;
2057
0
        flipped |= ::android::hardware::graphics::common::V1_0::Transform::ROT_90;
2058
0
    }
2059
0
    if ((o & ::android::hardware::graphics::common::V1_0::Transform::ROT_180) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Transform::ROT_180)) {
2060
0
        os += (first ? "" : " | ");
2061
0
        os += "ROT_180";
2062
0
        first = false;
2063
0
        flipped |= ::android::hardware::graphics::common::V1_0::Transform::ROT_180;
2064
0
    }
2065
0
    if ((o & ::android::hardware::graphics::common::V1_0::Transform::ROT_270) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Transform::ROT_270)) {
2066
0
        os += (first ? "" : " | ");
2067
0
        os += "ROT_270";
2068
0
        first = false;
2069
0
        flipped |= ::android::hardware::graphics::common::V1_0::Transform::ROT_270;
2070
0
    }
2071
0
    if (o != flipped) {
2072
0
        os += (first ? "" : " | ");
2073
0
        os += toHexString(o & (~flipped));
2074
0
    }os += " (";
2075
0
    os += toHexString(o);
2076
0
    os += ")";
2077
0
    return os;
2078
0
}
2079
2080
0
static inline std::string toString(::android::hardware::graphics::common::V1_0::Transform o) {
2081
0
    using ::android::hardware::details::toHexString;
2082
0
    if (o == ::android::hardware::graphics::common::V1_0::Transform::FLIP_H) {
2083
0
        return "FLIP_H";
2084
0
    }
2085
0
    if (o == ::android::hardware::graphics::common::V1_0::Transform::FLIP_V) {
2086
0
        return "FLIP_V";
2087
0
    }
2088
0
    if (o == ::android::hardware::graphics::common::V1_0::Transform::ROT_90) {
2089
0
        return "ROT_90";
2090
0
    }
2091
0
    if (o == ::android::hardware::graphics::common::V1_0::Transform::ROT_180) {
2092
0
        return "ROT_180";
2093
0
    }
2094
0
    if (o == ::android::hardware::graphics::common::V1_0::Transform::ROT_270) {
2095
0
        return "ROT_270";
2096
0
    }
2097
0
    std::string os;
2098
0
    os += toHexString(static_cast<int32_t>(o));
2099
0
    return os;
2100
0
}
2101
2102
template<>
2103
0
inline std::string toString<::android::hardware::graphics::common::V1_0::Dataspace>(int32_t o) {
2104
0
    using ::android::hardware::details::toHexString;
2105
0
    std::string os;
2106
0
    ::android::hardware::hidl_bitfield<::android::hardware::graphics::common::V1_0::Dataspace> flipped = 0;
2107
0
    bool first = true;
2108
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::UNKNOWN) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::UNKNOWN)) {
2109
0
        os += (first ? "" : " | ");
2110
0
        os += "UNKNOWN";
2111
0
        first = false;
2112
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::UNKNOWN;
2113
0
    }
2114
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::ARBITRARY) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::ARBITRARY)) {
2115
0
        os += (first ? "" : " | ");
2116
0
        os += "ARBITRARY";
2117
0
        first = false;
2118
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::ARBITRARY;
2119
0
    }
2120
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_SHIFT) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_SHIFT)) {
2121
0
        os += (first ? "" : " | ");
2122
0
        os += "STANDARD_SHIFT";
2123
0
        first = false;
2124
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_SHIFT;
2125
0
    }
2126
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_MASK) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_MASK)) {
2127
0
        os += (first ? "" : " | ");
2128
0
        os += "STANDARD_MASK";
2129
0
        first = false;
2130
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_MASK;
2131
0
    }
2132
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_UNSPECIFIED) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_UNSPECIFIED)) {
2133
0
        os += (first ? "" : " | ");
2134
0
        os += "STANDARD_UNSPECIFIED";
2135
0
        first = false;
2136
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_UNSPECIFIED;
2137
0
    }
2138
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT709) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT709)) {
2139
0
        os += (first ? "" : " | ");
2140
0
        os += "STANDARD_BT709";
2141
0
        first = false;
2142
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT709;
2143
0
    }
2144
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_625) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_625)) {
2145
0
        os += (first ? "" : " | ");
2146
0
        os += "STANDARD_BT601_625";
2147
0
        first = false;
2148
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_625;
2149
0
    }
2150
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_625_UNADJUSTED) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_625_UNADJUSTED)) {
2151
0
        os += (first ? "" : " | ");
2152
0
        os += "STANDARD_BT601_625_UNADJUSTED";
2153
0
        first = false;
2154
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_625_UNADJUSTED;
2155
0
    }
2156
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_525) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_525)) {
2157
0
        os += (first ? "" : " | ");
2158
0
        os += "STANDARD_BT601_525";
2159
0
        first = false;
2160
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_525;
2161
0
    }
2162
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_525_UNADJUSTED) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_525_UNADJUSTED)) {
2163
0
        os += (first ? "" : " | ");
2164
0
        os += "STANDARD_BT601_525_UNADJUSTED";
2165
0
        first = false;
2166
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_525_UNADJUSTED;
2167
0
    }
2168
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT2020) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT2020)) {
2169
0
        os += (first ? "" : " | ");
2170
0
        os += "STANDARD_BT2020";
2171
0
        first = false;
2172
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT2020;
2173
0
    }
2174
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT2020_CONSTANT_LUMINANCE) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT2020_CONSTANT_LUMINANCE)) {
2175
0
        os += (first ? "" : " | ");
2176
0
        os += "STANDARD_BT2020_CONSTANT_LUMINANCE";
2177
0
        first = false;
2178
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT2020_CONSTANT_LUMINANCE;
2179
0
    }
2180
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT470M) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT470M)) {
2181
0
        os += (first ? "" : " | ");
2182
0
        os += "STANDARD_BT470M";
2183
0
        first = false;
2184
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT470M;
2185
0
    }
2186
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_FILM) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_FILM)) {
2187
0
        os += (first ? "" : " | ");
2188
0
        os += "STANDARD_FILM";
2189
0
        first = false;
2190
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_FILM;
2191
0
    }
2192
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_DCI_P3) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_DCI_P3)) {
2193
0
        os += (first ? "" : " | ");
2194
0
        os += "STANDARD_DCI_P3";
2195
0
        first = false;
2196
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_DCI_P3;
2197
0
    }
2198
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_ADOBE_RGB) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_ADOBE_RGB)) {
2199
0
        os += (first ? "" : " | ");
2200
0
        os += "STANDARD_ADOBE_RGB";
2201
0
        first = false;
2202
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_ADOBE_RGB;
2203
0
    }
2204
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_SHIFT) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_SHIFT)) {
2205
0
        os += (first ? "" : " | ");
2206
0
        os += "TRANSFER_SHIFT";
2207
0
        first = false;
2208
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_SHIFT;
2209
0
    }
2210
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_MASK) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_MASK)) {
2211
0
        os += (first ? "" : " | ");
2212
0
        os += "TRANSFER_MASK";
2213
0
        first = false;
2214
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_MASK;
2215
0
    }
2216
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_UNSPECIFIED) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_UNSPECIFIED)) {
2217
0
        os += (first ? "" : " | ");
2218
0
        os += "TRANSFER_UNSPECIFIED";
2219
0
        first = false;
2220
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_UNSPECIFIED;
2221
0
    }
2222
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_LINEAR) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_LINEAR)) {
2223
0
        os += (first ? "" : " | ");
2224
0
        os += "TRANSFER_LINEAR";
2225
0
        first = false;
2226
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_LINEAR;
2227
0
    }
2228
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_SRGB) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_SRGB)) {
2229
0
        os += (first ? "" : " | ");
2230
0
        os += "TRANSFER_SRGB";
2231
0
        first = false;
2232
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_SRGB;
2233
0
    }
2234
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_SMPTE_170M) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_SMPTE_170M)) {
2235
0
        os += (first ? "" : " | ");
2236
0
        os += "TRANSFER_SMPTE_170M";
2237
0
        first = false;
2238
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_SMPTE_170M;
2239
0
    }
2240
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_GAMMA2_2) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_GAMMA2_2)) {
2241
0
        os += (first ? "" : " | ");
2242
0
        os += "TRANSFER_GAMMA2_2";
2243
0
        first = false;
2244
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_GAMMA2_2;
2245
0
    }
2246
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_GAMMA2_6) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_GAMMA2_6)) {
2247
0
        os += (first ? "" : " | ");
2248
0
        os += "TRANSFER_GAMMA2_6";
2249
0
        first = false;
2250
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_GAMMA2_6;
2251
0
    }
2252
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_GAMMA2_8) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_GAMMA2_8)) {
2253
0
        os += (first ? "" : " | ");
2254
0
        os += "TRANSFER_GAMMA2_8";
2255
0
        first = false;
2256
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_GAMMA2_8;
2257
0
    }
2258
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_ST2084) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_ST2084)) {
2259
0
        os += (first ? "" : " | ");
2260
0
        os += "TRANSFER_ST2084";
2261
0
        first = false;
2262
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_ST2084;
2263
0
    }
2264
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_HLG) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_HLG)) {
2265
0
        os += (first ? "" : " | ");
2266
0
        os += "TRANSFER_HLG";
2267
0
        first = false;
2268
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_HLG;
2269
0
    }
2270
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_SHIFT) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::RANGE_SHIFT)) {
2271
0
        os += (first ? "" : " | ");
2272
0
        os += "RANGE_SHIFT";
2273
0
        first = false;
2274
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_SHIFT;
2275
0
    }
2276
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_MASK) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::RANGE_MASK)) {
2277
0
        os += (first ? "" : " | ");
2278
0
        os += "RANGE_MASK";
2279
0
        first = false;
2280
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_MASK;
2281
0
    }
2282
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_UNSPECIFIED) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::RANGE_UNSPECIFIED)) {
2283
0
        os += (first ? "" : " | ");
2284
0
        os += "RANGE_UNSPECIFIED";
2285
0
        first = false;
2286
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_UNSPECIFIED;
2287
0
    }
2288
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_FULL) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::RANGE_FULL)) {
2289
0
        os += (first ? "" : " | ");
2290
0
        os += "RANGE_FULL";
2291
0
        first = false;
2292
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_FULL;
2293
0
    }
2294
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_LIMITED) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::RANGE_LIMITED)) {
2295
0
        os += (first ? "" : " | ");
2296
0
        os += "RANGE_LIMITED";
2297
0
        first = false;
2298
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_LIMITED;
2299
0
    }
2300
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_EXTENDED) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::RANGE_EXTENDED)) {
2301
0
        os += (first ? "" : " | ");
2302
0
        os += "RANGE_EXTENDED";
2303
0
        first = false;
2304
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_EXTENDED;
2305
0
    }
2306
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::SRGB_LINEAR) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::SRGB_LINEAR)) {
2307
0
        os += (first ? "" : " | ");
2308
0
        os += "SRGB_LINEAR";
2309
0
        first = false;
2310
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::SRGB_LINEAR;
2311
0
    }
2312
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::V0_SRGB_LINEAR) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::V0_SRGB_LINEAR)) {
2313
0
        os += (first ? "" : " | ");
2314
0
        os += "V0_SRGB_LINEAR";
2315
0
        first = false;
2316
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::V0_SRGB_LINEAR;
2317
0
    }
2318
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::V0_SCRGB_LINEAR) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::V0_SCRGB_LINEAR)) {
2319
0
        os += (first ? "" : " | ");
2320
0
        os += "V0_SCRGB_LINEAR";
2321
0
        first = false;
2322
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::V0_SCRGB_LINEAR;
2323
0
    }
2324
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::SRGB) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::SRGB)) {
2325
0
        os += (first ? "" : " | ");
2326
0
        os += "SRGB";
2327
0
        first = false;
2328
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::SRGB;
2329
0
    }
2330
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::V0_SRGB) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::V0_SRGB)) {
2331
0
        os += (first ? "" : " | ");
2332
0
        os += "V0_SRGB";
2333
0
        first = false;
2334
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::V0_SRGB;
2335
0
    }
2336
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::V0_SCRGB) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::V0_SCRGB)) {
2337
0
        os += (first ? "" : " | ");
2338
0
        os += "V0_SCRGB";
2339
0
        first = false;
2340
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::V0_SCRGB;
2341
0
    }
2342
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::JFIF) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::JFIF)) {
2343
0
        os += (first ? "" : " | ");
2344
0
        os += "JFIF";
2345
0
        first = false;
2346
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::JFIF;
2347
0
    }
2348
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::V0_JFIF) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::V0_JFIF)) {
2349
0
        os += (first ? "" : " | ");
2350
0
        os += "V0_JFIF";
2351
0
        first = false;
2352
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::V0_JFIF;
2353
0
    }
2354
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::BT601_625) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::BT601_625)) {
2355
0
        os += (first ? "" : " | ");
2356
0
        os += "BT601_625";
2357
0
        first = false;
2358
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::BT601_625;
2359
0
    }
2360
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::V0_BT601_625) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::V0_BT601_625)) {
2361
0
        os += (first ? "" : " | ");
2362
0
        os += "V0_BT601_625";
2363
0
        first = false;
2364
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::V0_BT601_625;
2365
0
    }
2366
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::BT601_525) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::BT601_525)) {
2367
0
        os += (first ? "" : " | ");
2368
0
        os += "BT601_525";
2369
0
        first = false;
2370
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::BT601_525;
2371
0
    }
2372
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::V0_BT601_525) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::V0_BT601_525)) {
2373
0
        os += (first ? "" : " | ");
2374
0
        os += "V0_BT601_525";
2375
0
        first = false;
2376
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::V0_BT601_525;
2377
0
    }
2378
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::BT709) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::BT709)) {
2379
0
        os += (first ? "" : " | ");
2380
0
        os += "BT709";
2381
0
        first = false;
2382
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::BT709;
2383
0
    }
2384
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::V0_BT709) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::V0_BT709)) {
2385
0
        os += (first ? "" : " | ");
2386
0
        os += "V0_BT709";
2387
0
        first = false;
2388
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::V0_BT709;
2389
0
    }
2390
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::DCI_P3_LINEAR) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::DCI_P3_LINEAR)) {
2391
0
        os += (first ? "" : " | ");
2392
0
        os += "DCI_P3_LINEAR";
2393
0
        first = false;
2394
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::DCI_P3_LINEAR;
2395
0
    }
2396
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::DCI_P3) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::DCI_P3)) {
2397
0
        os += (first ? "" : " | ");
2398
0
        os += "DCI_P3";
2399
0
        first = false;
2400
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::DCI_P3;
2401
0
    }
2402
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::DISPLAY_P3_LINEAR) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::DISPLAY_P3_LINEAR)) {
2403
0
        os += (first ? "" : " | ");
2404
0
        os += "DISPLAY_P3_LINEAR";
2405
0
        first = false;
2406
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::DISPLAY_P3_LINEAR;
2407
0
    }
2408
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::DISPLAY_P3) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::DISPLAY_P3)) {
2409
0
        os += (first ? "" : " | ");
2410
0
        os += "DISPLAY_P3";
2411
0
        first = false;
2412
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::DISPLAY_P3;
2413
0
    }
2414
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::ADOBE_RGB) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::ADOBE_RGB)) {
2415
0
        os += (first ? "" : " | ");
2416
0
        os += "ADOBE_RGB";
2417
0
        first = false;
2418
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::ADOBE_RGB;
2419
0
    }
2420
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::BT2020_LINEAR) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::BT2020_LINEAR)) {
2421
0
        os += (first ? "" : " | ");
2422
0
        os += "BT2020_LINEAR";
2423
0
        first = false;
2424
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::BT2020_LINEAR;
2425
0
    }
2426
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::BT2020) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::BT2020)) {
2427
0
        os += (first ? "" : " | ");
2428
0
        os += "BT2020";
2429
0
        first = false;
2430
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::BT2020;
2431
0
    }
2432
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::BT2020_PQ) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::BT2020_PQ)) {
2433
0
        os += (first ? "" : " | ");
2434
0
        os += "BT2020_PQ";
2435
0
        first = false;
2436
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::BT2020_PQ;
2437
0
    }
2438
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::DEPTH) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::DEPTH)) {
2439
0
        os += (first ? "" : " | ");
2440
0
        os += "DEPTH";
2441
0
        first = false;
2442
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::DEPTH;
2443
0
    }
2444
0
    if ((o & ::android::hardware::graphics::common::V1_0::Dataspace::SENSOR) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Dataspace::SENSOR)) {
2445
0
        os += (first ? "" : " | ");
2446
0
        os += "SENSOR";
2447
0
        first = false;
2448
0
        flipped |= ::android::hardware::graphics::common::V1_0::Dataspace::SENSOR;
2449
0
    }
2450
0
    if (o != flipped) {
2451
0
        os += (first ? "" : " | ");
2452
0
        os += toHexString(o & (~flipped));
2453
0
    }os += " (";
2454
0
    os += toHexString(o);
2455
0
    os += ")";
2456
0
    return os;
2457
0
}
2458
2459
0
static inline std::string toString(::android::hardware::graphics::common::V1_0::Dataspace o) {
2460
0
    using ::android::hardware::details::toHexString;
2461
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::UNKNOWN) {
2462
0
        return "UNKNOWN";
2463
0
    }
2464
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::ARBITRARY) {
2465
0
        return "ARBITRARY";
2466
0
    }
2467
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_SHIFT) {
2468
0
        return "STANDARD_SHIFT";
2469
0
    }
2470
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_MASK) {
2471
0
        return "STANDARD_MASK";
2472
0
    }
2473
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_UNSPECIFIED) {
2474
0
        return "STANDARD_UNSPECIFIED";
2475
0
    }
2476
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT709) {
2477
0
        return "STANDARD_BT709";
2478
0
    }
2479
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_625) {
2480
0
        return "STANDARD_BT601_625";
2481
0
    }
2482
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_625_UNADJUSTED) {
2483
0
        return "STANDARD_BT601_625_UNADJUSTED";
2484
0
    }
2485
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_525) {
2486
0
        return "STANDARD_BT601_525";
2487
0
    }
2488
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_525_UNADJUSTED) {
2489
0
        return "STANDARD_BT601_525_UNADJUSTED";
2490
0
    }
2491
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT2020) {
2492
0
        return "STANDARD_BT2020";
2493
0
    }
2494
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT2020_CONSTANT_LUMINANCE) {
2495
0
        return "STANDARD_BT2020_CONSTANT_LUMINANCE";
2496
0
    }
2497
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT470M) {
2498
0
        return "STANDARD_BT470M";
2499
0
    }
2500
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_FILM) {
2501
0
        return "STANDARD_FILM";
2502
0
    }
2503
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_DCI_P3) {
2504
0
        return "STANDARD_DCI_P3";
2505
0
    }
2506
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_ADOBE_RGB) {
2507
0
        return "STANDARD_ADOBE_RGB";
2508
0
    }
2509
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_SHIFT) {
2510
0
        return "TRANSFER_SHIFT";
2511
0
    }
2512
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_MASK) {
2513
0
        return "TRANSFER_MASK";
2514
0
    }
2515
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_UNSPECIFIED) {
2516
0
        return "TRANSFER_UNSPECIFIED";
2517
0
    }
2518
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_LINEAR) {
2519
0
        return "TRANSFER_LINEAR";
2520
0
    }
2521
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_SRGB) {
2522
0
        return "TRANSFER_SRGB";
2523
0
    }
2524
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_SMPTE_170M) {
2525
0
        return "TRANSFER_SMPTE_170M";
2526
0
    }
2527
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_GAMMA2_2) {
2528
0
        return "TRANSFER_GAMMA2_2";
2529
0
    }
2530
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_GAMMA2_6) {
2531
0
        return "TRANSFER_GAMMA2_6";
2532
0
    }
2533
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_GAMMA2_8) {
2534
0
        return "TRANSFER_GAMMA2_8";
2535
0
    }
2536
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_ST2084) {
2537
0
        return "TRANSFER_ST2084";
2538
0
    }
2539
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_HLG) {
2540
0
        return "TRANSFER_HLG";
2541
0
    }
2542
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_SHIFT) {
2543
0
        return "RANGE_SHIFT";
2544
0
    }
2545
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_MASK) {
2546
0
        return "RANGE_MASK";
2547
0
    }
2548
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_UNSPECIFIED) {
2549
0
        return "RANGE_UNSPECIFIED";
2550
0
    }
2551
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_FULL) {
2552
0
        return "RANGE_FULL";
2553
0
    }
2554
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_LIMITED) {
2555
0
        return "RANGE_LIMITED";
2556
0
    }
2557
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_EXTENDED) {
2558
0
        return "RANGE_EXTENDED";
2559
0
    }
2560
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::SRGB_LINEAR) {
2561
0
        return "SRGB_LINEAR";
2562
0
    }
2563
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::V0_SRGB_LINEAR) {
2564
0
        return "V0_SRGB_LINEAR";
2565
0
    }
2566
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::V0_SCRGB_LINEAR) {
2567
0
        return "V0_SCRGB_LINEAR";
2568
0
    }
2569
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::SRGB) {
2570
0
        return "SRGB";
2571
0
    }
2572
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::V0_SRGB) {
2573
0
        return "V0_SRGB";
2574
0
    }
2575
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::V0_SCRGB) {
2576
0
        return "V0_SCRGB";
2577
0
    }
2578
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::JFIF) {
2579
0
        return "JFIF";
2580
0
    }
2581
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::V0_JFIF) {
2582
0
        return "V0_JFIF";
2583
0
    }
2584
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::BT601_625) {
2585
0
        return "BT601_625";
2586
0
    }
2587
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::V0_BT601_625) {
2588
0
        return "V0_BT601_625";
2589
0
    }
2590
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::BT601_525) {
2591
0
        return "BT601_525";
2592
0
    }
2593
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::V0_BT601_525) {
2594
0
        return "V0_BT601_525";
2595
0
    }
2596
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::BT709) {
2597
0
        return "BT709";
2598
0
    }
2599
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::V0_BT709) {
2600
0
        return "V0_BT709";
2601
0
    }
2602
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::DCI_P3_LINEAR) {
2603
0
        return "DCI_P3_LINEAR";
2604
0
    }
2605
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::DCI_P3) {
2606
0
        return "DCI_P3";
2607
0
    }
2608
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::DISPLAY_P3_LINEAR) {
2609
0
        return "DISPLAY_P3_LINEAR";
2610
0
    }
2611
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::DISPLAY_P3) {
2612
0
        return "DISPLAY_P3";
2613
0
    }
2614
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::ADOBE_RGB) {
2615
0
        return "ADOBE_RGB";
2616
0
    }
2617
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::BT2020_LINEAR) {
2618
0
        return "BT2020_LINEAR";
2619
0
    }
2620
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::BT2020) {
2621
0
        return "BT2020";
2622
0
    }
2623
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::BT2020_PQ) {
2624
0
        return "BT2020_PQ";
2625
0
    }
2626
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::DEPTH) {
2627
0
        return "DEPTH";
2628
0
    }
2629
0
    if (o == ::android::hardware::graphics::common::V1_0::Dataspace::SENSOR) {
2630
0
        return "SENSOR";
2631
0
    }
2632
0
    std::string os;
2633
0
    os += toHexString(static_cast<int32_t>(o));
2634
0
    return os;
2635
0
}
2636
2637
template<>
2638
0
inline std::string toString<::android::hardware::graphics::common::V1_0::ColorMode>(int32_t o) {
2639
0
    using ::android::hardware::details::toHexString;
2640
0
    std::string os;
2641
0
    ::android::hardware::hidl_bitfield<::android::hardware::graphics::common::V1_0::ColorMode> flipped = 0;
2642
0
    bool first = true;
2643
0
    if ((o & ::android::hardware::graphics::common::V1_0::ColorMode::NATIVE) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::ColorMode::NATIVE)) {
2644
0
        os += (first ? "" : " | ");
2645
0
        os += "NATIVE";
2646
0
        first = false;
2647
0
        flipped |= ::android::hardware::graphics::common::V1_0::ColorMode::NATIVE;
2648
0
    }
2649
0
    if ((o & ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_625) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_625)) {
2650
0
        os += (first ? "" : " | ");
2651
0
        os += "STANDARD_BT601_625";
2652
0
        first = false;
2653
0
        flipped |= ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_625;
2654
0
    }
2655
0
    if ((o & ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_625_UNADJUSTED) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_625_UNADJUSTED)) {
2656
0
        os += (first ? "" : " | ");
2657
0
        os += "STANDARD_BT601_625_UNADJUSTED";
2658
0
        first = false;
2659
0
        flipped |= ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_625_UNADJUSTED;
2660
0
    }
2661
0
    if ((o & ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_525) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_525)) {
2662
0
        os += (first ? "" : " | ");
2663
0
        os += "STANDARD_BT601_525";
2664
0
        first = false;
2665
0
        flipped |= ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_525;
2666
0
    }
2667
0
    if ((o & ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_525_UNADJUSTED) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_525_UNADJUSTED)) {
2668
0
        os += (first ? "" : " | ");
2669
0
        os += "STANDARD_BT601_525_UNADJUSTED";
2670
0
        first = false;
2671
0
        flipped |= ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_525_UNADJUSTED;
2672
0
    }
2673
0
    if ((o & ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT709) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT709)) {
2674
0
        os += (first ? "" : " | ");
2675
0
        os += "STANDARD_BT709";
2676
0
        first = false;
2677
0
        flipped |= ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT709;
2678
0
    }
2679
0
    if ((o & ::android::hardware::graphics::common::V1_0::ColorMode::DCI_P3) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::ColorMode::DCI_P3)) {
2680
0
        os += (first ? "" : " | ");
2681
0
        os += "DCI_P3";
2682
0
        first = false;
2683
0
        flipped |= ::android::hardware::graphics::common::V1_0::ColorMode::DCI_P3;
2684
0
    }
2685
0
    if ((o & ::android::hardware::graphics::common::V1_0::ColorMode::SRGB) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::ColorMode::SRGB)) {
2686
0
        os += (first ? "" : " | ");
2687
0
        os += "SRGB";
2688
0
        first = false;
2689
0
        flipped |= ::android::hardware::graphics::common::V1_0::ColorMode::SRGB;
2690
0
    }
2691
0
    if ((o & ::android::hardware::graphics::common::V1_0::ColorMode::ADOBE_RGB) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::ColorMode::ADOBE_RGB)) {
2692
0
        os += (first ? "" : " | ");
2693
0
        os += "ADOBE_RGB";
2694
0
        first = false;
2695
0
        flipped |= ::android::hardware::graphics::common::V1_0::ColorMode::ADOBE_RGB;
2696
0
    }
2697
0
    if ((o & ::android::hardware::graphics::common::V1_0::ColorMode::DISPLAY_P3) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::ColorMode::DISPLAY_P3)) {
2698
0
        os += (first ? "" : " | ");
2699
0
        os += "DISPLAY_P3";
2700
0
        first = false;
2701
0
        flipped |= ::android::hardware::graphics::common::V1_0::ColorMode::DISPLAY_P3;
2702
0
    }
2703
0
    if (o != flipped) {
2704
0
        os += (first ? "" : " | ");
2705
0
        os += toHexString(o & (~flipped));
2706
0
    }os += " (";
2707
0
    os += toHexString(o);
2708
0
    os += ")";
2709
0
    return os;
2710
0
}
2711
2712
0
static inline std::string toString(::android::hardware::graphics::common::V1_0::ColorMode o) {
2713
0
    using ::android::hardware::details::toHexString;
2714
0
    if (o == ::android::hardware::graphics::common::V1_0::ColorMode::NATIVE) {
2715
0
        return "NATIVE";
2716
0
    }
2717
0
    if (o == ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_625) {
2718
0
        return "STANDARD_BT601_625";
2719
0
    }
2720
0
    if (o == ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_625_UNADJUSTED) {
2721
0
        return "STANDARD_BT601_625_UNADJUSTED";
2722
0
    }
2723
0
    if (o == ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_525) {
2724
0
        return "STANDARD_BT601_525";
2725
0
    }
2726
0
    if (o == ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_525_UNADJUSTED) {
2727
0
        return "STANDARD_BT601_525_UNADJUSTED";
2728
0
    }
2729
0
    if (o == ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT709) {
2730
0
        return "STANDARD_BT709";
2731
0
    }
2732
0
    if (o == ::android::hardware::graphics::common::V1_0::ColorMode::DCI_P3) {
2733
0
        return "DCI_P3";
2734
0
    }
2735
0
    if (o == ::android::hardware::graphics::common::V1_0::ColorMode::SRGB) {
2736
0
        return "SRGB";
2737
0
    }
2738
0
    if (o == ::android::hardware::graphics::common::V1_0::ColorMode::ADOBE_RGB) {
2739
0
        return "ADOBE_RGB";
2740
0
    }
2741
0
    if (o == ::android::hardware::graphics::common::V1_0::ColorMode::DISPLAY_P3) {
2742
0
        return "DISPLAY_P3";
2743
0
    }
2744
0
    std::string os;
2745
0
    os += toHexString(static_cast<int32_t>(o));
2746
0
    return os;
2747
0
}
2748
2749
template<>
2750
0
inline std::string toString<::android::hardware::graphics::common::V1_0::ColorTransform>(int32_t o) {
2751
0
    using ::android::hardware::details::toHexString;
2752
0
    std::string os;
2753
0
    ::android::hardware::hidl_bitfield<::android::hardware::graphics::common::V1_0::ColorTransform> flipped = 0;
2754
0
    bool first = true;
2755
0
    if ((o & ::android::hardware::graphics::common::V1_0::ColorTransform::IDENTITY) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::ColorTransform::IDENTITY)) {
2756
0
        os += (first ? "" : " | ");
2757
0
        os += "IDENTITY";
2758
0
        first = false;
2759
0
        flipped |= ::android::hardware::graphics::common::V1_0::ColorTransform::IDENTITY;
2760
0
    }
2761
0
    if ((o & ::android::hardware::graphics::common::V1_0::ColorTransform::ARBITRARY_MATRIX) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::ColorTransform::ARBITRARY_MATRIX)) {
2762
0
        os += (first ? "" : " | ");
2763
0
        os += "ARBITRARY_MATRIX";
2764
0
        first = false;
2765
0
        flipped |= ::android::hardware::graphics::common::V1_0::ColorTransform::ARBITRARY_MATRIX;
2766
0
    }
2767
0
    if ((o & ::android::hardware::graphics::common::V1_0::ColorTransform::VALUE_INVERSE) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::ColorTransform::VALUE_INVERSE)) {
2768
0
        os += (first ? "" : " | ");
2769
0
        os += "VALUE_INVERSE";
2770
0
        first = false;
2771
0
        flipped |= ::android::hardware::graphics::common::V1_0::ColorTransform::VALUE_INVERSE;
2772
0
    }
2773
0
    if ((o & ::android::hardware::graphics::common::V1_0::ColorTransform::GRAYSCALE) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::ColorTransform::GRAYSCALE)) {
2774
0
        os += (first ? "" : " | ");
2775
0
        os += "GRAYSCALE";
2776
0
        first = false;
2777
0
        flipped |= ::android::hardware::graphics::common::V1_0::ColorTransform::GRAYSCALE;
2778
0
    }
2779
0
    if ((o & ::android::hardware::graphics::common::V1_0::ColorTransform::CORRECT_PROTANOPIA) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::ColorTransform::CORRECT_PROTANOPIA)) {
2780
0
        os += (first ? "" : " | ");
2781
0
        os += "CORRECT_PROTANOPIA";
2782
0
        first = false;
2783
0
        flipped |= ::android::hardware::graphics::common::V1_0::ColorTransform::CORRECT_PROTANOPIA;
2784
0
    }
2785
0
    if ((o & ::android::hardware::graphics::common::V1_0::ColorTransform::CORRECT_DEUTERANOPIA) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::ColorTransform::CORRECT_DEUTERANOPIA)) {
2786
0
        os += (first ? "" : " | ");
2787
0
        os += "CORRECT_DEUTERANOPIA";
2788
0
        first = false;
2789
0
        flipped |= ::android::hardware::graphics::common::V1_0::ColorTransform::CORRECT_DEUTERANOPIA;
2790
0
    }
2791
0
    if ((o & ::android::hardware::graphics::common::V1_0::ColorTransform::CORRECT_TRITANOPIA) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::ColorTransform::CORRECT_TRITANOPIA)) {
2792
0
        os += (first ? "" : " | ");
2793
0
        os += "CORRECT_TRITANOPIA";
2794
0
        first = false;
2795
0
        flipped |= ::android::hardware::graphics::common::V1_0::ColorTransform::CORRECT_TRITANOPIA;
2796
0
    }
2797
0
    if (o != flipped) {
2798
0
        os += (first ? "" : " | ");
2799
0
        os += toHexString(o & (~flipped));
2800
0
    }os += " (";
2801
0
    os += toHexString(o);
2802
0
    os += ")";
2803
0
    return os;
2804
0
}
2805
2806
0
static inline std::string toString(::android::hardware::graphics::common::V1_0::ColorTransform o) {
2807
0
    using ::android::hardware::details::toHexString;
2808
0
    if (o == ::android::hardware::graphics::common::V1_0::ColorTransform::IDENTITY) {
2809
0
        return "IDENTITY";
2810
0
    }
2811
0
    if (o == ::android::hardware::graphics::common::V1_0::ColorTransform::ARBITRARY_MATRIX) {
2812
0
        return "ARBITRARY_MATRIX";
2813
0
    }
2814
0
    if (o == ::android::hardware::graphics::common::V1_0::ColorTransform::VALUE_INVERSE) {
2815
0
        return "VALUE_INVERSE";
2816
0
    }
2817
0
    if (o == ::android::hardware::graphics::common::V1_0::ColorTransform::GRAYSCALE) {
2818
0
        return "GRAYSCALE";
2819
0
    }
2820
0
    if (o == ::android::hardware::graphics::common::V1_0::ColorTransform::CORRECT_PROTANOPIA) {
2821
0
        return "CORRECT_PROTANOPIA";
2822
0
    }
2823
0
    if (o == ::android::hardware::graphics::common::V1_0::ColorTransform::CORRECT_DEUTERANOPIA) {
2824
0
        return "CORRECT_DEUTERANOPIA";
2825
0
    }
2826
0
    if (o == ::android::hardware::graphics::common::V1_0::ColorTransform::CORRECT_TRITANOPIA) {
2827
0
        return "CORRECT_TRITANOPIA";
2828
0
    }
2829
0
    std::string os;
2830
0
    os += toHexString(static_cast<int32_t>(o));
2831
0
    return os;
2832
0
}
2833
2834
template<>
2835
0
inline std::string toString<::android::hardware::graphics::common::V1_0::Hdr>(int32_t o) {
2836
0
    using ::android::hardware::details::toHexString;
2837
0
    std::string os;
2838
0
    ::android::hardware::hidl_bitfield<::android::hardware::graphics::common::V1_0::Hdr> flipped = 0;
2839
0
    bool first = true;
2840
0
    if ((o & ::android::hardware::graphics::common::V1_0::Hdr::DOLBY_VISION) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Hdr::DOLBY_VISION)) {
2841
0
        os += (first ? "" : " | ");
2842
0
        os += "DOLBY_VISION";
2843
0
        first = false;
2844
0
        flipped |= ::android::hardware::graphics::common::V1_0::Hdr::DOLBY_VISION;
2845
0
    }
2846
0
    if ((o & ::android::hardware::graphics::common::V1_0::Hdr::HDR10) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Hdr::HDR10)) {
2847
0
        os += (first ? "" : " | ");
2848
0
        os += "HDR10";
2849
0
        first = false;
2850
0
        flipped |= ::android::hardware::graphics::common::V1_0::Hdr::HDR10;
2851
0
    }
2852
0
    if ((o & ::android::hardware::graphics::common::V1_0::Hdr::HLG) == static_cast<int32_t>(::android::hardware::graphics::common::V1_0::Hdr::HLG)) {
2853
0
        os += (first ? "" : " | ");
2854
0
        os += "HLG";
2855
0
        first = false;
2856
0
        flipped |= ::android::hardware::graphics::common::V1_0::Hdr::HLG;
2857
0
    }
2858
0
    if (o != flipped) {
2859
0
        os += (first ? "" : " | ");
2860
0
        os += toHexString(o & (~flipped));
2861
0
    }os += " (";
2862
0
    os += toHexString(o);
2863
0
    os += ")";
2864
0
    return os;
2865
0
}
2866
2867
0
static inline std::string toString(::android::hardware::graphics::common::V1_0::Hdr o) {
2868
0
    using ::android::hardware::details::toHexString;
2869
0
    if (o == ::android::hardware::graphics::common::V1_0::Hdr::DOLBY_VISION) {
2870
0
        return "DOLBY_VISION";
2871
0
    }
2872
0
    if (o == ::android::hardware::graphics::common::V1_0::Hdr::HDR10) {
2873
0
        return "HDR10";
2874
0
    }
2875
0
    if (o == ::android::hardware::graphics::common::V1_0::Hdr::HLG) {
2876
0
        return "HLG";
2877
0
    }
2878
0
    std::string os;
2879
0
    os += toHexString(static_cast<int32_t>(o));
2880
0
    return os;
2881
0
}
2882
2883
2884
}  // namespace V1_0
2885
}  // namespace common
2886
}  // namespace graphics
2887
}  // namespace hardware
2888
}  // namespace android
2889
2890
//
2891
// global type declarations for package
2892
//
2893
2894
namespace android {
2895
namespace hardware {
2896
namespace details {
2897
template<> constexpr std::array<::android::hardware::graphics::common::V1_0::PixelFormat, 20> hidl_enum_values<::android::hardware::graphics::common::V1_0::PixelFormat> = {
2898
    ::android::hardware::graphics::common::V1_0::PixelFormat::RGBA_8888,
2899
    ::android::hardware::graphics::common::V1_0::PixelFormat::RGBX_8888,
2900
    ::android::hardware::graphics::common::V1_0::PixelFormat::RGB_888,
2901
    ::android::hardware::graphics::common::V1_0::PixelFormat::RGB_565,
2902
    ::android::hardware::graphics::common::V1_0::PixelFormat::BGRA_8888,
2903
    ::android::hardware::graphics::common::V1_0::PixelFormat::YCBCR_422_SP,
2904
    ::android::hardware::graphics::common::V1_0::PixelFormat::YCRCB_420_SP,
2905
    ::android::hardware::graphics::common::V1_0::PixelFormat::YCBCR_422_I,
2906
    ::android::hardware::graphics::common::V1_0::PixelFormat::RGBA_FP16,
2907
    ::android::hardware::graphics::common::V1_0::PixelFormat::RAW16,
2908
    ::android::hardware::graphics::common::V1_0::PixelFormat::BLOB,
2909
    ::android::hardware::graphics::common::V1_0::PixelFormat::IMPLEMENTATION_DEFINED,
2910
    ::android::hardware::graphics::common::V1_0::PixelFormat::YCBCR_420_888,
2911
    ::android::hardware::graphics::common::V1_0::PixelFormat::RAW_OPAQUE,
2912
    ::android::hardware::graphics::common::V1_0::PixelFormat::RAW10,
2913
    ::android::hardware::graphics::common::V1_0::PixelFormat::RAW12,
2914
    ::android::hardware::graphics::common::V1_0::PixelFormat::RGBA_1010102,
2915
    ::android::hardware::graphics::common::V1_0::PixelFormat::Y8,
2916
    ::android::hardware::graphics::common::V1_0::PixelFormat::Y16,
2917
    ::android::hardware::graphics::common::V1_0::PixelFormat::YV12,
2918
};
2919
}  // namespace details
2920
}  // namespace hardware
2921
}  // namespace android
2922
2923
namespace android {
2924
namespace hardware {
2925
namespace details {
2926
template<> constexpr std::array<::android::hardware::graphics::common::V1_0::BufferUsage, 23> hidl_enum_values<::android::hardware::graphics::common::V1_0::BufferUsage> = {
2927
    ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_MASK,
2928
    ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_NEVER,
2929
    ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_RARELY,
2930
    ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_READ_OFTEN,
2931
    ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_MASK,
2932
    ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_NEVER,
2933
    ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_RARELY,
2934
    ::android::hardware::graphics::common::V1_0::BufferUsage::CPU_WRITE_OFTEN,
2935
    ::android::hardware::graphics::common::V1_0::BufferUsage::GPU_TEXTURE,
2936
    ::android::hardware::graphics::common::V1_0::BufferUsage::GPU_RENDER_TARGET,
2937
    ::android::hardware::graphics::common::V1_0::BufferUsage::COMPOSER_OVERLAY,
2938
    ::android::hardware::graphics::common::V1_0::BufferUsage::COMPOSER_CLIENT_TARGET,
2939
    ::android::hardware::graphics::common::V1_0::BufferUsage::PROTECTED,
2940
    ::android::hardware::graphics::common::V1_0::BufferUsage::COMPOSER_CURSOR,
2941
    ::android::hardware::graphics::common::V1_0::BufferUsage::VIDEO_ENCODER,
2942
    ::android::hardware::graphics::common::V1_0::BufferUsage::CAMERA_OUTPUT,
2943
    ::android::hardware::graphics::common::V1_0::BufferUsage::CAMERA_INPUT,
2944
    ::android::hardware::graphics::common::V1_0::BufferUsage::RENDERSCRIPT,
2945
    ::android::hardware::graphics::common::V1_0::BufferUsage::VIDEO_DECODER,
2946
    ::android::hardware::graphics::common::V1_0::BufferUsage::SENSOR_DIRECT_DATA,
2947
    ::android::hardware::graphics::common::V1_0::BufferUsage::GPU_DATA_BUFFER,
2948
    ::android::hardware::graphics::common::V1_0::BufferUsage::VENDOR_MASK,
2949
    ::android::hardware::graphics::common::V1_0::BufferUsage::VENDOR_MASK_HI,
2950
};
2951
}  // namespace details
2952
}  // namespace hardware
2953
}  // namespace android
2954
2955
namespace android {
2956
namespace hardware {
2957
namespace details {
2958
template<> constexpr std::array<::android::hardware::graphics::common::V1_0::Transform, 5> hidl_enum_values<::android::hardware::graphics::common::V1_0::Transform> = {
2959
    ::android::hardware::graphics::common::V1_0::Transform::FLIP_H,
2960
    ::android::hardware::graphics::common::V1_0::Transform::FLIP_V,
2961
    ::android::hardware::graphics::common::V1_0::Transform::ROT_90,
2962
    ::android::hardware::graphics::common::V1_0::Transform::ROT_180,
2963
    ::android::hardware::graphics::common::V1_0::Transform::ROT_270,
2964
};
2965
}  // namespace details
2966
}  // namespace hardware
2967
}  // namespace android
2968
2969
namespace android {
2970
namespace hardware {
2971
namespace details {
2972
template<> constexpr std::array<::android::hardware::graphics::common::V1_0::Dataspace, 57> hidl_enum_values<::android::hardware::graphics::common::V1_0::Dataspace> = {
2973
    ::android::hardware::graphics::common::V1_0::Dataspace::UNKNOWN,
2974
    ::android::hardware::graphics::common::V1_0::Dataspace::ARBITRARY,
2975
    ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_SHIFT,
2976
    ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_MASK,
2977
    ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_UNSPECIFIED,
2978
    ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT709,
2979
    ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_625,
2980
    ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_625_UNADJUSTED,
2981
    ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_525,
2982
    ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT601_525_UNADJUSTED,
2983
    ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT2020,
2984
    ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT2020_CONSTANT_LUMINANCE,
2985
    ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_BT470M,
2986
    ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_FILM,
2987
    ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_DCI_P3,
2988
    ::android::hardware::graphics::common::V1_0::Dataspace::STANDARD_ADOBE_RGB,
2989
    ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_SHIFT,
2990
    ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_MASK,
2991
    ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_UNSPECIFIED,
2992
    ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_LINEAR,
2993
    ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_SRGB,
2994
    ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_SMPTE_170M,
2995
    ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_GAMMA2_2,
2996
    ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_GAMMA2_6,
2997
    ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_GAMMA2_8,
2998
    ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_ST2084,
2999
    ::android::hardware::graphics::common::V1_0::Dataspace::TRANSFER_HLG,
3000
    ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_SHIFT,
3001
    ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_MASK,
3002
    ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_UNSPECIFIED,
3003
    ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_FULL,
3004
    ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_LIMITED,
3005
    ::android::hardware::graphics::common::V1_0::Dataspace::RANGE_EXTENDED,
3006
    ::android::hardware::graphics::common::V1_0::Dataspace::SRGB_LINEAR,
3007
    ::android::hardware::graphics::common::V1_0::Dataspace::V0_SRGB_LINEAR,
3008
    ::android::hardware::graphics::common::V1_0::Dataspace::V0_SCRGB_LINEAR,
3009
    ::android::hardware::graphics::common::V1_0::Dataspace::SRGB,
3010
    ::android::hardware::graphics::common::V1_0::Dataspace::V0_SRGB,
3011
    ::android::hardware::graphics::common::V1_0::Dataspace::V0_SCRGB,
3012
    ::android::hardware::graphics::common::V1_0::Dataspace::JFIF,
3013
    ::android::hardware::graphics::common::V1_0::Dataspace::V0_JFIF,
3014
    ::android::hardware::graphics::common::V1_0::Dataspace::BT601_625,
3015
    ::android::hardware::graphics::common::V1_0::Dataspace::V0_BT601_625,
3016
    ::android::hardware::graphics::common::V1_0::Dataspace::BT601_525,
3017
    ::android::hardware::graphics::common::V1_0::Dataspace::V0_BT601_525,
3018
    ::android::hardware::graphics::common::V1_0::Dataspace::BT709,
3019
    ::android::hardware::graphics::common::V1_0::Dataspace::V0_BT709,
3020
    ::android::hardware::graphics::common::V1_0::Dataspace::DCI_P3_LINEAR,
3021
    ::android::hardware::graphics::common::V1_0::Dataspace::DCI_P3,
3022
    ::android::hardware::graphics::common::V1_0::Dataspace::DISPLAY_P3_LINEAR,
3023
    ::android::hardware::graphics::common::V1_0::Dataspace::DISPLAY_P3,
3024
    ::android::hardware::graphics::common::V1_0::Dataspace::ADOBE_RGB,
3025
    ::android::hardware::graphics::common::V1_0::Dataspace::BT2020_LINEAR,
3026
    ::android::hardware::graphics::common::V1_0::Dataspace::BT2020,
3027
    ::android::hardware::graphics::common::V1_0::Dataspace::BT2020_PQ,
3028
    ::android::hardware::graphics::common::V1_0::Dataspace::DEPTH,
3029
    ::android::hardware::graphics::common::V1_0::Dataspace::SENSOR,
3030
};
3031
}  // namespace details
3032
}  // namespace hardware
3033
}  // namespace android
3034
3035
namespace android {
3036
namespace hardware {
3037
namespace details {
3038
template<> constexpr std::array<::android::hardware::graphics::common::V1_0::ColorMode, 10> hidl_enum_values<::android::hardware::graphics::common::V1_0::ColorMode> = {
3039
    ::android::hardware::graphics::common::V1_0::ColorMode::NATIVE,
3040
    ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_625,
3041
    ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_625_UNADJUSTED,
3042
    ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_525,
3043
    ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT601_525_UNADJUSTED,
3044
    ::android::hardware::graphics::common::V1_0::ColorMode::STANDARD_BT709,
3045
    ::android::hardware::graphics::common::V1_0::ColorMode::DCI_P3,
3046
    ::android::hardware::graphics::common::V1_0::ColorMode::SRGB,
3047
    ::android::hardware::graphics::common::V1_0::ColorMode::ADOBE_RGB,
3048
    ::android::hardware::graphics::common::V1_0::ColorMode::DISPLAY_P3,
3049
};
3050
}  // namespace details
3051
}  // namespace hardware
3052
}  // namespace android
3053
3054
namespace android {
3055
namespace hardware {
3056
namespace details {
3057
template<> constexpr std::array<::android::hardware::graphics::common::V1_0::ColorTransform, 7> hidl_enum_values<::android::hardware::graphics::common::V1_0::ColorTransform> = {
3058
    ::android::hardware::graphics::common::V1_0::ColorTransform::IDENTITY,
3059
    ::android::hardware::graphics::common::V1_0::ColorTransform::ARBITRARY_MATRIX,
3060
    ::android::hardware::graphics::common::V1_0::ColorTransform::VALUE_INVERSE,
3061
    ::android::hardware::graphics::common::V1_0::ColorTransform::GRAYSCALE,
3062
    ::android::hardware::graphics::common::V1_0::ColorTransform::CORRECT_PROTANOPIA,
3063
    ::android::hardware::graphics::common::V1_0::ColorTransform::CORRECT_DEUTERANOPIA,
3064
    ::android::hardware::graphics::common::V1_0::ColorTransform::CORRECT_TRITANOPIA,
3065
};
3066
}  // namespace details
3067
}  // namespace hardware
3068
}  // namespace android
3069
3070
namespace android {
3071
namespace hardware {
3072
namespace details {
3073
template<> constexpr std::array<::android::hardware::graphics::common::V1_0::Hdr, 3> hidl_enum_values<::android::hardware::graphics::common::V1_0::Hdr> = {
3074
    ::android::hardware::graphics::common::V1_0::Hdr::DOLBY_VISION,
3075
    ::android::hardware::graphics::common::V1_0::Hdr::HDR10,
3076
    ::android::hardware::graphics::common::V1_0::Hdr::HLG,
3077
};
3078
}  // namespace details
3079
}  // namespace hardware
3080
}  // namespace android
3081
3082
3083
#endif  // HIDL_GENERATED_ANDROID_HARDWARE_GRAPHICS_COMMON_V1_0_TYPES_H
/proc/self/cwd/out/soong/.intermediates/hardware/interfaces/media/1.0/android.hardware.media@1.0_genc++_headers/gen/android/hardware/media/1.0/types.h
Line
Count
Source (jump to first uncovered line)
1
#ifndef HIDL_GENERATED_ANDROID_HARDWARE_MEDIA_V1_0_TYPES_H
2
#define HIDL_GENERATED_ANDROID_HARDWARE_MEDIA_V1_0_TYPES_H
3
4
#include <android/hardware/graphics/common/1.0/types.h>
5
6
#include <hidl/HidlSupport.h>
7
#include <hidl/MQDescriptor.h>
8
#include <utils/NativeHandle.h>
9
#include <utils/misc.h>
10
11
namespace android {
12
namespace hardware {
13
namespace media {
14
namespace V1_0 {
15
16
// Forward declaration for forward reference support:
17
struct AnwBufferAttributes;
18
struct AnwBuffer;
19
struct Rect;
20
21
/**
22
 * Aliases
23
 */
24
typedef ::android::hardware::hidl_handle FileDescriptor;
25
26
typedef ::android::hardware::hidl_handle Fence;
27
28
typedef ::android::hardware::hidl_vec<uint8_t> Bytes;
29
30
/**
31
 * Ref: frameworks/native/include/ui/GraphicBuffer.h
32
 * Ref: system/core/include/system/window.h: ANativeWindowBuffer
33
 * 
34
 * 
35
 * This struct contains attributes for a gralloc buffer that can be put into a
36
 * union.
37
 */
38
struct AnwBufferAttributes final {
39
    uint32_t width __attribute__ ((aligned(4)));
40
    uint32_t height __attribute__ ((aligned(4)));
41
    uint32_t stride __attribute__ ((aligned(4)));
42
    ::android::hardware::graphics::common::V1_0::PixelFormat format __attribute__ ((aligned(4)));
43
    uint32_t usage __attribute__ ((aligned(4)));
44
    uint32_t generationNumber __attribute__ ((aligned(4)));
45
    uint64_t layerCount __attribute__ ((aligned(8)));
46
    uint64_t id __attribute__ ((aligned(8)));
47
};
48
49
static_assert(offsetof(::android::hardware::media::V1_0::AnwBufferAttributes, width) == 0, "wrong offset");
50
static_assert(offsetof(::android::hardware::media::V1_0::AnwBufferAttributes, height) == 4, "wrong offset");
51
static_assert(offsetof(::android::hardware::media::V1_0::AnwBufferAttributes, stride) == 8, "wrong offset");
52
static_assert(offsetof(::android::hardware::media::V1_0::AnwBufferAttributes, format) == 12, "wrong offset");
53
static_assert(offsetof(::android::hardware::media::V1_0::AnwBufferAttributes, usage) == 16, "wrong offset");
54
static_assert(offsetof(::android::hardware::media::V1_0::AnwBufferAttributes, generationNumber) == 20, "wrong offset");
55
static_assert(offsetof(::android::hardware::media::V1_0::AnwBufferAttributes, layerCount) == 24, "wrong offset");
56
static_assert(offsetof(::android::hardware::media::V1_0::AnwBufferAttributes, id) == 32, "wrong offset");
57
static_assert(sizeof(::android::hardware::media::V1_0::AnwBufferAttributes) == 40, "wrong size");
58
static_assert(__alignof(::android::hardware::media::V1_0::AnwBufferAttributes) == 8, "wrong alignment");
59
60
/**
61
 * An AnwBuffer is simply AnwBufferAttributes plus a native handle.
62
 */
63
struct AnwBuffer final {
64
    ::android::hardware::hidl_handle nativeHandle __attribute__ ((aligned(8)));
65
    ::android::hardware::media::V1_0::AnwBufferAttributes attr __attribute__ ((aligned(8)));
66
};
67
68
static_assert(offsetof(::android::hardware::media::V1_0::AnwBuffer, nativeHandle) == 0, "wrong offset");
69
static_assert(offsetof(::android::hardware::media::V1_0::AnwBuffer, attr) == 16, "wrong offset");
70
static_assert(sizeof(::android::hardware::media::V1_0::AnwBuffer) == 56, "wrong size");
71
static_assert(__alignof(::android::hardware::media::V1_0::AnwBuffer) == 8, "wrong alignment");
72
73
/**
74
 * Ref: frameworks/native/include/android/rect.h
75
 * Ref: frameworks/native/include/ui/Rect.h
76
 */
77
struct Rect final {
78
    int32_t left __attribute__ ((aligned(4)));
79
    int32_t top __attribute__ ((aligned(4)));
80
    int32_t right __attribute__ ((aligned(4)));
81
    int32_t bottom __attribute__ ((aligned(4)));
82
};
83
84
static_assert(offsetof(::android::hardware::media::V1_0::Rect, left) == 0, "wrong offset");
85
static_assert(offsetof(::android::hardware::media::V1_0::Rect, top) == 4, "wrong offset");
86
static_assert(offsetof(::android::hardware::media::V1_0::Rect, right) == 8, "wrong offset");
87
static_assert(offsetof(::android::hardware::media::V1_0::Rect, bottom) == 12, "wrong offset");
88
static_assert(sizeof(::android::hardware::media::V1_0::Rect) == 16, "wrong size");
89
static_assert(__alignof(::android::hardware::media::V1_0::Rect) == 4, "wrong alignment");
90
91
/**
92
 * Ref: frameworks/native/include/ui/Region.h
93
 */
94
typedef ::android::hardware::hidl_vec<::android::hardware::media::V1_0::Rect> Region;
95
96
//
97
// type declarations for package
98
//
99
100
static inline std::string toString(const ::android::hardware::media::V1_0::AnwBufferAttributes& o);
101
static inline bool operator==(const ::android::hardware::media::V1_0::AnwBufferAttributes& lhs, const ::android::hardware::media::V1_0::AnwBufferAttributes& rhs);
102
static inline bool operator!=(const ::android::hardware::media::V1_0::AnwBufferAttributes& lhs, const ::android::hardware::media::V1_0::AnwBufferAttributes& rhs);
103
104
static inline std::string toString(const ::android::hardware::media::V1_0::AnwBuffer& o);
105
// operator== and operator!= are not generated for AnwBuffer
106
107
static inline std::string toString(const ::android::hardware::media::V1_0::Rect& o);
108
static inline bool operator==(const ::android::hardware::media::V1_0::Rect& lhs, const ::android::hardware::media::V1_0::Rect& rhs);
109
static inline bool operator!=(const ::android::hardware::media::V1_0::Rect& lhs, const ::android::hardware::media::V1_0::Rect& rhs);
110
111
//
112
// type header definitions for package
113
//
114
115
0
static inline std::string toString(const ::android::hardware::media::V1_0::AnwBufferAttributes& o) {
116
0
    using ::android::hardware::toString;
117
0
    std::string os;
118
0
    os += "{";
119
0
    os += ".width = ";
120
0
    os += ::android::hardware::toString(o.width);
121
0
    os += ", .height = ";
122
0
    os += ::android::hardware::toString(o.height);
123
0
    os += ", .stride = ";
124
0
    os += ::android::hardware::toString(o.stride);
125
0
    os += ", .format = ";
126
0
    os += ::android::hardware::graphics::common::V1_0::toString(o.format);
127
0
    os += ", .usage = ";
128
0
    os += ::android::hardware::toString(o.usage);
129
0
    os += ", .generationNumber = ";
130
0
    os += ::android::hardware::toString(o.generationNumber);
131
0
    os += ", .layerCount = ";
132
0
    os += ::android::hardware::toString(o.layerCount);
133
0
    os += ", .id = ";
134
0
    os += ::android::hardware::toString(o.id);
135
0
    os += "}"; return os;
136
0
}
137
138
0
static inline bool operator==(const ::android::hardware::media::V1_0::AnwBufferAttributes& lhs, const ::android::hardware::media::V1_0::AnwBufferAttributes& rhs) {
139
0
    if (lhs.width != rhs.width) {
140
0
        return false;
141
0
    }
142
0
    if (lhs.height != rhs.height) {
143
0
        return false;
144
0
    }
145
0
    if (lhs.stride != rhs.stride) {
146
0
        return false;
147
0
    }
148
0
    if (lhs.format != rhs.format) {
149
0
        return false;
150
0
    }
151
0
    if (lhs.usage != rhs.usage) {
152
0
        return false;
153
0
    }
154
0
    if (lhs.generationNumber != rhs.generationNumber) {
155
0
        return false;
156
0
    }
157
0
    if (lhs.layerCount != rhs.layerCount) {
158
0
        return false;
159
0
    }
160
0
    if (lhs.id != rhs.id) {
161
0
        return false;
162
0
    }
163
0
    return true;
164
0
}
165
166
0
static inline bool operator!=(const ::android::hardware::media::V1_0::AnwBufferAttributes& lhs, const ::android::hardware::media::V1_0::AnwBufferAttributes& rhs){
167
0
    return !(lhs == rhs);
168
0
}
169
170
0
static inline std::string toString(const ::android::hardware::media::V1_0::AnwBuffer& o) {
171
0
    using ::android::hardware::toString;
172
0
    std::string os;
173
0
    os += "{";
174
0
    os += ".nativeHandle = ";
175
0
    os += ::android::hardware::toString(o.nativeHandle);
176
0
    os += ", .attr = ";
177
0
    os += ::android::hardware::media::V1_0::toString(o.attr);
178
0
    os += "}"; return os;
179
0
}
180
181
// operator== and operator!= are not generated for AnwBuffer
182
183
0
static inline std::string toString(const ::android::hardware::media::V1_0::Rect& o) {
184
0
    using ::android::hardware::toString;
185
0
    std::string os;
186
0
    os += "{";
187
0
    os += ".left = ";
188
0
    os += ::android::hardware::toString(o.left);
189
0
    os += ", .top = ";
190
0
    os += ::android::hardware::toString(o.top);
191
0
    os += ", .right = ";
192
0
    os += ::android::hardware::toString(o.right);
193
0
    os += ", .bottom = ";
194
0
    os += ::android::hardware::toString(o.bottom);
195
0
    os += "}"; return os;
196
0
}
197
198
0
static inline bool operator==(const ::android::hardware::media::V1_0::Rect& lhs, const ::android::hardware::media::V1_0::Rect& rhs) {
199
0
    if (lhs.left != rhs.left) {
200
0
        return false;
201
0
    }
202
0
    if (lhs.top != rhs.top) {
203
0
        return false;
204
0
    }
205
0
    if (lhs.right != rhs.right) {
206
0
        return false;
207
0
    }
208
0
    if (lhs.bottom != rhs.bottom) {
209
0
        return false;
210
0
    }
211
0
    return true;
212
0
}
213
214
0
static inline bool operator!=(const ::android::hardware::media::V1_0::Rect& lhs, const ::android::hardware::media::V1_0::Rect& rhs){
215
0
    return !(lhs == rhs);
216
0
}
217
218
219
}  // namespace V1_0
220
}  // namespace media
221
}  // namespace hardware
222
}  // namespace android
223
224
//
225
// global type declarations for package
226
//
227
228
229
#endif  // HIDL_GENERATED_ANDROID_HARDWARE_MEDIA_V1_0_TYPES_H
/proc/self/cwd/out/soong/.intermediates/hardware/interfaces/media/omx/1.0/android.hardware.media.omx@1.0_genc++_headers/gen/android/hardware/media/omx/1.0/IOmxBufferSource.h
Line
Count
Source (jump to first uncovered line)
1
#ifndef HIDL_GENERATED_ANDROID_HARDWARE_MEDIA_OMX_V1_0_IOMXBUFFERSOURCE_H
2
#define HIDL_GENERATED_ANDROID_HARDWARE_MEDIA_OMX_V1_0_IOMXBUFFERSOURCE_H
3
4
#include <android/hardware/media/omx/1.0/types.h>
5
#include <android/hardware/media/1.0/types.h>
6
#include <android/hidl/base/1.0/IBase.h>
7
8
#include <android/hidl/manager/1.0/IServiceNotification.h>
9
10
#include <hidl/HidlSupport.h>
11
#include <hidl/MQDescriptor.h>
12
#include <hidl/Status.h>
13
#include <utils/NativeHandle.h>
14
#include <utils/misc.h>
15
16
namespace android {
17
namespace hardware {
18
namespace media {
19
namespace omx {
20
namespace V1_0 {
21
22
struct IOmxBufferSource : public ::android::hidl::base::V1_0::IBase {
23
    typedef android::hardware::details::i_tag _hidl_tag;
24
25
    // Forward declaration for forward reference support:
26
27
    /**
28
     * Ref: frameworks/av/media/libmedia/aidl/android/IOMXBufferSource.aidl
29
     * 
30
     * IOmxBufferSource is an interface for a listener for certain events from an
31
     * IOmxNode instance. Use IOmxNode::setInputSurface() to attach an
32
     * IOmxBufferSource instance to an IOmxNode instance.
33
     * 
34
     * @see OMX_STATETYPE in the OpenMax IL standard.
35
     */
36
0
    virtual bool isRemote() const override { return false; }
37
38
39
    /**
40
     * onOmxExecuting() is invoked when the node state changes to
41
     * OMX_StateExecuting state.
42
     */
43
    virtual ::android::hardware::Return<void> onOmxExecuting() = 0;
44
45
    /**
46
     * onOmxIdle() is invoked when the node transitions from OMX_StateExecuting
47
     * to OMX_StateIdle.
48
     */
49
    virtual ::android::hardware::Return<void> onOmxIdle() = 0;
50
51
    /**
52
     * onOmxLoaded() is invoked when the node transitions from OMX_StateIdle or
53
     * OMX_StateExecuting to OMX_StateLoaded.
54
     */
55
    virtual ::android::hardware::Return<void> onOmxLoaded() = 0;
56
57
    /**
58
     * onInputBufferAdded() is invoked after a new input buffer is added to the
59
     * node. This may happen within IOmxNode::allocateSecureBuffer() or
60
     * IOmxNode::useBuffer().
61
     * 
62
     * @param[in] buffer is the id of the added buffer.
63
     */
64
    virtual ::android::hardware::Return<void> onInputBufferAdded(uint32_t buffer) = 0;
65
66
    /**
67
     * onInputBufferEmptied() is invoked after an input buffer is emptied. This
68
     * may happen within IOmxNode::emptyBuffer().
69
     * 
70
     * @param[in] buffer is the id of the emptied buffer.
71
     * @param[in] fence is the fence associated with the buffer.
72
     */
73
    virtual ::android::hardware::Return<void> onInputBufferEmptied(uint32_t buffer, const ::android::hardware::hidl_handle& fence) = 0;
74
75
    using interfaceChain_cb = std::function<void(const ::android::hardware::hidl_vec<::android::hardware::hidl_string>& descriptors)>;
76
    virtual ::android::hardware::Return<void> interfaceChain(interfaceChain_cb _hidl_cb) override;
77
78
    virtual ::android::hardware::Return<void> debug(const ::android::hardware::hidl_handle& fd, const ::android::hardware::hidl_vec<::android::hardware::hidl_string>& options) override;
79
80
    using interfaceDescriptor_cb = std::function<void(const ::android::hardware::hidl_string& descriptor)>;
81
    virtual ::android::hardware::Return<void> interfaceDescriptor(interfaceDescriptor_cb _hidl_cb) override;
82
83
    using getHashChain_cb = std::function<void(const ::android::hardware::hidl_vec<::android::hardware::hidl_array<uint8_t, 32>>& hashchain)>;
84
    virtual ::android::hardware::Return<void> getHashChain(getHashChain_cb _hidl_cb) override;
85
86
    virtual ::android::hardware::Return<void> setHALInstrumentation() override;
87
88
    virtual ::android::hardware::Return<bool> linkToDeath(const ::android::sp<::android::hardware::hidl_death_recipient>& recipient, uint64_t cookie) override;
89
90
    virtual ::android::hardware::Return<void> ping() override;
91
92
    using getDebugInfo_cb = std::function<void(const ::android::hidl::base::V1_0::DebugInfo& info)>;
93
    virtual ::android::hardware::Return<void> getDebugInfo(getDebugInfo_cb _hidl_cb) override;
94
95
    virtual ::android::hardware::Return<void> notifySyspropsChanged() override;
96
97
    virtual ::android::hardware::Return<bool> unlinkToDeath(const ::android::sp<::android::hardware::hidl_death_recipient>& recipient) override;
98
    // cast static functions
99
    static ::android::hardware::Return<::android::sp<::android::hardware::media::omx::V1_0::IOmxBufferSource>> castFrom(const ::android::sp<::android::hardware::media::omx::V1_0::IOmxBufferSource>& parent, bool emitError = false);
100
    static ::android::hardware::Return<::android::sp<::android::hardware::media::omx::V1_0::IOmxBufferSource>> castFrom(const ::android::sp<::android::hidl::base::V1_0::IBase>& parent, bool emitError = false);
101
102
    static const char* descriptor;
103
104
    static ::android::sp<IOmxBufferSource> tryGetService(const std::string &serviceName="default", bool getStub=false);
105
0
    static ::android::sp<IOmxBufferSource> tryGetService(const char serviceName[], bool getStub=false)  { std::string str(serviceName ? serviceName : "");      return tryGetService(str, getStub); }
106
0
    static ::android::sp<IOmxBufferSource> tryGetService(const ::android::hardware::hidl_string& serviceName, bool getStub=false)  { std::string str(serviceName.c_str());      return tryGetService(str, getStub); }
107
0
    static ::android::sp<IOmxBufferSource> tryGetService(bool getStub) { return tryGetService("default", getStub); }
108
    static ::android::sp<IOmxBufferSource> getService(const std::string &serviceName="default", bool getStub=false);
109
0
    static ::android::sp<IOmxBufferSource> getService(const char serviceName[], bool getStub=false)  { std::string str(serviceName ? serviceName : "");      return getService(str, getStub); }
110
0
    static ::android::sp<IOmxBufferSource> getService(const ::android::hardware::hidl_string& serviceName, bool getStub=false)  { std::string str(serviceName.c_str());      return getService(str, getStub); }
111
0
    static ::android::sp<IOmxBufferSource> getService(bool getStub) { return getService("default", getStub); }
112
    __attribute__ ((warn_unused_result))::android::status_t registerAsService(const std::string &serviceName="default");
113
    static bool registerForNotifications(
114
            const std::string &serviceName,
115
            const ::android::sp<::android::hidl::manager::V1_0::IServiceNotification> &notification);
116
};
117
118
//
119
// type declarations for package
120
//
121
122
static inline std::string toString(const ::android::sp<::android::hardware::media::omx::V1_0::IOmxBufferSource>& o);
123
124
//
125
// type header definitions for package
126
//
127
128
0
static inline std::string toString(const ::android::sp<::android::hardware::media::omx::V1_0::IOmxBufferSource>& o) {
129
0
    std::string os = "[class or subclass of ";
130
0
    os += ::android::hardware::media::omx::V1_0::IOmxBufferSource::descriptor;
131
0
    os += "]";
132
0
    os += o->isRemote() ? "@remote" : "@local";
133
0
    return os;
134
0
}
135
136
137
}  // namespace V1_0
138
}  // namespace omx
139
}  // namespace media
140
}  // namespace hardware
141
}  // namespace android
142
143
//
144
// global type declarations for package
145
//
146
147
148
#endif  // HIDL_GENERATED_ANDROID_HARDWARE_MEDIA_OMX_V1_0_IOMXBUFFERSOURCE_H
/proc/self/cwd/out/soong/.intermediates/hardware/interfaces/media/omx/1.0/android.hardware.media.omx@1.0_genc++_headers/gen/android/hardware/media/omx/1.0/IOmxNode.h
Line
Count
Source (jump to first uncovered line)
1
#ifndef HIDL_GENERATED_ANDROID_HARDWARE_MEDIA_OMX_V1_0_IOMXNODE_H
2
#define HIDL_GENERATED_ANDROID_HARDWARE_MEDIA_OMX_V1_0_IOMXNODE_H
3
4
#include <android/hardware/media/omx/1.0/IOmxBufferSource.h>
5
#include <android/hardware/media/omx/1.0/types.h>
6
#include <android/hardware/media/1.0/types.h>
7
#include <android/hidl/base/1.0/IBase.h>
8
9
#include <android/hidl/manager/1.0/IServiceNotification.h>
10
11
#include <hidl/HidlSupport.h>
12
#include <hidl/MQDescriptor.h>
13
#include <hidl/Status.h>
14
#include <utils/NativeHandle.h>
15
#include <utils/misc.h>
16
17
namespace android {
18
namespace hardware {
19
namespace media {
20
namespace omx {
21
namespace V1_0 {
22
23
struct IOmxNode : public ::android::hidl::base::V1_0::IBase {
24
    typedef android::hardware::details::i_tag _hidl_tag;
25
26
    // Forward declaration for forward reference support:
27
28
    /**
29
     * Ref: frameworks/av/include/media/IOMX.h: IOMXNode
30
     * Ref: https://www.khronos.org/registry/omxil/specs/OpenMAX_IL_1_1_2_Specification.pdf
31
     * 
32
     * 
33
     * IOmxNode is an interface for communicating with an OMX component (called
34
     * "node" here) that has been previously obtained by calling
35
     * IOmx::allocateNode().
36
     */
37
0
    virtual bool isRemote() const override { return false; }
38
39
40
    /**
41
     * Free the node.
42
     * 
43
     * @return status Status of the call.
44
     */
45
    virtual ::android::hardware::Return<::android::hardware::media::omx::V1_0::Status> freeNode() = 0;
46
47
    /**
48
     * Invoke a command on the node.
49
     * 
50
     * @param cmd Type of the command.
51
     * @param param Parameter for the command.
52
     * @return status Status of the call.
53
     * 
54
     * @see OMX_SendCommand() in the OpenMax IL standard.
55
     */
56
    virtual ::android::hardware::Return<::android::hardware::media::omx::V1_0::Status> sendCommand(uint32_t cmd, int32_t param) = 0;
57
58
    using getParameter_cb = std::function<void(::android::hardware::media::omx::V1_0::Status status, const ::android::hardware::hidl_vec<uint8_t>& outParams)>;
59
    /**
60
     * Retrieve a parameter setting from the node.
61
     * 
62
     * @param index Type of the parameter to retrieve.
63
     * @param inParams Information about the retrieval.
64
     * @return status Status of the call.
65
     * @return outParams Current parameter setting.
66
     * 
67
     * @see OMX_GetParameter() in the OpenMax IL standard.
68
     */
69
    virtual ::android::hardware::Return<void> getParameter(uint32_t index, const ::android::hardware::hidl_vec<uint8_t>& inParams, getParameter_cb _hidl_cb) = 0;
70
71
    /**
72
     * Change a parameter setting of the node.
73
     * 
74
     * @param index Type of the parameter to change.
75
     * @param params New parameter setting.
76
     * @return status Status of the call.
77
     * 
78
     * @see OMX_SetParameter() in the OpenMax IL standard.
79
     */
80
    virtual ::android::hardware::Return<::android::hardware::media::omx::V1_0::Status> setParameter(uint32_t index, const ::android::hardware::hidl_vec<uint8_t>& params) = 0;
81
82
    using getConfig_cb = std::function<void(::android::hardware::media::omx::V1_0::Status status, const ::android::hardware::hidl_vec<uint8_t>& outConfig)>;
83
    /**
84
     * Retrieve a configuration from the node.
85
     * 
86
     * @param index Type of the configuration to retrieve.
87
     * @param inConfig Information about the retrieval.
88
     * @return status Status of the call.
89
     * @return outConfig Current configuration.
90
     * 
91
     * @see OMX_GetConfig() in the OpenMax IL standard.
92
     */
93
    virtual ::android::hardware::Return<void> getConfig(uint32_t index, const ::android::hardware::hidl_vec<uint8_t>& inConfig, getConfig_cb _hidl_cb) = 0;
94
95
    /**
96
     * Change a configuration of the node.
97
     * 
98
     * @param index Type of the configuration to change.
99
     * @param config New configuration.
100
     * @return status Status of the call.
101
     * 
102
     * @see OMX_SetConfig() in the OpenMax IL standard.
103
     */
104
    virtual ::android::hardware::Return<::android::hardware::media::omx::V1_0::Status> setConfig(uint32_t index, const ::android::hardware::hidl_vec<uint8_t>& config) = 0;
105
106
    /**
107
     * Set the mode of a port on the node.
108
     * 
109
     * @param portIndex Index of the port.
110
     * @param mode Target mode on the specified port.
111
     * @return status Status of the call.
112
     */
113
    virtual ::android::hardware::Return<::android::hardware::media::omx::V1_0::Status> setPortMode(uint32_t portIndex, ::android::hardware::media::omx::V1_0::PortMode mode) = 0;
114
115
    /**
116
     * Prepare a port for adaptive playback. This is based on the extension
117
     * "OMX.google.android.index.prepareForAdaptivePlayback".
118
     * 
119
     * @param portIndex Index of the port.
120
     * @param enable Whether the adaptive playback is enabled or not.
121
     * @param maxFrameWidth Maximum frame width.
122
     * @param maxFrameHeight Maximum frame height.
123
     * @return status Status of the call.
124
     */
125
    virtual ::android::hardware::Return<::android::hardware::media::omx::V1_0::Status> prepareForAdaptivePlayback(uint32_t portIndex, bool enable, uint32_t maxFrameWidth, uint32_t maxFrameHeight) = 0;
126
127
    using configureVideoTunnelMode_cb = std::function<void(::android::hardware::media::omx::V1_0::Status status, const ::android::hardware::hidl_handle& sidebandHandle)>;
128
    /**
129
     * Configure a port for a tunneled playback mode. This is based on the
130
     * extension "OMX.google.android.index.configureVideoTunnelMode".
131
     * 
132
     * @param portIndex Index of the port.
133
     * @param tunneled Whether the tunneled mode is used or not.
134
     * @param audioHwSync HW SYNC ID of the audio HAL output stream to sync
135
     * the video with.
136
     * @return status Status of the call.
137
     * @return sidebandHandle Codec-allocated sideband window handle.
138
     */
139
    virtual ::android::hardware::Return<void> configureVideoTunnelMode(uint32_t portIndex, bool tunneled, uint32_t audioHwSync, configureVideoTunnelMode_cb _hidl_cb) = 0;
140
141
    using getGraphicBufferUsage_cb = std::function<void(::android::hardware::media::omx::V1_0::Status status, uint32_t usage)>;
142
    /**
143
     * Retrieve the buffer usage on a port. This is based on the extension
144
     * "OMX.google.android.index.getAndroidNativeBufferUsage".
145
     * 
146
     * @param portIndex Index of the port.
147
     * @return status Status of the call.
148
     * @return usage Current graphic buffer usage.
149
     */
150
    virtual ::android::hardware::Return<void> getGraphicBufferUsage(uint32_t portIndex, getGraphicBufferUsage_cb _hidl_cb) = 0;
151
152
    /**
153
     * Set up a listener to events related to the input surface.
154
     * 
155
     * @param bufferSource Listener object that implements
156
     * IOmxBufferSource.
157
     * @return status Status of the call.
158
     * 
159
     * @see IOmxBufferSource.
160
     */
161
    virtual ::android::hardware::Return<::android::hardware::media::omx::V1_0::Status> setInputSurface(const ::android::sp<::android::hardware::media::omx::V1_0::IOmxBufferSource>& bufferSource) = 0;
162
163
    using allocateSecureBuffer_cb = std::function<void(::android::hardware::media::omx::V1_0::Status status, uint32_t buffer, const ::android::hardware::hidl_handle& nativeHandle)>;
164
    /**
165
     * Allocate an opaque buffer on a port as a native handle.
166
     * 
167
     * @param portIndex Index of the port.
168
     * @param size Desired size of the buffer.
169
     * @return status Status of the call.
170
     * @return buffer Id of the allocated buffer, which will be needed in
171
     * other buffer-related functions.
172
     * @return nativeHandle Native handle of the allocated buffer.
173
     * 
174
     * @see OMX_AllocateBuffer() in the OpenMax IL standard.
175
     */
176
    virtual ::android::hardware::Return<void> allocateSecureBuffer(uint32_t portIndex, uint64_t size, allocateSecureBuffer_cb _hidl_cb) = 0;
177
178
    using useBuffer_cb = std::function<void(::android::hardware::media::omx::V1_0::Status status, uint32_t buffer)>;
179
    /**
180
     * Assign a buffer to a port.
181
     * 
182
     * @param portIndex Index of the port.
183
     * @param omxBuffer Buffer to be assigned to the port.
184
     * @return status Status of the call.
185
     * @return buffer Id of the assigned buffer, which will be needed in
186
     * other buffer-related functions.
187
     * 
188
     * @see OMX_UseBuffer() in the OpenMax IL standard.
189
     */
190
    virtual ::android::hardware::Return<void> useBuffer(uint32_t portIndex, const ::android::hardware::media::omx::V1_0::CodecBuffer& omxBuffer, useBuffer_cb _hidl_cb) = 0;
191
192
    /**
193
     * Free a buffer previously assigned to a port by allocateSecureBuffer() or
194
     * useBuffer().
195
     * 
196
     * @param portIndex Index of the port.
197
     * @param buffer Id of the buffer to be freed.
198
     * @return status Status of the call.
199
     * 
200
     * @see OMX_FreeBuffer() in the OpenMax IL standard.
201
     */
202
    virtual ::android::hardware::Return<::android::hardware::media::omx::V1_0::Status> freeBuffer(uint32_t portIndex, uint32_t buffer) = 0;
203
204
    /**
205
     * Pass \p fence to the node if it supports fences. Otherwise, it waits on
206
     * \p fence before calling OMX_FillThisBuffer(). The node will take
207
     * ownership of the fence even if this call fails.
208
     * 
209
     * If the port is in metadata mode, the buffer will be updated to point to
210
     * the new buffer passed in via \p omxBuffer before OMX_FillThisBuffer() is
211
     * called. Otherwise, \p omxBuffer is not used.
212
     * 
213
     * @param buffer Id of the buffer to fill.
214
     * @param omxBuffer New buffer information (in metadata mode).
215
     * @param fence Fence to wait for (if not null).
216
     * @return status Status of the call.
217
     * 
218
     * @see OMX_FillThisBuffer() in the OpenMax IL standard.
219
     */
220
    virtual ::android::hardware::Return<::android::hardware::media::omx::V1_0::Status> fillBuffer(uint32_t buffer, const ::android::hardware::media::omx::V1_0::CodecBuffer& omxBuffer, const ::android::hardware::hidl_handle& fence) = 0;
221
222
    /**
223
     * Pass \p fence to the node if it supports fences. Otherwise, wait on
224
     * \p fence before calling OMX_EmptyThisBuffer(). The node will take
225
     * ownership of the fence even if this call fails.
226
     * 
227
     * If the port is in metadata mode, the buffer will be updated to point to
228
     * the new buffer passed in via \p omxBuffer before OMX_EmptyThisBuffer() is
229
     * called. Otherwise, \p omxBuffer is not used.
230
     * 
231
     * @param buffer Id of the buffer to fill.
232
     * @param omxBuffer New buffer information (in metadata mode).
233
     * @param flags Flags to be passed to OMX_EmptyBuffer().
234
     * @param timestampUs Timestamp OMX_EmptyBuffer().
235
     * @param fence Fence to wait for (if not null).
236
     * @return status Status of the call.
237
     * 
238
     * @see OMX_EmptyThisBuffer() in the OpenMax IL standard.
239
     */
240
    virtual ::android::hardware::Return<::android::hardware::media::omx::V1_0::Status> emptyBuffer(uint32_t buffer, const ::android::hardware::media::omx::V1_0::CodecBuffer& omxBuffer, uint32_t flags, uint64_t timestampUs, const ::android::hardware::hidl_handle& fence) = 0;
241
242
    using getExtensionIndex_cb = std::function<void(::android::hardware::media::omx::V1_0::Status status, uint32_t index)>;
243
    /**
244
     * Request the node to translate an extension string to an index.
245
     * 
246
     * @param parameterName Requested extension string.
247
     * @return status Status of the call.
248
     * @return index Translated index.
249
     * 
250
     * @see OMX_GetExtensionIndex() in the OpenMax IL standard.
251
     */
252
    virtual ::android::hardware::Return<void> getExtensionIndex(const ::android::hardware::hidl_string& parameterName, getExtensionIndex_cb _hidl_cb) = 0;
253
254
    /**
255
     * Add an OMX message on the node's message queue. The instance of
256
     * IOmxObserver that was obtained during the creation of the node will
257
     * receive the message in batches by the callback
258
     * IOmxObserver::onMessages().
259
     * 
260
     * @param msg Message to send.
261
     * @return status Status of the call.
262
     * 
263
     * @see IOmxObserver::onMessages().
264
     */
265
    virtual ::android::hardware::Return<::android::hardware::media::omx::V1_0::Status> dispatchMessage(const ::android::hardware::media::omx::V1_0::Message& msg) = 0;
266
267
    using interfaceChain_cb = std::function<void(const ::android::hardware::hidl_vec<::android::hardware::hidl_string>& descriptors)>;
268
    virtual ::android::hardware::Return<void> interfaceChain(interfaceChain_cb _hidl_cb) override;
269
270
    virtual ::android::hardware::Return<void> debug(const ::android::hardware::hidl_handle& fd, const ::android::hardware::hidl_vec<::android::hardware::hidl_string>& options) override;
271
272
    using interfaceDescriptor_cb = std::function<void(const ::android::hardware::hidl_string& descriptor)>;
273
    virtual ::android::hardware::Return<void> interfaceDescriptor(interfaceDescriptor_cb _hidl_cb) override;
274
275
    using getHashChain_cb = std::function<void(const ::android::hardware::hidl_vec<::android::hardware::hidl_array<uint8_t, 32>>& hashchain)>;
276
    virtual ::android::hardware::Return<void> getHashChain(getHashChain_cb _hidl_cb) override;
277
278
    virtual ::android::hardware::Return<void> setHALInstrumentation() override;
279
280
    virtual ::android::hardware::Return<bool> linkToDeath(const ::android::sp<::android::hardware::hidl_death_recipient>& recipient, uint64_t cookie) override;
281
282
    virtual ::android::hardware::Return<void> ping() override;
283
284
    using getDebugInfo_cb = std::function<void(const ::android::hidl::base::V1_0::DebugInfo& info)>;
285
    virtual ::android::hardware::Return<void> getDebugInfo(getDebugInfo_cb _hidl_cb) override;
286
287
    virtual ::android::hardware::Return<void> notifySyspropsChanged() override;
288
289
    virtual ::android::hardware::Return<bool> unlinkToDeath(const ::android::sp<::android::hardware::hidl_death_recipient>& recipient) override;
290
    // cast static functions
291
    static ::android::hardware::Return<::android::sp<::android::hardware::media::omx::V1_0::IOmxNode>> castFrom(const ::android::sp<::android::hardware::media::omx::V1_0::IOmxNode>& parent, bool emitError = false);
292
    static ::android::hardware::Return<::android::sp<::android::hardware::media::omx::V1_0::IOmxNode>> castFrom(const ::android::sp<::android::hidl::base::V1_0::IBase>& parent, bool emitError = false);
293
294
    static const char* descriptor;
295
296
    static ::android::sp<IOmxNode> tryGetService(const std::string &serviceName="default", bool getStub=false);
297
0
    static ::android::sp<IOmxNode> tryGetService(const char serviceName[], bool getStub=false)  { std::string str(serviceName ? serviceName : "");      return tryGetService(str, getStub); }
298
0
    static ::android::sp<IOmxNode> tryGetService(const ::android::hardware::hidl_string& serviceName, bool getStub=false)  { std::string str(serviceName.c_str());      return tryGetService(str, getStub); }
299
0
    static ::android::sp<IOmxNode> tryGetService(bool getStub) { return tryGetService("default", getStub); }
300
    static ::android::sp<IOmxNode> getService(const std::string &serviceName="default", bool getStub=false);
301
0
    static ::android::sp<IOmxNode> getService(const char serviceName[], bool getStub=false)  { std::string str(serviceName ? serviceName : "");      return getService(str, getStub); }
302
0
    static ::android::sp<IOmxNode> getService(const ::android::hardware::hidl_string& serviceName, bool getStub=false)  { std::string str(serviceName.c_str());      return getService(str, getStub); }
303
0
    static ::android::sp<IOmxNode> getService(bool getStub) { return getService("default", getStub); }
304
    __attribute__ ((warn_unused_result))::android::status_t registerAsService(const std::string &serviceName="default");
305
    static bool registerForNotifications(
306
            const std::string &serviceName,
307
            const ::android::sp<::android::hidl::manager::V1_0::IServiceNotification> &notification);
308
};
309
310
//
311
// type declarations for package
312
//
313
314
static inline std::string toString(const ::android::sp<::android::hardware::media::omx::V1_0::IOmxNode>& o);
315
316
//
317
// type header definitions for package
318
//
319
320
0
static inline std::string toString(const ::android::sp<::android::hardware::media::omx::V1_0::IOmxNode>& o) {
321
0
    std::string os = "[class or subclass of ";
322
0
    os += ::android::hardware::media::omx::V1_0::IOmxNode::descriptor;
323
0
    os += "]";
324
0
    os += o->isRemote() ? "@remote" : "@local";
325
0
    return os;
326
0
}
327
328
329
}  // namespace V1_0
330
}  // namespace omx
331
}  // namespace media
332
}  // namespace hardware
333
}  // namespace android
334
335
//
336
// global type declarations for package
337
//
338
339
340
#endif  // HIDL_GENERATED_ANDROID_HARDWARE_MEDIA_OMX_V1_0_IOMXNODE_H
/proc/self/cwd/out/soong/.intermediates/hardware/interfaces/media/omx/1.0/android.hardware.media.omx@1.0_genc++_headers/gen/android/hardware/media/omx/1.0/types.h
Line
Count
Source (jump to first uncovered line)
1
#ifndef HIDL_GENERATED_ANDROID_HARDWARE_MEDIA_OMX_V1_0_TYPES_H
2
#define HIDL_GENERATED_ANDROID_HARDWARE_MEDIA_OMX_V1_0_TYPES_H
3
4
#include <android/hardware/media/1.0/types.h>
5
6
#include <hidl/HidlSupport.h>
7
#include <hidl/MQDescriptor.h>
8
#include <utils/NativeHandle.h>
9
#include <utils/misc.h>
10
11
namespace android {
12
namespace hardware {
13
namespace media {
14
namespace omx {
15
namespace V1_0 {
16
17
// Forward declaration for forward reference support:
18
enum class Status : int32_t;
19
struct Message;
20
struct CodecBuffer;
21
enum class PortMode : int32_t;
22
struct ColorAspects;
23
24
typedef uint32_t BufferId;
25
26
/**
27
 * Ref: system/core/include/utils/Errors.h
28
 * Ref: bionic/libc/kernel/uapi/asm-generic/errno-base.h
29
 * Ref: bionic/libc/kernel/uapi/asm-generic/errno.h
30
 * Ref: frameworks/av/include/media/stagefright/MediaError.h
31
 * Ref: frameworks/av/media/libstagefright/omx/OMXUtils.cpp: StatusFromOMXError
32
 */
33
enum class Status : int32_t {
34
    OK = 0,
35
    NO_ERROR = 0,
36
    NAME_NOT_FOUND = -2 /* (-2) */,
37
    WOULD_BLOCK = -11 /* (-11) */,
38
    NO_MEMORY = -12 /* (-12) */,
39
    ALREADY_EXISTS = -17 /* (-17) */,
40
    NO_INIT = -19 /* (-19) */,
41
    BAD_VALUE = -22 /* (-22) */,
42
    DEAD_OBJECT = -32 /* (-32) */,
43
    INVALID_OPERATION = -38 /* (-38) */,
44
    TIMED_OUT = -110 /* (-110) */,
45
    ERROR_UNSUPPORTED = -1010 /* (-1010) */,
46
    UNKNOWN_ERROR = -2147483648 /* (-2147483648) */,
47
    BUFFER_NEEDS_REALLOCATION = 1 /* 0x1 */,
48
    RELEASE_ALL_BUFFERS = 2 /* 0x2 */,
49
};
50
51
/**
52
 * Ref: frameworks/av/include/media/IOMX.h: omx_message
53
 * 
54
 * Data structure for an OMX message. This is essentially a union of different
55
 * message types.
56
 */
57
struct Message final {
58
    // Forward declaration for forward reference support:
59
    enum class Type : uint32_t;
60
    struct EventData;
61
    struct BufferData;
62
    struct ExtendedBufferData;
63
    struct RenderData;
64
    union Data;
65
66
    enum class Type : uint32_t {
67
        EVENT = 0u,
68
        EMPTY_BUFFER_DONE = 1u /* (::android::hardware::media::omx::V1_0::Message::Type.EVENT implicitly + 1) */,
69
        FILL_BUFFER_DONE = 2u /* (::android::hardware::media::omx::V1_0::Message::Type.EMPTY_BUFFER_DONE implicitly + 1) */,
70
        FRAME_RENDERED = 3u /* (::android::hardware::media::omx::V1_0::Message::Type.FILL_BUFFER_DONE implicitly + 1) */,
71
    };
72
73
    struct EventData final {
74
        uint32_t event __attribute__ ((aligned(4)));
75
        uint32_t data1 __attribute__ ((aligned(4)));
76
        uint32_t data2 __attribute__ ((aligned(4)));
77
        uint32_t data3 __attribute__ ((aligned(4)));
78
        uint32_t data4 __attribute__ ((aligned(4)));
79
    };
80
81
    static_assert(offsetof(::android::hardware::media::omx::V1_0::Message::EventData, event) == 0, "wrong offset");
82
    static_assert(offsetof(::android::hardware::media::omx::V1_0::Message::EventData, data1) == 4, "wrong offset");
83
    static_assert(offsetof(::android::hardware::media::omx::V1_0::Message::EventData, data2) == 8, "wrong offset");
84
    static_assert(offsetof(::android::hardware::media::omx::V1_0::Message::EventData, data3) == 12, "wrong offset");
85
    static_assert(offsetof(::android::hardware::media::omx::V1_0::Message::EventData, data4) == 16, "wrong offset");
86
    static_assert(sizeof(::android::hardware::media::omx::V1_0::Message::EventData) == 20, "wrong size");
87
    static_assert(__alignof(::android::hardware::media::omx::V1_0::Message::EventData) == 4, "wrong alignment");
88
89
    struct BufferData final {
90
        uint32_t buffer __attribute__ ((aligned(4)));
91
    };
92
93
    static_assert(offsetof(::android::hardware::media::omx::V1_0::Message::BufferData, buffer) == 0, "wrong offset");
94
    static_assert(sizeof(::android::hardware::media::omx::V1_0::Message::BufferData) == 4, "wrong size");
95
    static_assert(__alignof(::android::hardware::media::omx::V1_0::Message::BufferData) == 4, "wrong alignment");
96
97
    struct ExtendedBufferData final {
98
        uint32_t buffer __attribute__ ((aligned(4)));
99
        uint32_t rangeOffset __attribute__ ((aligned(4)));
100
        uint32_t rangeLength __attribute__ ((aligned(4)));
101
        uint32_t flags __attribute__ ((aligned(4)));
102
        uint64_t timestampUs __attribute__ ((aligned(8)));
103
    };
104
105
    static_assert(offsetof(::android::hardware::media::omx::V1_0::Message::ExtendedBufferData, buffer) == 0, "wrong offset");
106
    static_assert(offsetof(::android::hardware::media::omx::V1_0::Message::ExtendedBufferData, rangeOffset) == 4, "wrong offset");
107
    static_assert(offsetof(::android::hardware::media::omx::V1_0::Message::ExtendedBufferData, rangeLength) == 8, "wrong offset");
108
    static_assert(offsetof(::android::hardware::media::omx::V1_0::Message::ExtendedBufferData, flags) == 12, "wrong offset");
109
    static_assert(offsetof(::android::hardware::media::omx::V1_0::Message::ExtendedBufferData, timestampUs) == 16, "wrong offset");
110
    static_assert(sizeof(::android::hardware::media::omx::V1_0::Message::ExtendedBufferData) == 24, "wrong size");
111
    static_assert(__alignof(::android::hardware::media::omx::V1_0::Message::ExtendedBufferData) == 8, "wrong alignment");
112
113
    struct RenderData final {
114
        uint64_t timestampUs __attribute__ ((aligned(8)));
115
        int64_t systemTimeNs __attribute__ ((aligned(8)));
116
    };
117
118
    static_assert(offsetof(::android::hardware::media::omx::V1_0::Message::RenderData, timestampUs) == 0, "wrong offset");
119
    static_assert(offsetof(::android::hardware::media::omx::V1_0::Message::RenderData, systemTimeNs) == 8, "wrong offset");
120
    static_assert(sizeof(::android::hardware::media::omx::V1_0::Message::RenderData) == 16, "wrong size");
121
    static_assert(__alignof(::android::hardware::media::omx::V1_0::Message::RenderData) == 8, "wrong alignment");
122
123
    union Data final {
124
        ::android::hardware::media::omx::V1_0::Message::EventData eventData __attribute__ ((aligned(4)));
125
        ::android::hardware::media::omx::V1_0::Message::BufferData bufferData __attribute__ ((aligned(4)));
126
        ::android::hardware::media::omx::V1_0::Message::ExtendedBufferData extendedBufferData __attribute__ ((aligned(8)));
127
        ::android::hardware::media::omx::V1_0::Message::RenderData renderData __attribute__ ((aligned(8)));
128
    };
129
130
    static_assert(offsetof(::android::hardware::media::omx::V1_0::Message::Data, eventData) == 0, "wrong offset");
131
    static_assert(offsetof(::android::hardware::media::omx::V1_0::Message::Data, bufferData) == 0, "wrong offset");
132
    static_assert(offsetof(::android::hardware::media::omx::V1_0::Message::Data, extendedBufferData) == 0, "wrong offset");
133
    static_assert(offsetof(::android::hardware::media::omx::V1_0::Message::Data, renderData) == 0, "wrong offset");
134
    static_assert(sizeof(::android::hardware::media::omx::V1_0::Message::Data) == 24, "wrong size");
135
    static_assert(__alignof(::android::hardware::media::omx::V1_0::Message::Data) == 8, "wrong alignment");
136
137
    ::android::hardware::media::omx::V1_0::Message::Type type __attribute__ ((aligned(4)));
138
    ::android::hardware::hidl_handle fence __attribute__ ((aligned(8)));
139
    ::android::hardware::media::omx::V1_0::Message::Data data __attribute__ ((aligned(8)));
140
};
141
142
static_assert(offsetof(::android::hardware::media::omx::V1_0::Message, type) == 0, "wrong offset");
143
static_assert(offsetof(::android::hardware::media::omx::V1_0::Message, fence) == 8, "wrong offset");
144
static_assert(offsetof(::android::hardware::media::omx::V1_0::Message, data) == 24, "wrong offset");
145
static_assert(sizeof(::android::hardware::media::omx::V1_0::Message) == 48, "wrong size");
146
static_assert(__alignof(::android::hardware::media::omx::V1_0::Message) == 8, "wrong alignment");
147
148
/**
149
 * Ref: frameworks/native/include/ui/GraphicBuffer.h
150
 * Ref: system/core/include/system/window.h
151
 * Ref: frameworks/native/include/binder/IMemory.h
152
 * Ref: frameworks/native/libs/binder/IMemory.cpp
153
 * Ref: frameworks/av/include/media/OMXBuffer.h
154
 * 
155
 * Data structure for buffer information. This is essentially a union of
156
 * different buffer types.
157
 */
158
struct CodecBuffer final {
159
    // Forward declaration for forward reference support:
160
    enum class Type : int32_t;
161
    struct PresetAttributes;
162
    union Attributes;
163
164
    enum class Type : int32_t {
165
        INVALID = 0,
166
        PRESET = 1 /* (::android::hardware::media::omx::V1_0::CodecBuffer::Type.INVALID implicitly + 1) */,
167
        SHARED_MEM = 2 /* (::android::hardware::media::omx::V1_0::CodecBuffer::Type.PRESET implicitly + 1) */,
168
        ANW_BUFFER = 3 /* (::android::hardware::media::omx::V1_0::CodecBuffer::Type.SHARED_MEM implicitly + 1) */,
169
        NATIVE_HANDLE = 4 /* (::android::hardware::media::omx::V1_0::CodecBuffer::Type.ANW_BUFFER implicitly + 1) */,
170
    };
171
172
    struct PresetAttributes final {
173
        uint32_t rangeOffset __attribute__ ((aligned(4)));
174
        uint32_t rangeLength __attribute__ ((aligned(4)));
175
    };
176
177
    static_assert(offsetof(::android::hardware::media::omx::V1_0::CodecBuffer::PresetAttributes, rangeOffset) == 0, "wrong offset");
178
    static_assert(offsetof(::android::hardware::media::omx::V1_0::CodecBuffer::PresetAttributes, rangeLength) == 4, "wrong offset");
179
    static_assert(sizeof(::android::hardware::media::omx::V1_0::CodecBuffer::PresetAttributes) == 8, "wrong size");
180
    static_assert(__alignof(::android::hardware::media::omx::V1_0::CodecBuffer::PresetAttributes) == 4, "wrong alignment");
181
182
    union Attributes final {
183
        ::android::hardware::media::omx::V1_0::CodecBuffer::PresetAttributes preset __attribute__ ((aligned(4)));
184
        ::android::hardware::media::V1_0::AnwBufferAttributes anwBuffer __attribute__ ((aligned(8)));
185
    };
186
187
    static_assert(offsetof(::android::hardware::media::omx::V1_0::CodecBuffer::Attributes, preset) == 0, "wrong offset");
188
    static_assert(offsetof(::android::hardware::media::omx::V1_0::CodecBuffer::Attributes, anwBuffer) == 0, "wrong offset");
189
    static_assert(sizeof(::android::hardware::media::omx::V1_0::CodecBuffer::Attributes) == 40, "wrong size");
190
    static_assert(__alignof(::android::hardware::media::omx::V1_0::CodecBuffer::Attributes) == 8, "wrong alignment");
191
192
    ::android::hardware::media::omx::V1_0::CodecBuffer::Type type __attribute__ ((aligned(4)));
193
    ::android::hardware::media::omx::V1_0::CodecBuffer::Attributes attr __attribute__ ((aligned(8)));
194
    ::android::hardware::hidl_handle nativeHandle __attribute__ ((aligned(8)));
195
    ::android::hardware::hidl_memory sharedMemory __attribute__ ((aligned(8)));
196
};
197
198
static_assert(offsetof(::android::hardware::media::omx::V1_0::CodecBuffer, type) == 0, "wrong offset");
199
static_assert(offsetof(::android::hardware::media::omx::V1_0::CodecBuffer, attr) == 8, "wrong offset");
200
static_assert(offsetof(::android::hardware::media::omx::V1_0::CodecBuffer, nativeHandle) == 48, "wrong offset");
201
static_assert(offsetof(::android::hardware::media::omx::V1_0::CodecBuffer, sharedMemory) == 64, "wrong offset");
202
static_assert(sizeof(::android::hardware::media::omx::V1_0::CodecBuffer) == 104, "wrong size");
203
static_assert(__alignof(::android::hardware::media::omx::V1_0::CodecBuffer) == 8, "wrong alignment");
204
205
/**
206
 * Ref: frameworks/av/include/media/IOMX.h
207
 * 
208
 * Enumeration of port modes.
209
 */
210
enum class PortMode : int32_t {
211
    PRESET_START = 0,
212
    PRESET_BYTE_BUFFER = 1 /* (::android::hardware::media::omx::V1_0::PortMode.PRESET_START implicitly + 1) */,
213
    PRESET_ANW_BUFFER = 2 /* (::android::hardware::media::omx::V1_0::PortMode.PRESET_BYTE_BUFFER implicitly + 1) */,
214
    PRESET_SECURE_BUFFER = 3 /* (::android::hardware::media::omx::V1_0::PortMode.PRESET_ANW_BUFFER implicitly + 1) */,
215
    PRESET_END = 4 /* (::android::hardware::media::omx::V1_0::PortMode.PRESET_SECURE_BUFFER implicitly + 1) */,
216
    DYNAMIC_START = 100,
217
    DYNAMIC_ANW_BUFFER = 101 /* (::android::hardware::media::omx::V1_0::PortMode.DYNAMIC_START implicitly + 1) */,
218
    DYNAMIC_NATIVE_HANDLE = 102 /* (::android::hardware::media::omx::V1_0::PortMode.DYNAMIC_ANW_BUFFER implicitly + 1) */,
219
    DYNAMIC_END = 103 /* (::android::hardware::media::omx::V1_0::PortMode.DYNAMIC_NATIVE_HANDLE implicitly + 1) */,
220
};
221
222
/**
223
 * Ref: frameworks/native/include/media/hardware/VideoAPI.h
224
 * 
225
 * Framework defined color aspects. These are based mainly on ISO 23001-8 spec. As this standard
226
 * continues to evolve, new values may be defined in the future. Use OTHER for these future values
227
 * as well as for values not listed here, as those are not supported by the framework.
228
 */
229
struct ColorAspects final {
230
    // Forward declaration for forward reference support:
231
    enum class Range : uint32_t;
232
    enum class Primaries : uint32_t;
233
    enum class Transfer : uint32_t;
234
    enum class MatrixCoeffs : uint32_t;
235
236
    enum class Range : uint32_t {
237
        UNSPECIFIED = 0u,
238
        FULL = 1u /* (::android::hardware::media::omx::V1_0::ColorAspects::Range.UNSPECIFIED implicitly + 1) */,
239
        LIMITED = 2u /* (::android::hardware::media::omx::V1_0::ColorAspects::Range.FULL implicitly + 1) */,
240
        OTHER = 255u /* 0xff */,
241
    };
242
243
    enum class Primaries : uint32_t {
244
        UNSPECIFIED = 0u,
245
        BT709_5 = 1u /* (::android::hardware::media::omx::V1_0::ColorAspects::Primaries.UNSPECIFIED implicitly + 1) */,
246
        BT470_6M = 2u /* (::android::hardware::media::omx::V1_0::ColorAspects::Primaries.BT709_5 implicitly + 1) */,
247
        BT601_6_625 = 3u /* (::android::hardware::media::omx::V1_0::ColorAspects::Primaries.BT470_6M implicitly + 1) */,
248
        BT601_6_525 = 4u /* (::android::hardware::media::omx::V1_0::ColorAspects::Primaries.BT601_6_625 implicitly + 1) */,
249
        GENERIC_FILM = 5u /* (::android::hardware::media::omx::V1_0::ColorAspects::Primaries.BT601_6_525 implicitly + 1) */,
250
        BT2020 = 6u /* (::android::hardware::media::omx::V1_0::ColorAspects::Primaries.GENERIC_FILM implicitly + 1) */,
251
        OTHER = 255u /* 0xff */,
252
    };
253
254
    enum class Transfer : uint32_t {
255
        UNSPECIFIED = 0u,
256
        LINEAR = 1u /* (::android::hardware::media::omx::V1_0::ColorAspects::Transfer.UNSPECIFIED implicitly + 1) */,
257
        SRGB = 2u /* (::android::hardware::media::omx::V1_0::ColorAspects::Transfer.LINEAR implicitly + 1) */,
258
        SMPTE170M = 3u /* (::android::hardware::media::omx::V1_0::ColorAspects::Transfer.SRGB implicitly + 1) */,
259
        GAMMA22 = 4u /* (::android::hardware::media::omx::V1_0::ColorAspects::Transfer.SMPTE170M implicitly + 1) */,
260
        GAMMA28 = 5u /* (::android::hardware::media::omx::V1_0::ColorAspects::Transfer.GAMMA22 implicitly + 1) */,
261
        ST2084 = 6u /* (::android::hardware::media::omx::V1_0::ColorAspects::Transfer.GAMMA28 implicitly + 1) */,
262
        HLG = 7u /* (::android::hardware::media::omx::V1_0::ColorAspects::Transfer.ST2084 implicitly + 1) */,
263
        SMPTE240M = 64u /* 0x40 */,
264
        XVYCC = 65u /* (::android::hardware::media::omx::V1_0::ColorAspects::Transfer.SMPTE240M implicitly + 1) */,
265
        BT1361 = 66u /* (::android::hardware::media::omx::V1_0::ColorAspects::Transfer.XVYCC implicitly + 1) */,
266
        ST428 = 67u /* (::android::hardware::media::omx::V1_0::ColorAspects::Transfer.BT1361 implicitly + 1) */,
267
        OTHER = 255u /* 0xff */,
268
    };
269
270
    enum class MatrixCoeffs : uint32_t {
271
        UNSPECIFIED = 0u,
272
        BT709_5 = 1u /* (::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs.UNSPECIFIED implicitly + 1) */,
273
        BT470_6M = 2u /* (::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs.BT709_5 implicitly + 1) */,
274
        BT601_6 = 3u /* (::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs.BT470_6M implicitly + 1) */,
275
        SMPTE240M = 4u /* (::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs.BT601_6 implicitly + 1) */,
276
        BT2020 = 5u /* (::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs.SMPTE240M implicitly + 1) */,
277
        BT2020CONSTANT = 6u /* (::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs.BT2020 implicitly + 1) */,
278
        OTHER = 255u /* 0xff */,
279
    };
280
281
    ::android::hardware::media::omx::V1_0::ColorAspects::Range range __attribute__ ((aligned(4)));
282
    ::android::hardware::media::omx::V1_0::ColorAspects::Primaries primaries __attribute__ ((aligned(4)));
283
    ::android::hardware::media::omx::V1_0::ColorAspects::Transfer transfer __attribute__ ((aligned(4)));
284
    ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs matrixCoeffs __attribute__ ((aligned(4)));
285
};
286
287
static_assert(offsetof(::android::hardware::media::omx::V1_0::ColorAspects, range) == 0, "wrong offset");
288
static_assert(offsetof(::android::hardware::media::omx::V1_0::ColorAspects, primaries) == 4, "wrong offset");
289
static_assert(offsetof(::android::hardware::media::omx::V1_0::ColorAspects, transfer) == 8, "wrong offset");
290
static_assert(offsetof(::android::hardware::media::omx::V1_0::ColorAspects, matrixCoeffs) == 12, "wrong offset");
291
static_assert(sizeof(::android::hardware::media::omx::V1_0::ColorAspects) == 16, "wrong size");
292
static_assert(__alignof(::android::hardware::media::omx::V1_0::ColorAspects) == 4, "wrong alignment");
293
294
//
295
// type declarations for package
296
//
297
298
template<typename>
299
static inline std::string toString(int32_t o);
300
static inline std::string toString(::android::hardware::media::omx::V1_0::Status o);
301
302
0
constexpr int32_t operator|(const ::android::hardware::media::omx::V1_0::Status lhs, const ::android::hardware::media::omx::V1_0::Status rhs) {
303
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) | static_cast<int32_t>(rhs));
304
0
}
305
0
constexpr int32_t operator|(const int32_t lhs, const ::android::hardware::media::omx::V1_0::Status rhs) {
306
0
    return static_cast<int32_t>(lhs | static_cast<int32_t>(rhs));
307
0
}
308
0
constexpr int32_t operator|(const ::android::hardware::media::omx::V1_0::Status lhs, const int32_t rhs) {
309
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) | rhs);
310
0
}
311
0
constexpr int32_t operator&(const ::android::hardware::media::omx::V1_0::Status lhs, const ::android::hardware::media::omx::V1_0::Status rhs) {
312
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) & static_cast<int32_t>(rhs));
313
0
}
314
0
constexpr int32_t operator&(const int32_t lhs, const ::android::hardware::media::omx::V1_0::Status rhs) {
315
0
    return static_cast<int32_t>(lhs & static_cast<int32_t>(rhs));
316
0
}
317
0
constexpr int32_t operator&(const ::android::hardware::media::omx::V1_0::Status lhs, const int32_t rhs) {
318
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) & rhs);
319
0
}
320
0
constexpr int32_t &operator|=(int32_t& v, const ::android::hardware::media::omx::V1_0::Status e) {
321
0
    v |= static_cast<int32_t>(e);
322
0
    return v;
323
0
}
324
0
constexpr int32_t &operator&=(int32_t& v, const ::android::hardware::media::omx::V1_0::Status e) {
325
0
    v &= static_cast<int32_t>(e);
326
0
    return v;
327
0
}
328
329
template<typename>
330
static inline std::string toString(uint32_t o);
331
static inline std::string toString(::android::hardware::media::omx::V1_0::Message::Type o);
332
333
0
constexpr uint32_t operator|(const ::android::hardware::media::omx::V1_0::Message::Type lhs, const ::android::hardware::media::omx::V1_0::Message::Type rhs) {
334
0
    return static_cast<uint32_t>(static_cast<uint32_t>(lhs) | static_cast<uint32_t>(rhs));
335
0
}
336
0
constexpr uint32_t operator|(const uint32_t lhs, const ::android::hardware::media::omx::V1_0::Message::Type rhs) {
337
0
    return static_cast<uint32_t>(lhs | static_cast<uint32_t>(rhs));
338
0
}
339
0
constexpr uint32_t operator|(const ::android::hardware::media::omx::V1_0::Message::Type lhs, const uint32_t rhs) {
340
0
    return static_cast<uint32_t>(static_cast<uint32_t>(lhs) | rhs);
341
0
}
342
0
constexpr uint32_t operator&(const ::android::hardware::media::omx::V1_0::Message::Type lhs, const ::android::hardware::media::omx::V1_0::Message::Type rhs) {
343
0
    return static_cast<uint32_t>(static_cast<uint32_t>(lhs) & static_cast<uint32_t>(rhs));
344
0
}
345
0
constexpr uint32_t operator&(const uint32_t lhs, const ::android::hardware::media::omx::V1_0::Message::Type rhs) {
346
0
    return static_cast<uint32_t>(lhs & static_cast<uint32_t>(rhs));
347
0
}
348
0
constexpr uint32_t operator&(const ::android::hardware::media::omx::V1_0::Message::Type lhs, const uint32_t rhs) {
349
0
    return static_cast<uint32_t>(static_cast<uint32_t>(lhs) & rhs);
350
0
}
351
0
constexpr uint32_t &operator|=(uint32_t& v, const ::android::hardware::media::omx::V1_0::Message::Type e) {
352
0
    v |= static_cast<uint32_t>(e);
353
0
    return v;
354
0
}
355
0
constexpr uint32_t &operator&=(uint32_t& v, const ::android::hardware::media::omx::V1_0::Message::Type e) {
356
0
    v &= static_cast<uint32_t>(e);
357
0
    return v;
358
0
}
359
360
static inline std::string toString(const ::android::hardware::media::omx::V1_0::Message::EventData& o);
361
static inline bool operator==(const ::android::hardware::media::omx::V1_0::Message::EventData& lhs, const ::android::hardware::media::omx::V1_0::Message::EventData& rhs);
362
static inline bool operator!=(const ::android::hardware::media::omx::V1_0::Message::EventData& lhs, const ::android::hardware::media::omx::V1_0::Message::EventData& rhs);
363
364
static inline std::string toString(const ::android::hardware::media::omx::V1_0::Message::BufferData& o);
365
static inline bool operator==(const ::android::hardware::media::omx::V1_0::Message::BufferData& lhs, const ::android::hardware::media::omx::V1_0::Message::BufferData& rhs);
366
static inline bool operator!=(const ::android::hardware::media::omx::V1_0::Message::BufferData& lhs, const ::android::hardware::media::omx::V1_0::Message::BufferData& rhs);
367
368
static inline std::string toString(const ::android::hardware::media::omx::V1_0::Message::ExtendedBufferData& o);
369
static inline bool operator==(const ::android::hardware::media::omx::V1_0::Message::ExtendedBufferData& lhs, const ::android::hardware::media::omx::V1_0::Message::ExtendedBufferData& rhs);
370
static inline bool operator!=(const ::android::hardware::media::omx::V1_0::Message::ExtendedBufferData& lhs, const ::android::hardware::media::omx::V1_0::Message::ExtendedBufferData& rhs);
371
372
static inline std::string toString(const ::android::hardware::media::omx::V1_0::Message::RenderData& o);
373
static inline bool operator==(const ::android::hardware::media::omx::V1_0::Message::RenderData& lhs, const ::android::hardware::media::omx::V1_0::Message::RenderData& rhs);
374
static inline bool operator!=(const ::android::hardware::media::omx::V1_0::Message::RenderData& lhs, const ::android::hardware::media::omx::V1_0::Message::RenderData& rhs);
375
376
static inline std::string toString(const ::android::hardware::media::omx::V1_0::Message::Data& o);
377
// operator== and operator!= are not generated for Data
378
379
static inline std::string toString(const ::android::hardware::media::omx::V1_0::Message& o);
380
// operator== and operator!= are not generated for Message
381
382
template<typename>
383
static inline std::string toString(int32_t o);
384
static inline std::string toString(::android::hardware::media::omx::V1_0::CodecBuffer::Type o);
385
386
0
constexpr int32_t operator|(const ::android::hardware::media::omx::V1_0::CodecBuffer::Type lhs, const ::android::hardware::media::omx::V1_0::CodecBuffer::Type rhs) {
387
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) | static_cast<int32_t>(rhs));
388
0
}
389
0
constexpr int32_t operator|(const int32_t lhs, const ::android::hardware::media::omx::V1_0::CodecBuffer::Type rhs) {
390
0
    return static_cast<int32_t>(lhs | static_cast<int32_t>(rhs));
391
0
}
392
0
constexpr int32_t operator|(const ::android::hardware::media::omx::V1_0::CodecBuffer::Type lhs, const int32_t rhs) {
393
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) | rhs);
394
0
}
395
0
constexpr int32_t operator&(const ::android::hardware::media::omx::V1_0::CodecBuffer::Type lhs, const ::android::hardware::media::omx::V1_0::CodecBuffer::Type rhs) {
396
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) & static_cast<int32_t>(rhs));
397
0
}
398
0
constexpr int32_t operator&(const int32_t lhs, const ::android::hardware::media::omx::V1_0::CodecBuffer::Type rhs) {
399
0
    return static_cast<int32_t>(lhs & static_cast<int32_t>(rhs));
400
0
}
401
0
constexpr int32_t operator&(const ::android::hardware::media::omx::V1_0::CodecBuffer::Type lhs, const int32_t rhs) {
402
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) & rhs);
403
0
}
404
0
constexpr int32_t &operator|=(int32_t& v, const ::android::hardware::media::omx::V1_0::CodecBuffer::Type e) {
405
0
    v |= static_cast<int32_t>(e);
406
0
    return v;
407
0
}
408
0
constexpr int32_t &operator&=(int32_t& v, const ::android::hardware::media::omx::V1_0::CodecBuffer::Type e) {
409
0
    v &= static_cast<int32_t>(e);
410
0
    return v;
411
0
}
412
413
static inline std::string toString(const ::android::hardware::media::omx::V1_0::CodecBuffer::PresetAttributes& o);
414
static inline bool operator==(const ::android::hardware::media::omx::V1_0::CodecBuffer::PresetAttributes& lhs, const ::android::hardware::media::omx::V1_0::CodecBuffer::PresetAttributes& rhs);
415
static inline bool operator!=(const ::android::hardware::media::omx::V1_0::CodecBuffer::PresetAttributes& lhs, const ::android::hardware::media::omx::V1_0::CodecBuffer::PresetAttributes& rhs);
416
417
static inline std::string toString(const ::android::hardware::media::omx::V1_0::CodecBuffer::Attributes& o);
418
// operator== and operator!= are not generated for Attributes
419
420
static inline std::string toString(const ::android::hardware::media::omx::V1_0::CodecBuffer& o);
421
// operator== and operator!= are not generated for CodecBuffer
422
423
template<typename>
424
static inline std::string toString(int32_t o);
425
static inline std::string toString(::android::hardware::media::omx::V1_0::PortMode o);
426
427
0
constexpr int32_t operator|(const ::android::hardware::media::omx::V1_0::PortMode lhs, const ::android::hardware::media::omx::V1_0::PortMode rhs) {
428
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) | static_cast<int32_t>(rhs));
429
0
}
430
0
constexpr int32_t operator|(const int32_t lhs, const ::android::hardware::media::omx::V1_0::PortMode rhs) {
431
0
    return static_cast<int32_t>(lhs | static_cast<int32_t>(rhs));
432
0
}
433
0
constexpr int32_t operator|(const ::android::hardware::media::omx::V1_0::PortMode lhs, const int32_t rhs) {
434
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) | rhs);
435
0
}
436
0
constexpr int32_t operator&(const ::android::hardware::media::omx::V1_0::PortMode lhs, const ::android::hardware::media::omx::V1_0::PortMode rhs) {
437
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) & static_cast<int32_t>(rhs));
438
0
}
439
0
constexpr int32_t operator&(const int32_t lhs, const ::android::hardware::media::omx::V1_0::PortMode rhs) {
440
0
    return static_cast<int32_t>(lhs & static_cast<int32_t>(rhs));
441
0
}
442
0
constexpr int32_t operator&(const ::android::hardware::media::omx::V1_0::PortMode lhs, const int32_t rhs) {
443
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) & rhs);
444
0
}
445
0
constexpr int32_t &operator|=(int32_t& v, const ::android::hardware::media::omx::V1_0::PortMode e) {
446
0
    v |= static_cast<int32_t>(e);
447
0
    return v;
448
0
}
449
0
constexpr int32_t &operator&=(int32_t& v, const ::android::hardware::media::omx::V1_0::PortMode e) {
450
0
    v &= static_cast<int32_t>(e);
451
0
    return v;
452
0
}
453
454
template<typename>
455
static inline std::string toString(uint32_t o);
456
static inline std::string toString(::android::hardware::media::omx::V1_0::ColorAspects::Range o);
457
458
0
constexpr uint32_t operator|(const ::android::hardware::media::omx::V1_0::ColorAspects::Range lhs, const ::android::hardware::media::omx::V1_0::ColorAspects::Range rhs) {
459
0
    return static_cast<uint32_t>(static_cast<uint32_t>(lhs) | static_cast<uint32_t>(rhs));
460
0
}
461
0
constexpr uint32_t operator|(const uint32_t lhs, const ::android::hardware::media::omx::V1_0::ColorAspects::Range rhs) {
462
0
    return static_cast<uint32_t>(lhs | static_cast<uint32_t>(rhs));
463
0
}
464
0
constexpr uint32_t operator|(const ::android::hardware::media::omx::V1_0::ColorAspects::Range lhs, const uint32_t rhs) {
465
0
    return static_cast<uint32_t>(static_cast<uint32_t>(lhs) | rhs);
466
0
}
467
0
constexpr uint32_t operator&(const ::android::hardware::media::omx::V1_0::ColorAspects::Range lhs, const ::android::hardware::media::omx::V1_0::ColorAspects::Range rhs) {
468
0
    return static_cast<uint32_t>(static_cast<uint32_t>(lhs) & static_cast<uint32_t>(rhs));
469
0
}
470
0
constexpr uint32_t operator&(const uint32_t lhs, const ::android::hardware::media::omx::V1_0::ColorAspects::Range rhs) {
471
0
    return static_cast<uint32_t>(lhs & static_cast<uint32_t>(rhs));
472
0
}
473
0
constexpr uint32_t operator&(const ::android::hardware::media::omx::V1_0::ColorAspects::Range lhs, const uint32_t rhs) {
474
0
    return static_cast<uint32_t>(static_cast<uint32_t>(lhs) & rhs);
475
0
}
476
0
constexpr uint32_t &operator|=(uint32_t& v, const ::android::hardware::media::omx::V1_0::ColorAspects::Range e) {
477
0
    v |= static_cast<uint32_t>(e);
478
0
    return v;
479
0
}
480
0
constexpr uint32_t &operator&=(uint32_t& v, const ::android::hardware::media::omx::V1_0::ColorAspects::Range e) {
481
0
    v &= static_cast<uint32_t>(e);
482
0
    return v;
483
0
}
484
485
template<typename>
486
static inline std::string toString(uint32_t o);
487
static inline std::string toString(::android::hardware::media::omx::V1_0::ColorAspects::Primaries o);
488
489
0
constexpr uint32_t operator|(const ::android::hardware::media::omx::V1_0::ColorAspects::Primaries lhs, const ::android::hardware::media::omx::V1_0::ColorAspects::Primaries rhs) {
490
0
    return static_cast<uint32_t>(static_cast<uint32_t>(lhs) | static_cast<uint32_t>(rhs));
491
0
}
492
0
constexpr uint32_t operator|(const uint32_t lhs, const ::android::hardware::media::omx::V1_0::ColorAspects::Primaries rhs) {
493
0
    return static_cast<uint32_t>(lhs | static_cast<uint32_t>(rhs));
494
0
}
495
0
constexpr uint32_t operator|(const ::android::hardware::media::omx::V1_0::ColorAspects::Primaries lhs, const uint32_t rhs) {
496
0
    return static_cast<uint32_t>(static_cast<uint32_t>(lhs) | rhs);
497
0
}
498
0
constexpr uint32_t operator&(const ::android::hardware::media::omx::V1_0::ColorAspects::Primaries lhs, const ::android::hardware::media::omx::V1_0::ColorAspects::Primaries rhs) {
499
0
    return static_cast<uint32_t>(static_cast<uint32_t>(lhs) & static_cast<uint32_t>(rhs));
500
0
}
501
0
constexpr uint32_t operator&(const uint32_t lhs, const ::android::hardware::media::omx::V1_0::ColorAspects::Primaries rhs) {
502
0
    return static_cast<uint32_t>(lhs & static_cast<uint32_t>(rhs));
503
0
}
504
0
constexpr uint32_t operator&(const ::android::hardware::media::omx::V1_0::ColorAspects::Primaries lhs, const uint32_t rhs) {
505
0
    return static_cast<uint32_t>(static_cast<uint32_t>(lhs) & rhs);
506
0
}
507
0
constexpr uint32_t &operator|=(uint32_t& v, const ::android::hardware::media::omx::V1_0::ColorAspects::Primaries e) {
508
0
    v |= static_cast<uint32_t>(e);
509
0
    return v;
510
0
}
511
0
constexpr uint32_t &operator&=(uint32_t& v, const ::android::hardware::media::omx::V1_0::ColorAspects::Primaries e) {
512
0
    v &= static_cast<uint32_t>(e);
513
0
    return v;
514
0
}
515
516
template<typename>
517
static inline std::string toString(uint32_t o);
518
static inline std::string toString(::android::hardware::media::omx::V1_0::ColorAspects::Transfer o);
519
520
0
constexpr uint32_t operator|(const ::android::hardware::media::omx::V1_0::ColorAspects::Transfer lhs, const ::android::hardware::media::omx::V1_0::ColorAspects::Transfer rhs) {
521
0
    return static_cast<uint32_t>(static_cast<uint32_t>(lhs) | static_cast<uint32_t>(rhs));
522
0
}
523
0
constexpr uint32_t operator|(const uint32_t lhs, const ::android::hardware::media::omx::V1_0::ColorAspects::Transfer rhs) {
524
0
    return static_cast<uint32_t>(lhs | static_cast<uint32_t>(rhs));
525
0
}
526
0
constexpr uint32_t operator|(const ::android::hardware::media::omx::V1_0::ColorAspects::Transfer lhs, const uint32_t rhs) {
527
0
    return static_cast<uint32_t>(static_cast<uint32_t>(lhs) | rhs);
528
0
}
529
0
constexpr uint32_t operator&(const ::android::hardware::media::omx::V1_0::ColorAspects::Transfer lhs, const ::android::hardware::media::omx::V1_0::ColorAspects::Transfer rhs) {
530
0
    return static_cast<uint32_t>(static_cast<uint32_t>(lhs) & static_cast<uint32_t>(rhs));
531
0
}
532
0
constexpr uint32_t operator&(const uint32_t lhs, const ::android::hardware::media::omx::V1_0::ColorAspects::Transfer rhs) {
533
0
    return static_cast<uint32_t>(lhs & static_cast<uint32_t>(rhs));
534
0
}
535
0
constexpr uint32_t operator&(const ::android::hardware::media::omx::V1_0::ColorAspects::Transfer lhs, const uint32_t rhs) {
536
0
    return static_cast<uint32_t>(static_cast<uint32_t>(lhs) & rhs);
537
0
}
538
0
constexpr uint32_t &operator|=(uint32_t& v, const ::android::hardware::media::omx::V1_0::ColorAspects::Transfer e) {
539
0
    v |= static_cast<uint32_t>(e);
540
0
    return v;
541
0
}
542
0
constexpr uint32_t &operator&=(uint32_t& v, const ::android::hardware::media::omx::V1_0::ColorAspects::Transfer e) {
543
0
    v &= static_cast<uint32_t>(e);
544
0
    return v;
545
0
}
546
547
template<typename>
548
static inline std::string toString(uint32_t o);
549
static inline std::string toString(::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs o);
550
551
0
constexpr uint32_t operator|(const ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs lhs, const ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs rhs) {
552
0
    return static_cast<uint32_t>(static_cast<uint32_t>(lhs) | static_cast<uint32_t>(rhs));
553
0
}
554
0
constexpr uint32_t operator|(const uint32_t lhs, const ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs rhs) {
555
0
    return static_cast<uint32_t>(lhs | static_cast<uint32_t>(rhs));
556
0
}
557
0
constexpr uint32_t operator|(const ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs lhs, const uint32_t rhs) {
558
0
    return static_cast<uint32_t>(static_cast<uint32_t>(lhs) | rhs);
559
0
}
560
0
constexpr uint32_t operator&(const ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs lhs, const ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs rhs) {
561
0
    return static_cast<uint32_t>(static_cast<uint32_t>(lhs) & static_cast<uint32_t>(rhs));
562
0
}
563
0
constexpr uint32_t operator&(const uint32_t lhs, const ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs rhs) {
564
0
    return static_cast<uint32_t>(lhs & static_cast<uint32_t>(rhs));
565
0
}
566
0
constexpr uint32_t operator&(const ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs lhs, const uint32_t rhs) {
567
0
    return static_cast<uint32_t>(static_cast<uint32_t>(lhs) & rhs);
568
0
}
569
0
constexpr uint32_t &operator|=(uint32_t& v, const ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs e) {
570
0
    v |= static_cast<uint32_t>(e);
571
0
    return v;
572
0
}
573
0
constexpr uint32_t &operator&=(uint32_t& v, const ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs e) {
574
0
    v &= static_cast<uint32_t>(e);
575
0
    return v;
576
0
}
577
578
static inline std::string toString(const ::android::hardware::media::omx::V1_0::ColorAspects& o);
579
static inline bool operator==(const ::android::hardware::media::omx::V1_0::ColorAspects& lhs, const ::android::hardware::media::omx::V1_0::ColorAspects& rhs);
580
static inline bool operator!=(const ::android::hardware::media::omx::V1_0::ColorAspects& lhs, const ::android::hardware::media::omx::V1_0::ColorAspects& rhs);
581
582
//
583
// type header definitions for package
584
//
585
586
template<>
587
0
inline std::string toString<::android::hardware::media::omx::V1_0::Status>(int32_t o) {
588
0
    using ::android::hardware::details::toHexString;
589
0
    std::string os;
590
0
    ::android::hardware::hidl_bitfield<::android::hardware::media::omx::V1_0::Status> flipped = 0;
591
0
    bool first = true;
592
0
    if ((o & ::android::hardware::media::omx::V1_0::Status::OK) == static_cast<int32_t>(::android::hardware::media::omx::V1_0::Status::OK)) {
593
0
        os += (first ? "" : " | ");
594
0
        os += "OK";
595
0
        first = false;
596
0
        flipped |= ::android::hardware::media::omx::V1_0::Status::OK;
597
0
    }
598
0
    if ((o & ::android::hardware::media::omx::V1_0::Status::NO_ERROR) == static_cast<int32_t>(::android::hardware::media::omx::V1_0::Status::NO_ERROR)) {
599
0
        os += (first ? "" : " | ");
600
0
        os += "NO_ERROR";
601
0
        first = false;
602
0
        flipped |= ::android::hardware::media::omx::V1_0::Status::NO_ERROR;
603
0
    }
604
0
    if ((o & ::android::hardware::media::omx::V1_0::Status::NAME_NOT_FOUND) == static_cast<int32_t>(::android::hardware::media::omx::V1_0::Status::NAME_NOT_FOUND)) {
605
0
        os += (first ? "" : " | ");
606
0
        os += "NAME_NOT_FOUND";
607
0
        first = false;
608
0
        flipped |= ::android::hardware::media::omx::V1_0::Status::NAME_NOT_FOUND;
609
0
    }
610
0
    if ((o & ::android::hardware::media::omx::V1_0::Status::WOULD_BLOCK) == static_cast<int32_t>(::android::hardware::media::omx::V1_0::Status::WOULD_BLOCK)) {
611
0
        os += (first ? "" : " | ");
612
0
        os += "WOULD_BLOCK";
613
0
        first = false;
614
0
        flipped |= ::android::hardware::media::omx::V1_0::Status::WOULD_BLOCK;
615
0
    }
616
0
    if ((o & ::android::hardware::media::omx::V1_0::Status::NO_MEMORY) == static_cast<int32_t>(::android::hardware::media::omx::V1_0::Status::NO_MEMORY)) {
617
0
        os += (first ? "" : " | ");
618
0
        os += "NO_MEMORY";
619
0
        first = false;
620
0
        flipped |= ::android::hardware::media::omx::V1_0::Status::NO_MEMORY;
621
0
    }
622
0
    if ((o & ::android::hardware::media::omx::V1_0::Status::ALREADY_EXISTS) == static_cast<int32_t>(::android::hardware::media::omx::V1_0::Status::ALREADY_EXISTS)) {
623
0
        os += (first ? "" : " | ");
624
0
        os += "ALREADY_EXISTS";
625
0
        first = false;
626
0
        flipped |= ::android::hardware::media::omx::V1_0::Status::ALREADY_EXISTS;
627
0
    }
628
0
    if ((o & ::android::hardware::media::omx::V1_0::Status::NO_INIT) == static_cast<int32_t>(::android::hardware::media::omx::V1_0::Status::NO_INIT)) {
629
0
        os += (first ? "" : " | ");
630
0
        os += "NO_INIT";
631
0
        first = false;
632
0
        flipped |= ::android::hardware::media::omx::V1_0::Status::NO_INIT;
633
0
    }
634
0
    if ((o & ::android::hardware::media::omx::V1_0::Status::BAD_VALUE) == static_cast<int32_t>(::android::hardware::media::omx::V1_0::Status::BAD_VALUE)) {
635
0
        os += (first ? "" : " | ");
636
0
        os += "BAD_VALUE";
637
0
        first = false;
638
0
        flipped |= ::android::hardware::media::omx::V1_0::Status::BAD_VALUE;
639
0
    }
640
0
    if ((o & ::android::hardware::media::omx::V1_0::Status::DEAD_OBJECT) == static_cast<int32_t>(::android::hardware::media::omx::V1_0::Status::DEAD_OBJECT)) {
641
0
        os += (first ? "" : " | ");
642
0
        os += "DEAD_OBJECT";
643
0
        first = false;
644
0
        flipped |= ::android::hardware::media::omx::V1_0::Status::DEAD_OBJECT;
645
0
    }
646
0
    if ((o & ::android::hardware::media::omx::V1_0::Status::INVALID_OPERATION) == static_cast<int32_t>(::android::hardware::media::omx::V1_0::Status::INVALID_OPERATION)) {
647
0
        os += (first ? "" : " | ");
648
0
        os += "INVALID_OPERATION";
649
0
        first = false;
650
0
        flipped |= ::android::hardware::media::omx::V1_0::Status::INVALID_OPERATION;
651
0
    }
652
0
    if ((o & ::android::hardware::media::omx::V1_0::Status::TIMED_OUT) == static_cast<int32_t>(::android::hardware::media::omx::V1_0::Status::TIMED_OUT)) {
653
0
        os += (first ? "" : " | ");
654
0
        os += "TIMED_OUT";
655
0
        first = false;
656
0
        flipped |= ::android::hardware::media::omx::V1_0::Status::TIMED_OUT;
657
0
    }
658
0
    if ((o & ::android::hardware::media::omx::V1_0::Status::ERROR_UNSUPPORTED) == static_cast<int32_t>(::android::hardware::media::omx::V1_0::Status::ERROR_UNSUPPORTED)) {
659
0
        os += (first ? "" : " | ");
660
0
        os += "ERROR_UNSUPPORTED";
661
0
        first = false;
662
0
        flipped |= ::android::hardware::media::omx::V1_0::Status::ERROR_UNSUPPORTED;
663
0
    }
664
0
    if ((o & ::android::hardware::media::omx::V1_0::Status::UNKNOWN_ERROR) == static_cast<int32_t>(::android::hardware::media::omx::V1_0::Status::UNKNOWN_ERROR)) {
665
0
        os += (first ? "" : " | ");
666
0
        os += "UNKNOWN_ERROR";
667
0
        first = false;
668
0
        flipped |= ::android::hardware::media::omx::V1_0::Status::UNKNOWN_ERROR;
669
0
    }
670
0
    if ((o & ::android::hardware::media::omx::V1_0::Status::BUFFER_NEEDS_REALLOCATION) == static_cast<int32_t>(::android::hardware::media::omx::V1_0::Status::BUFFER_NEEDS_REALLOCATION)) {
671
0
        os += (first ? "" : " | ");
672
0
        os += "BUFFER_NEEDS_REALLOCATION";
673
0
        first = false;
674
0
        flipped |= ::android::hardware::media::omx::V1_0::Status::BUFFER_NEEDS_REALLOCATION;
675
0
    }
676
0
    if ((o & ::android::hardware::media::omx::V1_0::Status::RELEASE_ALL_BUFFERS) == static_cast<int32_t>(::android::hardware::media::omx::V1_0::Status::RELEASE_ALL_BUFFERS)) {
677
0
        os += (first ? "" : " | ");
678
0
        os += "RELEASE_ALL_BUFFERS";
679
0
        first = false;
680
0
        flipped |= ::android::hardware::media::omx::V1_0::Status::RELEASE_ALL_BUFFERS;
681
0
    }
682
0
    if (o != flipped) {
683
0
        os += (first ? "" : " | ");
684
0
        os += toHexString(o & (~flipped));
685
0
    }os += " (";
686
0
    os += toHexString(o);
687
0
    os += ")";
688
0
    return os;
689
0
}
690
691
0
static inline std::string toString(::android::hardware::media::omx::V1_0::Status o) {
692
0
    using ::android::hardware::details::toHexString;
693
0
    if (o == ::android::hardware::media::omx::V1_0::Status::OK) {
694
0
        return "OK";
695
0
    }
696
0
    if (o == ::android::hardware::media::omx::V1_0::Status::NO_ERROR) {
697
0
        return "NO_ERROR";
698
0
    }
699
0
    if (o == ::android::hardware::media::omx::V1_0::Status::NAME_NOT_FOUND) {
700
0
        return "NAME_NOT_FOUND";
701
0
    }
702
0
    if (o == ::android::hardware::media::omx::V1_0::Status::WOULD_BLOCK) {
703
0
        return "WOULD_BLOCK";
704
0
    }
705
0
    if (o == ::android::hardware::media::omx::V1_0::Status::NO_MEMORY) {
706
0
        return "NO_MEMORY";
707
0
    }
708
0
    if (o == ::android::hardware::media::omx::V1_0::Status::ALREADY_EXISTS) {
709
0
        return "ALREADY_EXISTS";
710
0
    }
711
0
    if (o == ::android::hardware::media::omx::V1_0::Status::NO_INIT) {
712
0
        return "NO_INIT";
713
0
    }
714
0
    if (o == ::android::hardware::media::omx::V1_0::Status::BAD_VALUE) {
715
0
        return "BAD_VALUE";
716
0
    }
717
0
    if (o == ::android::hardware::media::omx::V1_0::Status::DEAD_OBJECT) {
718
0
        return "DEAD_OBJECT";
719
0
    }
720
0
    if (o == ::android::hardware::media::omx::V1_0::Status::INVALID_OPERATION) {
721
0
        return "INVALID_OPERATION";
722
0
    }
723
0
    if (o == ::android::hardware::media::omx::V1_0::Status::TIMED_OUT) {
724
0
        return "TIMED_OUT";
725
0
    }
726
0
    if (o == ::android::hardware::media::omx::V1_0::Status::ERROR_UNSUPPORTED) {
727
0
        return "ERROR_UNSUPPORTED";
728
0
    }
729
0
    if (o == ::android::hardware::media::omx::V1_0::Status::UNKNOWN_ERROR) {
730
0
        return "UNKNOWN_ERROR";
731
0
    }
732
0
    if (o == ::android::hardware::media::omx::V1_0::Status::BUFFER_NEEDS_REALLOCATION) {
733
0
        return "BUFFER_NEEDS_REALLOCATION";
734
0
    }
735
0
    if (o == ::android::hardware::media::omx::V1_0::Status::RELEASE_ALL_BUFFERS) {
736
0
        return "RELEASE_ALL_BUFFERS";
737
0
    }
738
0
    std::string os;
739
0
    os += toHexString(static_cast<int32_t>(o));
740
0
    return os;
741
0
}
742
743
template<>
744
0
inline std::string toString<::android::hardware::media::omx::V1_0::Message::Type>(uint32_t o) {
745
0
    using ::android::hardware::details::toHexString;
746
0
    std::string os;
747
0
    ::android::hardware::hidl_bitfield<::android::hardware::media::omx::V1_0::Message::Type> flipped = 0;
748
0
    bool first = true;
749
0
    if ((o & ::android::hardware::media::omx::V1_0::Message::Type::EVENT) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::Message::Type::EVENT)) {
750
0
        os += (first ? "" : " | ");
751
0
        os += "EVENT";
752
0
        first = false;
753
0
        flipped |= ::android::hardware::media::omx::V1_0::Message::Type::EVENT;
754
0
    }
755
0
    if ((o & ::android::hardware::media::omx::V1_0::Message::Type::EMPTY_BUFFER_DONE) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::Message::Type::EMPTY_BUFFER_DONE)) {
756
0
        os += (first ? "" : " | ");
757
0
        os += "EMPTY_BUFFER_DONE";
758
0
        first = false;
759
0
        flipped |= ::android::hardware::media::omx::V1_0::Message::Type::EMPTY_BUFFER_DONE;
760
0
    }
761
0
    if ((o & ::android::hardware::media::omx::V1_0::Message::Type::FILL_BUFFER_DONE) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::Message::Type::FILL_BUFFER_DONE)) {
762
0
        os += (first ? "" : " | ");
763
0
        os += "FILL_BUFFER_DONE";
764
0
        first = false;
765
0
        flipped |= ::android::hardware::media::omx::V1_0::Message::Type::FILL_BUFFER_DONE;
766
0
    }
767
0
    if ((o & ::android::hardware::media::omx::V1_0::Message::Type::FRAME_RENDERED) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::Message::Type::FRAME_RENDERED)) {
768
0
        os += (first ? "" : " | ");
769
0
        os += "FRAME_RENDERED";
770
0
        first = false;
771
0
        flipped |= ::android::hardware::media::omx::V1_0::Message::Type::FRAME_RENDERED;
772
0
    }
773
0
    if (o != flipped) {
774
0
        os += (first ? "" : " | ");
775
0
        os += toHexString(o & (~flipped));
776
0
    }os += " (";
777
0
    os += toHexString(o);
778
0
    os += ")";
779
0
    return os;
780
0
}
781
782
0
static inline std::string toString(::android::hardware::media::omx::V1_0::Message::Type o) {
783
0
    using ::android::hardware::details::toHexString;
784
0
    if (o == ::android::hardware::media::omx::V1_0::Message::Type::EVENT) {
785
0
        return "EVENT";
786
0
    }
787
0
    if (o == ::android::hardware::media::omx::V1_0::Message::Type::EMPTY_BUFFER_DONE) {
788
0
        return "EMPTY_BUFFER_DONE";
789
0
    }
790
0
    if (o == ::android::hardware::media::omx::V1_0::Message::Type::FILL_BUFFER_DONE) {
791
0
        return "FILL_BUFFER_DONE";
792
0
    }
793
0
    if (o == ::android::hardware::media::omx::V1_0::Message::Type::FRAME_RENDERED) {
794
0
        return "FRAME_RENDERED";
795
0
    }
796
0
    std::string os;
797
0
    os += toHexString(static_cast<uint32_t>(o));
798
0
    return os;
799
0
}
800
801
0
static inline std::string toString(const ::android::hardware::media::omx::V1_0::Message::EventData& o) {
802
0
    using ::android::hardware::toString;
803
0
    std::string os;
804
0
    os += "{";
805
0
    os += ".event = ";
806
0
    os += ::android::hardware::toString(o.event);
807
0
    os += ", .data1 = ";
808
0
    os += ::android::hardware::toString(o.data1);
809
0
    os += ", .data2 = ";
810
0
    os += ::android::hardware::toString(o.data2);
811
0
    os += ", .data3 = ";
812
0
    os += ::android::hardware::toString(o.data3);
813
0
    os += ", .data4 = ";
814
0
    os += ::android::hardware::toString(o.data4);
815
0
    os += "}"; return os;
816
0
}
817
818
0
static inline bool operator==(const ::android::hardware::media::omx::V1_0::Message::EventData& lhs, const ::android::hardware::media::omx::V1_0::Message::EventData& rhs) {
819
0
    if (lhs.event != rhs.event) {
820
0
        return false;
821
0
    }
822
0
    if (lhs.data1 != rhs.data1) {
823
0
        return false;
824
0
    }
825
0
    if (lhs.data2 != rhs.data2) {
826
0
        return false;
827
0
    }
828
0
    if (lhs.data3 != rhs.data3) {
829
0
        return false;
830
0
    }
831
0
    if (lhs.data4 != rhs.data4) {
832
0
        return false;
833
0
    }
834
0
    return true;
835
0
}
836
837
0
static inline bool operator!=(const ::android::hardware::media::omx::V1_0::Message::EventData& lhs, const ::android::hardware::media::omx::V1_0::Message::EventData& rhs){
838
0
    return !(lhs == rhs);
839
0
}
840
841
0
static inline std::string toString(const ::android::hardware::media::omx::V1_0::Message::BufferData& o) {
842
0
    using ::android::hardware::toString;
843
0
    std::string os;
844
0
    os += "{";
845
0
    os += ".buffer = ";
846
0
    os += ::android::hardware::toString(o.buffer);
847
0
    os += "}"; return os;
848
0
}
849
850
0
static inline bool operator==(const ::android::hardware::media::omx::V1_0::Message::BufferData& lhs, const ::android::hardware::media::omx::V1_0::Message::BufferData& rhs) {
851
0
    if (lhs.buffer != rhs.buffer) {
852
0
        return false;
853
0
    }
854
0
    return true;
855
0
}
856
857
0
static inline bool operator!=(const ::android::hardware::media::omx::V1_0::Message::BufferData& lhs, const ::android::hardware::media::omx::V1_0::Message::BufferData& rhs){
858
0
    return !(lhs == rhs);
859
0
}
860
861
0
static inline std::string toString(const ::android::hardware::media::omx::V1_0::Message::ExtendedBufferData& o) {
862
0
    using ::android::hardware::toString;
863
0
    std::string os;
864
0
    os += "{";
865
0
    os += ".buffer = ";
866
0
    os += ::android::hardware::toString(o.buffer);
867
0
    os += ", .rangeOffset = ";
868
0
    os += ::android::hardware::toString(o.rangeOffset);
869
0
    os += ", .rangeLength = ";
870
0
    os += ::android::hardware::toString(o.rangeLength);
871
0
    os += ", .flags = ";
872
0
    os += ::android::hardware::toString(o.flags);
873
0
    os += ", .timestampUs = ";
874
0
    os += ::android::hardware::toString(o.timestampUs);
875
0
    os += "}"; return os;
876
0
}
877
878
0
static inline bool operator==(const ::android::hardware::media::omx::V1_0::Message::ExtendedBufferData& lhs, const ::android::hardware::media::omx::V1_0::Message::ExtendedBufferData& rhs) {
879
0
    if (lhs.buffer != rhs.buffer) {
880
0
        return false;
881
0
    }
882
0
    if (lhs.rangeOffset != rhs.rangeOffset) {
883
0
        return false;
884
0
    }
885
0
    if (lhs.rangeLength != rhs.rangeLength) {
886
0
        return false;
887
0
    }
888
0
    if (lhs.flags != rhs.flags) {
889
0
        return false;
890
0
    }
891
0
    if (lhs.timestampUs != rhs.timestampUs) {
892
0
        return false;
893
0
    }
894
0
    return true;
895
0
}
896
897
0
static inline bool operator!=(const ::android::hardware::media::omx::V1_0::Message::ExtendedBufferData& lhs, const ::android::hardware::media::omx::V1_0::Message::ExtendedBufferData& rhs){
898
0
    return !(lhs == rhs);
899
0
}
900
901
0
static inline std::string toString(const ::android::hardware::media::omx::V1_0::Message::RenderData& o) {
902
0
    using ::android::hardware::toString;
903
0
    std::string os;
904
0
    os += "{";
905
0
    os += ".timestampUs = ";
906
0
    os += ::android::hardware::toString(o.timestampUs);
907
0
    os += ", .systemTimeNs = ";
908
0
    os += ::android::hardware::toString(o.systemTimeNs);
909
0
    os += "}"; return os;
910
0
}
911
912
0
static inline bool operator==(const ::android::hardware::media::omx::V1_0::Message::RenderData& lhs, const ::android::hardware::media::omx::V1_0::Message::RenderData& rhs) {
913
0
    if (lhs.timestampUs != rhs.timestampUs) {
914
0
        return false;
915
0
    }
916
0
    if (lhs.systemTimeNs != rhs.systemTimeNs) {
917
0
        return false;
918
0
    }
919
0
    return true;
920
0
}
921
922
0
static inline bool operator!=(const ::android::hardware::media::omx::V1_0::Message::RenderData& lhs, const ::android::hardware::media::omx::V1_0::Message::RenderData& rhs){
923
0
    return !(lhs == rhs);
924
0
}
925
926
0
static inline std::string toString(const ::android::hardware::media::omx::V1_0::Message::Data& o) {
927
0
    using ::android::hardware::toString;
928
0
    std::string os;
929
0
    os += "{";
930
0
    os += ".eventData = ";
931
0
    os += ::android::hardware::media::omx::V1_0::toString(o.eventData);
932
0
    os += ", .bufferData = ";
933
0
    os += ::android::hardware::media::omx::V1_0::toString(o.bufferData);
934
0
    os += ", .extendedBufferData = ";
935
0
    os += ::android::hardware::media::omx::V1_0::toString(o.extendedBufferData);
936
0
    os += ", .renderData = ";
937
0
    os += ::android::hardware::media::omx::V1_0::toString(o.renderData);
938
0
    os += "}"; return os;
939
0
}
940
941
// operator== and operator!= are not generated for Data
942
943
0
static inline std::string toString(const ::android::hardware::media::omx::V1_0::Message& o) {
944
0
    using ::android::hardware::toString;
945
0
    std::string os;
946
0
    os += "{";
947
0
    os += ".type = ";
948
0
    os += ::android::hardware::media::omx::V1_0::toString(o.type);
949
0
    os += ", .fence = ";
950
0
    os += ::android::hardware::toString(o.fence);
951
0
    os += ", .data = ";
952
0
    os += ::android::hardware::media::omx::V1_0::toString(o.data);
953
0
    os += "}"; return os;
954
0
}
955
956
// operator== and operator!= are not generated for Message
957
958
template<>
959
0
inline std::string toString<::android::hardware::media::omx::V1_0::CodecBuffer::Type>(int32_t o) {
960
0
    using ::android::hardware::details::toHexString;
961
0
    std::string os;
962
0
    ::android::hardware::hidl_bitfield<::android::hardware::media::omx::V1_0::CodecBuffer::Type> flipped = 0;
963
0
    bool first = true;
964
0
    if ((o & ::android::hardware::media::omx::V1_0::CodecBuffer::Type::INVALID) == static_cast<int32_t>(::android::hardware::media::omx::V1_0::CodecBuffer::Type::INVALID)) {
965
0
        os += (first ? "" : " | ");
966
0
        os += "INVALID";
967
0
        first = false;
968
0
        flipped |= ::android::hardware::media::omx::V1_0::CodecBuffer::Type::INVALID;
969
0
    }
970
0
    if ((o & ::android::hardware::media::omx::V1_0::CodecBuffer::Type::PRESET) == static_cast<int32_t>(::android::hardware::media::omx::V1_0::CodecBuffer::Type::PRESET)) {
971
0
        os += (first ? "" : " | ");
972
0
        os += "PRESET";
973
0
        first = false;
974
0
        flipped |= ::android::hardware::media::omx::V1_0::CodecBuffer::Type::PRESET;
975
0
    }
976
0
    if ((o & ::android::hardware::media::omx::V1_0::CodecBuffer::Type::SHARED_MEM) == static_cast<int32_t>(::android::hardware::media::omx::V1_0::CodecBuffer::Type::SHARED_MEM)) {
977
0
        os += (first ? "" : " | ");
978
0
        os += "SHARED_MEM";
979
0
        first = false;
980
0
        flipped |= ::android::hardware::media::omx::V1_0::CodecBuffer::Type::SHARED_MEM;
981
0
    }
982
0
    if ((o & ::android::hardware::media::omx::V1_0::CodecBuffer::Type::ANW_BUFFER) == static_cast<int32_t>(::android::hardware::media::omx::V1_0::CodecBuffer::Type::ANW_BUFFER)) {
983
0
        os += (first ? "" : " | ");
984
0
        os += "ANW_BUFFER";
985
0
        first = false;
986
0
        flipped |= ::android::hardware::media::omx::V1_0::CodecBuffer::Type::ANW_BUFFER;
987
0
    }
988
0
    if ((o & ::android::hardware::media::omx::V1_0::CodecBuffer::Type::NATIVE_HANDLE) == static_cast<int32_t>(::android::hardware::media::omx::V1_0::CodecBuffer::Type::NATIVE_HANDLE)) {
989
0
        os += (first ? "" : " | ");
990
0
        os += "NATIVE_HANDLE";
991
0
        first = false;
992
0
        flipped |= ::android::hardware::media::omx::V1_0::CodecBuffer::Type::NATIVE_HANDLE;
993
0
    }
994
0
    if (o != flipped) {
995
0
        os += (first ? "" : " | ");
996
0
        os += toHexString(o & (~flipped));
997
0
    }os += " (";
998
0
    os += toHexString(o);
999
0
    os += ")";
1000
0
    return os;
1001
0
}
1002
1003
0
static inline std::string toString(::android::hardware::media::omx::V1_0::CodecBuffer::Type o) {
1004
0
    using ::android::hardware::details::toHexString;
1005
0
    if (o == ::android::hardware::media::omx::V1_0::CodecBuffer::Type::INVALID) {
1006
0
        return "INVALID";
1007
0
    }
1008
0
    if (o == ::android::hardware::media::omx::V1_0::CodecBuffer::Type::PRESET) {
1009
0
        return "PRESET";
1010
0
    }
1011
0
    if (o == ::android::hardware::media::omx::V1_0::CodecBuffer::Type::SHARED_MEM) {
1012
0
        return "SHARED_MEM";
1013
0
    }
1014
0
    if (o == ::android::hardware::media::omx::V1_0::CodecBuffer::Type::ANW_BUFFER) {
1015
0
        return "ANW_BUFFER";
1016
0
    }
1017
0
    if (o == ::android::hardware::media::omx::V1_0::CodecBuffer::Type::NATIVE_HANDLE) {
1018
0
        return "NATIVE_HANDLE";
1019
0
    }
1020
0
    std::string os;
1021
0
    os += toHexString(static_cast<int32_t>(o));
1022
0
    return os;
1023
0
}
1024
1025
0
static inline std::string toString(const ::android::hardware::media::omx::V1_0::CodecBuffer::PresetAttributes& o) {
1026
0
    using ::android::hardware::toString;
1027
0
    std::string os;
1028
0
    os += "{";
1029
0
    os += ".rangeOffset = ";
1030
0
    os += ::android::hardware::toString(o.rangeOffset);
1031
0
    os += ", .rangeLength = ";
1032
0
    os += ::android::hardware::toString(o.rangeLength);
1033
0
    os += "}"; return os;
1034
0
}
1035
1036
0
static inline bool operator==(const ::android::hardware::media::omx::V1_0::CodecBuffer::PresetAttributes& lhs, const ::android::hardware::media::omx::V1_0::CodecBuffer::PresetAttributes& rhs) {
1037
0
    if (lhs.rangeOffset != rhs.rangeOffset) {
1038
0
        return false;
1039
0
    }
1040
0
    if (lhs.rangeLength != rhs.rangeLength) {
1041
0
        return false;
1042
0
    }
1043
0
    return true;
1044
0
}
1045
1046
0
static inline bool operator!=(const ::android::hardware::media::omx::V1_0::CodecBuffer::PresetAttributes& lhs, const ::android::hardware::media::omx::V1_0::CodecBuffer::PresetAttributes& rhs){
1047
0
    return !(lhs == rhs);
1048
0
}
1049
1050
0
static inline std::string toString(const ::android::hardware::media::omx::V1_0::CodecBuffer::Attributes& o) {
1051
0
    using ::android::hardware::toString;
1052
0
    std::string os;
1053
0
    os += "{";
1054
0
    os += ".preset = ";
1055
0
    os += ::android::hardware::media::omx::V1_0::toString(o.preset);
1056
0
    os += ", .anwBuffer = ";
1057
0
    os += ::android::hardware::media::V1_0::toString(o.anwBuffer);
1058
0
    os += "}"; return os;
1059
0
}
1060
1061
// operator== and operator!= are not generated for Attributes
1062
1063
0
static inline std::string toString(const ::android::hardware::media::omx::V1_0::CodecBuffer& o) {
1064
0
    using ::android::hardware::toString;
1065
0
    std::string os;
1066
0
    os += "{";
1067
0
    os += ".type = ";
1068
0
    os += ::android::hardware::media::omx::V1_0::toString(o.type);
1069
0
    os += ", .attr = ";
1070
0
    os += ::android::hardware::media::omx::V1_0::toString(o.attr);
1071
0
    os += ", .nativeHandle = ";
1072
0
    os += ::android::hardware::toString(o.nativeHandle);
1073
0
    os += ", .sharedMemory = ";
1074
0
    os += ::android::hardware::toString(o.sharedMemory);
1075
0
    os += "}"; return os;
1076
0
}
1077
1078
// operator== and operator!= are not generated for CodecBuffer
1079
1080
template<>
1081
0
inline std::string toString<::android::hardware::media::omx::V1_0::PortMode>(int32_t o) {
1082
0
    using ::android::hardware::details::toHexString;
1083
0
    std::string os;
1084
0
    ::android::hardware::hidl_bitfield<::android::hardware::media::omx::V1_0::PortMode> flipped = 0;
1085
0
    bool first = true;
1086
0
    if ((o & ::android::hardware::media::omx::V1_0::PortMode::PRESET_START) == static_cast<int32_t>(::android::hardware::media::omx::V1_0::PortMode::PRESET_START)) {
1087
0
        os += (first ? "" : " | ");
1088
0
        os += "PRESET_START";
1089
0
        first = false;
1090
0
        flipped |= ::android::hardware::media::omx::V1_0::PortMode::PRESET_START;
1091
0
    }
1092
0
    if ((o & ::android::hardware::media::omx::V1_0::PortMode::PRESET_BYTE_BUFFER) == static_cast<int32_t>(::android::hardware::media::omx::V1_0::PortMode::PRESET_BYTE_BUFFER)) {
1093
0
        os += (first ? "" : " | ");
1094
0
        os += "PRESET_BYTE_BUFFER";
1095
0
        first = false;
1096
0
        flipped |= ::android::hardware::media::omx::V1_0::PortMode::PRESET_BYTE_BUFFER;
1097
0
    }
1098
0
    if ((o & ::android::hardware::media::omx::V1_0::PortMode::PRESET_ANW_BUFFER) == static_cast<int32_t>(::android::hardware::media::omx::V1_0::PortMode::PRESET_ANW_BUFFER)) {
1099
0
        os += (first ? "" : " | ");
1100
0
        os += "PRESET_ANW_BUFFER";
1101
0
        first = false;
1102
0
        flipped |= ::android::hardware::media::omx::V1_0::PortMode::PRESET_ANW_BUFFER;
1103
0
    }
1104
0
    if ((o & ::android::hardware::media::omx::V1_0::PortMode::PRESET_SECURE_BUFFER) == static_cast<int32_t>(::android::hardware::media::omx::V1_0::PortMode::PRESET_SECURE_BUFFER)) {
1105
0
        os += (first ? "" : " | ");
1106
0
        os += "PRESET_SECURE_BUFFER";
1107
0
        first = false;
1108
0
        flipped |= ::android::hardware::media::omx::V1_0::PortMode::PRESET_SECURE_BUFFER;
1109
0
    }
1110
0
    if ((o & ::android::hardware::media::omx::V1_0::PortMode::PRESET_END) == static_cast<int32_t>(::android::hardware::media::omx::V1_0::PortMode::PRESET_END)) {
1111
0
        os += (first ? "" : " | ");
1112
0
        os += "PRESET_END";
1113
0
        first = false;
1114
0
        flipped |= ::android::hardware::media::omx::V1_0::PortMode::PRESET_END;
1115
0
    }
1116
0
    if ((o & ::android::hardware::media::omx::V1_0::PortMode::DYNAMIC_START) == static_cast<int32_t>(::android::hardware::media::omx::V1_0::PortMode::DYNAMIC_START)) {
1117
0
        os += (first ? "" : " | ");
1118
0
        os += "DYNAMIC_START";
1119
0
        first = false;
1120
0
        flipped |= ::android::hardware::media::omx::V1_0::PortMode::DYNAMIC_START;
1121
0
    }
1122
0
    if ((o & ::android::hardware::media::omx::V1_0::PortMode::DYNAMIC_ANW_BUFFER) == static_cast<int32_t>(::android::hardware::media::omx::V1_0::PortMode::DYNAMIC_ANW_BUFFER)) {
1123
0
        os += (first ? "" : " | ");
1124
0
        os += "DYNAMIC_ANW_BUFFER";
1125
0
        first = false;
1126
0
        flipped |= ::android::hardware::media::omx::V1_0::PortMode::DYNAMIC_ANW_BUFFER;
1127
0
    }
1128
0
    if ((o & ::android::hardware::media::omx::V1_0::PortMode::DYNAMIC_NATIVE_HANDLE) == static_cast<int32_t>(::android::hardware::media::omx::V1_0::PortMode::DYNAMIC_NATIVE_HANDLE)) {
1129
0
        os += (first ? "" : " | ");
1130
0
        os += "DYNAMIC_NATIVE_HANDLE";
1131
0
        first = false;
1132
0
        flipped |= ::android::hardware::media::omx::V1_0::PortMode::DYNAMIC_NATIVE_HANDLE;
1133
0
    }
1134
0
    if ((o & ::android::hardware::media::omx::V1_0::PortMode::DYNAMIC_END) == static_cast<int32_t>(::android::hardware::media::omx::V1_0::PortMode::DYNAMIC_END)) {
1135
0
        os += (first ? "" : " | ");
1136
0
        os += "DYNAMIC_END";
1137
0
        first = false;
1138
0
        flipped |= ::android::hardware::media::omx::V1_0::PortMode::DYNAMIC_END;
1139
0
    }
1140
0
    if (o != flipped) {
1141
0
        os += (first ? "" : " | ");
1142
0
        os += toHexString(o & (~flipped));
1143
0
    }os += " (";
1144
0
    os += toHexString(o);
1145
0
    os += ")";
1146
0
    return os;
1147
0
}
1148
1149
0
static inline std::string toString(::android::hardware::media::omx::V1_0::PortMode o) {
1150
0
    using ::android::hardware::details::toHexString;
1151
0
    if (o == ::android::hardware::media::omx::V1_0::PortMode::PRESET_START) {
1152
0
        return "PRESET_START";
1153
0
    }
1154
0
    if (o == ::android::hardware::media::omx::V1_0::PortMode::PRESET_BYTE_BUFFER) {
1155
0
        return "PRESET_BYTE_BUFFER";
1156
0
    }
1157
0
    if (o == ::android::hardware::media::omx::V1_0::PortMode::PRESET_ANW_BUFFER) {
1158
0
        return "PRESET_ANW_BUFFER";
1159
0
    }
1160
0
    if (o == ::android::hardware::media::omx::V1_0::PortMode::PRESET_SECURE_BUFFER) {
1161
0
        return "PRESET_SECURE_BUFFER";
1162
0
    }
1163
0
    if (o == ::android::hardware::media::omx::V1_0::PortMode::PRESET_END) {
1164
0
        return "PRESET_END";
1165
0
    }
1166
0
    if (o == ::android::hardware::media::omx::V1_0::PortMode::DYNAMIC_START) {
1167
0
        return "DYNAMIC_START";
1168
0
    }
1169
0
    if (o == ::android::hardware::media::omx::V1_0::PortMode::DYNAMIC_ANW_BUFFER) {
1170
0
        return "DYNAMIC_ANW_BUFFER";
1171
0
    }
1172
0
    if (o == ::android::hardware::media::omx::V1_0::PortMode::DYNAMIC_NATIVE_HANDLE) {
1173
0
        return "DYNAMIC_NATIVE_HANDLE";
1174
0
    }
1175
0
    if (o == ::android::hardware::media::omx::V1_0::PortMode::DYNAMIC_END) {
1176
0
        return "DYNAMIC_END";
1177
0
    }
1178
0
    std::string os;
1179
0
    os += toHexString(static_cast<int32_t>(o));
1180
0
    return os;
1181
0
}
1182
1183
template<>
1184
0
inline std::string toString<::android::hardware::media::omx::V1_0::ColorAspects::Range>(uint32_t o) {
1185
0
    using ::android::hardware::details::toHexString;
1186
0
    std::string os;
1187
0
    ::android::hardware::hidl_bitfield<::android::hardware::media::omx::V1_0::ColorAspects::Range> flipped = 0;
1188
0
    bool first = true;
1189
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::Range::UNSPECIFIED) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::Range::UNSPECIFIED)) {
1190
0
        os += (first ? "" : " | ");
1191
0
        os += "UNSPECIFIED";
1192
0
        first = false;
1193
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::Range::UNSPECIFIED;
1194
0
    }
1195
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::Range::FULL) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::Range::FULL)) {
1196
0
        os += (first ? "" : " | ");
1197
0
        os += "FULL";
1198
0
        first = false;
1199
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::Range::FULL;
1200
0
    }
1201
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::Range::LIMITED) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::Range::LIMITED)) {
1202
0
        os += (first ? "" : " | ");
1203
0
        os += "LIMITED";
1204
0
        first = false;
1205
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::Range::LIMITED;
1206
0
    }
1207
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::Range::OTHER) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::Range::OTHER)) {
1208
0
        os += (first ? "" : " | ");
1209
0
        os += "OTHER";
1210
0
        first = false;
1211
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::Range::OTHER;
1212
0
    }
1213
0
    if (o != flipped) {
1214
0
        os += (first ? "" : " | ");
1215
0
        os += toHexString(o & (~flipped));
1216
0
    }os += " (";
1217
0
    os += toHexString(o);
1218
0
    os += ")";
1219
0
    return os;
1220
0
}
1221
1222
0
static inline std::string toString(::android::hardware::media::omx::V1_0::ColorAspects::Range o) {
1223
0
    using ::android::hardware::details::toHexString;
1224
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::Range::UNSPECIFIED) {
1225
0
        return "UNSPECIFIED";
1226
0
    }
1227
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::Range::FULL) {
1228
0
        return "FULL";
1229
0
    }
1230
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::Range::LIMITED) {
1231
0
        return "LIMITED";
1232
0
    }
1233
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::Range::OTHER) {
1234
0
        return "OTHER";
1235
0
    }
1236
0
    std::string os;
1237
0
    os += toHexString(static_cast<uint32_t>(o));
1238
0
    return os;
1239
0
}
1240
1241
template<>
1242
0
inline std::string toString<::android::hardware::media::omx::V1_0::ColorAspects::Primaries>(uint32_t o) {
1243
0
    using ::android::hardware::details::toHexString;
1244
0
    std::string os;
1245
0
    ::android::hardware::hidl_bitfield<::android::hardware::media::omx::V1_0::ColorAspects::Primaries> flipped = 0;
1246
0
    bool first = true;
1247
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::Primaries::UNSPECIFIED) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::Primaries::UNSPECIFIED)) {
1248
0
        os += (first ? "" : " | ");
1249
0
        os += "UNSPECIFIED";
1250
0
        first = false;
1251
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::Primaries::UNSPECIFIED;
1252
0
    }
1253
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::Primaries::BT709_5) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::Primaries::BT709_5)) {
1254
0
        os += (first ? "" : " | ");
1255
0
        os += "BT709_5";
1256
0
        first = false;
1257
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::Primaries::BT709_5;
1258
0
    }
1259
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::Primaries::BT470_6M) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::Primaries::BT470_6M)) {
1260
0
        os += (first ? "" : " | ");
1261
0
        os += "BT470_6M";
1262
0
        first = false;
1263
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::Primaries::BT470_6M;
1264
0
    }
1265
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::Primaries::BT601_6_625) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::Primaries::BT601_6_625)) {
1266
0
        os += (first ? "" : " | ");
1267
0
        os += "BT601_6_625";
1268
0
        first = false;
1269
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::Primaries::BT601_6_625;
1270
0
    }
1271
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::Primaries::BT601_6_525) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::Primaries::BT601_6_525)) {
1272
0
        os += (first ? "" : " | ");
1273
0
        os += "BT601_6_525";
1274
0
        first = false;
1275
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::Primaries::BT601_6_525;
1276
0
    }
1277
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::Primaries::GENERIC_FILM) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::Primaries::GENERIC_FILM)) {
1278
0
        os += (first ? "" : " | ");
1279
0
        os += "GENERIC_FILM";
1280
0
        first = false;
1281
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::Primaries::GENERIC_FILM;
1282
0
    }
1283
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::Primaries::BT2020) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::Primaries::BT2020)) {
1284
0
        os += (first ? "" : " | ");
1285
0
        os += "BT2020";
1286
0
        first = false;
1287
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::Primaries::BT2020;
1288
0
    }
1289
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::Primaries::OTHER) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::Primaries::OTHER)) {
1290
0
        os += (first ? "" : " | ");
1291
0
        os += "OTHER";
1292
0
        first = false;
1293
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::Primaries::OTHER;
1294
0
    }
1295
0
    if (o != flipped) {
1296
0
        os += (first ? "" : " | ");
1297
0
        os += toHexString(o & (~flipped));
1298
0
    }os += " (";
1299
0
    os += toHexString(o);
1300
0
    os += ")";
1301
0
    return os;
1302
0
}
1303
1304
0
static inline std::string toString(::android::hardware::media::omx::V1_0::ColorAspects::Primaries o) {
1305
0
    using ::android::hardware::details::toHexString;
1306
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::Primaries::UNSPECIFIED) {
1307
0
        return "UNSPECIFIED";
1308
0
    }
1309
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::Primaries::BT709_5) {
1310
0
        return "BT709_5";
1311
0
    }
1312
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::Primaries::BT470_6M) {
1313
0
        return "BT470_6M";
1314
0
    }
1315
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::Primaries::BT601_6_625) {
1316
0
        return "BT601_6_625";
1317
0
    }
1318
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::Primaries::BT601_6_525) {
1319
0
        return "BT601_6_525";
1320
0
    }
1321
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::Primaries::GENERIC_FILM) {
1322
0
        return "GENERIC_FILM";
1323
0
    }
1324
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::Primaries::BT2020) {
1325
0
        return "BT2020";
1326
0
    }
1327
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::Primaries::OTHER) {
1328
0
        return "OTHER";
1329
0
    }
1330
0
    std::string os;
1331
0
    os += toHexString(static_cast<uint32_t>(o));
1332
0
    return os;
1333
0
}
1334
1335
template<>
1336
0
inline std::string toString<::android::hardware::media::omx::V1_0::ColorAspects::Transfer>(uint32_t o) {
1337
0
    using ::android::hardware::details::toHexString;
1338
0
    std::string os;
1339
0
    ::android::hardware::hidl_bitfield<::android::hardware::media::omx::V1_0::ColorAspects::Transfer> flipped = 0;
1340
0
    bool first = true;
1341
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::UNSPECIFIED) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::Transfer::UNSPECIFIED)) {
1342
0
        os += (first ? "" : " | ");
1343
0
        os += "UNSPECIFIED";
1344
0
        first = false;
1345
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::UNSPECIFIED;
1346
0
    }
1347
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::LINEAR) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::Transfer::LINEAR)) {
1348
0
        os += (first ? "" : " | ");
1349
0
        os += "LINEAR";
1350
0
        first = false;
1351
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::LINEAR;
1352
0
    }
1353
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::SRGB) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::Transfer::SRGB)) {
1354
0
        os += (first ? "" : " | ");
1355
0
        os += "SRGB";
1356
0
        first = false;
1357
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::SRGB;
1358
0
    }
1359
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::SMPTE170M) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::Transfer::SMPTE170M)) {
1360
0
        os += (first ? "" : " | ");
1361
0
        os += "SMPTE170M";
1362
0
        first = false;
1363
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::SMPTE170M;
1364
0
    }
1365
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::GAMMA22) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::Transfer::GAMMA22)) {
1366
0
        os += (first ? "" : " | ");
1367
0
        os += "GAMMA22";
1368
0
        first = false;
1369
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::GAMMA22;
1370
0
    }
1371
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::GAMMA28) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::Transfer::GAMMA28)) {
1372
0
        os += (first ? "" : " | ");
1373
0
        os += "GAMMA28";
1374
0
        first = false;
1375
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::GAMMA28;
1376
0
    }
1377
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::ST2084) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::Transfer::ST2084)) {
1378
0
        os += (first ? "" : " | ");
1379
0
        os += "ST2084";
1380
0
        first = false;
1381
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::ST2084;
1382
0
    }
1383
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::HLG) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::Transfer::HLG)) {
1384
0
        os += (first ? "" : " | ");
1385
0
        os += "HLG";
1386
0
        first = false;
1387
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::HLG;
1388
0
    }
1389
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::SMPTE240M) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::Transfer::SMPTE240M)) {
1390
0
        os += (first ? "" : " | ");
1391
0
        os += "SMPTE240M";
1392
0
        first = false;
1393
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::SMPTE240M;
1394
0
    }
1395
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::XVYCC) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::Transfer::XVYCC)) {
1396
0
        os += (first ? "" : " | ");
1397
0
        os += "XVYCC";
1398
0
        first = false;
1399
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::XVYCC;
1400
0
    }
1401
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::BT1361) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::Transfer::BT1361)) {
1402
0
        os += (first ? "" : " | ");
1403
0
        os += "BT1361";
1404
0
        first = false;
1405
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::BT1361;
1406
0
    }
1407
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::ST428) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::Transfer::ST428)) {
1408
0
        os += (first ? "" : " | ");
1409
0
        os += "ST428";
1410
0
        first = false;
1411
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::ST428;
1412
0
    }
1413
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::OTHER) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::Transfer::OTHER)) {
1414
0
        os += (first ? "" : " | ");
1415
0
        os += "OTHER";
1416
0
        first = false;
1417
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::OTHER;
1418
0
    }
1419
0
    if (o != flipped) {
1420
0
        os += (first ? "" : " | ");
1421
0
        os += toHexString(o & (~flipped));
1422
0
    }os += " (";
1423
0
    os += toHexString(o);
1424
0
    os += ")";
1425
0
    return os;
1426
0
}
1427
1428
0
static inline std::string toString(::android::hardware::media::omx::V1_0::ColorAspects::Transfer o) {
1429
0
    using ::android::hardware::details::toHexString;
1430
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::UNSPECIFIED) {
1431
0
        return "UNSPECIFIED";
1432
0
    }
1433
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::LINEAR) {
1434
0
        return "LINEAR";
1435
0
    }
1436
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::SRGB) {
1437
0
        return "SRGB";
1438
0
    }
1439
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::SMPTE170M) {
1440
0
        return "SMPTE170M";
1441
0
    }
1442
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::GAMMA22) {
1443
0
        return "GAMMA22";
1444
0
    }
1445
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::GAMMA28) {
1446
0
        return "GAMMA28";
1447
0
    }
1448
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::ST2084) {
1449
0
        return "ST2084";
1450
0
    }
1451
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::HLG) {
1452
0
        return "HLG";
1453
0
    }
1454
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::SMPTE240M) {
1455
0
        return "SMPTE240M";
1456
0
    }
1457
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::XVYCC) {
1458
0
        return "XVYCC";
1459
0
    }
1460
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::BT1361) {
1461
0
        return "BT1361";
1462
0
    }
1463
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::ST428) {
1464
0
        return "ST428";
1465
0
    }
1466
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::OTHER) {
1467
0
        return "OTHER";
1468
0
    }
1469
0
    std::string os;
1470
0
    os += toHexString(static_cast<uint32_t>(o));
1471
0
    return os;
1472
0
}
1473
1474
template<>
1475
0
inline std::string toString<::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs>(uint32_t o) {
1476
0
    using ::android::hardware::details::toHexString;
1477
0
    std::string os;
1478
0
    ::android::hardware::hidl_bitfield<::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs> flipped = 0;
1479
0
    bool first = true;
1480
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::UNSPECIFIED) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::UNSPECIFIED)) {
1481
0
        os += (first ? "" : " | ");
1482
0
        os += "UNSPECIFIED";
1483
0
        first = false;
1484
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::UNSPECIFIED;
1485
0
    }
1486
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::BT709_5) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::BT709_5)) {
1487
0
        os += (first ? "" : " | ");
1488
0
        os += "BT709_5";
1489
0
        first = false;
1490
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::BT709_5;
1491
0
    }
1492
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::BT470_6M) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::BT470_6M)) {
1493
0
        os += (first ? "" : " | ");
1494
0
        os += "BT470_6M";
1495
0
        first = false;
1496
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::BT470_6M;
1497
0
    }
1498
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::BT601_6) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::BT601_6)) {
1499
0
        os += (first ? "" : " | ");
1500
0
        os += "BT601_6";
1501
0
        first = false;
1502
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::BT601_6;
1503
0
    }
1504
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::SMPTE240M) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::SMPTE240M)) {
1505
0
        os += (first ? "" : " | ");
1506
0
        os += "SMPTE240M";
1507
0
        first = false;
1508
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::SMPTE240M;
1509
0
    }
1510
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::BT2020) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::BT2020)) {
1511
0
        os += (first ? "" : " | ");
1512
0
        os += "BT2020";
1513
0
        first = false;
1514
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::BT2020;
1515
0
    }
1516
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::BT2020CONSTANT) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::BT2020CONSTANT)) {
1517
0
        os += (first ? "" : " | ");
1518
0
        os += "BT2020CONSTANT";
1519
0
        first = false;
1520
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::BT2020CONSTANT;
1521
0
    }
1522
0
    if ((o & ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::OTHER) == static_cast<uint32_t>(::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::OTHER)) {
1523
0
        os += (first ? "" : " | ");
1524
0
        os += "OTHER";
1525
0
        first = false;
1526
0
        flipped |= ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::OTHER;
1527
0
    }
1528
0
    if (o != flipped) {
1529
0
        os += (first ? "" : " | ");
1530
0
        os += toHexString(o & (~flipped));
1531
0
    }os += " (";
1532
0
    os += toHexString(o);
1533
0
    os += ")";
1534
0
    return os;
1535
0
}
1536
1537
0
static inline std::string toString(::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs o) {
1538
0
    using ::android::hardware::details::toHexString;
1539
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::UNSPECIFIED) {
1540
0
        return "UNSPECIFIED";
1541
0
    }
1542
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::BT709_5) {
1543
0
        return "BT709_5";
1544
0
    }
1545
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::BT470_6M) {
1546
0
        return "BT470_6M";
1547
0
    }
1548
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::BT601_6) {
1549
0
        return "BT601_6";
1550
0
    }
1551
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::SMPTE240M) {
1552
0
        return "SMPTE240M";
1553
0
    }
1554
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::BT2020) {
1555
0
        return "BT2020";
1556
0
    }
1557
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::BT2020CONSTANT) {
1558
0
        return "BT2020CONSTANT";
1559
0
    }
1560
0
    if (o == ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::OTHER) {
1561
0
        return "OTHER";
1562
0
    }
1563
0
    std::string os;
1564
0
    os += toHexString(static_cast<uint32_t>(o));
1565
0
    return os;
1566
0
}
1567
1568
0
static inline std::string toString(const ::android::hardware::media::omx::V1_0::ColorAspects& o) {
1569
0
    using ::android::hardware::toString;
1570
0
    std::string os;
1571
0
    os += "{";
1572
0
    os += ".range = ";
1573
0
    os += ::android::hardware::media::omx::V1_0::toString(o.range);
1574
0
    os += ", .primaries = ";
1575
0
    os += ::android::hardware::media::omx::V1_0::toString(o.primaries);
1576
0
    os += ", .transfer = ";
1577
0
    os += ::android::hardware::media::omx::V1_0::toString(o.transfer);
1578
0
    os += ", .matrixCoeffs = ";
1579
0
    os += ::android::hardware::media::omx::V1_0::toString(o.matrixCoeffs);
1580
0
    os += "}"; return os;
1581
0
}
1582
1583
0
static inline bool operator==(const ::android::hardware::media::omx::V1_0::ColorAspects& lhs, const ::android::hardware::media::omx::V1_0::ColorAspects& rhs) {
1584
0
    if (lhs.range != rhs.range) {
1585
0
        return false;
1586
0
    }
1587
0
    if (lhs.primaries != rhs.primaries) {
1588
0
        return false;
1589
0
    }
1590
0
    if (lhs.transfer != rhs.transfer) {
1591
0
        return false;
1592
0
    }
1593
0
    if (lhs.matrixCoeffs != rhs.matrixCoeffs) {
1594
0
        return false;
1595
0
    }
1596
0
    return true;
1597
0
}
1598
1599
0
static inline bool operator!=(const ::android::hardware::media::omx::V1_0::ColorAspects& lhs, const ::android::hardware::media::omx::V1_0::ColorAspects& rhs){
1600
0
    return !(lhs == rhs);
1601
0
}
1602
1603
1604
}  // namespace V1_0
1605
}  // namespace omx
1606
}  // namespace media
1607
}  // namespace hardware
1608
}  // namespace android
1609
1610
//
1611
// global type declarations for package
1612
//
1613
1614
namespace android {
1615
namespace hardware {
1616
namespace details {
1617
template<> constexpr std::array<::android::hardware::media::omx::V1_0::Status, 15> hidl_enum_values<::android::hardware::media::omx::V1_0::Status> = {
1618
    ::android::hardware::media::omx::V1_0::Status::OK,
1619
    ::android::hardware::media::omx::V1_0::Status::NO_ERROR,
1620
    ::android::hardware::media::omx::V1_0::Status::NAME_NOT_FOUND,
1621
    ::android::hardware::media::omx::V1_0::Status::WOULD_BLOCK,
1622
    ::android::hardware::media::omx::V1_0::Status::NO_MEMORY,
1623
    ::android::hardware::media::omx::V1_0::Status::ALREADY_EXISTS,
1624
    ::android::hardware::media::omx::V1_0::Status::NO_INIT,
1625
    ::android::hardware::media::omx::V1_0::Status::BAD_VALUE,
1626
    ::android::hardware::media::omx::V1_0::Status::DEAD_OBJECT,
1627
    ::android::hardware::media::omx::V1_0::Status::INVALID_OPERATION,
1628
    ::android::hardware::media::omx::V1_0::Status::TIMED_OUT,
1629
    ::android::hardware::media::omx::V1_0::Status::ERROR_UNSUPPORTED,
1630
    ::android::hardware::media::omx::V1_0::Status::UNKNOWN_ERROR,
1631
    ::android::hardware::media::omx::V1_0::Status::BUFFER_NEEDS_REALLOCATION,
1632
    ::android::hardware::media::omx::V1_0::Status::RELEASE_ALL_BUFFERS,
1633
};
1634
}  // namespace details
1635
}  // namespace hardware
1636
}  // namespace android
1637
1638
namespace android {
1639
namespace hardware {
1640
namespace details {
1641
template<> constexpr std::array<::android::hardware::media::omx::V1_0::Message::Type, 4> hidl_enum_values<::android::hardware::media::omx::V1_0::Message::Type> = {
1642
    ::android::hardware::media::omx::V1_0::Message::Type::EVENT,
1643
    ::android::hardware::media::omx::V1_0::Message::Type::EMPTY_BUFFER_DONE,
1644
    ::android::hardware::media::omx::V1_0::Message::Type::FILL_BUFFER_DONE,
1645
    ::android::hardware::media::omx::V1_0::Message::Type::FRAME_RENDERED,
1646
};
1647
}  // namespace details
1648
}  // namespace hardware
1649
}  // namespace android
1650
1651
namespace android {
1652
namespace hardware {
1653
namespace details {
1654
template<> constexpr std::array<::android::hardware::media::omx::V1_0::CodecBuffer::Type, 5> hidl_enum_values<::android::hardware::media::omx::V1_0::CodecBuffer::Type> = {
1655
    ::android::hardware::media::omx::V1_0::CodecBuffer::Type::INVALID,
1656
    ::android::hardware::media::omx::V1_0::CodecBuffer::Type::PRESET,
1657
    ::android::hardware::media::omx::V1_0::CodecBuffer::Type::SHARED_MEM,
1658
    ::android::hardware::media::omx::V1_0::CodecBuffer::Type::ANW_BUFFER,
1659
    ::android::hardware::media::omx::V1_0::CodecBuffer::Type::NATIVE_HANDLE,
1660
};
1661
}  // namespace details
1662
}  // namespace hardware
1663
}  // namespace android
1664
1665
namespace android {
1666
namespace hardware {
1667
namespace details {
1668
template<> constexpr std::array<::android::hardware::media::omx::V1_0::PortMode, 9> hidl_enum_values<::android::hardware::media::omx::V1_0::PortMode> = {
1669
    ::android::hardware::media::omx::V1_0::PortMode::PRESET_START,
1670
    ::android::hardware::media::omx::V1_0::PortMode::PRESET_BYTE_BUFFER,
1671
    ::android::hardware::media::omx::V1_0::PortMode::PRESET_ANW_BUFFER,
1672
    ::android::hardware::media::omx::V1_0::PortMode::PRESET_SECURE_BUFFER,
1673
    ::android::hardware::media::omx::V1_0::PortMode::PRESET_END,
1674
    ::android::hardware::media::omx::V1_0::PortMode::DYNAMIC_START,
1675
    ::android::hardware::media::omx::V1_0::PortMode::DYNAMIC_ANW_BUFFER,
1676
    ::android::hardware::media::omx::V1_0::PortMode::DYNAMIC_NATIVE_HANDLE,
1677
    ::android::hardware::media::omx::V1_0::PortMode::DYNAMIC_END,
1678
};
1679
}  // namespace details
1680
}  // namespace hardware
1681
}  // namespace android
1682
1683
namespace android {
1684
namespace hardware {
1685
namespace details {
1686
template<> constexpr std::array<::android::hardware::media::omx::V1_0::ColorAspects::Range, 4> hidl_enum_values<::android::hardware::media::omx::V1_0::ColorAspects::Range> = {
1687
    ::android::hardware::media::omx::V1_0::ColorAspects::Range::UNSPECIFIED,
1688
    ::android::hardware::media::omx::V1_0::ColorAspects::Range::FULL,
1689
    ::android::hardware::media::omx::V1_0::ColorAspects::Range::LIMITED,
1690
    ::android::hardware::media::omx::V1_0::ColorAspects::Range::OTHER,
1691
};
1692
}  // namespace details
1693
}  // namespace hardware
1694
}  // namespace android
1695
1696
namespace android {
1697
namespace hardware {
1698
namespace details {
1699
template<> constexpr std::array<::android::hardware::media::omx::V1_0::ColorAspects::Primaries, 8> hidl_enum_values<::android::hardware::media::omx::V1_0::ColorAspects::Primaries> = {
1700
    ::android::hardware::media::omx::V1_0::ColorAspects::Primaries::UNSPECIFIED,
1701
    ::android::hardware::media::omx::V1_0::ColorAspects::Primaries::BT709_5,
1702
    ::android::hardware::media::omx::V1_0::ColorAspects::Primaries::BT470_6M,
1703
    ::android::hardware::media::omx::V1_0::ColorAspects::Primaries::BT601_6_625,
1704
    ::android::hardware::media::omx::V1_0::ColorAspects::Primaries::BT601_6_525,
1705
    ::android::hardware::media::omx::V1_0::ColorAspects::Primaries::GENERIC_FILM,
1706
    ::android::hardware::media::omx::V1_0::ColorAspects::Primaries::BT2020,
1707
    ::android::hardware::media::omx::V1_0::ColorAspects::Primaries::OTHER,
1708
};
1709
}  // namespace details
1710
}  // namespace hardware
1711
}  // namespace android
1712
1713
namespace android {
1714
namespace hardware {
1715
namespace details {
1716
template<> constexpr std::array<::android::hardware::media::omx::V1_0::ColorAspects::Transfer, 13> hidl_enum_values<::android::hardware::media::omx::V1_0::ColorAspects::Transfer> = {
1717
    ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::UNSPECIFIED,
1718
    ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::LINEAR,
1719
    ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::SRGB,
1720
    ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::SMPTE170M,
1721
    ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::GAMMA22,
1722
    ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::GAMMA28,
1723
    ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::ST2084,
1724
    ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::HLG,
1725
    ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::SMPTE240M,
1726
    ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::XVYCC,
1727
    ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::BT1361,
1728
    ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::ST428,
1729
    ::android::hardware::media::omx::V1_0::ColorAspects::Transfer::OTHER,
1730
};
1731
}  // namespace details
1732
}  // namespace hardware
1733
}  // namespace android
1734
1735
namespace android {
1736
namespace hardware {
1737
namespace details {
1738
template<> constexpr std::array<::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs, 8> hidl_enum_values<::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs> = {
1739
    ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::UNSPECIFIED,
1740
    ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::BT709_5,
1741
    ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::BT470_6M,
1742
    ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::BT601_6,
1743
    ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::SMPTE240M,
1744
    ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::BT2020,
1745
    ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::BT2020CONSTANT,
1746
    ::android::hardware::media::omx::V1_0::ColorAspects::MatrixCoeffs::OTHER,
1747
};
1748
}  // namespace details
1749
}  // namespace hardware
1750
}  // namespace android
1751
1752
1753
#endif  // HIDL_GENERATED_ANDROID_HARDWARE_MEDIA_OMX_V1_0_TYPES_H
/proc/self/cwd/out/soong/.intermediates/system/libhidl/transport/base/1.0/android.hidl.base@1.0_genc++_headers/gen/android/hidl/base/1.0/IBase.h
Line
Count
Source (jump to first uncovered line)
1
#ifndef HIDL_GENERATED_ANDROID_HIDL_BASE_V1_0_IBASE_H
2
#define HIDL_GENERATED_ANDROID_HIDL_BASE_V1_0_IBASE_H
3
4
#include <android/hidl/base/1.0/types.h>
5
6
// skipped #include IServiceNotification.h
7
8
#include <hidl/HidlSupport.h>
9
#include <hidl/MQDescriptor.h>
10
#include <hidl/Status.h>
11
#include <utils/NativeHandle.h>
12
#include <utils/misc.h>
13
14
namespace android {
15
namespace hidl {
16
namespace base {
17
namespace V1_0 {
18
19
struct IBase : virtual public ::android::RefBase {
20
    typedef android::hardware::details::i_tag _hidl_tag;
21
22
    // Forward declaration for forward reference support:
23
24
0
    virtual bool isRemote() const { return false; }
25
26
27
    using interfaceChain_cb = std::function<void(const ::android::hardware::hidl_vec<::android::hardware::hidl_string>& descriptors)>;
28
    virtual ::android::hardware::Return<void> interfaceChain(interfaceChain_cb _hidl_cb);
29
30
    virtual ::android::hardware::Return<void> debug(const ::android::hardware::hidl_handle& fd, const ::android::hardware::hidl_vec<::android::hardware::hidl_string>& options);
31
32
    using interfaceDescriptor_cb = std::function<void(const ::android::hardware::hidl_string& descriptor)>;
33
    virtual ::android::hardware::Return<void> interfaceDescriptor(interfaceDescriptor_cb _hidl_cb);
34
35
    using getHashChain_cb = std::function<void(const ::android::hardware::hidl_vec<::android::hardware::hidl_array<uint8_t, 32>>& hashchain)>;
36
    virtual ::android::hardware::Return<void> getHashChain(getHashChain_cb _hidl_cb);
37
38
    virtual ::android::hardware::Return<void> setHALInstrumentation();
39
40
    virtual ::android::hardware::Return<bool> linkToDeath(const ::android::sp<::android::hardware::hidl_death_recipient>& recipient, uint64_t cookie);
41
42
    virtual ::android::hardware::Return<void> ping();
43
44
    using getDebugInfo_cb = std::function<void(const ::android::hidl::base::V1_0::DebugInfo& info)>;
45
    virtual ::android::hardware::Return<void> getDebugInfo(getDebugInfo_cb _hidl_cb);
46
47
    virtual ::android::hardware::Return<void> notifySyspropsChanged();
48
49
    virtual ::android::hardware::Return<bool> unlinkToDeath(const ::android::sp<::android::hardware::hidl_death_recipient>& recipient);
50
    // cast static functions
51
    static ::android::hardware::Return<::android::sp<::android::hidl::base::V1_0::IBase>> castFrom(const ::android::sp<::android::hidl::base::V1_0::IBase>& parent, bool emitError = false);
52
53
    static const char* descriptor;
54
55
    // skipped getService, registerAsService, registerForNotifications
56
57
};
58
59
//
60
// type declarations for package
61
//
62
63
static inline std::string toString(const ::android::sp<::android::hidl::base::V1_0::IBase>& o);
64
65
//
66
// type header definitions for package
67
//
68
69
0
static inline std::string toString(const ::android::sp<::android::hidl::base::V1_0::IBase>& o) {
70
0
    std::string os = "[class or subclass of ";
71
0
    os += ::android::hidl::base::V1_0::IBase::descriptor;
72
0
    os += "]";
73
0
    os += o->isRemote() ? "@remote" : "@local";
74
0
    return os;
75
0
}
76
77
78
}  // namespace V1_0
79
}  // namespace base
80
}  // namespace hidl
81
}  // namespace android
82
83
//
84
// global type declarations for package
85
//
86
87
88
#endif  // HIDL_GENERATED_ANDROID_HIDL_BASE_V1_0_IBASE_H
/proc/self/cwd/out/soong/.intermediates/system/libhidl/transport/base/1.0/android.hidl.base@1.0_genc++_headers/gen/android/hidl/base/1.0/types.h
Line
Count
Source (jump to first uncovered line)
1
#ifndef HIDL_GENERATED_ANDROID_HIDL_BASE_V1_0_TYPES_H
2
#define HIDL_GENERATED_ANDROID_HIDL_BASE_V1_0_TYPES_H
3
4
#include <hidl/HidlSupport.h>
5
#include <hidl/MQDescriptor.h>
6
#include <utils/NativeHandle.h>
7
#include <utils/misc.h>
8
9
namespace android {
10
namespace hidl {
11
namespace base {
12
namespace V1_0 {
13
14
// Forward declaration for forward reference support:
15
struct DebugInfo;
16
17
struct DebugInfo final {
18
    // Forward declaration for forward reference support:
19
    enum class Architecture : int32_t;
20
21
    enum class Architecture : int32_t {
22
        UNKNOWN = 0,
23
        IS_64BIT = 1 /* (::android::hidl::base::V1_0::DebugInfo::Architecture.UNKNOWN implicitly + 1) */,
24
        IS_32BIT = 2 /* (::android::hidl::base::V1_0::DebugInfo::Architecture.IS_64BIT implicitly + 1) */,
25
    };
26
27
    int32_t pid __attribute__ ((aligned(4)));
28
    uint64_t ptr __attribute__ ((aligned(8)));
29
    ::android::hidl::base::V1_0::DebugInfo::Architecture arch __attribute__ ((aligned(4)));
30
};
31
32
static_assert(offsetof(::android::hidl::base::V1_0::DebugInfo, pid) == 0, "wrong offset");
33
static_assert(offsetof(::android::hidl::base::V1_0::DebugInfo, ptr) == 8, "wrong offset");
34
static_assert(offsetof(::android::hidl::base::V1_0::DebugInfo, arch) == 16, "wrong offset");
35
static_assert(sizeof(::android::hidl::base::V1_0::DebugInfo) == 24, "wrong size");
36
static_assert(__alignof(::android::hidl::base::V1_0::DebugInfo) == 8, "wrong alignment");
37
38
//
39
// type declarations for package
40
//
41
42
template<typename>
43
static inline std::string toString(int32_t o);
44
static inline std::string toString(::android::hidl::base::V1_0::DebugInfo::Architecture o);
45
46
0
constexpr int32_t operator|(const ::android::hidl::base::V1_0::DebugInfo::Architecture lhs, const ::android::hidl::base::V1_0::DebugInfo::Architecture rhs) {
47
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) | static_cast<int32_t>(rhs));
48
0
}
49
0
constexpr int32_t operator|(const int32_t lhs, const ::android::hidl::base::V1_0::DebugInfo::Architecture rhs) {
50
0
    return static_cast<int32_t>(lhs | static_cast<int32_t>(rhs));
51
0
}
52
0
constexpr int32_t operator|(const ::android::hidl::base::V1_0::DebugInfo::Architecture lhs, const int32_t rhs) {
53
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) | rhs);
54
0
}
55
0
constexpr int32_t operator&(const ::android::hidl::base::V1_0::DebugInfo::Architecture lhs, const ::android::hidl::base::V1_0::DebugInfo::Architecture rhs) {
56
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) & static_cast<int32_t>(rhs));
57
0
}
58
0
constexpr int32_t operator&(const int32_t lhs, const ::android::hidl::base::V1_0::DebugInfo::Architecture rhs) {
59
0
    return static_cast<int32_t>(lhs & static_cast<int32_t>(rhs));
60
0
}
61
0
constexpr int32_t operator&(const ::android::hidl::base::V1_0::DebugInfo::Architecture lhs, const int32_t rhs) {
62
0
    return static_cast<int32_t>(static_cast<int32_t>(lhs) & rhs);
63
0
}
64
0
constexpr int32_t &operator|=(int32_t& v, const ::android::hidl::base::V1_0::DebugInfo::Architecture e) {
65
0
    v |= static_cast<int32_t>(e);
66
0
    return v;
67
0
}
68
0
constexpr int32_t &operator&=(int32_t& v, const ::android::hidl::base::V1_0::DebugInfo::Architecture e) {
69
0
    v &= static_cast<int32_t>(e);
70
0
    return v;
71
0
}
72
73
static inline std::string toString(const ::android::hidl::base::V1_0::DebugInfo& o);
74
static inline bool operator==(const ::android::hidl::base::V1_0::DebugInfo& lhs, const ::android::hidl::base::V1_0::DebugInfo& rhs);
75
static inline bool operator!=(const ::android::hidl::base::V1_0::DebugInfo& lhs, const ::android::hidl::base::V1_0::DebugInfo& rhs);
76
77
//
78
// type header definitions for package
79
//
80
81
template<>
82
0
inline std::string toString<::android::hidl::base::V1_0::DebugInfo::Architecture>(int32_t o) {
83
0
    using ::android::hardware::details::toHexString;
84
0
    std::string os;
85
0
    ::android::hardware::hidl_bitfield<::android::hidl::base::V1_0::DebugInfo::Architecture> flipped = 0;
86
0
    bool first = true;
87
0
    if ((o & ::android::hidl::base::V1_0::DebugInfo::Architecture::UNKNOWN) == static_cast<int32_t>(::android::hidl::base::V1_0::DebugInfo::Architecture::UNKNOWN)) {
88
0
        os += (first ? "" : " | ");
89
0
        os += "UNKNOWN";
90
0
        first = false;
91
0
        flipped |= ::android::hidl::base::V1_0::DebugInfo::Architecture::UNKNOWN;
92
0
    }
93
0
    if ((o & ::android::hidl::base::V1_0::DebugInfo::Architecture::IS_64BIT) == static_cast<int32_t>(::android::hidl::base::V1_0::DebugInfo::Architecture::IS_64BIT)) {
94
0
        os += (first ? "" : " | ");
95
0
        os += "IS_64BIT";
96
0
        first = false;
97
0
        flipped |= ::android::hidl::base::V1_0::DebugInfo::Architecture::IS_64BIT;
98
0
    }
99
0
    if ((o & ::android::hidl::base::V1_0::DebugInfo::Architecture::IS_32BIT) == static_cast<int32_t>(::android::hidl::base::V1_0::DebugInfo::Architecture::IS_32BIT)) {
100
0
        os += (first ? "" : " | ");
101
0
        os += "IS_32BIT";
102
0
        first = false;
103
0
        flipped |= ::android::hidl::base::V1_0::DebugInfo::Architecture::IS_32BIT;
104
0
    }
105
0
    if (o != flipped) {
106
0
        os += (first ? "" : " | ");
107
0
        os += toHexString(o & (~flipped));
108
0
    }os += " (";
109
0
    os += toHexString(o);
110
0
    os += ")";
111
0
    return os;
112
0
}
113
114
0
static inline std::string toString(::android::hidl::base::V1_0::DebugInfo::Architecture o) {
115
0
    using ::android::hardware::details::toHexString;
116
0
    if (o == ::android::hidl::base::V1_0::DebugInfo::Architecture::UNKNOWN) {
117
0
        return "UNKNOWN";
118
0
    }
119
0
    if (o == ::android::hidl::base::V1_0::DebugInfo::Architecture::IS_64BIT) {
120
0
        return "IS_64BIT";
121
0
    }
122
0
    if (o == ::android::hidl::base::V1_0::DebugInfo::Architecture::IS_32BIT) {
123
0
        return "IS_32BIT";
124
0
    }
125
0
    std::string os;
126
0
    os += toHexString(static_cast<int32_t>(o));
127
0
    return os;
128
0
}
129
130
0
static inline std::string toString(const ::android::hidl::base::V1_0::DebugInfo& o) {
131
0
    using ::android::hardware::toString;
132
0
    std::string os;
133
0
    os += "{";
134
0
    os += ".pid = ";
135
0
    os += ::android::hardware::toString(o.pid);
136
0
    os += ", .ptr = ";
137
0
    os += ::android::hardware::toString(o.ptr);
138
0
    os += ", .arch = ";
139
0
    os += ::android::hidl::base::V1_0::toString(o.arch);
140
0
    os += "}"; return os;
141
0
}
142
143
0
static inline bool operator==(const ::android::hidl::base::V1_0::DebugInfo& lhs, const ::android::hidl::base::V1_0::DebugInfo& rhs) {
144
0
    if (lhs.pid != rhs.pid) {
145
0
        return false;
146
0
    }
147
0
    if (lhs.ptr != rhs.ptr) {
148
0
        return false;
149
0
    }
150
0
    if (lhs.arch != rhs.arch) {
151
0
        return false;
152
0
    }
153
0
    return true;
154
0
}
155
156
0
static inline bool operator!=(const ::android::hidl::base::V1_0::DebugInfo& lhs, const ::android::hidl::base::V1_0::DebugInfo& rhs){
157
0
    return !(lhs == rhs);
158
0
}
159
160
161
}  // namespace V1_0
162
}  // namespace base
163
}  // namespace hidl
164
}  // namespace android
165
166
//
167
// global type declarations for package
168
//
169
170
namespace android {
171
namespace hardware {
172
namespace details {
173
template<> constexpr std::array<::android::hidl::base::V1_0::DebugInfo::Architecture, 3> hidl_enum_values<::android::hidl::base::V1_0::DebugInfo::Architecture> = {
174
    ::android::hidl::base::V1_0::DebugInfo::Architecture::UNKNOWN,
175
    ::android::hidl::base::V1_0::DebugInfo::Architecture::IS_64BIT,
176
    ::android::hidl::base::V1_0::DebugInfo::Architecture::IS_32BIT,
177
};
178
}  // namespace details
179
}  // namespace hardware
180
}  // namespace android
181
182
183
#endif  // HIDL_GENERATED_ANDROID_HIDL_BASE_V1_0_TYPES_H
/proc/self/cwd/out/soong/.intermediates/system/libhidl/transport/manager/1.0/android.hidl.manager@1.0_genc++_headers/gen/android/hidl/manager/1.0/IServiceNotification.h
Line
Count
Source (jump to first uncovered line)
1
#ifndef HIDL_GENERATED_ANDROID_HIDL_MANAGER_V1_0_ISERVICENOTIFICATION_H
2
#define HIDL_GENERATED_ANDROID_HIDL_MANAGER_V1_0_ISERVICENOTIFICATION_H
3
4
#include <android/hidl/base/1.0/IBase.h>
5
6
#include <android/hidl/manager/1.0/IServiceNotification.h>
7
8
#include <hidl/HidlSupport.h>
9
#include <hidl/MQDescriptor.h>
10
#include <hidl/Status.h>
11
#include <utils/NativeHandle.h>
12
#include <utils/misc.h>
13
14
namespace android {
15
namespace hidl {
16
namespace manager {
17
namespace V1_0 {
18
19
struct IServiceNotification : public ::android::hidl::base::V1_0::IBase {
20
    typedef android::hardware::details::i_tag _hidl_tag;
21
22
    // Forward declaration for forward reference support:
23
24
0
    virtual bool isRemote() const override { return false; }
25
26
27
    /**
28
     * Must be called when a service is registered.
29
     * 
30
     * @param fqName         Fully-qualified instance name (see IServiceManager)
31
     * @param preexisting    If true, this means the registration was
32
     *                       pre-existing at the time this IServiceNotification
33
     *                       object is itself registered. Otherwise, this means
34
     *                       onRegistration is triggered by a newly registered
35
     *                       service.
36
     */
37
    virtual ::android::hardware::Return<void> onRegistration(const ::android::hardware::hidl_string& fqName, const ::android::hardware::hidl_string& name, bool preexisting) = 0;
38
39
    using interfaceChain_cb = std::function<void(const ::android::hardware::hidl_vec<::android::hardware::hidl_string>& descriptors)>;
40
    virtual ::android::hardware::Return<void> interfaceChain(interfaceChain_cb _hidl_cb) override;
41
42
    virtual ::android::hardware::Return<void> debug(const ::android::hardware::hidl_handle& fd, const ::android::hardware::hidl_vec<::android::hardware::hidl_string>& options) override;
43
44
    using interfaceDescriptor_cb = std::function<void(const ::android::hardware::hidl_string& descriptor)>;
45
    virtual ::android::hardware::Return<void> interfaceDescriptor(interfaceDescriptor_cb _hidl_cb) override;
46
47
    using getHashChain_cb = std::function<void(const ::android::hardware::hidl_vec<::android::hardware::hidl_array<uint8_t, 32>>& hashchain)>;
48
    virtual ::android::hardware::Return<void> getHashChain(getHashChain_cb _hidl_cb) override;
49
50
    virtual ::android::hardware::Return<void> setHALInstrumentation() override;
51
52
    virtual ::android::hardware::Return<bool> linkToDeath(const ::android::sp<::android::hardware::hidl_death_recipient>& recipient, uint64_t cookie) override;
53
54
    virtual ::android::hardware::Return<void> ping() override;
55
56
    using getDebugInfo_cb = std::function<void(const ::android::hidl::base::V1_0::DebugInfo& info)>;
57
    virtual ::android::hardware::Return<void> getDebugInfo(getDebugInfo_cb _hidl_cb) override;
58
59
    virtual ::android::hardware::Return<void> notifySyspropsChanged() override;
60
61
    virtual ::android::hardware::Return<bool> unlinkToDeath(const ::android::sp<::android::hardware::hidl_death_recipient>& recipient) override;
62
    // cast static functions
63
    static ::android::hardware::Return<::android::sp<::android::hidl::manager::V1_0::IServiceNotification>> castFrom(const ::android::sp<::android::hidl::manager::V1_0::IServiceNotification>& parent, bool emitError = false);
64
    static ::android::hardware::Return<::android::sp<::android::hidl::manager::V1_0::IServiceNotification>> castFrom(const ::android::sp<::android::hidl::base::V1_0::IBase>& parent, bool emitError = false);
65
66
    static const char* descriptor;
67
68
    static ::android::sp<IServiceNotification> tryGetService(const std::string &serviceName="default", bool getStub=false);
69
0
    static ::android::sp<IServiceNotification> tryGetService(const char serviceName[], bool getStub=false)  { std::string str(serviceName ? serviceName : "");      return tryGetService(str, getStub); }
70
0
    static ::android::sp<IServiceNotification> tryGetService(const ::android::hardware::hidl_string& serviceName, bool getStub=false)  { std::string str(serviceName.c_str());      return tryGetService(str, getStub); }
71
0
    static ::android::sp<IServiceNotification> tryGetService(bool getStub) { return tryGetService("default", getStub); }
72
    static ::android::sp<IServiceNotification> getService(const std::string &serviceName="default", bool getStub=false);
73
0
    static ::android::sp<IServiceNotification> getService(const char serviceName[], bool getStub=false)  { std::string str(serviceName ? serviceName : "");      return getService(str, getStub); }
74
0
    static ::android::sp<IServiceNotification> getService(const ::android::hardware::hidl_string& serviceName, bool getStub=false)  { std::string str(serviceName.c_str());      return getService(str, getStub); }
75
0
    static ::android::sp<IServiceNotification> getService(bool getStub) { return getService("default", getStub); }
76
    __attribute__ ((warn_unused_result))::android::status_t registerAsService(const std::string &serviceName="default");
77
    static bool registerForNotifications(
78
            const std::string &serviceName,
79
            const ::android::sp<::android::hidl::manager::V1_0::IServiceNotification> &notification);
80
};
81
82
//
83
// type declarations for package
84
//
85
86
static inline std::string toString(const ::android::sp<::android::hidl::manager::V1_0::IServiceNotification>& o);
87
88
//
89
// type header definitions for package
90
//
91
92
0
static inline std::string toString(const ::android::sp<::android::hidl::manager::V1_0::IServiceNotification>& o) {
93
0
    std::string os = "[class or subclass of ";
94
0
    os += ::android::hidl::manager::V1_0::IServiceNotification::descriptor;
95
0
    os += "]";
96
0
    os += o->isRemote() ? "@remote" : "@local";
97
0
    return os;
98
0
}
99
100
101
}  // namespace V1_0
102
}  // namespace manager
103
}  // namespace hidl
104
}  // namespace android
105
106
//
107
// global type declarations for package
108
//
109
110
111
#endif  // HIDL_GENERATED_ANDROID_HIDL_MANAGER_V1_0_ISERVICENOTIFICATION_H
/proc/self/cwd/system/core/base/include/android-base/unique_fd.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2015 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#pragma once
18
19
#include <fcntl.h>
20
21
#if !defined(_WIN32)
22
#include <dirent.h>
23
#include <sys/socket.h>
24
#endif
25
26
#include <stdio.h>
27
#include <sys/types.h>
28
#include <unistd.h>
29
30
// DO NOT INCLUDE OTHER LIBBASE HEADERS!
31
// This file gets used in libbinder, and libbinder is used everywhere.
32
// Including other headers from libbase frequently results in inclusion of
33
// android-base/macros.h, which causes macro collisions.
34
35
// Container for a file descriptor that automatically closes the descriptor as
36
// it goes out of scope.
37
//
38
//      unique_fd ufd(open("/some/path", "r"));
39
//      if (ufd.get() == -1) return error;
40
//
41
//      // Do something useful, possibly including 'return'.
42
//
43
//      return 0; // Descriptor is closed for you.
44
//
45
// unique_fd is also known as ScopedFd/ScopedFD/scoped_fd; mentioned here to help
46
// you find this class if you're searching for one of those names.
47
48
#if defined(__BIONIC__)
49
#include <android/fdsan.h>
50
#endif
51
52
namespace android {
53
namespace base {
54
55
struct DefaultCloser {
56
#if defined(__BIONIC__)
57
0
  static void Tag(int fd, void* old_addr, void* new_addr) {
58
0
    if (android_fdsan_exchange_owner_tag) {
59
0
      uint64_t old_tag = android_fdsan_create_owner_tag(ANDROID_FDSAN_OWNER_TYPE_UNIQUE_FD,
60
0
                                                        reinterpret_cast<uint64_t>(old_addr));
61
0
      uint64_t new_tag = android_fdsan_create_owner_tag(ANDROID_FDSAN_OWNER_TYPE_UNIQUE_FD,
62
0
                                                        reinterpret_cast<uint64_t>(new_addr));
63
0
      android_fdsan_exchange_owner_tag(fd, old_tag, new_tag);
64
0
    }
65
0
  }
66
0
  static void Close(int fd, void* addr) {
67
0
    if (android_fdsan_close_with_tag) {
68
0
      uint64_t tag = android_fdsan_create_owner_tag(ANDROID_FDSAN_OWNER_TYPE_UNIQUE_FD,
69
0
                                                    reinterpret_cast<uint64_t>(addr));
70
0
      android_fdsan_close_with_tag(fd, tag);
71
0
    } else {
72
0
      close(fd);
73
0
    }
74
0
  }
75
#else
76
  static void Close(int fd) {
77
    // Even if close(2) fails with EINTR, the fd will have been closed.
78
    // Using TEMP_FAILURE_RETRY will either lead to EBADF or closing someone
79
    // else's fd.
80
    // http://lkml.indiana.edu/hypermail/linux/kernel/0509.1/0877.html
81
    ::close(fd);
82
  }
83
#endif
84
};
85
86
template <typename Closer>
87
class unique_fd_impl final {
88
 public:
89
  unique_fd_impl() {}
90
91
  explicit unique_fd_impl(int fd) { reset(fd); }
92
  ~unique_fd_impl() { reset(); }
93
94
  unique_fd_impl(unique_fd_impl&& other) noexcept { reset(other.release()); }
95
  unique_fd_impl& operator=(unique_fd_impl&& s) noexcept {
96
    int fd = s.fd_;
97
    s.fd_ = -1;
98
    reset(fd, &s);
99
    return *this;
100
  }
101
102
  void reset(int new_value = -1) { reset(new_value, nullptr); }
103
104
  int get() const { return fd_; }
105
  operator int() const { return get(); }
106
107
0
  int release() __attribute__((warn_unused_result)) {
108
0
    tag(fd_, this, nullptr);
109
0
    int ret = fd_;
110
0
    fd_ = -1;
111
0
    return ret;
112
0
  }
113
114
 private:
115
  void reset(int new_value, void* previous_tag) {
116
    if (fd_ != -1) {
117
      close(fd_, this);
118
    }
119
120
    fd_ = new_value;
121
    if (new_value != -1) {
122
      tag(new_value, previous_tag, this);
123
    }
124
  }
125
126
  int fd_ = -1;
127
128
  // Template magic to use Closer::Tag if available, and do nothing if not.
129
  // If Closer::Tag exists, this implementation is preferred, because int is a better match.
130
  // If not, this implementation is SFINAEd away, and the no-op below is the only one that exists.
131
  template <typename T = Closer>
132
  static auto tag(int fd, void* old_tag, void* new_tag)
133
0
      -> decltype(T::Tag(fd, old_tag, new_tag), void()) {
134
0
    T::Tag(fd, old_tag, new_tag);
135
0
  }
136
137
  template <typename T = Closer>
138
  static void tag(long, void*, void*) {
139
    // No-op.
140
  }
141
142
  // Same as above, to select between Closer::Close(int) and Closer::Close(int, void*).
143
  template <typename T = Closer>
144
  static auto close(int fd, void* tag_value) -> decltype(T::Close(fd, tag_value), void()) {
145
    T::Close(fd, tag_value);
146
  }
147
148
  template <typename T = Closer>
149
  static auto close(int fd, void*) -> decltype(T::Close(fd), void()) {
150
    T::Close(fd);
151
  }
152
153
  unique_fd_impl(const unique_fd_impl&);
154
  void operator=(const unique_fd_impl&);
155
};
156
157
using unique_fd = unique_fd_impl<DefaultCloser>;
158
159
#if !defined(_WIN32)
160
161
// Inline functions, so that they can be used header-only.
162
template <typename Closer>
163
inline bool Pipe(unique_fd_impl<Closer>* read, unique_fd_impl<Closer>* write) {
164
  int pipefd[2];
165
166
#if defined(__linux__)
167
  if (pipe2(pipefd, O_CLOEXEC) != 0) {
168
    return false;
169
  }
170
#else  // defined(__APPLE__)
171
  if (pipe(pipefd) != 0) {
172
    return false;
173
  }
174
175
  if (fcntl(pipefd[0], F_SETFD, FD_CLOEXEC) != 0 || fcntl(pipefd[1], F_SETFD, FD_CLOEXEC) != 0) {
176
    close(pipefd[0]);
177
    close(pipefd[1]);
178
    return false;
179
  }
180
#endif
181
182
  read->reset(pipefd[0]);
183
  write->reset(pipefd[1]);
184
  return true;
185
}
186
187
template <typename Closer>
188
inline bool Socketpair(int domain, int type, int protocol, unique_fd_impl<Closer>* left,
189
                       unique_fd_impl<Closer>* right) {
190
  int sockfd[2];
191
  if (socketpair(domain, type, protocol, sockfd) != 0) {
192
    return false;
193
  }
194
  left->reset(sockfd[0]);
195
  right->reset(sockfd[1]);
196
  return true;
197
}
198
199
template <typename Closer>
200
inline bool Socketpair(int type, unique_fd_impl<Closer>* left, unique_fd_impl<Closer>* right) {
201
  return Socketpair(AF_UNIX, type, 0, left, right);
202
}
203
204
// Using fdopen with unique_fd correctly is more annoying than it should be,
205
// because fdopen doesn't close the file descriptor received upon failure.
206
0
inline FILE* Fdopen(unique_fd&& ufd, const char* mode) {
207
0
  int fd = ufd.release();
208
0
  FILE* file = fdopen(fd, mode);
209
0
  if (!file) {
210
0
    close(fd);
211
0
  }
212
0
  return file;
213
0
}
214
215
// Using fdopendir with unique_fd correctly is more annoying than it should be,
216
// because fdopen doesn't close the file descriptor received upon failure.
217
0
inline DIR* Fdopendir(unique_fd&& ufd) {
218
0
  int fd = ufd.release();
219
0
  DIR* dir = fdopendir(fd);
220
0
  if (dir == nullptr) {
221
0
    close(fd);
222
0
  }
223
0
  return dir;
224
0
}
225
226
#endif  // !defined(_WIN32)
227
228
}  // namespace base
229
}  // namespace android
230
231
template <typename T>
232
int close(const android::base::unique_fd_impl<T>&)
233
    __attribute__((__unavailable__("close called on unique_fd")));
/proc/self/cwd/system/core/liblog/include/log/log_main.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2005-2017 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef _LIBS_LOG_LOG_MAIN_H
18
#define _LIBS_LOG_LOG_MAIN_H
19
20
#include <stdbool.h>
21
22
#include <android/log.h>
23
#include <sys/cdefs.h>
24
25
__BEGIN_DECLS
26
27
/*
28
 * Normally we strip the effects of ALOGV (VERBOSE messages),
29
 * LOG_FATAL and LOG_FATAL_IF (FATAL assert messages) from the
30
 * release builds be defining NDEBUG.  You can modify this (for
31
 * example with "#define LOG_NDEBUG 0" at the top of your source
32
 * file) to change that behavior.
33
 */
34
35
#ifndef LOG_NDEBUG
36
#ifdef NDEBUG
37
#define LOG_NDEBUG 1
38
#else
39
#define LOG_NDEBUG 0
40
#endif
41
#endif
42
43
/* --------------------------------------------------------------------- */
44
45
/*
46
 * This file uses ", ## __VA_ARGS__" zero-argument token pasting to
47
 * work around issues with debug-only syntax errors in assertions
48
 * that are missing format strings.  See commit
49
 * 19299904343daf191267564fe32e6cd5c165cd42
50
 */
51
#if defined(__clang__)
52
#pragma clang diagnostic push
53
#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
54
#endif
55
56
/*
57
 * Use __VA_ARGS__ if running a static analyzer,
58
 * to avoid warnings of unused variables in __VA_ARGS__.
59
 * Use contexpr function in C++ mode, so these macros can be used
60
 * in other constexpr functions without warning.
61
 */
62
#ifdef __clang_analyzer__
63
#ifdef __cplusplus
64
extern "C++" {
65
template <typename... Ts>
66
constexpr int __fake_use_va_args(Ts...) {
67
  return 0;
68
}
69
}
70
#else
71
extern int __fake_use_va_args(int, ...);
72
#endif /* __cplusplus */
73
#define __FAKE_USE_VA_ARGS(...) ((void)__fake_use_va_args(0, ##__VA_ARGS__))
74
#else
75
18
#define __FAKE_USE_VA_ARGS(...) ((void)(0))
76
#endif /* __clang_analyzer__ */
77
78
#ifndef __predict_false
79
#define __predict_false(exp) __builtin_expect((exp) != 0, 0)
80
#endif
81
82
#define android_writeLog(prio, tag, text) __android_log_write(prio, tag, text)
83
84
#define android_printLog(prio, tag, ...) \
85
0
  __android_log_print(prio, tag, __VA_ARGS__)
86
87
#define android_vprintLog(prio, cond, tag, ...) \
88
  __android_log_vprint(prio, tag, __VA_ARGS__)
89
90
/*
91
 * Log macro that allows you to specify a number for the priority.
92
 */
93
#ifndef LOG_PRI
94
0
#define LOG_PRI(priority, tag, ...) android_printLog(priority, tag, __VA_ARGS__)
95
#endif
96
97
/*
98
 * Log macro that allows you to pass in a varargs ("args" is a va_list).
99
 */
100
#ifndef LOG_PRI_VA
101
#define LOG_PRI_VA(priority, tag, fmt, args) \
102
  android_vprintLog(priority, NULL, tag, fmt, args)
103
#endif
104
105
/* --------------------------------------------------------------------- */
106
107
/* XXX Macros to work around syntax errors in places where format string
108
 * arg is not passed to ALOG_ASSERT, LOG_ALWAYS_FATAL or LOG_ALWAYS_FATAL_IF
109
 * (happens only in debug builds).
110
 */
111
112
/* Returns 2nd arg.  Used to substitute default value if caller's vararg list
113
 * is empty.
114
 */
115
0
#define __android_second(dummy, second, ...) second
116
117
/* If passed multiple args, returns ',' followed by all but 1st arg, otherwise
118
 * returns nothing.
119
 */
120
0
#define __android_rest(first, ...) , ##__VA_ARGS__
121
122
#define android_printAssert(cond, tag, ...)                     \
123
0
  __android_log_assert(cond, tag,                               \
124
0
                       __android_second(0, ##__VA_ARGS__, NULL) \
125
0
                           __android_rest(__VA_ARGS__))
126
127
/*
128
 * Log a fatal error.  If the given condition fails, this stops program
129
 * execution like a normal assertion, but also generating the given message.
130
 * It is NOT stripped from release builds.  Note that the condition test
131
 * is -inverted- from the normal assert() semantics.
132
 */
133
#ifndef LOG_ALWAYS_FATAL_IF
134
#define LOG_ALWAYS_FATAL_IF(cond, ...)                              \
135
2
  ((__predict_false(cond))                                          \
136
2
       ? ((void)android_printAssert(#cond, LOG_TAG, ##__VA_ARGS__)) \
137
2
       : __FAKE_USE_VA_ARGS(__VA_ARGS__))
138
#endif
139
140
#ifndef LOG_ALWAYS_FATAL
141
#define LOG_ALWAYS_FATAL(...) \
142
0
  (((void)android_printAssert(NULL, LOG_TAG, ##__VA_ARGS__)))
143
#endif
144
145
/*
146
 * Versions of LOG_ALWAYS_FATAL_IF and LOG_ALWAYS_FATAL that
147
 * are stripped out of release builds.
148
 */
149
150
#if LOG_NDEBUG
151
152
#ifndef LOG_FATAL_IF
153
#define LOG_FATAL_IF(cond, ...) __FAKE_USE_VA_ARGS(__VA_ARGS__)
154
#endif
155
#ifndef LOG_FATAL
156
#define LOG_FATAL(...) __FAKE_USE_VA_ARGS(__VA_ARGS__)
157
#endif
158
159
#else
160
161
#ifndef LOG_FATAL_IF
162
#define LOG_FATAL_IF(cond, ...) LOG_ALWAYS_FATAL_IF(cond, ##__VA_ARGS__)
163
#endif
164
#ifndef LOG_FATAL
165
#define LOG_FATAL(...) LOG_ALWAYS_FATAL(__VA_ARGS__)
166
#endif
167
168
#endif
169
170
/*
171
 * Assertion that generates a log message when the assertion fails.
172
 * Stripped out of release builds.  Uses the current LOG_TAG.
173
 */
174
#ifndef ALOG_ASSERT
175
#define ALOG_ASSERT(cond, ...) LOG_FATAL_IF(!(cond), ##__VA_ARGS__)
176
#endif
177
178
/* --------------------------------------------------------------------- */
179
180
/*
181
 * C/C++ logging functions.  See the logging documentation for API details.
182
 *
183
 * We'd like these to be available from C code (in case we import some from
184
 * somewhere), so this has a C interface.
185
 *
186
 * The output will be correct when the log file is shared between multiple
187
 * threads and/or multiple processes so long as the operating system
188
 * supports O_APPEND.  These calls have mutex-protected data structures
189
 * and so are NOT reentrant.  Do not use LOG in a signal handler.
190
 */
191
192
/* --------------------------------------------------------------------- */
193
194
/*
195
 * Simplified macro to send a verbose log message using the current LOG_TAG.
196
 */
197
#ifndef ALOGV
198
0
#define __ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
199
#if LOG_NDEBUG
200
#define ALOGV(...)                   \
201
16
  do {                               \
202
16
    __FAKE_USE_VA_ARGS(__VA_ARGS__); \
203
16
    if (false) {                     \
204
0
      __ALOGV(__VA_ARGS__);          \
205
0
    }                                \
206
16
  } while (false)
207
#else
208
#define ALOGV(...) __ALOGV(__VA_ARGS__)
209
#endif
210
#endif
211
212
#ifndef ALOGV_IF
213
#if LOG_NDEBUG
214
#define ALOGV_IF(cond, ...) __FAKE_USE_VA_ARGS(__VA_ARGS__)
215
#else
216
#define ALOGV_IF(cond, ...)                                                  \
217
  ((__predict_false(cond)) ? ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
218
                           : __FAKE_USE_VA_ARGS(__VA_ARGS__))
219
#endif
220
#endif
221
222
/*
223
 * Simplified macro to send a debug log message using the current LOG_TAG.
224
 */
225
#ifndef ALOGD
226
#define ALOGD(...) ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
227
#endif
228
229
#ifndef ALOGD_IF
230
#define ALOGD_IF(cond, ...)                                                \
231
  ((__predict_false(cond)) ? ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
232
                           : __FAKE_USE_VA_ARGS(__VA_ARGS__))
233
#endif
234
235
/*
236
 * Simplified macro to send an info log message using the current LOG_TAG.
237
 */
238
#ifndef ALOGI
239
#define ALOGI(...) ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
240
#endif
241
242
#ifndef ALOGI_IF
243
#define ALOGI_IF(cond, ...)                                               \
244
  ((__predict_false(cond)) ? ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
245
                           : __FAKE_USE_VA_ARGS(__VA_ARGS__))
246
#endif
247
248
/*
249
 * Simplified macro to send a warning log message using the current LOG_TAG.
250
 */
251
#ifndef ALOGW
252
0
#define ALOGW(...) ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
253
#endif
254
255
#ifndef ALOGW_IF
256
#define ALOGW_IF(cond, ...)                                               \
257
  ((__predict_false(cond)) ? ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
258
                           : __FAKE_USE_VA_ARGS(__VA_ARGS__))
259
#endif
260
261
/*
262
 * Simplified macro to send an error log message using the current LOG_TAG.
263
 */
264
#ifndef ALOGE
265
0
#define ALOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
266
#endif
267
268
#ifndef ALOGE_IF
269
#define ALOGE_IF(cond, ...)                                                \
270
  ((__predict_false(cond)) ? ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
271
                           : __FAKE_USE_VA_ARGS(__VA_ARGS__))
272
#endif
273
274
/* --------------------------------------------------------------------- */
275
276
/*
277
 * Conditional based on whether the current LOG_TAG is enabled at
278
 * verbose priority.
279
 */
280
#ifndef IF_ALOGV
281
#if LOG_NDEBUG
282
#define IF_ALOGV() if (false)
283
#else
284
#define IF_ALOGV() IF_ALOG(LOG_VERBOSE, LOG_TAG)
285
#endif
286
#endif
287
288
/*
289
 * Conditional based on whether the current LOG_TAG is enabled at
290
 * debug priority.
291
 */
292
#ifndef IF_ALOGD
293
#define IF_ALOGD() IF_ALOG(LOG_DEBUG, LOG_TAG)
294
#endif
295
296
/*
297
 * Conditional based on whether the current LOG_TAG is enabled at
298
 * info priority.
299
 */
300
#ifndef IF_ALOGI
301
#define IF_ALOGI() IF_ALOG(LOG_INFO, LOG_TAG)
302
#endif
303
304
/*
305
 * Conditional based on whether the current LOG_TAG is enabled at
306
 * warn priority.
307
 */
308
#ifndef IF_ALOGW
309
#define IF_ALOGW() IF_ALOG(LOG_WARN, LOG_TAG)
310
#endif
311
312
/*
313
 * Conditional based on whether the current LOG_TAG is enabled at
314
 * error priority.
315
 */
316
#ifndef IF_ALOGE
317
#define IF_ALOGE() IF_ALOG(LOG_ERROR, LOG_TAG)
318
#endif
319
320
/* --------------------------------------------------------------------- */
321
322
/*
323
 * Basic log message macro.
324
 *
325
 * Example:
326
 *  ALOG(LOG_WARN, NULL, "Failed with error %d", errno);
327
 *
328
 * The second argument may be NULL or "" to indicate the "global" tag.
329
 */
330
#ifndef ALOG
331
0
#define ALOG(priority, tag, ...) LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__)
332
#endif
333
334
/*
335
 * Conditional given a desired logging priority and tag.
336
 */
337
#ifndef IF_ALOG
338
#define IF_ALOG(priority, tag) if (android_testLog(ANDROID_##priority, tag))
339
#endif
340
341
/* --------------------------------------------------------------------- */
342
343
/*
344
 *    IF_ALOG uses android_testLog, but IF_ALOG can be overridden.
345
 *    android_testLog will remain constant in its purpose as a wrapper
346
 *        for Android logging filter policy, and can be subject to
347
 *        change. It can be reused by the developers that override
348
 *        IF_ALOG as a convenient means to reimplement their policy
349
 *        over Android.
350
 */
351
352
#ifndef __ANDROID_USE_LIBLOG_LOGGABLE_INTERFACE
353
#ifndef __ANDROID_API__
354
#define __ANDROID_USE_LIBLOG_LOGGABLE_INTERFACE 2
355
#elif __ANDROID_API__ > 24 /* > Nougat */
356
#define __ANDROID_USE_LIBLOG_LOGGABLE_INTERFACE 2
357
#elif __ANDROID_API__ > 22 /* > Lollipop */
358
#define __ANDROID_USE_LIBLOG_LOGGABLE_INTERFACE 1
359
#else
360
#define __ANDROID_USE_LIBLOG_LOGGABLE_INTERFACE 0
361
#endif
362
#endif
363
364
#if __ANDROID_USE_LIBLOG_LOGGABLE_INTERFACE
365
366
/*
367
 * Use the per-tag properties "log.tag.<tagname>" to generate a runtime
368
 * result of non-zero to expose a log. prio is ANDROID_LOG_VERBOSE to
369
 * ANDROID_LOG_FATAL. default_prio if no property. Undefined behavior if
370
 * any other value.
371
 */
372
int __android_log_is_loggable(int prio, const char* tag, int default_prio);
373
374
#if __ANDROID_USE_LIBLOG_LOGGABLE_INTERFACE > 1
375
#include <sys/types.h>
376
377
int __android_log_is_loggable_len(int prio, const char* tag, size_t len,
378
                                  int default_prio);
379
380
#if LOG_NDEBUG /* Production */
381
#define android_testLog(prio, tag)                                           \
382
  (__android_log_is_loggable_len(prio, tag, ((tag) && *(tag)) ? strlen(tag) : 0, \
383
                                 ANDROID_LOG_DEBUG) != 0)
384
#else
385
#define android_testLog(prio, tag)                                           \
386
  (__android_log_is_loggable_len(prio, tag, ((tag) && *(tag)) ? strlen(tag) : 0, \
387
                                 ANDROID_LOG_VERBOSE) != 0)
388
#endif
389
390
#else
391
392
#if LOG_NDEBUG /* Production */
393
#define android_testLog(prio, tag) \
394
  (__android_log_is_loggable(prio, tag, ANDROID_LOG_DEBUG) != 0)
395
#else
396
#define android_testLog(prio, tag) \
397
  (__android_log_is_loggable(prio, tag, ANDROID_LOG_VERBOSE) != 0)
398
#endif
399
400
#endif
401
402
#else /* __ANDROID_USE_LIBLOG_LOGGABLE_INTERFACE */
403
404
#define android_testLog(prio, tag) (1)
405
406
#endif /* !__ANDROID_USE_LIBLOG_LOGGABLE_INTERFACE */
407
408
#if defined(__clang__)
409
#pragma clang diagnostic pop
410
#endif
411
412
__END_DECLS
413
414
#endif /* _LIBS_LOG_LOG_MAIN_H */
/proc/self/cwd/system/core/liblog/include/log/log_read.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2005-2017 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef _LIBS_LOG_LOG_READ_H
18
#define _LIBS_LOG_LOG_READ_H
19
20
/* deal with possible sys/cdefs.h conflict with fcntl.h */
21
#ifdef __unused
22
#define __unused_defined __unused
23
#undef __unused
24
#endif
25
26
#include <fcntl.h> /* Pick up O_* macros */
27
28
/* restore definitions from above */
29
#ifdef __unused_defined
30
#define __unused __attribute__((__unused__))
31
#endif
32
33
#include <stdint.h>
34
35
#include <log/log_id.h>
36
#include <log/log_time.h>
37
38
#ifdef __cplusplus
39
extern "C" {
40
#endif
41
42
/*
43
 * Native log reading interface section. See logcat for sample code.
44
 *
45
 * The preferred API is an exec of logcat. Likely uses of this interface
46
 * are if native code suffers from exec or filtration being too costly,
47
 * access to raw information, or parsing is an issue.
48
 */
49
50
/*
51
 * The userspace structure for version 1 of the logger_entry ABI.
52
 */
53
#ifndef __struct_logger_entry_defined
54
#define __struct_logger_entry_defined
55
struct logger_entry {
56
  uint16_t len;   /* length of the payload */
57
  uint16_t __pad; /* no matter what, we get 2 bytes of padding */
58
  int32_t pid;    /* generating process's pid */
59
  int32_t tid;    /* generating process's tid */
60
  int32_t sec;    /* seconds since Epoch */
61
  int32_t nsec;   /* nanoseconds */
62
#ifndef __cplusplus
63
  char msg[0]; /* the entry's payload */
64
#endif
65
};
66
#endif
67
68
/*
69
 * The userspace structure for version 2 of the logger_entry ABI.
70
 */
71
#ifndef __struct_logger_entry_v2_defined
72
#define __struct_logger_entry_v2_defined
73
struct logger_entry_v2 {
74
  uint16_t len;      /* length of the payload */
75
  uint16_t hdr_size; /* sizeof(struct logger_entry_v2) */
76
  int32_t pid;       /* generating process's pid */
77
  int32_t tid;       /* generating process's tid */
78
  int32_t sec;       /* seconds since Epoch */
79
  int32_t nsec;      /* nanoseconds */
80
  uint32_t euid;     /* effective UID of logger */
81
#ifndef __cplusplus
82
  char msg[0]; /* the entry's payload */
83
#endif
84
} __attribute__((__packed__));
85
#endif
86
87
/*
88
 * The userspace structure for version 3 of the logger_entry ABI.
89
 */
90
#ifndef __struct_logger_entry_v3_defined
91
#define __struct_logger_entry_v3_defined
92
struct logger_entry_v3 {
93
  uint16_t len;      /* length of the payload */
94
  uint16_t hdr_size; /* sizeof(struct logger_entry_v3) */
95
  int32_t pid;       /* generating process's pid */
96
  int32_t tid;       /* generating process's tid */
97
  int32_t sec;       /* seconds since Epoch */
98
  int32_t nsec;      /* nanoseconds */
99
  uint32_t lid;      /* log id of the payload */
100
#ifndef __cplusplus
101
  char msg[0]; /* the entry's payload */
102
#endif
103
} __attribute__((__packed__));
104
#endif
105
106
/*
107
 * The userspace structure for version 4 of the logger_entry ABI.
108
 */
109
#ifndef __struct_logger_entry_v4_defined
110
#define __struct_logger_entry_v4_defined
111
struct logger_entry_v4 {
112
  uint16_t len;      /* length of the payload */
113
  uint16_t hdr_size; /* sizeof(struct logger_entry_v4) */
114
  int32_t pid;       /* generating process's pid */
115
  uint32_t tid;      /* generating process's tid */
116
  uint32_t sec;      /* seconds since Epoch */
117
  uint32_t nsec;     /* nanoseconds */
118
  uint32_t lid;      /* log id of the payload, bottom 4 bits currently */
119
  uint32_t uid;      /* generating process's uid */
120
#ifndef __cplusplus
121
  char msg[0]; /* the entry's payload */
122
#endif
123
};
124
#endif
125
126
/*
127
 * The maximum size of the log entry payload that can be
128
 * written to the logger. An attempt to write more than
129
 * this amount will result in a truncated log entry.
130
 */
131
#define LOGGER_ENTRY_MAX_PAYLOAD 4068
132
133
/*
134
 * The maximum size of a log entry which can be read.
135
 * An attempt to read less than this amount may result
136
 * in read() returning EINVAL.
137
 */
138
#define LOGGER_ENTRY_MAX_LEN (5 * 1024)
139
140
#ifndef __struct_log_msg_defined
141
#define __struct_log_msg_defined
142
struct log_msg {
143
  union {
144
    unsigned char buf[LOGGER_ENTRY_MAX_LEN + 1];
145
    struct logger_entry_v4 entry;
146
    struct logger_entry_v4 entry_v4;
147
    struct logger_entry_v3 entry_v3;
148
    struct logger_entry_v2 entry_v2;
149
    struct logger_entry entry_v1;
150
  } __attribute__((aligned(4)));
151
#ifdef __cplusplus
152
  /* Matching log_time operators */
153
0
  bool operator==(const log_msg& T) const {
154
0
    return (entry.sec == T.entry.sec) && (entry.nsec == T.entry.nsec);
155
0
  }
156
0
  bool operator!=(const log_msg& T) const {
157
0
    return !(*this == T);
158
0
  }
159
0
  bool operator<(const log_msg& T) const {
160
0
    return (entry.sec < T.entry.sec) ||
161
0
           ((entry.sec == T.entry.sec) && (entry.nsec < T.entry.nsec));
162
0
  }
163
0
  bool operator>=(const log_msg& T) const {
164
0
    return !(*this < T);
165
0
  }
166
0
  bool operator>(const log_msg& T) const {
167
0
    return (entry.sec > T.entry.sec) ||
168
0
           ((entry.sec == T.entry.sec) && (entry.nsec > T.entry.nsec));
169
0
  }
170
0
  bool operator<=(const log_msg& T) const {
171
0
    return !(*this > T);
172
0
  }
173
0
  uint64_t nsec() const {
174
0
    return static_cast<uint64_t>(entry.sec) * NS_PER_SEC + entry.nsec;
175
0
  }
176
177
  /* packet methods */
178
0
  log_id_t id() {
179
0
    return static_cast<log_id_t>(entry.lid);
180
0
  }
181
0
  char* msg() {
182
0
    unsigned short hdr_size = entry.hdr_size;
183
0
    if (!hdr_size) {
184
0
      hdr_size = sizeof(entry_v1);
185
0
    }
186
0
    if ((hdr_size < sizeof(entry_v1)) || (hdr_size > sizeof(entry))) {
187
0
      return nullptr;
188
0
    }
189
0
    return reinterpret_cast<char*>(buf) + hdr_size;
190
0
  }
191
0
  unsigned int len() {
192
0
    return (entry.hdr_size ? entry.hdr_size
193
0
                           : static_cast<uint16_t>(sizeof(entry_v1))) +
194
0
           entry.len;
195
0
  }
196
#endif
197
};
198
#endif
199
200
#ifndef __ANDROID_USE_LIBLOG_READER_INTERFACE
201
#ifndef __ANDROID_API__
202
#define __ANDROID_USE_LIBLOG_READER_INTERFACE 3
203
#elif __ANDROID_API__ > 23 /* > Marshmallow */
204
#define __ANDROID_USE_LIBLOG_READER_INTERFACE 3
205
#elif __ANDROID_API__ > 22 /* > Lollipop */
206
#define __ANDROID_USE_LIBLOG_READER_INTERFACE 2
207
#elif __ANDROID_API__ > 19 /* > KitKat */
208
#define __ANDROID_USE_LIBLOG_READER_INTERFACE 1
209
#else
210
#define __ANDROID_USE_LIBLOG_READER_INTERFACE 0
211
#endif
212
#endif
213
214
#if __ANDROID_USE_LIBLOG_READER_INTERFACE
215
216
struct logger;
217
218
log_id_t android_logger_get_id(struct logger* logger);
219
220
int android_logger_clear(struct logger* logger);
221
long android_logger_get_log_size(struct logger* logger);
222
int android_logger_set_log_size(struct logger* logger, unsigned long size);
223
long android_logger_get_log_readable_size(struct logger* logger);
224
int android_logger_get_log_version(struct logger* logger);
225
226
struct logger_list;
227
228
#if __ANDROID_USE_LIBLOG_READER_INTERFACE > 1
229
ssize_t android_logger_get_statistics(struct logger_list* logger_list,
230
                                      char* buf, size_t len);
231
ssize_t android_logger_get_prune_list(struct logger_list* logger_list,
232
                                      char* buf, size_t len);
233
int android_logger_set_prune_list(struct logger_list* logger_list, char* buf,
234
                                  size_t len);
235
#endif
236
237
#define ANDROID_LOG_RDONLY O_RDONLY
238
#define ANDROID_LOG_WRONLY O_WRONLY
239
#define ANDROID_LOG_RDWR O_RDWR
240
#define ANDROID_LOG_ACCMODE O_ACCMODE
241
#ifndef O_NONBLOCK
242
#define ANDROID_LOG_NONBLOCK 0x00000800
243
#else
244
#define ANDROID_LOG_NONBLOCK O_NONBLOCK
245
#endif
246
#if __ANDROID_USE_LIBLOG_READER_INTERFACE > 2
247
#define ANDROID_LOG_WRAP 0x40000000 /* Block until buffer about to wrap */
248
#define ANDROID_LOG_WRAP_DEFAULT_TIMEOUT 7200 /* 2 hour default */
249
#endif
250
#if __ANDROID_USE_LIBLOG_READER_INTERFACE > 1
251
#define ANDROID_LOG_PSTORE 0x80000000
252
#endif
253
254
struct logger_list* android_logger_list_alloc(int mode, unsigned int tail,
255
                                              pid_t pid);
256
struct logger_list* android_logger_list_alloc_time(int mode, log_time start,
257
                                                   pid_t pid);
258
void android_logger_list_free(struct logger_list* logger_list);
259
/* In the purest sense, the following two are orthogonal interfaces */
260
int android_logger_list_read(struct logger_list* logger_list,
261
                             struct log_msg* log_msg);
262
263
/* Multiple log_id_t opens */
264
struct logger* android_logger_open(struct logger_list* logger_list, log_id_t id);
265
#define android_logger_close android_logger_free
266
/* Single log_id_t open */
267
struct logger_list* android_logger_list_open(log_id_t id, int mode,
268
                                             unsigned int tail, pid_t pid);
269
#define android_logger_list_close android_logger_list_free
270
271
#endif /* __ANDROID_USE_LIBLOG_READER_INTERFACE */
272
273
#ifdef __cplusplus
274
}
275
#endif
276
277
#endif /* _LIBS_LOG_LOG_H */
/proc/self/cwd/system/core/liblog/include/log/log_safetynet.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
**
3
** Copyright 2017, The Android Open Source Project
4
**
5
** This file is dual licensed.  It may be redistributed and/or modified
6
** under the terms of the Apache 2.0 License OR version 2 of the GNU
7
** General Public License.
8
*/
9
10
#ifndef _LIBS_LOG_SAFETYNET_H
11
#define _LIBS_LOG_SAFETYNET_H
12
13
#include <stdint.h>
14
15
#ifdef __cplusplus
16
extern "C" {
17
#endif
18
19
#ifndef _ANDROID_USE_LIBLOG_SAFETYNET_INTERFACE
20
#ifndef __ANDROID_API__
21
#define __ANDROID_USE_LIBLOG_SAFETYNET_INTERFACE 1
22
#elif __ANDROID_API__ > 22 /* > Lollipop */
23
#define __ANDROID_USE_LIBLOG_SAFETYNET_INTERFACE 1
24
#else
25
#define __ANDROID_USE_LIBLOG_SAFETYNET_INTERFACE 0
26
#endif
27
#endif
28
29
#if __ANDROID_USE_LIBLOG_SAFETYNET_INTERFACE
30
31
#define android_errorWriteLog(tag, subTag) \
32
0
  __android_log_error_write(tag, subTag, -1, NULL, 0)
33
34
#define android_errorWriteWithInfoLog(tag, subTag, uid, data, dataLen) \
35
  __android_log_error_write(tag, subTag, uid, data, dataLen)
36
37
int __android_log_error_write(int tag, const char* subTag, int32_t uid,
38
                              const char* data, uint32_t dataLen);
39
40
#endif /* __ANDROID_USE_LIBLOG_SAFETYNET_INTERFACE */
41
42
#ifdef __cplusplus
43
}
44
#endif
45
46
#endif /* _LIBS_LOG_SAFETYNET_H */
/proc/self/cwd/system/core/liblog/include/log/log_time.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2005-2017 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef _LIBS_LOG_LOG_TIME_H
18
#define _LIBS_LOG_LOG_TIME_H
19
20
#include <stdint.h>
21
#include <time.h>
22
23
/* struct log_time is a wire-format variant of struct timespec */
24
#define NS_PER_SEC 1000000000ULL
25
#define US_PER_SEC 1000000ULL
26
#define MS_PER_SEC 1000ULL
27
28
#ifndef __struct_log_time_defined
29
#define __struct_log_time_defined
30
31
#define LOG_TIME_SEC(t) ((t)->tv_sec)
32
/* next power of two after NS_PER_SEC */
33
#define LOG_TIME_NSEC(t) ((t)->tv_nsec & (UINT32_MAX >> 2))
34
35
#ifdef __cplusplus
36
37
/*
38
 * NB: we did NOT define a copy constructor. This will result in structure
39
 * no longer being compatible with pass-by-value which is desired
40
 * efficient behavior. Also, pass-by-reference breaks C/C++ ABI.
41
 */
42
struct log_time {
43
 public:
44
  uint32_t tv_sec; /* good to Feb 5 2106 */
45
  uint32_t tv_nsec;
46
47
  static const uint32_t tv_sec_max = 0xFFFFFFFFUL;
48
  static const uint32_t tv_nsec_max = 999999999UL;
49
50
  log_time(const timespec& T)
51
      : tv_sec(static_cast<uint32_t>(T.tv_sec)),
52
0
        tv_nsec(static_cast<uint32_t>(T.tv_nsec)) {
53
0
  }
54
  explicit log_time(uint32_t sec, uint32_t nsec = 0)
55
0
      : tv_sec(sec), tv_nsec(nsec) {
56
0
  }
57
#ifdef _SYSTEM_CORE_INCLUDE_PRIVATE_ANDROID_LOGGER_H_
58
#define __struct_log_time_private_defined
59
  static const timespec EPOCH;
60
#endif
61
0
  log_time() {
62
0
  }
63
#ifdef __linux__
64
0
  explicit log_time(clockid_t id) {
65
0
    timespec T;
66
0
    clock_gettime(id, &T);
67
0
    tv_sec = static_cast<uint32_t>(T.tv_sec);
68
0
    tv_nsec = static_cast<uint32_t>(T.tv_nsec);
69
0
  }
70
#endif
71
0
  explicit log_time(const char* T) {
72
0
    const uint8_t* c = reinterpret_cast<const uint8_t*>(T);
73
0
    tv_sec = c[0] | (static_cast<uint32_t>(c[1]) << 8) |
74
0
             (static_cast<uint32_t>(c[2]) << 16) |
75
0
             (static_cast<uint32_t>(c[3]) << 24);
76
0
    tv_nsec = c[4] | (static_cast<uint32_t>(c[5]) << 8) |
77
0
              (static_cast<uint32_t>(c[6]) << 16) |
78
0
              (static_cast<uint32_t>(c[7]) << 24);
79
0
  }
80
81
  /* timespec */
82
0
  bool operator==(const timespec& T) const {
83
0
    return (tv_sec == static_cast<uint32_t>(T.tv_sec)) &&
84
0
           (tv_nsec == static_cast<uint32_t>(T.tv_nsec));
85
0
  }
86
0
  bool operator!=(const timespec& T) const {
87
0
    return !(*this == T);
88
0
  }
89
0
  bool operator<(const timespec& T) const {
90
0
    return (tv_sec < static_cast<uint32_t>(T.tv_sec)) ||
91
0
           ((tv_sec == static_cast<uint32_t>(T.tv_sec)) &&
92
0
            (tv_nsec < static_cast<uint32_t>(T.tv_nsec)));
93
0
  }
94
0
  bool operator>=(const timespec& T) const {
95
0
    return !(*this < T);
96
0
  }
97
0
  bool operator>(const timespec& T) const {
98
0
    return (tv_sec > static_cast<uint32_t>(T.tv_sec)) ||
99
0
           ((tv_sec == static_cast<uint32_t>(T.tv_sec)) &&
100
0
            (tv_nsec > static_cast<uint32_t>(T.tv_nsec)));
101
0
  }
102
0
  bool operator<=(const timespec& T) const {
103
0
    return !(*this > T);
104
0
  }
105
106
#ifdef _SYSTEM_CORE_INCLUDE_PRIVATE_ANDROID_LOGGER_H_
107
  log_time operator-=(const timespec& T);
108
  log_time operator-(const timespec& T) const {
109
    log_time local(*this);
110
    return local -= T;
111
  }
112
  log_time operator+=(const timespec& T);
113
  log_time operator+(const timespec& T) const {
114
    log_time local(*this);
115
    return local += T;
116
  }
117
#endif
118
119
  /* log_time */
120
0
  bool operator==(const log_time& T) const {
121
0
    return (tv_sec == T.tv_sec) && (tv_nsec == T.tv_nsec);
122
0
  }
123
0
  bool operator!=(const log_time& T) const {
124
0
    return !(*this == T);
125
0
  }
126
0
  bool operator<(const log_time& T) const {
127
0
    return (tv_sec < T.tv_sec) ||
128
0
           ((tv_sec == T.tv_sec) && (tv_nsec < T.tv_nsec));
129
0
  }
130
0
  bool operator>=(const log_time& T) const {
131
0
    return !(*this < T);
132
0
  }
133
0
  bool operator>(const log_time& T) const {
134
0
    return (tv_sec > T.tv_sec) ||
135
0
           ((tv_sec == T.tv_sec) && (tv_nsec > T.tv_nsec));
136
0
  }
137
0
  bool operator<=(const log_time& T) const {
138
0
    return !(*this > T);
139
0
  }
140
141
#ifdef _SYSTEM_CORE_INCLUDE_PRIVATE_ANDROID_LOGGER_H_
142
  log_time operator-=(const log_time& T);
143
  log_time operator-(const log_time& T) const {
144
    log_time local(*this);
145
    return local -= T;
146
  }
147
  log_time operator+=(const log_time& T);
148
  log_time operator+(const log_time& T) const {
149
    log_time local(*this);
150
    return local += T;
151
  }
152
#endif
153
154
0
  uint64_t nsec() const {
155
0
    return static_cast<uint64_t>(tv_sec) * NS_PER_SEC + tv_nsec;
156
0
  }
157
0
  uint64_t usec() const {
158
0
    return static_cast<uint64_t>(tv_sec) * US_PER_SEC +
159
0
           tv_nsec / (NS_PER_SEC / US_PER_SEC);
160
0
  }
161
0
  uint64_t msec() const {
162
0
    return static_cast<uint64_t>(tv_sec) * MS_PER_SEC +
163
0
           tv_nsec / (NS_PER_SEC / MS_PER_SEC);
164
0
  }
165
166
#ifdef _SYSTEM_CORE_INCLUDE_PRIVATE_ANDROID_LOGGER_H_
167
  static const char default_format[];
168
169
  /* Add %#q for the fraction of a second to the standard library functions */
170
  char* strptime(const char* s, const char* format = default_format);
171
#endif
172
} __attribute__((__packed__));
173
174
#else /* __cplusplus */
175
176
typedef struct log_time {
177
  uint32_t tv_sec;
178
  uint32_t tv_nsec;
179
} __attribute__((__packed__)) log_time;
180
181
#endif /* __cplusplus */
182
183
#endif /* __struct_log_time_defined */
184
185
#endif /* _LIBS_LOG_LOG_TIME_H */
/proc/self/cwd/system/core/libutils/include/utils/AndroidThreads.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2007 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef _LIBS_UTILS_ANDROID_THREADS_H
18
#define _LIBS_UTILS_ANDROID_THREADS_H
19
20
#include <stdint.h>
21
#include <sys/types.h>
22
23
#if !defined(_WIN32)
24
# include <pthread.h>
25
#endif
26
27
#include <utils/ThreadDefs.h>
28
29
// ---------------------------------------------------------------------------
30
// C API
31
32
#ifdef __cplusplus
33
extern "C" {
34
#endif
35
36
// Create and run a new thread.
37
extern int androidCreateThread(android_thread_func_t, void *);
38
39
// Create thread with lots of parameters
40
extern int androidCreateThreadEtc(android_thread_func_t entryFunction,
41
                                  void *userData,
42
                                  const char* threadName,
43
                                  int32_t threadPriority,
44
                                  size_t threadStackSize,
45
                                  android_thread_id_t *threadId);
46
47
// Get some sort of unique identifier for the current thread.
48
extern android_thread_id_t androidGetThreadId();
49
50
// Low-level thread creation -- never creates threads that can
51
// interact with the Java VM.
52
extern int androidCreateRawThreadEtc(android_thread_func_t entryFunction,
53
                                     void *userData,
54
                                     const char* threadName,
55
                                     int32_t threadPriority,
56
                                     size_t threadStackSize,
57
                                     android_thread_id_t *threadId);
58
59
// set the same of the running thread
60
extern void androidSetThreadName(const char* name);
61
62
// Used by the Java Runtime to control how threads are created, so that
63
// they can be proper and lovely Java threads.
64
typedef int (*android_create_thread_fn)(android_thread_func_t entryFunction,
65
                                        void *userData,
66
                                        const char* threadName,
67
                                        int32_t threadPriority,
68
                                        size_t threadStackSize,
69
                                        android_thread_id_t *threadId);
70
71
extern void androidSetCreateThreadFunc(android_create_thread_fn func);
72
73
// ------------------------------------------------------------------
74
// Extra functions working with raw pids.
75
76
#if defined(__ANDROID__)
77
// Change the priority AND scheduling group of a particular thread.  The priority
78
// should be one of the ANDROID_PRIORITY constants.  Returns INVALID_OPERATION
79
// if the priority set failed, else another value if just the group set failed;
80
// in either case errno is set.  Thread ID zero means current thread.
81
extern int androidSetThreadPriority(pid_t tid, int prio);
82
83
// Get the current priority of a particular thread. Returns one of the
84
// ANDROID_PRIORITY constants or a negative result in case of error.
85
extern int androidGetThreadPriority(pid_t tid);
86
#endif
87
88
#ifdef __cplusplus
89
} // extern "C"
90
#endif
91
92
// ----------------------------------------------------------------------------
93
// C++ API
94
#ifdef __cplusplus
95
namespace android {
96
// ----------------------------------------------------------------------------
97
98
// Create and run a new thread.
99
0
inline bool createThread(thread_func_t f, void *a) {
100
0
    return androidCreateThread(f, a) ? true : false;
101
0
}
102
103
// Create thread with lots of parameters
104
inline bool createThreadEtc(thread_func_t entryFunction,
105
                            void *userData,
106
                            const char* threadName = "android:unnamed_thread",
107
                            int32_t threadPriority = PRIORITY_DEFAULT,
108
                            size_t threadStackSize = 0,
109
                            thread_id_t *threadId = nullptr)
110
0
{
111
0
    return androidCreateThreadEtc(entryFunction, userData, threadName,
112
0
        threadPriority, threadStackSize, threadId) ? true : false;
113
0
}
114
115
// Get some sort of unique identifier for the current thread.
116
0
inline thread_id_t getThreadId() {
117
0
    return androidGetThreadId();
118
0
}
119
120
// ----------------------------------------------------------------------------
121
}  // namespace android
122
#endif  // __cplusplus
123
// ----------------------------------------------------------------------------
124
125
#endif // _LIBS_UTILS_ANDROID_THREADS_H
/proc/self/cwd/system/core/libutils/include/utils/Condition.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2007 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef _LIBS_UTILS_CONDITION_H
18
#define _LIBS_UTILS_CONDITION_H
19
20
#include <limits.h>
21
#include <stdint.h>
22
#include <sys/types.h>
23
#include <time.h>
24
25
#if !defined(_WIN32)
26
# include <pthread.h>
27
#endif
28
29
#include <utils/Errors.h>
30
#include <utils/Mutex.h>
31
#include <utils/Timers.h>
32
33
// ---------------------------------------------------------------------------
34
namespace android {
35
// ---------------------------------------------------------------------------
36
37
// DO NOT USE: please use std::condition_variable instead.
38
39
/*
40
 * Condition variable class.  The implementation is system-dependent.
41
 *
42
 * Condition variables are paired up with mutexes.  Lock the mutex,
43
 * call wait(), then either re-wait() if things aren't quite what you want,
44
 * or unlock the mutex and continue.  All threads calling wait() must
45
 * use the same mutex for a given Condition.
46
 *
47
 * On Android and Apple platforms, these are implemented as a simple wrapper
48
 * around pthread condition variables.  Care must be taken to abide by
49
 * the pthreads semantics, in particular, a boolean predicate must
50
 * be re-evaluated after a wake-up, as spurious wake-ups may happen.
51
 */
52
class Condition {
53
public:
54
    enum {
55
        PRIVATE = 0,
56
        SHARED = 1
57
    };
58
59
    enum WakeUpType {
60
        WAKE_UP_ONE = 0,
61
        WAKE_UP_ALL = 1
62
    };
63
64
    Condition();
65
    explicit Condition(int type);
66
    ~Condition();
67
    // Wait on the condition variable.  Lock the mutex before calling.
68
    // Note that spurious wake-ups may happen.
69
    status_t wait(Mutex& mutex);
70
    // same with relative timeout
71
    status_t waitRelative(Mutex& mutex, nsecs_t reltime);
72
    // Signal the condition variable, allowing one thread to continue.
73
    void signal();
74
    // Signal the condition variable, allowing one or all threads to continue.
75
0
    void signal(WakeUpType type) {
76
0
        if (type == WAKE_UP_ONE) {
77
0
            signal();
78
0
        } else {
79
0
            broadcast();
80
0
        }
81
0
    }
82
    // Signal the condition variable, allowing all threads to continue.
83
    void broadcast();
84
85
private:
86
#if !defined(_WIN32)
87
    pthread_cond_t mCond;
88
#else
89
    void*   mState;
90
#endif
91
};
92
93
// ---------------------------------------------------------------------------
94
95
#if !defined(_WIN32)
96
97
inline Condition::Condition() : Condition(PRIVATE) {
98
}
99
inline Condition::Condition(int type) {
100
    pthread_condattr_t attr;
101
    pthread_condattr_init(&attr);
102
#if defined(__linux__)
103
    pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
104
#endif
105
106
    if (type == SHARED) {
107
        pthread_condattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
108
    }
109
110
    pthread_cond_init(&mCond, &attr);
111
    pthread_condattr_destroy(&attr);
112
113
}
114
inline Condition::~Condition() {
115
    pthread_cond_destroy(&mCond);
116
}
117
0
inline status_t Condition::wait(Mutex& mutex) {
118
0
    return -pthread_cond_wait(&mCond, &mutex.mMutex);
119
0
}
120
0
inline status_t Condition::waitRelative(Mutex& mutex, nsecs_t reltime) {
121
0
    struct timespec ts;
122
0
#if defined(__linux__)
123
0
    clock_gettime(CLOCK_MONOTONIC, &ts);
124
0
#else // __APPLE__
125
0
    // Apple doesn't support POSIX clocks.
126
0
    struct timeval t;
127
0
    gettimeofday(&t, nullptr);
128
0
    ts.tv_sec = t.tv_sec;
129
0
    ts.tv_nsec = t.tv_usec*1000;
130
0
#endif
131
0
132
0
    // On 32-bit devices, tv_sec is 32-bit, but `reltime` is 64-bit.
133
0
    int64_t reltime_sec = reltime/1000000000;
134
0
135
0
    ts.tv_nsec += static_cast<long>(reltime%1000000000);
136
0
    if (reltime_sec < INT64_MAX && ts.tv_nsec >= 1000000000) {
137
0
        ts.tv_nsec -= 1000000000;
138
0
        ++reltime_sec;
139
0
    }
140
0
141
0
    int64_t time_sec = ts.tv_sec;
142
0
    if (time_sec > INT64_MAX - reltime_sec) {
143
0
        time_sec = INT64_MAX;
144
0
    } else {
145
0
        time_sec += reltime_sec;
146
0
    }
147
0
148
0
    ts.tv_sec = (time_sec > LONG_MAX) ? LONG_MAX : static_cast<long>(time_sec);
149
0
150
0
    return -pthread_cond_timedwait(&mCond, &mutex.mMutex, &ts);
151
0
}
152
0
inline void Condition::signal() {
153
0
    pthread_cond_signal(&mCond);
154
0
}
155
0
inline void Condition::broadcast() {
156
0
    pthread_cond_broadcast(&mCond);
157
0
}
158
159
#endif // !defined(_WIN32)
160
161
// ---------------------------------------------------------------------------
162
}  // namespace android
163
// ---------------------------------------------------------------------------
164
165
#endif // _LIBS_UTILS_CONDITON_H
/proc/self/cwd/system/core/libutils/include/utils/Flattenable.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2010 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef ANDROID_UTILS_FLATTENABLE_H
18
#define ANDROID_UTILS_FLATTENABLE_H
19
20
21
#include <stdint.h>
22
#include <string.h>
23
#include <sys/types.h>
24
#include <utils/Errors.h>
25
#include <utils/Debug.h>
26
27
#include <type_traits>
28
29
namespace android {
30
31
32
class FlattenableUtils {
33
public:
34
    template<size_t N>
35
    static size_t align(size_t size) {
36
        static_assert(!(N & (N - 1)), "Can only align to a power of 2.");
37
        return (size + (N-1)) & ~(N-1);
38
    }
39
40
    template<size_t N>
41
    static size_t align(void const*& buffer) {
42
        static_assert(!(N & (N - 1)), "Can only align to a power of 2.");
43
        uintptr_t b = uintptr_t(buffer);
44
        buffer = reinterpret_cast<void*>((uintptr_t(buffer) + (N-1)) & ~(N-1));
45
        return size_t(uintptr_t(buffer) - b);
46
    }
47
48
    template<size_t N>
49
    static size_t align(void*& buffer) {
50
        return align<N>( const_cast<void const*&>(buffer) );
51
    }
52
53
0
    static void advance(void*& buffer, size_t& size, size_t offset) {
54
0
        buffer = reinterpret_cast<void*>( uintptr_t(buffer) + offset );
55
0
        size -= offset;
56
0
    }
57
58
0
    static void advance(void const*& buffer, size_t& size, size_t offset) {
59
0
        buffer = reinterpret_cast<void const*>( uintptr_t(buffer) + offset );
60
0
        size -= offset;
61
0
    }
62
63
    // write a POD structure
64
    template<typename T>
65
    static void write(void*& buffer, size_t& size, const T& value) {
66
        static_assert(std::is_trivially_copyable<T>::value,
67
                      "Cannot flatten a non-trivially-copyable type");
68
        memcpy(buffer, &value, sizeof(T));
69
        advance(buffer, size, sizeof(T));
70
    }
71
72
    // read a POD structure
73
    template<typename T>
74
    static void read(void const*& buffer, size_t& size, T& value) {
75
        static_assert(std::is_trivially_copyable<T>::value,
76
                      "Cannot unflatten a non-trivially-copyable type");
77
        memcpy(&value, buffer, sizeof(T));
78
        advance(buffer, size, sizeof(T));
79
    }
80
};
81
82
83
/*
84
 * The Flattenable protocol allows an object to serialize itself out
85
 * to a byte-buffer and an array of file descriptors.
86
 * Flattenable objects must implement this protocol.
87
 */
88
89
template <typename T>
90
class Flattenable {
91
public:
92
    // size in bytes of the flattened object
93
    inline size_t getFlattenedSize() const;
94
95
    // number of file descriptors to flatten
96
    inline size_t getFdCount() const;
97
98
    // flattens the object into buffer.
99
    // size should be at least of getFlattenedSize()
100
    // file descriptors are written in the fds[] array but ownership is
101
    // not transfered (ie: they must be dupped by the caller of
102
    // flatten() if needed).
103
    inline status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const;
104
105
    // unflattens the object from buffer.
106
    // size should be equal to the value of getFlattenedSize() when the
107
    // object was flattened.
108
    // unflattened file descriptors are found in the fds[] array and
109
    // don't need to be dupped(). ie: the caller of unflatten doesn't
110
    // keep ownership. If a fd is not retained by unflatten() it must be
111
    // explicitly closed.
112
    inline status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count);
113
};
114
115
template<typename T>
116
inline size_t Flattenable<T>::getFlattenedSize() const {
117
    return static_cast<T const*>(this)->T::getFlattenedSize();
118
}
119
template<typename T>
120
inline size_t Flattenable<T>::getFdCount() const {
121
    return static_cast<T const*>(this)->T::getFdCount();
122
}
123
template<typename T>
124
inline status_t Flattenable<T>::flatten(
125
        void*& buffer, size_t& size, int*& fds, size_t& count) const {
126
    return static_cast<T const*>(this)->T::flatten(buffer, size, fds, count);
127
}
128
template<typename T>
129
inline status_t Flattenable<T>::unflatten(
130
        void const*& buffer, size_t& size, int const*& fds, size_t& count) {
131
    return static_cast<T*>(this)->T::unflatten(buffer, size, fds, count);
132
}
133
134
/*
135
 * LightFlattenable is a protocol allowing object to serialize themselves out
136
 * to a byte-buffer. Because it doesn't handle file-descriptors,
137
 * LightFlattenable is usually more size efficient than Flattenable.
138
 * LightFlattenable objects must implement this protocol.
139
 */
140
template <typename T>
141
class LightFlattenable {
142
public:
143
    // returns whether this object always flatten into the same size.
144
    // for efficiency, this should always be inline.
145
    inline bool isFixedSize() const;
146
147
    // returns size in bytes of the flattened object. must be a constant.
148
    inline size_t getFlattenedSize() const;
149
150
    // flattens the object into buffer.
151
    inline status_t flatten(void* buffer, size_t size) const;
152
153
    // unflattens the object from buffer of given size.
154
    inline status_t unflatten(void const* buffer, size_t size);
155
};
156
157
template <typename T>
158
inline bool LightFlattenable<T>::isFixedSize() const {
159
    return static_cast<T const*>(this)->T::isFixedSize();
160
}
161
template <typename T>
162
inline size_t LightFlattenable<T>::getFlattenedSize() const {
163
    return static_cast<T const*>(this)->T::getFlattenedSize();
164
}
165
template <typename T>
166
inline status_t LightFlattenable<T>::flatten(void* buffer, size_t size) const {
167
    return static_cast<T const*>(this)->T::flatten(buffer, size);
168
}
169
template <typename T>
170
inline status_t LightFlattenable<T>::unflatten(void const* buffer, size_t size) {
171
    return static_cast<T*>(this)->T::unflatten(buffer, size);
172
}
173
174
/*
175
 * LightFlattenablePod is an implementation of the LightFlattenable protocol
176
 * for POD (plain-old-data) objects.
177
 * Simply derive from LightFlattenablePod<Foo> to make Foo flattenable; no
178
 * need to implement any methods; obviously Foo must be a POD structure.
179
 */
180
template <typename T>
181
class LightFlattenablePod : public LightFlattenable<T> {
182
public:
183
    inline bool isFixedSize() const {
184
        return true;
185
    }
186
187
    inline size_t getFlattenedSize() const {
188
        return sizeof(T);
189
    }
190
    inline status_t flatten(void* buffer, size_t size) const {
191
        if (size < sizeof(T)) return NO_MEMORY;
192
        memcpy(buffer, static_cast<T const*>(this), sizeof(T));
193
        return OK;
194
    }
195
    inline status_t unflatten(void const* buffer, size_t) {
196
        memcpy(static_cast<T*>(this), buffer, sizeof(T));
197
        return OK;
198
    }
199
};
200
201
}  // namespace android
202
203
#endif /* ANDROID_UTILS_FLATTENABLE_H */
/proc/self/cwd/system/core/libutils/include/utils/List.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2005 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
//
18
// Templated list class.  Normally we'd use STL, but we don't have that.
19
// This class mimics STL's interfaces.
20
//
21
// Objects are copied into the list with the '=' operator or with copy-
22
// construction, so if the compiler's auto-generated versions won't work for
23
// you, define your own.
24
//
25
// The only class you want to use from here is "List".
26
//
27
#ifndef _LIBS_UTILS_LIST_H
28
#define _LIBS_UTILS_LIST_H
29
30
#include <stddef.h>
31
#include <stdint.h>
32
33
namespace android {
34
35
/*
36
 * Doubly-linked list.  Instantiate with "List<MyClass> myList".
37
 *
38
 * Objects added to the list are copied using the assignment operator,
39
 * so this must be defined.
40
 *
41
 * DO NOT USE: please use std::list<T>
42
 */
43
template<typename T> 
44
class List 
45
{
46
protected:
47
    /*
48
     * One element in the list.
49
     */
50
    class _Node {
51
    public:
52
0
        explicit _Node(const T& val) : mVal(val) {}
53
22
        ~_Node() {}
54
26
        inline T& getRef() { return mVal; }
55
0
        inline const T& getRef() const { return mVal; }
56
22
        inline _Node* getPrev() const { return mpPrev; }
57
148
        inline _Node* getNext() const { return mpNext; }
58
        inline void setVal(const T& val) { mVal = val; }
59
26
        inline void setPrev(_Node* ptr) { mpPrev = ptr; }
60
26
        inline void setNext(_Node* ptr) { mpNext = ptr; }
61
    private:
62
        friend class List;
63
        friend class _ListIterator;
64
        T           mVal;
65
        _Node*      mpPrev;
66
        _Node*      mpNext;
67
    };
68
69
    /*
70
     * Iterator for walking through the list.
71
     */
72
    
73
    template <typename TYPE>
74
    struct CONST_ITERATOR {
75
        typedef _Node const * NodePtr;
76
        typedef const TYPE Type;
77
    };
78
    
79
    template <typename TYPE>
80
    struct NON_CONST_ITERATOR {
81
        typedef _Node* NodePtr;
82
        typedef TYPE Type;
83
    };
84
    
85
    template<
86
        typename U,
87
        template <class> class Constness
88
    > 
89
    class _ListIterator {
90
        typedef _ListIterator<U, Constness>     _Iter;
91
        typedef typename Constness<U>::NodePtr  _NodePtr;
92
        typedef typename Constness<U>::Type     _Type;
93
94
70
        explicit _ListIterator(_NodePtr ptr) : mpNode(ptr) {}
_ZN7android4ListIPNS_22SimpleSoftOMXComponent10BufferInfoEE13_ListIteratorIS3_NS4_18NON_CONST_ITERATOREEC2EPNS4_5_NodeE
Line
Count
Source
94
70
        explicit _ListIterator(_NodePtr ptr) : mpNode(ptr) {}
Unexecuted instantiation: _ZN7android4ListIPNS_22SimpleSoftOMXComponent10BufferInfoEE13_ListIteratorIS3_NS4_14CONST_ITERATOREEC2EPKNS4_5_NodeE
95
96
    public:
97
        _ListIterator() {}
98
0
        _ListIterator(const _Iter& rhs) : mpNode(rhs.mpNode) {}
99
70
        ~_ListIterator() {}
Unexecuted instantiation: _ZN7android4ListIPNS_22SimpleSoftOMXComponent10BufferInfoEE13_ListIteratorIS3_NS4_14CONST_ITERATOREED2Ev
_ZN7android4ListIPNS_22SimpleSoftOMXComponent10BufferInfoEE13_ListIteratorIS3_NS4_18NON_CONST_ITERATOREED2Ev
Line
Count
Source
99
70
        ~_ListIterator() {}
100
        
101
        // this will handle conversions from iterator to const_iterator
102
        // (and also all convertible iterators)
103
        // Here, in this implementation, the iterators can be converted
104
        // if the nodes can be converted
105
        template<typename V> explicit 
106
        _ListIterator(const V& rhs) : mpNode(rhs.mpNode) {}
107
        
108
109
        /*
110
         * Dereference operator.  Used to get at the juicy insides.
111
         */
112
26
        _Type& operator*() const { return mpNode->getRef(); }
Unexecuted instantiation: _ZNK7android4ListIPNS_22SimpleSoftOMXComponent10BufferInfoEE13_ListIteratorIS3_NS4_14CONST_ITERATOREEdeEv
_ZNK7android4ListIPNS_22SimpleSoftOMXComponent10BufferInfoEE13_ListIteratorIS3_NS4_18NON_CONST_ITERATOREEdeEv
Line
Count
Source
112
26
        _Type& operator*() const { return mpNode->getRef(); }
113
        _Type* operator->() const { return &(mpNode->getRef()); }
114
115
        /*
116
         * Iterator comparison.
117
         */
118
0
        inline bool operator==(const _Iter& right) const { 
119
0
            return mpNode == right.mpNode; }
120
        
121
0
        inline bool operator!=(const _Iter& right) const { 
122
0
            return mpNode != right.mpNode; }
Unexecuted instantiation: _ZNK7android4ListIPNS_22SimpleSoftOMXComponent10BufferInfoEE13_ListIteratorIS3_NS4_14CONST_ITERATOREEneERKS7_
Unexecuted instantiation: _ZNK7android4ListIPNS_22SimpleSoftOMXComponent10BufferInfoEE13_ListIteratorIS3_NS4_18NON_CONST_ITERATOREEneERKS7_
123
124
        /*
125
         * handle comparisons between iterator and const_iterator
126
         */
127
        template<typename OTHER>
128
        inline bool operator==(const OTHER& right) const { 
129
            return mpNode == right.mpNode; }
130
        
131
        template<typename OTHER>
132
        inline bool operator!=(const OTHER& right) const { 
133
            return mpNode != right.mpNode; }
134
135
        /*
136
         * Incr/decr, used to move through the list.
137
         */
138
0
        inline _Iter& operator++() {     // pre-increment
139
0
            mpNode = mpNode->getNext();
140
0
            return *this;
141
0
        }
142
0
        const _Iter operator++(int) {    // post-increment
143
0
            _Iter tmp(*this);
144
0
            mpNode = mpNode->getNext();
145
0
            return tmp;
146
0
        }
Unexecuted instantiation: _ZN7android4ListIPNS_22SimpleSoftOMXComponent10BufferInfoEE13_ListIteratorIS3_NS4_18NON_CONST_ITERATOREEppEi
Unexecuted instantiation: _ZN7android4ListIPNS_22SimpleSoftOMXComponent10BufferInfoEE13_ListIteratorIS3_NS4_14CONST_ITERATOREEppEi
147
        inline _Iter& operator--() {     // pre-increment
148
            mpNode = mpNode->getPrev();
149
            return *this;
150
        }
151
        const _Iter operator--(int) {   // post-increment
152
            _Iter tmp(*this);
153
            mpNode = mpNode->getPrev();
154
            return tmp;
155
        }
156
157
66
        inline _NodePtr getNode() const { return mpNode; }
158
159
        _NodePtr mpNode;    /* should be private, but older gcc fails */
160
    private:
161
        friend class List;
162
    };
163
164
public:
165
0
    List() {
166
0
        prep();
167
0
    }
168
0
    List(const List<T>& src) {      // copy-constructor
169
0
        prep();
170
0
        insert(begin(), src.begin(), src.end());
171
0
    }
172
4
    virtual ~List() {
173
4
        clear();
174
4
        delete[] (unsigned char*) mpMiddle;
175
4
    }
176
177
    typedef _ListIterator<T, NON_CONST_ITERATOR> iterator;
178
    typedef _ListIterator<T, CONST_ITERATOR> const_iterator;
179
180
    List<T>& operator=(const List<T>& right);
181
182
    /* returns true if the list is empty */
183
74
    inline bool empty() const { return mpMiddle->getNext() == mpMiddle; }
184
185
    /* return #of elements in list */
186
    size_t size() const {
187
        return size_t(distance(begin(), end()));
188
    }
189
190
    /*
191
     * Return the first element or one past the last element.  The
192
     * _Node* we're returning is converted to an "iterator" by a
193
     * constructor in _ListIterator.
194
     */
195
48
    inline iterator begin() { 
196
48
        return iterator(mpMiddle->getNext()); 
197
48
    }
198
0
    inline const_iterator begin() const { 
199
0
        return const_iterator(const_cast<_Node const*>(mpMiddle->getNext())); 
200
0
    }
201
0
    inline iterator end() { 
202
0
        return iterator(mpMiddle); 
203
0
    }
204
0
    inline const_iterator end() const { 
205
0
        return const_iterator(const_cast<_Node const*>(mpMiddle)); 
206
0
    }
207
208
    /* add the object to the head or tail of the list */
209
    void push_front(const T& val) { insert(begin(), val); }
210
    void push_back(const T& val) { insert(end(), val); }
211
212
    /* insert before the current node; returns iterator at new node */
213
    iterator insert(iterator posn, const T& val) 
214
0
    {
215
0
        _Node* newNode = new _Node(val);        // alloc & copy-construct
216
0
        newNode->setNext(posn.getNode());
217
0
        newNode->setPrev(posn.getNode()->getPrev());
218
0
        posn.getNode()->getPrev()->setNext(newNode);
219
0
        posn.getNode()->setPrev(newNode);
220
0
        return iterator(newNode);
221
0
    }
222
223
    /* insert a range of elements before the current node */
224
0
    void insert(iterator posn, const_iterator first, const_iterator last) {
225
0
        for ( ; first != last; ++first)
226
0
            insert(posn, *first);
227
0
    }
228
229
    /* remove one entry; returns iterator at next node */
230
22
    iterator erase(iterator posn) {
231
22
        _Node* pNext = posn.getNode()->getNext();
232
22
        _Node* pPrev = posn.getNode()->getPrev();
233
22
        pPrev->setNext(pNext);
234
22
        pNext->setPrev(pPrev);
235
22
        delete posn.getNode();
236
22
        return iterator(pNext);
237
22
    }
238
239
    /* remove a range of elements */
240
0
    iterator erase(iterator first, iterator last) {
241
0
        while (first != last)
242
0
            erase(first++);     // don't erase than incr later!
243
0
        return iterator(last);
244
0
    }
245
246
    /* remove all contents of the list */
247
4
    void clear() {
248
4
        _Node* pCurrent = mpMiddle->getNext();
249
4
        _Node* pNext;
250
4
251
4
        while (pCurrent != mpMiddle) {
252
0
            pNext = pCurrent->getNext();
253
0
            delete pCurrent;
254
0
            pCurrent = pNext;
255
0
        }
256
4
        mpMiddle->setPrev(mpMiddle);
257
4
        mpMiddle->setNext(mpMiddle);
258
4
    }
259
260
    /*
261
     * Measure the distance between two iterators.  On exist, "first"
262
     * will be equal to "last".  The iterators must refer to the same
263
     * list.
264
     *
265
     * FIXME: This is actually a generic iterator function. It should be a 
266
     * template function at the top-level with specializations for things like
267
     * vector<>, which can just do pointer math). Here we limit it to
268
     * _ListIterator of the same type but different constness.
269
     */
270
    template<
271
        typename U,
272
        template <class> class CL,
273
        template <class> class CR
274
    > 
275
    ptrdiff_t distance(
276
            _ListIterator<U, CL> first, _ListIterator<U, CR> last) const 
277
    {
278
        ptrdiff_t count = 0;
279
        while (first != last) {
280
            ++first;
281
            ++count;
282
        }
283
        return count;
284
    }
285
286
private:
287
    /*
288
     * I want a _Node but don't need it to hold valid data.  More
289
     * to the point, I don't want T's constructor to fire, since it
290
     * might have side-effects or require arguments.  So, we do this
291
     * slightly uncouth storage alloc.
292
     */
293
0
    void prep() {
294
0
        mpMiddle = (_Node*) new unsigned char[sizeof(_Node)];
295
0
        mpMiddle->setPrev(mpMiddle);
296
0
        mpMiddle->setNext(mpMiddle);
297
0
    }
298
299
    /*
300
     * This node plays the role of "pointer to head" and "pointer to tail".
301
     * It sits in the middle of a circular list of nodes.  The iterator
302
     * runs around the circle until it encounters this one.
303
     */
304
    _Node*      mpMiddle;
305
};
306
307
/*
308
 * Assignment operator.
309
 *
310
 * The simplest way to do this would be to clear out the target list and
311
 * fill it with the source.  However, we can speed things along by
312
 * re-using existing elements.
313
 */
314
template<class T>
315
List<T>& List<T>::operator=(const List<T>& right)
316
0
{
317
0
    if (this == &right)
318
0
        return *this;       // self-assignment
319
0
    iterator firstDst = begin();
320
0
    iterator lastDst = end();
321
0
    const_iterator firstSrc = right.begin();
322
0
    const_iterator lastSrc = right.end();
323
0
    while (firstSrc != lastSrc && firstDst != lastDst)
324
0
        *firstDst++ = *firstSrc++;
325
0
    if (firstSrc == lastSrc)        // ran out of elements in source?
326
0
        erase(firstDst, lastDst);   // yes, erase any extras
327
0
    else
328
0
        insert(lastDst, firstSrc, lastSrc);     // copy remaining over
329
0
    return *this;
330
0
}
331
332
}  // namespace android
333
334
#endif // _LIBS_UTILS_LIST_H
/proc/self/cwd/system/core/libutils/include/utils/Mutex.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2007 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef _LIBS_UTILS_MUTEX_H
18
#define _LIBS_UTILS_MUTEX_H
19
20
#include <stdint.h>
21
#include <sys/types.h>
22
#include <time.h>
23
24
#if !defined(_WIN32)
25
# include <pthread.h>
26
#endif
27
28
#include <utils/Errors.h>
29
#include <utils/Timers.h>
30
31
// Enable thread safety attributes only with clang.
32
// The attributes can be safely erased when compiling with other compilers.
33
#if defined(__clang__) && (!defined(SWIG))
34
#define THREAD_ANNOTATION_ATTRIBUTE__(x) __attribute__((x))
35
#else
36
#define THREAD_ANNOTATION_ATTRIBUTE__(x)  // no-op
37
#endif
38
39
#define CAPABILITY(x) THREAD_ANNOTATION_ATTRIBUTE__(capability(x))
40
41
#define SCOPED_CAPABILITY THREAD_ANNOTATION_ATTRIBUTE__(scoped_lockable)
42
43
#define GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x))
44
45
#define PT_GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE__(pt_guarded_by(x))
46
47
#define ACQUIRED_BEFORE(...) THREAD_ANNOTATION_ATTRIBUTE__(acquired_before(__VA_ARGS__))
48
49
#define ACQUIRED_AFTER(...) THREAD_ANNOTATION_ATTRIBUTE__(acquired_after(__VA_ARGS__))
50
51
#define REQUIRES(...) THREAD_ANNOTATION_ATTRIBUTE__(requires_capability(__VA_ARGS__))
52
53
#define REQUIRES_SHARED(...) THREAD_ANNOTATION_ATTRIBUTE__(requires_shared_capability(__VA_ARGS__))
54
55
#define ACQUIRE(...) THREAD_ANNOTATION_ATTRIBUTE__(acquire_capability(__VA_ARGS__))
56
57
#define ACQUIRE_SHARED(...) THREAD_ANNOTATION_ATTRIBUTE__(acquire_shared_capability(__VA_ARGS__))
58
59
#define RELEASE(...) THREAD_ANNOTATION_ATTRIBUTE__(release_capability(__VA_ARGS__))
60
61
#define RELEASE_SHARED(...) THREAD_ANNOTATION_ATTRIBUTE__(release_shared_capability(__VA_ARGS__))
62
63
#define TRY_ACQUIRE(...) THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_capability(__VA_ARGS__))
64
65
#define TRY_ACQUIRE_SHARED(...) \
66
    THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_shared_capability(__VA_ARGS__))
67
68
#define EXCLUDES(...) THREAD_ANNOTATION_ATTRIBUTE__(locks_excluded(__VA_ARGS__))
69
70
#define ASSERT_CAPABILITY(x) THREAD_ANNOTATION_ATTRIBUTE__(assert_capability(x))
71
72
#define ASSERT_SHARED_CAPABILITY(x) THREAD_ANNOTATION_ATTRIBUTE__(assert_shared_capability(x))
73
74
#define RETURN_CAPABILITY(x) THREAD_ANNOTATION_ATTRIBUTE__(lock_returned(x))
75
76
#define NO_THREAD_SAFETY_ANALYSIS THREAD_ANNOTATION_ATTRIBUTE__(no_thread_safety_analysis)
77
78
// ---------------------------------------------------------------------------
79
namespace android {
80
// ---------------------------------------------------------------------------
81
82
class Condition;
83
84
/*
85
 * NOTE: This class is for code that builds on Win32.  Its usage is
86
 * deprecated for code which doesn't build for Win32.  New code which
87
 * doesn't build for Win32 should use std::mutex and std::lock_guard instead.
88
 *
89
 * Simple mutex class.  The implementation is system-dependent.
90
 *
91
 * The mutex must be unlocked by the thread that locked it.  They are not
92
 * recursive, i.e. the same thread can't lock it multiple times.
93
 */
94
class CAPABILITY("mutex") Mutex {
95
  public:
96
    enum {
97
        PRIVATE = 0,
98
        SHARED = 1
99
    };
100
101
    Mutex();
102
    explicit Mutex(const char* name);
103
    explicit Mutex(int type, const char* name = nullptr);
104
    ~Mutex();
105
106
    // lock or unlock the mutex
107
    status_t lock() ACQUIRE();
108
    void unlock() RELEASE();
109
110
    // lock if possible; returns 0 on success, error otherwise
111
    status_t tryLock() TRY_ACQUIRE(true);
112
113
#if defined(__ANDROID__)
114
    // Lock the mutex, but don't wait longer than timeoutNs (relative time).
115
    // Returns 0 on success, TIMED_OUT for failure due to timeout expiration.
116
    //
117
    // OSX doesn't have pthread_mutex_timedlock() or equivalent. To keep
118
    // capabilities consistent across host OSes, this method is only available
119
    // when building Android binaries.
120
    //
121
    // FIXME?: pthread_mutex_timedlock is based on CLOCK_REALTIME,
122
    // which is subject to NTP adjustments, and includes time during suspend,
123
    // so a timeout may occur even though no processes could run.
124
    // Not holding a partial wakelock may lead to a system suspend.
125
    status_t timedLock(nsecs_t timeoutNs) TRY_ACQUIRE(true);
126
#endif
127
128
    // Manages the mutex automatically. It'll be locked when Autolock is
129
    // constructed and released when Autolock goes out of scope.
130
    class SCOPED_CAPABILITY Autolock {
131
      public:
132
0
        inline explicit Autolock(Mutex& mutex) ACQUIRE(mutex) : mLock(mutex) { mLock.lock(); }
133
0
        inline explicit Autolock(Mutex* mutex) ACQUIRE(mutex) : mLock(*mutex) { mLock.lock(); }
134
0
        inline ~Autolock() RELEASE() { mLock.unlock(); }
135
136
      private:
137
        Mutex& mLock;
138
        // Cannot be copied or moved - declarations only
139
        Autolock(const Autolock&);
140
        Autolock& operator=(const Autolock&);
141
    };
142
143
  private:
144
    friend class Condition;
145
146
    // A mutex cannot be copied
147
    Mutex(const Mutex&);
148
    Mutex& operator=(const Mutex&);
149
150
#if !defined(_WIN32)
151
    pthread_mutex_t mMutex;
152
#else
153
    void _init();
154
    void* mState;
155
#endif
156
};
157
158
// ---------------------------------------------------------------------------
159
160
#if !defined(_WIN32)
161
162
inline Mutex::Mutex() {
163
    pthread_mutex_init(&mMutex, nullptr);
164
}
165
inline Mutex::Mutex(__attribute__((unused)) const char* name) {
166
    pthread_mutex_init(&mMutex, nullptr);
167
}
168
inline Mutex::Mutex(int type, __attribute__((unused)) const char* name) {
169
    if (type == SHARED) {
170
        pthread_mutexattr_t attr;
171
        pthread_mutexattr_init(&attr);
172
        pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
173
        pthread_mutex_init(&mMutex, &attr);
174
        pthread_mutexattr_destroy(&attr);
175
    } else {
176
        pthread_mutex_init(&mMutex, nullptr);
177
    }
178
}
179
4
inline Mutex::~Mutex() {
180
4
    pthread_mutex_destroy(&mMutex);
181
4
}
182
0
inline status_t Mutex::lock() {
183
0
    return -pthread_mutex_lock(&mMutex);
184
0
}
185
0
inline void Mutex::unlock() {
186
0
    pthread_mutex_unlock(&mMutex);
187
0
}
188
0
inline status_t Mutex::tryLock() {
189
0
    return -pthread_mutex_trylock(&mMutex);
190
0
}
191
#if defined(__ANDROID__)
192
0
inline status_t Mutex::timedLock(nsecs_t timeoutNs) {
193
0
    timeoutNs += systemTime(SYSTEM_TIME_REALTIME);
194
0
    const struct timespec ts = {
195
0
        /* .tv_sec = */ static_cast<time_t>(timeoutNs / 1000000000),
196
0
        /* .tv_nsec = */ static_cast<long>(timeoutNs % 1000000000),
197
0
    };
198
0
    return -pthread_mutex_timedlock(&mMutex, &ts);
199
0
}
200
#endif
201
202
#endif // !defined(_WIN32)
203
204
// ---------------------------------------------------------------------------
205
206
/*
207
 * Automatic mutex.  Declare one of these at the top of a function.
208
 * When the function returns, it will go out of scope, and release the
209
 * mutex.
210
 */
211
212
typedef Mutex::Autolock AutoMutex;
213
214
// ---------------------------------------------------------------------------
215
}  // namespace android
216
// ---------------------------------------------------------------------------
217
218
#endif // _LIBS_UTILS_MUTEX_H
/proc/self/cwd/system/core/libutils/include/utils/NativeHandle.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2014 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef ANDROID_NATIVE_HANDLE_H
18
#define ANDROID_NATIVE_HANDLE_H
19
20
#include <utils/RefBase.h>
21
#include <utils/StrongPointer.h>
22
23
typedef struct native_handle native_handle_t;
24
25
namespace android {
26
27
class NativeHandle : public LightRefBase<NativeHandle> {
28
public:
29
    // Create a refcounted wrapper around a native_handle_t, and declare
30
    // whether the wrapper owns the handle (so that it should clean up the
31
    // handle upon destruction) or not.
32
    // If handle is NULL, no NativeHandle will be created.
33
    static sp<NativeHandle> create(native_handle_t* handle, bool ownsHandle);
34
35
0
    const native_handle_t* handle() const {
36
0
        return mHandle;
37
0
    }
38
39
private:
40
    // for access to the destructor
41
    friend class LightRefBase<NativeHandle>;
42
43
    NativeHandle(native_handle_t* handle, bool ownsHandle);
44
    ~NativeHandle();
45
46
    native_handle_t* mHandle;
47
    bool mOwnsHandle;
48
49
    // non-copyable
50
    NativeHandle(const NativeHandle&);
51
    NativeHandle& operator=(const NativeHandle&);
52
};
53
54
} // namespace android
55
56
#endif // ANDROID_NATIVE_HANDLE_H
/proc/self/cwd/system/core/libutils/include/utils/RWLock.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2007 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef _LIBS_UTILS_RWLOCK_H
18
#define _LIBS_UTILS_RWLOCK_H
19
20
#include <stdint.h>
21
#include <sys/types.h>
22
23
#if !defined(_WIN32)
24
# include <pthread.h>
25
#endif
26
27
#include <utils/Errors.h>
28
#include <utils/ThreadDefs.h>
29
30
// ---------------------------------------------------------------------------
31
namespace android {
32
// ---------------------------------------------------------------------------
33
34
#if !defined(_WIN32)
35
36
/*
37
 * Simple mutex class.  The implementation is system-dependent.
38
 *
39
 * The mutex must be unlocked by the thread that locked it.  They are not
40
 * recursive, i.e. the same thread can't lock it multiple times.
41
 */
42
class RWLock {
43
public:
44
    enum {
45
        PRIVATE = 0,
46
        SHARED = 1
47
    };
48
49
                RWLock();
50
    explicit    RWLock(const char* name);
51
    explicit    RWLock(int type, const char* name = nullptr);
52
                ~RWLock();
53
54
    status_t    readLock();
55
    status_t    tryReadLock();
56
    status_t    writeLock();
57
    status_t    tryWriteLock();
58
    void        unlock();
59
60
    class AutoRLock {
61
    public:
62
0
        inline explicit AutoRLock(RWLock& rwlock) : mLock(rwlock)  { mLock.readLock(); }
63
0
        inline ~AutoRLock() { mLock.unlock(); }
64
    private:
65
        RWLock& mLock;
66
    };
67
68
    class AutoWLock {
69
    public:
70
0
        inline explicit AutoWLock(RWLock& rwlock) : mLock(rwlock)  { mLock.writeLock(); }
71
0
        inline ~AutoWLock() { mLock.unlock(); }
72
    private:
73
        RWLock& mLock;
74
    };
75
76
private:
77
    // A RWLock cannot be copied
78
                RWLock(const RWLock&);
79
   RWLock&      operator = (const RWLock&);
80
81
   pthread_rwlock_t mRWLock;
82
};
83
84
inline RWLock::RWLock() {
85
    pthread_rwlock_init(&mRWLock, nullptr);
86
}
87
inline RWLock::RWLock(__attribute__((unused)) const char* name) {
88
    pthread_rwlock_init(&mRWLock, nullptr);
89
}
90
inline RWLock::RWLock(int type, __attribute__((unused)) const char* name) {
91
    if (type == SHARED) {
92
        pthread_rwlockattr_t attr;
93
        pthread_rwlockattr_init(&attr);
94
        pthread_rwlockattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
95
        pthread_rwlock_init(&mRWLock, &attr);
96
        pthread_rwlockattr_destroy(&attr);
97
    } else {
98
        pthread_rwlock_init(&mRWLock, nullptr);
99
    }
100
}
101
inline RWLock::~RWLock() {
102
    pthread_rwlock_destroy(&mRWLock);
103
}
104
0
inline status_t RWLock::readLock() {
105
0
    return -pthread_rwlock_rdlock(&mRWLock);
106
0
}
107
0
inline status_t RWLock::tryReadLock() {
108
0
    return -pthread_rwlock_tryrdlock(&mRWLock);
109
0
}
110
0
inline status_t RWLock::writeLock() {
111
0
    return -pthread_rwlock_wrlock(&mRWLock);
112
0
}
113
0
inline status_t RWLock::tryWriteLock() {
114
0
    return -pthread_rwlock_trywrlock(&mRWLock);
115
0
}
116
0
inline void RWLock::unlock() {
117
0
    pthread_rwlock_unlock(&mRWLock);
118
0
}
119
120
#endif // !defined(_WIN32)
121
122
// ---------------------------------------------------------------------------
123
}  // namespace android
124
// ---------------------------------------------------------------------------
125
126
#endif // _LIBS_UTILS_RWLOCK_H
/proc/self/cwd/system/core/libutils/include/utils/RefBase.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2016 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
18
// SOME COMMENTS ABOUT USAGE:
19
20
// This provides primarily wp<> weak pointer types and RefBase, which work
21
// together with sp<> from <StrongPointer.h>.
22
23
// sp<> (and wp<>) are a type of smart pointer that use a well defined protocol
24
// to operate. As long as the object they are templated with implements that
25
// protocol, these smart pointers work. In several places the platform
26
// instantiates sp<> with non-RefBase objects; the two are not tied to each
27
// other.
28
29
// RefBase is such an implementation and it supports strong pointers, weak
30
// pointers and some magic features for the binder.
31
32
// So, when using RefBase objects, you have the ability to use strong and weak
33
// pointers through sp<> and wp<>.
34
35
// Normally, when the last strong pointer goes away, the object is destroyed,
36
// i.e. it's destructor is called. HOWEVER, parts of its associated memory is not
37
// freed until the last weak pointer is released.
38
39
// Weak pointers are essentially "safe" pointers. They are always safe to
40
// access through promote(). They may return nullptr if the object was
41
// destroyed because it ran out of strong pointers. This makes them good candidates
42
// for keys in a cache for instance.
43
44
// Weak pointers remain valid for comparison purposes even after the underlying
45
// object has been destroyed. Even if object A is destroyed and its memory reused
46
// for B, A remaining weak pointer to A will not compare equal to one to B.
47
// This again makes them attractive for use as keys.
48
49
// How is this supposed / intended to be used?
50
51
// Our recommendation is to use strong references (sp<>) when there is an
52
// ownership relation. e.g. when an object "owns" another one, use a strong
53
// ref. And of course use strong refs as arguments of functions (it's extremely
54
// rare that a function will take a wp<>).
55
56
// Typically a newly allocated object will immediately be used to initialize
57
// a strong pointer, which may then be used to construct or assign to other
58
// strong and weak pointers.
59
60
// Use weak references when there are no ownership relation. e.g. the keys in a
61
// cache (you cannot use plain pointers because there is no safe way to acquire
62
// a strong reference from a vanilla pointer).
63
64
// This implies that two objects should never (or very rarely) have sp<> on
65
// each other, because they can't both own each other.
66
67
68
// Caveats with reference counting
69
70
// Obviously, circular strong references are a big problem; this creates leaks
71
// and it's hard to debug -- except it's in fact really easy because RefBase has
72
// tons of debugging code for that. It can basically tell you exactly where the
73
// leak is.
74
75
// Another problem has to do with destructors with side effects. You must
76
// assume that the destructor of reference counted objects can be called AT ANY
77
// TIME. For instance code as simple as this:
78
79
// void setStuff(const sp<Stuff>& stuff) {
80
//   std::lock_guard<std::mutex> lock(mMutex);
81
//   mStuff = stuff;
82
// }
83
84
// is very dangerous. This code WILL deadlock one day or another.
85
86
// What isn't obvious is that ~Stuff() can be called as a result of the
87
// assignment. And it gets called with the lock held. First of all, the lock is
88
// protecting mStuff, not ~Stuff(). Secondly, if ~Stuff() uses its own internal
89
// mutex, now you have mutex ordering issues.  Even worse, if ~Stuff() is
90
// virtual, now you're calling into "user" code (potentially), by that, I mean,
91
// code you didn't even write.
92
93
// A correct way to write this code is something like:
94
95
// void setStuff(const sp<Stuff>& stuff) {
96
//   std::unique_lock<std::mutex> lock(mMutex);
97
//   sp<Stuff> hold = mStuff;
98
//   mStuff = stuff;
99
//   lock.unlock();
100
// }
101
102
// More importantly, reference counted objects should do as little work as
103
// possible in their destructor, or at least be mindful that their destructor
104
// could be called from very weird and unintended places.
105
106
// Other more specific restrictions for wp<> and sp<>:
107
108
// Do not construct a strong pointer to "this" in an object's constructor.
109
// The onFirstRef() callback would be made on an incompletely constructed
110
// object.
111
// Construction of a weak pointer to "this" in an object's constructor is also
112
// discouraged. But the implementation was recently changed so that, in the
113
// absence of extendObjectLifetime() calls, weak pointers no longer impact
114
// object lifetime, and hence this no longer risks premature deallocation,
115
// and hence usually works correctly.
116
117
// Such strong or weak pointers can be safely created in the RefBase onFirstRef()
118
// callback.
119
120
// Use of wp::unsafe_get() for any purpose other than debugging is almost
121
// always wrong.  Unless you somehow know that there is a longer-lived sp<> to
122
// the same object, it may well return a pointer to a deallocated object that
123
// has since been reallocated for a different purpose. (And if you know there
124
// is a longer-lived sp<>, why not use an sp<> directly?) A wp<> should only be
125
// dereferenced by using promote().
126
127
// Any object inheriting from RefBase should always be destroyed as the result
128
// of a reference count decrement, not via any other means.  Such objects
129
// should never be stack allocated, or appear directly as data members in other
130
// objects. Objects inheriting from RefBase should have their strong reference
131
// count incremented as soon as possible after construction. Usually this
132
// will be done via construction of an sp<> to the object, but may instead
133
// involve other means of calling RefBase::incStrong().
134
// Explicitly deleting or otherwise destroying a RefBase object with outstanding
135
// wp<> or sp<> pointers to it will result in an abort or heap corruption.
136
137
// It is particularly important not to mix sp<> and direct storage management
138
// since the sp from raw pointer constructor is implicit. Thus if a RefBase-
139
// -derived object of type T is managed without ever incrementing its strong
140
// count, and accidentally passed to f(sp<T>), a strong pointer to the object
141
// will be temporarily constructed and destroyed, prematurely deallocating the
142
// object, and resulting in heap corruption. None of this would be easily
143
// visible in the source.
144
145
// Extra Features:
146
147
// RefBase::extendObjectLifetime() can be used to prevent destruction of the
148
// object while there are still weak references. This is really special purpose
149
// functionality to support Binder.
150
151
// Wp::promote(), implemented via the attemptIncStrong() member function, is
152
// used to try to convert a weak pointer back to a strong pointer.  It's the
153
// normal way to try to access the fields of an object referenced only through
154
// a wp<>.  Binder code also sometimes uses attemptIncStrong() directly.
155
156
// RefBase provides a number of additional callbacks for certain reference count
157
// events, as well as some debugging facilities.
158
159
// Debugging support can be enabled by turning on DEBUG_REFS in RefBase.cpp.
160
// Otherwise little checking is provided.
161
162
// Thread safety:
163
164
// Like std::shared_ptr, sp<> and wp<> allow concurrent accesses to DIFFERENT
165
// sp<> and wp<> instances that happen to refer to the same underlying object.
166
// They do NOT support concurrent access (where at least one access is a write)
167
// to THE SAME sp<> or wp<>.  In effect, their thread-safety properties are
168
// exactly like those of T*, NOT atomic<T*>.
169
170
#ifndef ANDROID_REF_BASE_H
171
#define ANDROID_REF_BASE_H
172
173
#include <atomic>
174
175
#include <stdint.h>
176
#include <sys/types.h>
177
#include <stdlib.h>
178
#include <string.h>
179
180
// LightRefBase used to be declared in this header, so we have to include it
181
#include <utils/LightRefBase.h>
182
183
#include <utils/StrongPointer.h>
184
#include <utils/TypeHelpers.h>
185
186
// ---------------------------------------------------------------------------
187
namespace android {
188
189
class TextOutput;
190
TextOutput& printWeakPointer(TextOutput& to, const void* val);
191
192
// ---------------------------------------------------------------------------
193
194
#define COMPARE_WEAK(_op_)                                      \
195
inline bool operator _op_ (const sp<T>& o) const {              \
196
    return m_ptr _op_ o.m_ptr;                                  \
197
}                                                               \
198
inline bool operator _op_ (const T* o) const {                  \
199
    return m_ptr _op_ o;                                        \
200
}                                                               \
201
template<typename U>                                            \
202
inline bool operator _op_ (const sp<U>& o) const {              \
203
    return m_ptr _op_ o.m_ptr;                                  \
204
}                                                               \
205
template<typename U>                                            \
206
inline bool operator _op_ (const U* o) const {                  \
207
    return m_ptr _op_ o;                                        \
208
}
209
210
// ---------------------------------------------------------------------------
211
212
// RefererenceRenamer is pure abstract, there is no virtual method
213
// implementation to put in a translation unit in order to silence the
214
// weak vtables warning.
215
#if defined(__clang__)
216
#pragma clang diagnostic push
217
#pragma clang diagnostic ignored "-Wweak-vtables"
218
#endif
219
220
class ReferenceRenamer {
221
protected:
222
    // destructor is purposely not virtual so we avoid code overhead from
223
    // subclasses; we have to make it protected to guarantee that it
224
    // cannot be called from this base class (and to make strict compilers
225
    // happy).
226
0
    ~ReferenceRenamer() { }
227
public:
228
    virtual void operator()(size_t i) const = 0;
229
};
230
231
#if defined(__clang__)
232
#pragma clang diagnostic pop
233
#endif
234
235
// ---------------------------------------------------------------------------
236
237
class RefBase
238
{
239
public:
240
            void            incStrong(const void* id) const;
241
            void            decStrong(const void* id) const;
242
    
243
            void            forceIncStrong(const void* id) const;
244
245
            //! DEBUGGING ONLY: Get current strong ref count.
246
            int32_t         getStrongCount() const;
247
248
    class weakref_type
249
    {
250
    public:
251
        RefBase*            refBase() const;
252
253
        void                incWeak(const void* id);
254
        void                decWeak(const void* id);
255
256
        // acquires a strong reference if there is already one.
257
        bool                attemptIncStrong(const void* id);
258
259
        // acquires a weak reference if there is already one.
260
        // This is not always safe. see ProcessState.cpp and BpBinder.cpp
261
        // for proper use.
262
        bool                attemptIncWeak(const void* id);
263
264
        //! DEBUGGING ONLY: Get current weak ref count.
265
        int32_t             getWeakCount() const;
266
267
        //! DEBUGGING ONLY: Print references held on object.
268
        void                printRefs() const;
269
270
        //! DEBUGGING ONLY: Enable tracking for this object.
271
        // enable -- enable/disable tracking
272
        // retain -- when tracking is enable, if true, then we save a stack trace
273
        //           for each reference and dereference; when retain == false, we
274
        //           match up references and dereferences and keep only the
275
        //           outstanding ones.
276
277
        void                trackMe(bool enable, bool retain);
278
    };
279
280
            weakref_type*   createWeak(const void* id) const;
281
            
282
            weakref_type*   getWeakRefs() const;
283
284
            //! DEBUGGING ONLY: Print references held on object.
285
0
    inline  void            printRefs() const { getWeakRefs()->printRefs(); }
286
287
            //! DEBUGGING ONLY: Enable tracking of object.
288
    inline  void            trackMe(bool enable, bool retain)
289
0
    { 
290
0
        getWeakRefs()->trackMe(enable, retain); 
291
0
    }
292
293
    typedef RefBase basetype;
294
295
protected:
296
                            RefBase();
297
    virtual                 ~RefBase();
298
    
299
    //! Flags for extendObjectLifetime()
300
    enum {
301
        OBJECT_LIFETIME_STRONG  = 0x0000,
302
        OBJECT_LIFETIME_WEAK    = 0x0001,
303
        OBJECT_LIFETIME_MASK    = 0x0001
304
    };
305
    
306
            void            extendObjectLifetime(int32_t mode);
307
            
308
    //! Flags for onIncStrongAttempted()
309
    enum {
310
        FIRST_INC_STRONG = 0x0001
311
    };
312
    
313
    // Invoked after creation of initial strong pointer/reference.
314
    virtual void            onFirstRef();
315
    // Invoked when either the last strong reference goes away, or we need to undo
316
    // the effect of an unnecessary onIncStrongAttempted.
317
    virtual void            onLastStrongRef(const void* id);
318
    // Only called in OBJECT_LIFETIME_WEAK case.  Returns true if OK to promote to
319
    // strong reference. May have side effects if it returns true.
320
    // The first flags argument is always FIRST_INC_STRONG.
321
    // TODO: Remove initial flag argument.
322
    virtual bool            onIncStrongAttempted(uint32_t flags, const void* id);
323
    // Invoked in the OBJECT_LIFETIME_WEAK case when the last reference of either
324
    // kind goes away.  Unused.
325
    // TODO: Remove.
326
    virtual void            onLastWeakRef(const void* id);
327
328
private:
329
    friend class weakref_type;
330
    class weakref_impl;
331
    
332
                            RefBase(const RefBase& o);
333
            RefBase&        operator=(const RefBase& o);
334
335
private:
336
    friend class ReferenceMover;
337
338
    static void renameRefs(size_t n, const ReferenceRenamer& renamer);
339
340
    static void renameRefId(weakref_type* ref,
341
            const void* old_id, const void* new_id);
342
343
    static void renameRefId(RefBase* ref,
344
            const void* old_id, const void* new_id);
345
346
        weakref_impl* const mRefs;
347
};
348
349
// ---------------------------------------------------------------------------
350
351
template <typename T>
352
class wp
353
{
354
public:
355
    typedef typename RefBase::weakref_type weakref_type;
356
357
    inline wp() : m_ptr(nullptr) { }
358
359
    wp(T* other);  // NOLINT(implicit)
360
    wp(const wp<T>& other);
361
    explicit wp(const sp<T>& other);
362
    template<typename U> wp(U* other);  // NOLINT(implicit)
363
    template<typename U> wp(const sp<U>& other);  // NOLINT(implicit)
364
    template<typename U> wp(const wp<U>& other);  // NOLINT(implicit)
365
366
    ~wp();
367
368
    // Assignment
369
370
    wp& operator = (T* other);
371
    wp& operator = (const wp<T>& other);
372
    wp& operator = (const sp<T>& other);
373
374
    template<typename U> wp& operator = (U* other);
375
    template<typename U> wp& operator = (const wp<U>& other);
376
    template<typename U> wp& operator = (const sp<U>& other);
377
378
    void set_object_and_refs(T* other, weakref_type* refs);
379
380
    // promotion to sp
381
382
    sp<T> promote() const;
383
384
    // Reset
385
386
    void clear();
387
388
    // Accessors
389
390
    inline  weakref_type* get_refs() const { return m_refs; }
391
392
    inline  T* unsafe_get() const { return m_ptr; }
393
394
    // Operators
395
396
    COMPARE_WEAK(==)
397
    COMPARE_WEAK(!=)
398
    COMPARE_WEAK(>)
399
    COMPARE_WEAK(<)
400
    COMPARE_WEAK(<=)
401
    COMPARE_WEAK(>=)
402
403
    inline bool operator == (const wp<T>& o) const {
404
        return (m_ptr == o.m_ptr) && (m_refs == o.m_refs);
405
    }
406
    template<typename U>
407
    inline bool operator == (const wp<U>& o) const {
408
        return m_ptr == o.m_ptr;
409
    }
410
411
    inline bool operator > (const wp<T>& o) const {
412
        return (m_ptr == o.m_ptr) ? (m_refs > o.m_refs) : (m_ptr > o.m_ptr);
413
    }
414
    template<typename U>
415
    inline bool operator > (const wp<U>& o) const {
416
        return (m_ptr == o.m_ptr) ? (m_refs > o.m_refs) : (m_ptr > o.m_ptr);
417
    }
418
419
    inline bool operator < (const wp<T>& o) const {
420
        return (m_ptr == o.m_ptr) ? (m_refs < o.m_refs) : (m_ptr < o.m_ptr);
421
    }
422
    template<typename U>
423
    inline bool operator < (const wp<U>& o) const {
424
        return (m_ptr == o.m_ptr) ? (m_refs < o.m_refs) : (m_ptr < o.m_ptr);
425
    }
426
                         inline bool operator != (const wp<T>& o) const { return m_refs != o.m_refs; }
427
    template<typename U> inline bool operator != (const wp<U>& o) const { return !operator == (o); }
428
                         inline bool operator <= (const wp<T>& o) const { return !operator > (o); }
429
    template<typename U> inline bool operator <= (const wp<U>& o) const { return !operator > (o); }
430
                         inline bool operator >= (const wp<T>& o) const { return !operator < (o); }
431
    template<typename U> inline bool operator >= (const wp<U>& o) const { return !operator < (o); }
432
433
private:
434
    template<typename Y> friend class sp;
435
    template<typename Y> friend class wp;
436
437
    T*              m_ptr;
438
    weakref_type*   m_refs;
439
};
440
441
template <typename T>
442
TextOutput& operator<<(TextOutput& to, const wp<T>& val);
443
444
#undef COMPARE_WEAK
445
446
// ---------------------------------------------------------------------------
447
// No user serviceable parts below here.
448
449
template<typename T>
450
wp<T>::wp(T* other)
451
    : m_ptr(other)
452
{
453
    if (other) m_refs = other->createWeak(this);
454
}
455
456
template<typename T>
457
wp<T>::wp(const wp<T>& other)
458
    : m_ptr(other.m_ptr), m_refs(other.m_refs)
459
{
460
    if (m_ptr) m_refs->incWeak(this);
461
}
462
463
template<typename T>
464
wp<T>::wp(const sp<T>& other)
465
    : m_ptr(other.m_ptr)
466
{
467
    if (m_ptr) {
468
        m_refs = m_ptr->createWeak(this);
469
    }
470
}
471
472
template<typename T> template<typename U>
473
wp<T>::wp(U* other)
474
    : m_ptr(other)
475
{
476
    if (other) m_refs = other->createWeak(this);
477
}
478
479
template<typename T> template<typename U>
480
wp<T>::wp(const wp<U>& other)
481
    : m_ptr(other.m_ptr)
482
{
483
    if (m_ptr) {
484
        m_refs = other.m_refs;
485
        m_refs->incWeak(this);
486
    }
487
}
488
489
template<typename T> template<typename U>
490
wp<T>::wp(const sp<U>& other)
491
    : m_ptr(other.m_ptr)
492
{
493
    if (m_ptr) {
494
        m_refs = m_ptr->createWeak(this);
495
    }
496
}
497
498
template<typename T>
499
wp<T>::~wp()
500
{
501
    if (m_ptr) m_refs->decWeak(this);
502
}
503
504
template<typename T>
505
wp<T>& wp<T>::operator = (T* other)
506
{
507
    weakref_type* newRefs =
508
        other ? other->createWeak(this) : nullptr;
509
    if (m_ptr) m_refs->decWeak(this);
510
    m_ptr = other;
511
    m_refs = newRefs;
512
    return *this;
513
}
514
515
template<typename T>
516
wp<T>& wp<T>::operator = (const wp<T>& other)
517
0
{
518
0
    weakref_type* otherRefs(other.m_refs);
519
0
    T* otherPtr(other.m_ptr);
520
0
    if (otherPtr) otherRefs->incWeak(this);
521
0
    if (m_ptr) m_refs->decWeak(this);
522
0
    m_ptr = otherPtr;
523
0
    m_refs = otherRefs;
524
0
    return *this;
525
0
}
526
527
template<typename T>
528
wp<T>& wp<T>::operator = (const sp<T>& other)
529
{
530
    weakref_type* newRefs =
531
        other != nullptr ? other->createWeak(this) : nullptr;
532
    T* otherPtr(other.m_ptr);
533
    if (m_ptr) m_refs->decWeak(this);
534
    m_ptr = otherPtr;
535
    m_refs = newRefs;
536
    return *this;
537
}
538
539
template<typename T> template<typename U>
540
wp<T>& wp<T>::operator = (U* other)
541
{
542
    weakref_type* newRefs =
543
        other ? other->createWeak(this) : 0;
544
    if (m_ptr) m_refs->decWeak(this);
545
    m_ptr = other;
546
    m_refs = newRefs;
547
    return *this;
548
}
549
550
template<typename T> template<typename U>
551
wp<T>& wp<T>::operator = (const wp<U>& other)
552
{
553
    weakref_type* otherRefs(other.m_refs);
554
    U* otherPtr(other.m_ptr);
555
    if (otherPtr) otherRefs->incWeak(this);
556
    if (m_ptr) m_refs->decWeak(this);
557
    m_ptr = otherPtr;
558
    m_refs = otherRefs;
559
    return *this;
560
}
561
562
template<typename T> template<typename U>
563
wp<T>& wp<T>::operator = (const sp<U>& other)
564
{
565
    weakref_type* newRefs =
566
        other != nullptr ? other->createWeak(this) : 0;
567
    U* otherPtr(other.m_ptr);
568
    if (m_ptr) m_refs->decWeak(this);
569
    m_ptr = otherPtr;
570
    m_refs = newRefs;
571
    return *this;
572
}
573
574
template<typename T>
575
void wp<T>::set_object_and_refs(T* other, weakref_type* refs)
576
{
577
    if (other) refs->incWeak(this);
578
    if (m_ptr) m_refs->decWeak(this);
579
    m_ptr = other;
580
    m_refs = refs;
581
}
582
583
template<typename T>
584
sp<T> wp<T>::promote() const
585
0
{
586
0
    sp<T> result;
587
0
    if (m_ptr && m_refs->attemptIncStrong(&result)) {
588
0
        result.set_pointer(m_ptr);
589
0
    }
590
0
    return result;
591
0
}
592
593
template<typename T>
594
void wp<T>::clear()
595
{
596
    if (m_ptr) {
597
        m_refs->decWeak(this);
598
        m_ptr = 0;
599
    }
600
}
601
602
template <typename T>
603
inline TextOutput& operator<<(TextOutput& to, const wp<T>& val)
604
{
605
    return printWeakPointer(to, val.unsafe_get());
606
}
607
608
// ---------------------------------------------------------------------------
609
610
// this class just serves as a namespace so TYPE::moveReferences can stay
611
// private.
612
class ReferenceMover {
613
public:
614
    // it would be nice if we could make sure no extra code is generated
615
    // for sp<TYPE> or wp<TYPE> when TYPE is a descendant of RefBase:
616
    // Using a sp<RefBase> override doesn't work; it's a bit like we wanted
617
    // a template<typename TYPE inherits RefBase> template...
618
619
    template<typename TYPE> static inline
620
    void move_references(sp<TYPE>* dest, sp<TYPE> const* src, size_t n) {
621
622
        class Renamer : public ReferenceRenamer {
623
            sp<TYPE>* d_;
624
            sp<TYPE> const* s_;
625
            virtual void operator()(size_t i) const {
626
                // The id are known to be the sp<>'s this pointer
627
                TYPE::renameRefId(d_[i].get(), &s_[i], &d_[i]);
628
            }
629
        public:
630
            Renamer(sp<TYPE>* d, sp<TYPE> const* s) : d_(d), s_(s) { }
631
            virtual ~Renamer() { }
632
        };
633
634
        memmove(dest, src, n*sizeof(sp<TYPE>));
635
        TYPE::renameRefs(n, Renamer(dest, src));
636
    }
637
638
639
    template<typename TYPE> static inline
640
    void move_references(wp<TYPE>* dest, wp<TYPE> const* src, size_t n) {
641
642
        class Renamer : public ReferenceRenamer {
643
            wp<TYPE>* d_;
644
            wp<TYPE> const* s_;
645
            virtual void operator()(size_t i) const {
646
                // The id are known to be the wp<>'s this pointer
647
                TYPE::renameRefId(d_[i].get_refs(), &s_[i], &d_[i]);
648
            }
649
        public:
650
            Renamer(wp<TYPE>* rd, wp<TYPE> const* rs) : d_(rd), s_(rs) { }
651
            virtual ~Renamer() { }
652
        };
653
654
        memmove(dest, src, n*sizeof(wp<TYPE>));
655
        TYPE::renameRefs(n, Renamer(dest, src));
656
    }
657
};
658
659
// specialization for moving sp<> and wp<> types.
660
// these are used by the [Sorted|Keyed]Vector<> implementations
661
// sp<> and wp<> need to be handled specially, because they do not
662
// have trivial copy operation in the general case (see RefBase.cpp
663
// when DEBUG ops are enabled), but can be implemented very
664
// efficiently in most cases.
665
666
template<typename TYPE> inline
667
void move_forward_type(sp<TYPE>* d, sp<TYPE> const* s, size_t n) {
668
    ReferenceMover::move_references(d, s, n);
669
}
670
671
template<typename TYPE> inline
672
void move_backward_type(sp<TYPE>* d, sp<TYPE> const* s, size_t n) {
673
    ReferenceMover::move_references(d, s, n);
674
}
675
676
template<typename TYPE> inline
677
void move_forward_type(wp<TYPE>* d, wp<TYPE> const* s, size_t n) {
678
    ReferenceMover::move_references(d, s, n);
679
}
680
681
template<typename TYPE> inline
682
void move_backward_type(wp<TYPE>* d, wp<TYPE> const* s, size_t n) {
683
    ReferenceMover::move_references(d, s, n);
684
}
685
686
}  // namespace android
687
688
// ---------------------------------------------------------------------------
689
690
#endif // ANDROID_REF_BASE_H
/proc/self/cwd/system/core/libutils/include/utils/SortedVector.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2005 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef ANDROID_SORTED_VECTOR_H
18
#define ANDROID_SORTED_VECTOR_H
19
20
#include <assert.h>
21
#include <stdint.h>
22
#include <sys/types.h>
23
24
#include <log/log.h>
25
#include <utils/TypeHelpers.h>
26
#include <utils/Vector.h>
27
#include <utils/VectorImpl.h>
28
29
// ---------------------------------------------------------------------------
30
31
namespace android {
32
33
// DO NOT USE: please use std::set
34
35
template <class TYPE>
36
class SortedVector : private SortedVectorImpl
37
{
38
    friend class Vector<TYPE>;
39
40
public:
41
            typedef TYPE    value_type;
42
43
    /*!
44
     * Constructors and destructors
45
     */
46
47
                            SortedVector();
48
                            SortedVector(const SortedVector<TYPE>& rhs);
49
    virtual                 ~SortedVector();
50
51
    /*! copy operator */
52
    const SortedVector<TYPE>&   operator = (const SortedVector<TYPE>& rhs) const;
53
    SortedVector<TYPE>&         operator = (const SortedVector<TYPE>& rhs);
54
55
    /*
56
     * empty the vector
57
     */
58
59
    inline  void            clear()             { VectorImpl::clear(); }
60
61
    /*!
62
     * vector stats
63
     */
64
65
    //! returns number of items in the vector
66
    inline  size_t          size() const                { return VectorImpl::size(); }
67
    //! returns whether or not the vector is empty
68
    inline  bool            isEmpty() const             { return VectorImpl::isEmpty(); }
69
    //! returns how many items can be stored without reallocating the backing store
70
    inline  size_t          capacity() const            { return VectorImpl::capacity(); }
71
    //! sets the capacity. capacity can never be reduced less than size()
72
    inline  ssize_t         setCapacity(size_t size)    { return VectorImpl::setCapacity(size); }
73
74
    /*!
75
     * C-style array access
76
     */
77
78
    //! read-only C-style access
79
    inline  const TYPE*     array() const;
80
81
    //! read-write C-style access. BE VERY CAREFUL when modifying the array
82
    //! you must keep it sorted! You usually don't use this function.
83
            TYPE*           editArray();
84
85
            //! finds the index of an item
86
            ssize_t         indexOf(const TYPE& item) const;
87
88
            //! finds where this item should be inserted
89
            size_t          orderOf(const TYPE& item) const;
90
91
92
    /*!
93
     * accessors
94
     */
95
96
    //! read-only access to an item at a given index
97
    inline  const TYPE&     operator [] (size_t index) const;
98
    //! alternate name for operator []
99
    inline  const TYPE&     itemAt(size_t index) const;
100
    //! stack-usage of the vector. returns the top of the stack (last element)
101
            const TYPE&     top() const;
102
103
    /*!
104
     * modifying the array
105
     */
106
107
            //! add an item in the right place (and replace the one that is there)
108
            ssize_t         add(const TYPE& item);
109
110
            //! editItemAt() MUST NOT change the order of this item
111
            TYPE&           editItemAt(size_t index) {
112
                return *( static_cast<TYPE *>(VectorImpl::editItemLocation(index)) );
113
            }
114
115
            //! merges a vector into this one
116
            ssize_t         merge(const Vector<TYPE>& vector);
117
            ssize_t         merge(const SortedVector<TYPE>& vector);
118
119
            //! removes an item
120
            ssize_t         remove(const TYPE&);
121
122
    //! remove several items
123
    inline  ssize_t         removeItemsAt(size_t index, size_t count = 1);
124
    //! remove one item
125
    inline  ssize_t         removeAt(size_t index)  { return removeItemsAt(index); }
126
127
    /*
128
     * these inlines add some level of compatibility with STL.
129
     */
130
    typedef TYPE* iterator;
131
    typedef TYPE const* const_iterator;
132
133
    inline iterator begin() { return editArray(); }
134
    inline iterator end()   { return editArray() + size(); }
135
    inline const_iterator begin() const { return array(); }
136
    inline const_iterator end() const   { return array() + size(); }
137
    inline void reserve(size_t n) { setCapacity(n); }
138
    inline bool empty() const{ return isEmpty(); }
139
    inline iterator erase(iterator pos) {
140
        ssize_t index = removeItemsAt(pos-array());
141
        return begin() + index;
142
    }
143
144
protected:
145
    virtual void    do_construct(void* storage, size_t num) const;
146
    virtual void    do_destroy(void* storage, size_t num) const;
147
    virtual void    do_copy(void* dest, const void* from, size_t num) const;
148
    virtual void    do_splat(void* dest, const void* item, size_t num) const;
149
    virtual void    do_move_forward(void* dest, const void* from, size_t num) const;
150
    virtual void    do_move_backward(void* dest, const void* from, size_t num) const;
151
    virtual int     do_compare(const void* lhs, const void* rhs) const;
152
};
153
154
// ---------------------------------------------------------------------------
155
// No user serviceable parts from here...
156
// ---------------------------------------------------------------------------
157
158
template<class TYPE> inline
159
SortedVector<TYPE>::SortedVector()
160
    : SortedVectorImpl(sizeof(TYPE),
161
                ((traits<TYPE>::has_trivial_ctor   ? HAS_TRIVIAL_CTOR   : 0)
162
                |(traits<TYPE>::has_trivial_dtor   ? HAS_TRIVIAL_DTOR   : 0)
163
                |(traits<TYPE>::has_trivial_copy   ? HAS_TRIVIAL_COPY   : 0))
164
                )
165
{
166
}
167
168
template<class TYPE> inline
169
SortedVector<TYPE>::SortedVector(const SortedVector<TYPE>& rhs)
170
    : SortedVectorImpl(rhs) {
171
}
172
173
template<class TYPE> inline
174
SortedVector<TYPE>::~SortedVector() {
175
    finish_vector();
176
}
177
178
template<class TYPE> inline
179
SortedVector<TYPE>& SortedVector<TYPE>::operator = (const SortedVector<TYPE>& rhs) {
180
    SortedVectorImpl::operator = (rhs);
181
    return *this;
182
}
183
184
template<class TYPE> inline
185
const SortedVector<TYPE>& SortedVector<TYPE>::operator = (const SortedVector<TYPE>& rhs) const {
186
    SortedVectorImpl::operator = (rhs);
187
    return *this;
188
}
189
190
template<class TYPE> inline
191
const TYPE* SortedVector<TYPE>::array() const {
192
    return static_cast<const TYPE *>(arrayImpl());
193
}
194
195
template<class TYPE> inline
196
TYPE* SortedVector<TYPE>::editArray() {
197
    return static_cast<TYPE *>(editArrayImpl());
198
}
199
200
201
template<class TYPE> inline
202
const TYPE& SortedVector<TYPE>::operator[](size_t index) const {
203
    LOG_FATAL_IF(index>=size(),
204
            "%s: index=%u out of range (%u)", __PRETTY_FUNCTION__,
205
            int(index), int(size()));
206
    return *(array() + index);
207
}
208
209
template<class TYPE> inline
210
const TYPE& SortedVector<TYPE>::itemAt(size_t index) const {
211
    return operator[](index);
212
}
213
214
template<class TYPE> inline
215
const TYPE& SortedVector<TYPE>::top() const {
216
    return *(array() + size() - 1);
217
}
218
219
template<class TYPE> inline
220
ssize_t SortedVector<TYPE>::add(const TYPE& item) {
221
    return SortedVectorImpl::add(&item);
222
}
223
224
template<class TYPE> inline
225
ssize_t SortedVector<TYPE>::indexOf(const TYPE& item) const {
226
    return SortedVectorImpl::indexOf(&item);
227
}
228
229
template<class TYPE> inline
230
size_t SortedVector<TYPE>::orderOf(const TYPE& item) const {
231
    return SortedVectorImpl::orderOf(&item);
232
}
233
234
template<class TYPE> inline
235
ssize_t SortedVector<TYPE>::merge(const Vector<TYPE>& vector) {
236
    return SortedVectorImpl::merge(reinterpret_cast<const VectorImpl&>(vector));
237
}
238
239
template<class TYPE> inline
240
ssize_t SortedVector<TYPE>::merge(const SortedVector<TYPE>& vector) {
241
    return SortedVectorImpl::merge(reinterpret_cast<const SortedVectorImpl&>(vector));
242
}
243
244
template<class TYPE> inline
245
ssize_t SortedVector<TYPE>::remove(const TYPE& item) {
246
    return SortedVectorImpl::remove(&item);
247
}
248
249
template<class TYPE> inline
250
ssize_t SortedVector<TYPE>::removeItemsAt(size_t index, size_t count) {
251
    return VectorImpl::removeItemsAt(index, count);
252
}
253
254
// ---------------------------------------------------------------------------
255
256
template<class TYPE>
257
0
UTILS_VECTOR_NO_CFI void SortedVector<TYPE>::do_construct(void* storage, size_t num) const {
258
0
    construct_type( reinterpret_cast<TYPE*>(storage), num );
259
0
}
260
261
template<class TYPE>
262
0
void SortedVector<TYPE>::do_destroy(void* storage, size_t num) const {
263
0
    destroy_type( reinterpret_cast<TYPE*>(storage), num );
264
0
}
265
266
template<class TYPE>
267
0
UTILS_VECTOR_NO_CFI void SortedVector<TYPE>::do_copy(void* dest, const void* from, size_t num) const {
268
0
    copy_type( reinterpret_cast<TYPE*>(dest), reinterpret_cast<const TYPE*>(from), num );
269
0
}
270
271
template<class TYPE>
272
0
UTILS_VECTOR_NO_CFI void SortedVector<TYPE>::do_splat(void* dest, const void* item, size_t num) const {
273
0
    splat_type( reinterpret_cast<TYPE*>(dest), reinterpret_cast<const TYPE*>(item), num );
274
0
}
275
276
template<class TYPE>
277
0
UTILS_VECTOR_NO_CFI void SortedVector<TYPE>::do_move_forward(void* dest, const void* from, size_t num) const {
278
0
    move_forward_type( reinterpret_cast<TYPE*>(dest), reinterpret_cast<const TYPE*>(from), num );
279
0
}
280
281
template<class TYPE>
282
0
UTILS_VECTOR_NO_CFI void SortedVector<TYPE>::do_move_backward(void* dest, const void* from, size_t num) const {
283
0
    move_backward_type( reinterpret_cast<TYPE*>(dest), reinterpret_cast<const TYPE*>(from), num );
284
0
}
285
286
template<class TYPE>
287
0
int SortedVector<TYPE>::do_compare(const void* lhs, const void* rhs) const {
288
0
    return compare_type( *reinterpret_cast<const TYPE*>(lhs), *reinterpret_cast<const TYPE*>(rhs) );
289
0
}
290
291
}  // namespace android
292
293
// ---------------------------------------------------------------------------
294
295
#endif // ANDROID_SORTED_VECTOR_H
/proc/self/cwd/system/core/libutils/include/utils/String16.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2005 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef ANDROID_STRING16_H
18
#define ANDROID_STRING16_H
19
20
#include <string> // for std::string
21
22
#include <utils/Errors.h>
23
#include <utils/String8.h>
24
#include <utils/TypeHelpers.h>
25
26
// ---------------------------------------------------------------------------
27
28
extern "C" {
29
30
}
31
32
// ---------------------------------------------------------------------------
33
34
namespace android {
35
36
// ---------------------------------------------------------------------------
37
38
class String8;
39
40
// DO NOT USE: please use std::u16string
41
42
//! This is a string holding UTF-16 characters.
43
class String16
44
{
45
public:
46
    /* use String16(StaticLinkage) if you're statically linking against
47
     * libutils and declaring an empty static String16, e.g.:
48
     *
49
     *   static String16 sAStaticEmptyString(String16::kEmptyString);
50
     *   static String16 sAnotherStaticEmptyString(sAStaticEmptyString);
51
     */
52
    enum StaticLinkage { kEmptyString };
53
54
                                String16();
55
    explicit                    String16(StaticLinkage);
56
                                String16(const String16& o);
57
                                String16(const String16& o,
58
                                         size_t len,
59
                                         size_t begin=0);
60
    explicit                    String16(const char16_t* o);
61
    explicit                    String16(const char16_t* o, size_t len);
62
    explicit                    String16(const String8& o);
63
    explicit                    String16(const char* o);
64
    explicit                    String16(const char* o, size_t len);
65
66
                                ~String16();
67
68
    inline  const char16_t*     string() const;
69
70
private:
71
    static inline std::string   std_string(const String16& str);
72
public:
73
            size_t              size() const;
74
            void                setTo(const String16& other);
75
            status_t            setTo(const char16_t* other);
76
            status_t            setTo(const char16_t* other, size_t len);
77
            status_t            setTo(const String16& other,
78
                                      size_t len,
79
                                      size_t begin=0);
80
81
            status_t            append(const String16& other);
82
            status_t            append(const char16_t* other, size_t len);
83
84
    inline  String16&           operator=(const String16& other);
85
86
    inline  String16&           operator+=(const String16& other);
87
    inline  String16            operator+(const String16& other) const;
88
89
            status_t            insert(size_t pos, const char16_t* chrs);
90
            status_t            insert(size_t pos,
91
                                       const char16_t* chrs, size_t len);
92
93
            ssize_t             findFirst(char16_t c) const;
94
            ssize_t             findLast(char16_t c) const;
95
96
            bool                startsWith(const String16& prefix) const;
97
            bool                startsWith(const char16_t* prefix) const;
98
99
            bool                contains(const char16_t* chrs) const;
100
101
            status_t            makeLower();
102
103
            status_t            replaceAll(char16_t replaceThis,
104
                                           char16_t withThis);
105
106
            status_t            remove(size_t len, size_t begin=0);
107
108
    inline  int                 compare(const String16& other) const;
109
110
    inline  bool                operator<(const String16& other) const;
111
    inline  bool                operator<=(const String16& other) const;
112
    inline  bool                operator==(const String16& other) const;
113
    inline  bool                operator!=(const String16& other) const;
114
    inline  bool                operator>=(const String16& other) const;
115
    inline  bool                operator>(const String16& other) const;
116
117
    inline  bool                operator<(const char16_t* other) const;
118
    inline  bool                operator<=(const char16_t* other) const;
119
    inline  bool                operator==(const char16_t* other) const;
120
    inline  bool                operator!=(const char16_t* other) const;
121
    inline  bool                operator>=(const char16_t* other) const;
122
    inline  bool                operator>(const char16_t* other) const;
123
124
    inline                      operator const char16_t*() const;
125
126
private:
127
            const char16_t*     mString;
128
};
129
130
// String16 can be trivially moved using memcpy() because moving does not
131
// require any change to the underlying SharedBuffer contents or reference count.
132
ANDROID_TRIVIAL_MOVE_TRAIT(String16)
133
134
// ---------------------------------------------------------------------------
135
// No user servicable parts below.
136
137
inline int compare_type(const String16& lhs, const String16& rhs)
138
0
{
139
0
    return lhs.compare(rhs);
140
0
}
141
142
inline int strictly_order_type(const String16& lhs, const String16& rhs)
143
0
{
144
0
    return compare_type(lhs, rhs) < 0;
145
0
}
146
147
inline const char16_t* String16::string() const
148
0
{
149
0
    return mString;
150
0
}
151
152
inline std::string String16::std_string(const String16& str)
153
0
{
154
0
    return std::string(String8(str).string());
155
0
}
156
157
inline String16& String16::operator=(const String16& other)
158
0
{
159
0
    setTo(other);
160
0
    return *this;
161
0
}
162
163
inline String16& String16::operator+=(const String16& other)
164
0
{
165
0
    append(other);
166
0
    return *this;
167
0
}
168
169
inline String16 String16::operator+(const String16& other) const
170
0
{
171
0
    String16 tmp(*this);
172
0
    tmp += other;
173
0
    return tmp;
174
0
}
175
176
inline int String16::compare(const String16& other) const
177
0
{
178
0
    return strzcmp16(mString, size(), other.mString, other.size());
179
0
}
180
181
inline bool String16::operator<(const String16& other) const
182
0
{
183
0
    return strzcmp16(mString, size(), other.mString, other.size()) < 0;
184
0
}
185
186
inline bool String16::operator<=(const String16& other) const
187
0
{
188
0
    return strzcmp16(mString, size(), other.mString, other.size()) <= 0;
189
0
}
190
191
inline bool String16::operator==(const String16& other) const
192
0
{
193
0
    return strzcmp16(mString, size(), other.mString, other.size()) == 0;
194
0
}
195
196
inline bool String16::operator!=(const String16& other) const
197
0
{
198
0
    return strzcmp16(mString, size(), other.mString, other.size()) != 0;
199
0
}
200
201
inline bool String16::operator>=(const String16& other) const
202
0
{
203
0
    return strzcmp16(mString, size(), other.mString, other.size()) >= 0;
204
0
}
205
206
inline bool String16::operator>(const String16& other) const
207
0
{
208
0
    return strzcmp16(mString, size(), other.mString, other.size()) > 0;
209
0
}
210
211
inline bool String16::operator<(const char16_t* other) const
212
0
{
213
0
    return strcmp16(mString, other) < 0;
214
0
}
215
216
inline bool String16::operator<=(const char16_t* other) const
217
0
{
218
0
    return strcmp16(mString, other) <= 0;
219
0
}
220
221
inline bool String16::operator==(const char16_t* other) const
222
0
{
223
0
    return strcmp16(mString, other) == 0;
224
0
}
225
226
inline bool String16::operator!=(const char16_t* other) const
227
0
{
228
0
    return strcmp16(mString, other) != 0;
229
0
}
230
231
inline bool String16::operator>=(const char16_t* other) const
232
0
{
233
0
    return strcmp16(mString, other) >= 0;
234
0
}
235
236
inline bool String16::operator>(const char16_t* other) const
237
0
{
238
0
    return strcmp16(mString, other) > 0;
239
0
}
240
241
inline String16::operator const char16_t*() const
242
0
{
243
0
    return mString;
244
0
}
245
246
}  // namespace android
247
248
// ---------------------------------------------------------------------------
249
250
#endif // ANDROID_STRING16_H
/proc/self/cwd/system/core/libutils/include/utils/String8.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2005 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef ANDROID_STRING8_H
18
#define ANDROID_STRING8_H
19
20
#include <string> // for std::string
21
22
#include <utils/Errors.h>
23
#include <utils/Unicode.h>
24
#include <utils/TypeHelpers.h>
25
26
#include <string.h> // for strcmp
27
#include <stdarg.h>
28
29
// ---------------------------------------------------------------------------
30
31
namespace android {
32
33
class String16;
34
35
// DO NOT USE: please use std::string
36
37
//! This is a string holding UTF-8 characters. Does not allow the value more
38
// than 0x10FFFF, which is not valid unicode codepoint.
39
class String8
40
{
41
public:
42
    /* use String8(StaticLinkage) if you're statically linking against
43
     * libutils and declaring an empty static String8, e.g.:
44
     *
45
     *   static String8 sAStaticEmptyString(String8::kEmptyString);
46
     *   static String8 sAnotherStaticEmptyString(sAStaticEmptyString);
47
     */
48
    enum StaticLinkage { kEmptyString };
49
50
                                String8();
51
    explicit                    String8(StaticLinkage);
52
                                String8(const String8& o);
53
    explicit                    String8(const char* o);
54
    explicit                    String8(const char* o, size_t numChars);
55
56
    explicit                    String8(const String16& o);
57
    explicit                    String8(const char16_t* o);
58
    explicit                    String8(const char16_t* o, size_t numChars);
59
    explicit                    String8(const char32_t* o);
60
    explicit                    String8(const char32_t* o, size_t numChars);
61
                                ~String8();
62
63
    static inline const String8 empty();
64
65
    static String8              format(const char* fmt, ...) __attribute__((format (printf, 1, 2)));
66
    static String8              formatV(const char* fmt, va_list args);
67
68
    inline  const char*         c_str() const;
69
    inline  const char*         string() const;
70
71
private:
72
    static inline std::string   std_string(const String8& str);
73
public:
74
75
    inline  size_t              size() const;
76
    inline  size_t              bytes() const;
77
    inline  bool                isEmpty() const;
78
79
            size_t              length() const;
80
81
            void                clear();
82
83
            void                setTo(const String8& other);
84
            status_t            setTo(const char* other);
85
            status_t            setTo(const char* other, size_t numChars);
86
            status_t            setTo(const char16_t* other, size_t numChars);
87
            status_t            setTo(const char32_t* other,
88
                                      size_t length);
89
90
            status_t            append(const String8& other);
91
            status_t            append(const char* other);
92
            status_t            append(const char* other, size_t numChars);
93
94
            status_t            appendFormat(const char* fmt, ...)
95
                    __attribute__((format (printf, 2, 3)));
96
            status_t            appendFormatV(const char* fmt, va_list args);
97
98
            // Note that this function takes O(N) time to calculate the value.
99
            // No cache value is stored.
100
            size_t              getUtf32Length() const;
101
            int32_t             getUtf32At(size_t index,
102
                                           size_t *next_index) const;
103
            void                getUtf32(char32_t* dst) const;
104
105
    inline  String8&            operator=(const String8& other);
106
    inline  String8&            operator=(const char* other);
107
108
    inline  String8&            operator+=(const String8& other);
109
    inline  String8             operator+(const String8& other) const;
110
111
    inline  String8&            operator+=(const char* other);
112
    inline  String8             operator+(const char* other) const;
113
114
    inline  int                 compare(const String8& other) const;
115
116
    inline  bool                operator<(const String8& other) const;
117
    inline  bool                operator<=(const String8& other) const;
118
    inline  bool                operator==(const String8& other) const;
119
    inline  bool                operator!=(const String8& other) const;
120
    inline  bool                operator>=(const String8& other) const;
121
    inline  bool                operator>(const String8& other) const;
122
123
    inline  bool                operator<(const char* other) const;
124
    inline  bool                operator<=(const char* other) const;
125
    inline  bool                operator==(const char* other) const;
126
    inline  bool                operator!=(const char* other) const;
127
    inline  bool                operator>=(const char* other) const;
128
    inline  bool                operator>(const char* other) const;
129
130
    inline                      operator const char*() const;
131
132
            char*               lockBuffer(size_t size);
133
            void                unlockBuffer();
134
            status_t            unlockBuffer(size_t size);
135
136
            // return the index of the first byte of other in this at or after
137
            // start, or -1 if not found
138
            ssize_t             find(const char* other, size_t start = 0) const;
139
140
            // return true if this string contains the specified substring
141
    inline  bool                contains(const char* other) const;
142
143
            // removes all occurrence of the specified substring
144
            // returns true if any were found and removed
145
            bool                removeAll(const char* other);
146
147
            void                toLower();
148
            void                toLower(size_t start, size_t numChars);
149
            void                toUpper();
150
            void                toUpper(size_t start, size_t numChars);
151
152
153
    /*
154
     * These methods operate on the string as if it were a path name.
155
     */
156
157
    /*
158
     * Set the filename field to a specific value.
159
     *
160
     * Normalizes the filename, removing a trailing '/' if present.
161
     */
162
    void setPathName(const char* name);
163
    void setPathName(const char* name, size_t numChars);
164
165
    /*
166
     * Get just the filename component.
167
     *
168
     * "/tmp/foo/bar.c" --> "bar.c"
169
     */
170
    String8 getPathLeaf(void) const;
171
172
    /*
173
     * Remove the last (file name) component, leaving just the directory
174
     * name.
175
     *
176
     * "/tmp/foo/bar.c" --> "/tmp/foo"
177
     * "/tmp" --> "" // ????? shouldn't this be "/" ???? XXX
178
     * "bar.c" --> ""
179
     */
180
    String8 getPathDir(void) const;
181
182
    /*
183
     * Retrieve the front (root dir) component.  Optionally also return the
184
     * remaining components.
185
     *
186
     * "/tmp/foo/bar.c" --> "tmp" (remain = "foo/bar.c")
187
     * "/tmp" --> "tmp" (remain = "")
188
     * "bar.c" --> "bar.c" (remain = "")
189
     */
190
    String8 walkPath(String8* outRemains = nullptr) const;
191
192
    /*
193
     * Return the filename extension.  This is the last '.' and any number
194
     * of characters that follow it.  The '.' is included in case we
195
     * decide to expand our definition of what constitutes an extension.
196
     *
197
     * "/tmp/foo/bar.c" --> ".c"
198
     * "/tmp" --> ""
199
     * "/tmp/foo.bar/baz" --> ""
200
     * "foo.jpeg" --> ".jpeg"
201
     * "foo." --> ""
202
     */
203
    String8 getPathExtension(void) const;
204
205
    /*
206
     * Return the path without the extension.  Rules for what constitutes
207
     * an extension are described in the comment for getPathExtension().
208
     *
209
     * "/tmp/foo/bar.c" --> "/tmp/foo/bar"
210
     */
211
    String8 getBasePath(void) const;
212
213
    /*
214
     * Add a component to the pathname.  We guarantee that there is
215
     * exactly one path separator between the old path and the new.
216
     * If there is no existing name, we just copy the new name in.
217
     *
218
     * If leaf is a fully qualified path (i.e. starts with '/', it
219
     * replaces whatever was there before.
220
     */
221
    String8& appendPath(const char* leaf);
222
0
    String8& appendPath(const String8& leaf)  { return appendPath(leaf.string()); }
223
224
    /*
225
     * Like appendPath(), but does not affect this string.  Returns a new one instead.
226
     */
227
    String8 appendPathCopy(const char* leaf) const
228
0
                                             { String8 p(*this); p.appendPath(leaf); return p; }
229
0
    String8 appendPathCopy(const String8& leaf) const { return appendPathCopy(leaf.string()); }
230
231
    /*
232
     * Converts all separators in this string to /, the default path separator.
233
     *
234
     * If the default OS separator is backslash, this converts all
235
     * backslashes to slashes, in-place. Otherwise it does nothing.
236
     * Returns self.
237
     */
238
    String8& convertToResPath();
239
240
private:
241
            status_t            real_append(const char* other, size_t numChars);
242
            char*               find_extension(void) const;
243
244
            const char* mString;
245
};
246
247
// String8 can be trivially moved using memcpy() because moving does not
248
// require any change to the underlying SharedBuffer contents or reference count.
249
ANDROID_TRIVIAL_MOVE_TRAIT(String8)
250
251
// ---------------------------------------------------------------------------
252
// No user servicable parts below.
253
254
inline int compare_type(const String8& lhs, const String8& rhs)
255
0
{
256
0
    return lhs.compare(rhs);
257
0
}
258
259
inline int strictly_order_type(const String8& lhs, const String8& rhs)
260
0
{
261
0
    return compare_type(lhs, rhs) < 0;
262
0
}
263
264
0
inline const String8 String8::empty() {
265
0
    return String8();
266
0
}
267
268
inline const char* String8::c_str() const
269
0
{
270
0
    return mString;
271
0
}
272
inline const char* String8::string() const
273
0
{
274
0
    return mString;
275
0
}
276
277
inline std::string String8::std_string(const String8& str)
278
0
{
279
0
    return std::string(str.string());
280
0
}
281
282
inline size_t String8::size() const
283
0
{
284
0
    return length();
285
0
}
286
287
inline bool String8::isEmpty() const
288
0
{
289
0
    return length() == 0;
290
0
}
291
292
inline size_t String8::bytes() const
293
0
{
294
0
    return length();
295
0
}
296
297
inline bool String8::contains(const char* other) const
298
0
{
299
0
    return find(other) >= 0;
300
0
}
301
302
inline String8& String8::operator=(const String8& other)
303
0
{
304
0
    setTo(other);
305
0
    return *this;
306
0
}
307
308
inline String8& String8::operator=(const char* other)
309
0
{
310
0
    setTo(other);
311
0
    return *this;
312
0
}
313
314
inline String8& String8::operator+=(const String8& other)
315
0
{
316
0
    append(other);
317
0
    return *this;
318
0
}
319
320
inline String8 String8::operator+(const String8& other) const
321
0
{
322
0
    String8 tmp(*this);
323
0
    tmp += other;
324
0
    return tmp;
325
0
}
326
327
inline String8& String8::operator+=(const char* other)
328
0
{
329
0
    append(other);
330
0
    return *this;
331
0
}
332
333
inline String8 String8::operator+(const char* other) const
334
0
{
335
0
    String8 tmp(*this);
336
0
    tmp += other;
337
0
    return tmp;
338
0
}
339
340
inline int String8::compare(const String8& other) const
341
0
{
342
0
    return strcmp(mString, other.mString);
343
0
}
344
345
inline bool String8::operator<(const String8& other) const
346
0
{
347
0
    return strcmp(mString, other.mString) < 0;
348
0
}
349
350
inline bool String8::operator<=(const String8& other) const
351
0
{
352
0
    return strcmp(mString, other.mString) <= 0;
353
0
}
354
355
inline bool String8::operator==(const String8& other) const
356
0
{
357
0
    return strcmp(mString, other.mString) == 0;
358
0
}
359
360
inline bool String8::operator!=(const String8& other) const
361
0
{
362
0
    return strcmp(mString, other.mString) != 0;
363
0
}
364
365
inline bool String8::operator>=(const String8& other) const
366
0
{
367
0
    return strcmp(mString, other.mString) >= 0;
368
0
}
369
370
inline bool String8::operator>(const String8& other) const
371
0
{
372
0
    return strcmp(mString, other.mString) > 0;
373
0
}
374
375
inline bool String8::operator<(const char* other) const
376
0
{
377
0
    return strcmp(mString, other) < 0;
378
0
}
379
380
inline bool String8::operator<=(const char* other) const
381
0
{
382
0
    return strcmp(mString, other) <= 0;
383
0
}
384
385
inline bool String8::operator==(const char* other) const
386
0
{
387
0
    return strcmp(mString, other) == 0;
388
0
}
389
390
inline bool String8::operator!=(const char* other) const
391
0
{
392
0
    return strcmp(mString, other) != 0;
393
0
}
394
395
inline bool String8::operator>=(const char* other) const
396
0
{
397
0
    return strcmp(mString, other) >= 0;
398
0
}
399
400
inline bool String8::operator>(const char* other) const
401
0
{
402
0
    return strcmp(mString, other) > 0;
403
0
}
404
405
inline String8::operator const char*() const
406
0
{
407
0
    return mString;
408
0
}
409
410
}  // namespace android
411
412
// ---------------------------------------------------------------------------
413
414
#endif // ANDROID_STRING8_H
/proc/self/cwd/system/core/libutils/include/utils/StrongPointer.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2005 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef ANDROID_STRONG_POINTER_H
18
#define ANDROID_STRONG_POINTER_H
19
20
// ---------------------------------------------------------------------------
21
namespace android {
22
23
template<typename T> class wp;
24
25
// ---------------------------------------------------------------------------
26
27
#define COMPARE(_op_)                                           \
28
inline bool operator _op_ (const sp<T>& o) const {              \
29
    return m_ptr _op_ o.m_ptr;                                  \
30
}                                                               \
31
inline bool operator _op_ (const T* o) const {                  \
32
    return m_ptr _op_ o;                                        \
33
}                                                               \
34
template<typename U>                                            \
35
inline bool operator _op_ (const sp<U>& o) const {              \
36
    return m_ptr _op_ o.m_ptr;                                  \
37
}                                                               \
38
template<typename U>                                            \
39
inline bool operator _op_ (const U* o) const {                  \
40
    return m_ptr _op_ o;                                        \
41
}                                                               \
42
inline bool operator _op_ (const wp<T>& o) const {              \
43
    return m_ptr _op_ o.m_ptr;                                  \
44
}                                                               \
45
template<typename U>                                            \
46
inline bool operator _op_ (const wp<U>& o) const {              \
47
    return m_ptr _op_ o.m_ptr;                                  \
48
}
49
50
// ---------------------------------------------------------------------------
51
52
template<typename T>
53
class sp {
54
public:
55
    inline sp() : m_ptr(nullptr) { }
56
57
    sp(T* other);  // NOLINT(implicit)
58
    sp(const sp<T>& other);
59
    sp(sp<T>&& other) noexcept;
60
    template<typename U> sp(U* other);  // NOLINT(implicit)
61
    template<typename U> sp(const sp<U>& other);  // NOLINT(implicit)
62
    template<typename U> sp(sp<U>&& other);  // NOLINT(implicit)
63
64
    ~sp();
65
66
    // Assignment
67
68
    sp& operator = (T* other);
69
    sp& operator = (const sp<T>& other);
70
    sp& operator=(sp<T>&& other) noexcept;
71
72
    template<typename U> sp& operator = (const sp<U>& other);
73
    template<typename U> sp& operator = (sp<U>&& other);
74
    template<typename U> sp& operator = (U* other);
75
76
    //! Special optimization for use by ProcessState (and nobody else).
77
    void force_set(T* other);
78
79
    // Reset
80
81
    void clear();
82
83
    // Accessors
84
85
    inline T&       operator* () const     { return *m_ptr; }
86
0
    inline T*       operator-> () const    { return m_ptr;  }
Unexecuted instantiation: _ZNK7android2spINS_4hidl4base4V1_05IBaseEEptEv
Unexecuted instantiation: _ZNK7android2spINS_4hidl7manager4V1_020IServiceNotificationEEptEv
Unexecuted instantiation: _ZNK7android2spINS_8hardware5media3omx4V1_016IOmxBufferSourceEEptEv
Unexecuted instantiation: _ZNK7android2spINS_8hardware5media3omx4V1_08IOmxNodeEEptEv
87
0
    inline T*       get() const            { return m_ptr; }
88
    inline explicit operator bool () const { return m_ptr != nullptr; }
89
90
    // Operators
91
92
    COMPARE(==)
93
    COMPARE(!=)
94
    COMPARE(>)
95
    COMPARE(<)
96
    COMPARE(<=)
97
    COMPARE(>=)
98
99
private:    
100
    template<typename Y> friend class sp;
101
    template<typename Y> friend class wp;
102
    void set_pointer(T* ptr);
103
    T* m_ptr;
104
};
105
106
// For code size reasons, we do not want this inlined or templated.
107
void sp_report_race();
108
109
#undef COMPARE
110
111
// ---------------------------------------------------------------------------
112
// No user serviceable parts below here.
113
114
template<typename T>
115
sp<T>::sp(T* other)
116
        : m_ptr(other) {
117
    if (other)
118
        other->incStrong(this);
119
}
120
121
template<typename T>
122
sp<T>::sp(const sp<T>& other)
123
        : m_ptr(other.m_ptr) {
124
    if (m_ptr)
125
        m_ptr->incStrong(this);
126
}
127
128
template <typename T>
129
sp<T>::sp(sp<T>&& other) noexcept : m_ptr(other.m_ptr) {
130
    other.m_ptr = nullptr;
131
}
132
133
template<typename T> template<typename U>
134
sp<T>::sp(U* other)
135
        : m_ptr(other) {
136
    if (other)
137
        (static_cast<T*>(other))->incStrong(this);
138
}
139
140
template<typename T> template<typename U>
141
sp<T>::sp(const sp<U>& other)
142
        : m_ptr(other.m_ptr) {
143
    if (m_ptr)
144
        m_ptr->incStrong(this);
145
}
146
147
template<typename T> template<typename U>
148
sp<T>::sp(sp<U>&& other)
149
        : m_ptr(other.m_ptr) {
150
    other.m_ptr = nullptr;
151
}
152
153
template<typename T>
154
4
sp<T>::~sp() {
155
4
    if (m_ptr)
156
4
        m_ptr->decStrong(this);
157
4
}
_ZN7android2spINS_17AHandlerReflectorINS_22SimpleSoftOMXComponentEEEED2Ev
Line
Count
Source
154
2
sp<T>::~sp() {
155
2
    if (m_ptr)
156
2
        m_ptr->decStrong(this);
157
2
}
_ZN7android2spINS_7ALooperEED2Ev
Line
Count
Source
154
2
sp<T>::~sp() {
155
2
    if (m_ptr)
156
2
        m_ptr->decStrong(this);
157
2
}
158
159
template<typename T>
160
0
sp<T>& sp<T>::operator =(const sp<T>& other) {
161
0
    // Force m_ptr to be read twice, to heuristically check for data races.
162
0
    T* oldPtr(*const_cast<T* volatile*>(&m_ptr));
163
0
    T* otherPtr(other.m_ptr);
164
0
    if (otherPtr) otherPtr->incStrong(this);
165
0
    if (oldPtr) oldPtr->decStrong(this);
166
0
    if (oldPtr != *const_cast<T* volatile*>(&m_ptr)) sp_report_race();
167
0
    m_ptr = otherPtr;
168
0
    return *this;
169
0
}
170
171
template <typename T>
172
sp<T>& sp<T>::operator=(sp<T>&& other) noexcept {
173
    T* oldPtr(*const_cast<T* volatile*>(&m_ptr));
174
    if (oldPtr) oldPtr->decStrong(this);
175
    if (oldPtr != *const_cast<T* volatile*>(&m_ptr)) sp_report_race();
176
    m_ptr = other.m_ptr;
177
    other.m_ptr = nullptr;
178
    return *this;
179
}
180
181
template<typename T>
182
sp<T>& sp<T>::operator =(T* other) {
183
    T* oldPtr(*const_cast<T* volatile*>(&m_ptr));
184
    if (other) other->incStrong(this);
185
    if (oldPtr) oldPtr->decStrong(this);
186
    if (oldPtr != *const_cast<T* volatile*>(&m_ptr)) sp_report_race();
187
    m_ptr = other;
188
    return *this;
189
}
190
191
template<typename T> template<typename U>
192
sp<T>& sp<T>::operator =(const sp<U>& other) {
193
    T* oldPtr(*const_cast<T* volatile*>(&m_ptr));
194
    T* otherPtr(other.m_ptr);
195
    if (otherPtr) otherPtr->incStrong(this);
196
    if (oldPtr) oldPtr->decStrong(this);
197
    if (oldPtr != *const_cast<T* volatile*>(&m_ptr)) sp_report_race();
198
    m_ptr = otherPtr;
199
    return *this;
200
}
201
202
template<typename T> template<typename U>
203
sp<T>& sp<T>::operator =(sp<U>&& other) {
204
    T* oldPtr(*const_cast<T* volatile*>(&m_ptr));
205
    if (m_ptr) m_ptr->decStrong(this);
206
    if (oldPtr != *const_cast<T* volatile*>(&m_ptr)) sp_report_race();
207
    m_ptr = other.m_ptr;
208
    other.m_ptr = nullptr;
209
    return *this;
210
}
211
212
template<typename T> template<typename U>
213
sp<T>& sp<T>::operator =(U* other) {
214
    T* oldPtr(*const_cast<T* volatile*>(&m_ptr));
215
    if (other) (static_cast<T*>(other))->incStrong(this);
216
    if (oldPtr) oldPtr->decStrong(this);
217
    if (oldPtr != *const_cast<T* volatile*>(&m_ptr)) sp_report_race();
218
    m_ptr = other;
219
    return *this;
220
}
221
222
template<typename T>
223
void sp<T>::force_set(T* other) {
224
    other->forceIncStrong(this);
225
    m_ptr = other;
226
}
227
228
template<typename T>
229
0
void sp<T>::clear() {
230
0
    T* oldPtr(*const_cast<T* volatile*>(&m_ptr));
231
0
    if (oldPtr) {
232
0
        oldPtr->decStrong(this);
233
0
        if (oldPtr != *const_cast<T* volatile*>(&m_ptr)) sp_report_race();
234
0
        m_ptr = nullptr;
235
0
    }
236
0
}
237
238
template<typename T>
239
0
void sp<T>::set_pointer(T* ptr) {
240
0
    m_ptr = ptr;
241
0
}
242
243
}  // namespace android
244
245
// ---------------------------------------------------------------------------
246
247
#endif // ANDROID_STRONG_POINTER_H
/proc/self/cwd/system/core/libutils/include/utils/Timers.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2005 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
//
18
// Timer functions.
19
//
20
#ifndef _LIBS_UTILS_TIMERS_H
21
#define _LIBS_UTILS_TIMERS_H
22
23
#include <stdint.h>
24
#include <sys/types.h>
25
#include <sys/time.h>
26
27
#include <utils/Compat.h>
28
29
// ------------------------------------------------------------------
30
// C API
31
32
#ifdef __cplusplus
33
extern "C" {
34
#endif
35
36
typedef int64_t nsecs_t;       // nano-seconds
37
38
static CONSTEXPR inline nsecs_t seconds_to_nanoseconds(nsecs_t secs)
39
0
{
40
0
    return secs*1000000000;
41
0
}
42
43
static CONSTEXPR inline nsecs_t milliseconds_to_nanoseconds(nsecs_t secs)
44
0
{
45
0
    return secs*1000000;
46
0
}
47
48
static CONSTEXPR inline nsecs_t microseconds_to_nanoseconds(nsecs_t secs)
49
0
{
50
0
    return secs*1000;
51
0
}
52
53
static CONSTEXPR inline nsecs_t nanoseconds_to_seconds(nsecs_t secs)
54
0
{
55
0
    return secs/1000000000;
56
0
}
57
58
static CONSTEXPR inline nsecs_t nanoseconds_to_milliseconds(nsecs_t secs)
59
0
{
60
0
    return secs/1000000;
61
0
}
62
63
static CONSTEXPR inline nsecs_t nanoseconds_to_microseconds(nsecs_t secs)
64
0
{
65
0
    return secs/1000;
66
0
}
67
68
0
static CONSTEXPR inline nsecs_t s2ns(nsecs_t v)  {return seconds_to_nanoseconds(v);}
69
0
static CONSTEXPR inline nsecs_t ms2ns(nsecs_t v) {return milliseconds_to_nanoseconds(v);}
70
0
static CONSTEXPR inline nsecs_t us2ns(nsecs_t v) {return microseconds_to_nanoseconds(v);}
71
0
static CONSTEXPR inline nsecs_t ns2s(nsecs_t v)  {return nanoseconds_to_seconds(v);}
72
0
static CONSTEXPR inline nsecs_t ns2ms(nsecs_t v) {return nanoseconds_to_milliseconds(v);}
73
0
static CONSTEXPR inline nsecs_t ns2us(nsecs_t v) {return nanoseconds_to_microseconds(v);}
74
75
0
static CONSTEXPR inline nsecs_t seconds(nsecs_t v)      { return s2ns(v); }
76
0
static CONSTEXPR inline nsecs_t milliseconds(nsecs_t v) { return ms2ns(v); }
77
0
static CONSTEXPR inline nsecs_t microseconds(nsecs_t v) { return us2ns(v); }
78
79
enum {
80
    SYSTEM_TIME_REALTIME = 0,  // system-wide realtime clock
81
    SYSTEM_TIME_MONOTONIC = 1, // monotonic time since unspecified starting point
82
    SYSTEM_TIME_PROCESS = 2,   // high-resolution per-process clock
83
    SYSTEM_TIME_THREAD = 3,    // high-resolution per-thread clock
84
    SYSTEM_TIME_BOOTTIME = 4   // same as SYSTEM_TIME_MONOTONIC, but including CPU suspend time
85
};
86
87
// return the system-time according to the specified clock
88
#ifdef __cplusplus
89
nsecs_t systemTime(int clock = SYSTEM_TIME_MONOTONIC);
90
#else
91
nsecs_t systemTime(int clock);
92
#endif // def __cplusplus
93
94
/**
95
 * Returns the number of milliseconds to wait between the reference time and the timeout time.
96
 * If the timeout is in the past relative to the reference time, returns 0.
97
 * If the timeout is more than INT_MAX milliseconds in the future relative to the reference time,
98
 * such as when timeoutTime == LLONG_MAX, returns -1 to indicate an infinite timeout delay.
99
 * Otherwise, returns the difference between the reference time and timeout time
100
 * rounded up to the next millisecond.
101
 */
102
int toMillisecondTimeoutDelay(nsecs_t referenceTime, nsecs_t timeoutTime);
103
104
#ifdef __cplusplus
105
} // extern "C"
106
#endif
107
108
#endif // _LIBS_UTILS_TIMERS_H
/proc/self/cwd/system/core/libutils/include/utils/TypeHelpers.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2005 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef ANDROID_TYPE_HELPERS_H
18
#define ANDROID_TYPE_HELPERS_H
19
20
#include <new>
21
#include <type_traits>
22
23
#include <stdint.h>
24
#include <string.h>
25
#include <sys/types.h>
26
27
// ---------------------------------------------------------------------------
28
29
namespace android {
30
31
/*
32
 * Types traits
33
 */
34
35
template <typename T> struct trait_trivial_ctor { enum { value = false }; };
36
template <typename T> struct trait_trivial_dtor { enum { value = false }; };
37
template <typename T> struct trait_trivial_copy { enum { value = false }; };
38
template <typename T> struct trait_trivial_move { enum { value = false }; };
39
template <typename T> struct trait_pointer      { enum { value = false }; };
40
template <typename T> struct trait_pointer<T*>  { enum { value = true }; };
41
42
template <typename TYPE>
43
struct traits {
44
    enum {
45
        // whether this type is a pointer
46
        is_pointer          = trait_pointer<TYPE>::value,
47
        // whether this type's constructor is a no-op
48
        has_trivial_ctor    = is_pointer || trait_trivial_ctor<TYPE>::value,
49
        // whether this type's destructor is a no-op
50
        has_trivial_dtor    = is_pointer || trait_trivial_dtor<TYPE>::value,
51
        // whether this type type can be copy-constructed with memcpy
52
        has_trivial_copy    = is_pointer || trait_trivial_copy<TYPE>::value,
53
        // whether this type can be moved with memmove
54
        has_trivial_move    = is_pointer || trait_trivial_move<TYPE>::value
55
    };
56
};
57
58
template <typename T, typename U>
59
struct aggregate_traits {
60
    enum {
61
        is_pointer          = false,
62
        has_trivial_ctor    =
63
            traits<T>::has_trivial_ctor && traits<U>::has_trivial_ctor,
64
        has_trivial_dtor    =
65
            traits<T>::has_trivial_dtor && traits<U>::has_trivial_dtor,
66
        has_trivial_copy    =
67
            traits<T>::has_trivial_copy && traits<U>::has_trivial_copy,
68
        has_trivial_move    =
69
            traits<T>::has_trivial_move && traits<U>::has_trivial_move
70
    };
71
};
72
73
#define ANDROID_TRIVIAL_CTOR_TRAIT( T ) \
74
    template<> struct trait_trivial_ctor< T >   { enum { value = true }; };
75
76
#define ANDROID_TRIVIAL_DTOR_TRAIT( T ) \
77
    template<> struct trait_trivial_dtor< T >   { enum { value = true }; };
78
79
#define ANDROID_TRIVIAL_COPY_TRAIT( T ) \
80
    template<> struct trait_trivial_copy< T >   { enum { value = true }; };
81
82
#define ANDROID_TRIVIAL_MOVE_TRAIT( T ) \
83
    template<> struct trait_trivial_move< T >   { enum { value = true }; };
84
85
#define ANDROID_BASIC_TYPES_TRAITS( T ) \
86
    ANDROID_TRIVIAL_CTOR_TRAIT( T ) \
87
    ANDROID_TRIVIAL_DTOR_TRAIT( T ) \
88
    ANDROID_TRIVIAL_COPY_TRAIT( T ) \
89
    ANDROID_TRIVIAL_MOVE_TRAIT( T )
90
91
// ---------------------------------------------------------------------------
92
93
/*
94
 * basic types traits
95
 */
96
97
ANDROID_BASIC_TYPES_TRAITS( void )
98
ANDROID_BASIC_TYPES_TRAITS( bool )
99
ANDROID_BASIC_TYPES_TRAITS( char )
100
ANDROID_BASIC_TYPES_TRAITS( unsigned char )
101
ANDROID_BASIC_TYPES_TRAITS( short )
102
ANDROID_BASIC_TYPES_TRAITS( unsigned short )
103
ANDROID_BASIC_TYPES_TRAITS( int )
104
ANDROID_BASIC_TYPES_TRAITS( unsigned int )
105
ANDROID_BASIC_TYPES_TRAITS( long )
106
ANDROID_BASIC_TYPES_TRAITS( unsigned long )
107
ANDROID_BASIC_TYPES_TRAITS( long long )
108
ANDROID_BASIC_TYPES_TRAITS( unsigned long long )
109
ANDROID_BASIC_TYPES_TRAITS( float )
110
ANDROID_BASIC_TYPES_TRAITS( double )
111
112
// ---------------------------------------------------------------------------
113
114
115
/*
116
 * compare and order types
117
 */
118
119
template<typename TYPE> inline
120
0
int strictly_order_type(const TYPE& lhs, const TYPE& rhs) {
121
0
    return (lhs < rhs) ? 1 : 0;
122
0
}
Unexecuted instantiation: _ZN7android19strictly_order_typeINS_16key_value_pair_tIjjEEEEiRKT_S5_
Unexecuted instantiation: _ZN7android19strictly_order_typeIjEEiRKT_S3_
123
124
template<typename TYPE> inline
125
0
int compare_type(const TYPE& lhs, const TYPE& rhs) {
126
0
    return strictly_order_type(rhs, lhs) - strictly_order_type(lhs, rhs);
127
0
}
128
129
/*
130
 * create, destroy, copy and move types...
131
 */
132
133
template<typename TYPE> inline
134
0
void construct_type(TYPE* p, size_t n) {
135
0
    if (!traits<TYPE>::has_trivial_ctor) {
136
0
        while (n > 0) {
137
0
            n--;
138
0
            new(p++) TYPE;
139
0
        }
140
0
    }
141
0
}
Unexecuted instantiation: _ZN7android14construct_typeINS_22SimpleSoftOMXComponent8PortInfoEEEvPT_j
Unexecuted instantiation: _ZN7android14construct_typeINS_22SimpleSoftOMXComponent10BufferInfoEEEvPT_j
Unexecuted instantiation: _ZN7android14construct_typeINS_16key_value_pair_tIjjEEEEvPT_j
142
143
template<typename TYPE> inline
144
4
void destroy_type(TYPE* p, size_t n) {
145
4
    if (!traits<TYPE>::has_trivial_dtor) {
146
8
        while (n > 0) {
147
4
            n--;
148
4
            p->~TYPE();
149
4
            p++;
150
4
        }
151
4
    }
152
4
}
_ZN7android12destroy_typeINS_22SimpleSoftOMXComponent10BufferInfoEEEvPT_j
Line
Count
Source
144
2
void destroy_type(TYPE* p, size_t n) {
145
2
    if (!traits<TYPE>::has_trivial_dtor) {
146
2
        while (n > 0) {
147
0
            n--;
148
0
            p->~TYPE();
149
0
            p++;
150
0
        }
151
2
    }
152
2
}
_ZN7android12destroy_typeINS_22SimpleSoftOMXComponent8PortInfoEEEvPT_j
Line
Count
Source
144
2
void destroy_type(TYPE* p, size_t n) {
145
2
    if (!traits<TYPE>::has_trivial_dtor) {
146
6
        while (n > 0) {
147
4
            n--;
148
4
            p->~TYPE();
149
4
            p++;
150
4
        }
151
2
    }
152
2
}
Unexecuted instantiation: _ZN7android12destroy_typeINS_16key_value_pair_tIjjEEEEvPT_j
153
154
template<typename TYPE>
155
typename std::enable_if<traits<TYPE>::has_trivial_copy>::type
156
inline
157
0
copy_type(TYPE* d, const TYPE* s, size_t n) {
158
0
    memcpy(d,s,n*sizeof(TYPE));
159
0
}
160
161
template<typename TYPE>
162
typename std::enable_if<!traits<TYPE>::has_trivial_copy>::type
163
inline
164
0
copy_type(TYPE* d, const TYPE* s, size_t n) {
165
0
    while (n > 0) {
166
0
        n--;
167
0
        new(d) TYPE(*s);
168
0
        d++, s++;
169
0
    }
170
0
}
Unexecuted instantiation: _ZN7android9copy_typeINS_22SimpleSoftOMXComponent10BufferInfoEEENSt3__19enable_ifIXntsr6traitsIT_EE16has_trivial_copyEvE4typeEPS5_PKS5_j
Unexecuted instantiation: _ZN7android9copy_typeINS_22SimpleSoftOMXComponent8PortInfoEEENSt3__19enable_ifIXntsr6traitsIT_EE16has_trivial_copyEvE4typeEPS5_PKS5_j
171
172
template<typename TYPE> inline
173
0
void splat_type(TYPE* where, const TYPE* what, size_t n) {
174
0
    if (!traits<TYPE>::has_trivial_copy) {
175
0
        while (n > 0) {
176
0
            n--;
177
0
            new(where) TYPE(*what);
178
0
            where++;
179
0
        }
180
0
    } else {
181
0
        while (n > 0) {
182
0
            n--;
183
0
            *where++ = *what;
184
0
        }
185
0
    }
186
0
}
Unexecuted instantiation: _ZN7android10splat_typeINS_22SimpleSoftOMXComponent10BufferInfoEEEvPT_PKS3_j
Unexecuted instantiation: _ZN7android10splat_typeINS_22SimpleSoftOMXComponent8PortInfoEEEvPT_PKS3_j
Unexecuted instantiation: _ZN7android10splat_typeINS_16key_value_pair_tIjjEEEEvPT_PKS3_j
187
188
template<typename TYPE>
189
struct use_trivial_move : public std::integral_constant<bool,
190
    (traits<TYPE>::has_trivial_dtor && traits<TYPE>::has_trivial_copy)
191
    || traits<TYPE>::has_trivial_move
192
> {};
193
194
template<typename TYPE>
195
typename std::enable_if<use_trivial_move<TYPE>::value>::type
196
inline
197
0
move_forward_type(TYPE* d, const TYPE* s, size_t n = 1) {
198
0
    memmove(d, s, n*sizeof(TYPE));
199
0
}
200
201
template<typename TYPE>
202
typename std::enable_if<!use_trivial_move<TYPE>::value>::type
203
inline
204
0
move_forward_type(TYPE* d, const TYPE* s, size_t n = 1) {
205
0
    d += n;
206
0
    s += n;
207
0
    while (n > 0) {
208
0
        n--;
209
0
        --d, --s;
210
0
        if (!traits<TYPE>::has_trivial_copy) {
211
0
            new(d) TYPE(*s);
212
0
        } else {
213
0
            *d = *s;
214
0
        }
215
0
        if (!traits<TYPE>::has_trivial_dtor) {
216
0
            s->~TYPE();
217
0
        }
218
0
    }
219
0
}
Unexecuted instantiation: _ZN7android17move_forward_typeINS_22SimpleSoftOMXComponent10BufferInfoEEENSt3__19enable_ifIXntsr16use_trivial_moveIT_EE5valueEvE4typeEPS5_PKS5_j
Unexecuted instantiation: _ZN7android17move_forward_typeINS_22SimpleSoftOMXComponent8PortInfoEEENSt3__19enable_ifIXntsr16use_trivial_moveIT_EE5valueEvE4typeEPS5_PKS5_j
220
221
template<typename TYPE>
222
typename std::enable_if<use_trivial_move<TYPE>::value>::type
223
inline
224
0
move_backward_type(TYPE* d, const TYPE* s, size_t n = 1) {
225
0
    memmove(d, s, n*sizeof(TYPE));
226
0
}
227
228
template<typename TYPE>
229
typename std::enable_if<!use_trivial_move<TYPE>::value>::type
230
inline
231
0
move_backward_type(TYPE* d, const TYPE* s, size_t n = 1) {
232
0
    while (n > 0) {
233
0
        n--;
234
0
        if (!traits<TYPE>::has_trivial_copy) {
235
0
            new(d) TYPE(*s);
236
0
        } else {
237
0
            *d = *s;
238
0
        }
239
0
        if (!traits<TYPE>::has_trivial_dtor) {
240
0
            s->~TYPE();
241
0
        }
242
0
        d++, s++;
243
0
    }
244
0
}
Unexecuted instantiation: _ZN7android18move_backward_typeINS_22SimpleSoftOMXComponent10BufferInfoEEENSt3__19enable_ifIXntsr16use_trivial_moveIT_EE5valueEvE4typeEPS5_PKS5_j
Unexecuted instantiation: _ZN7android18move_backward_typeINS_22SimpleSoftOMXComponent8PortInfoEEENSt3__19enable_ifIXntsr16use_trivial_moveIT_EE5valueEvE4typeEPS5_PKS5_j
245
246
// ---------------------------------------------------------------------------
247
248
/*
249
 * a key/value pair
250
 */
251
252
template <typename KEY, typename VALUE>
253
struct key_value_pair_t {
254
    typedef KEY key_t;
255
    typedef VALUE value_t;
256
257
    KEY     key;
258
    VALUE   value;
259
    key_value_pair_t() { }
260
    key_value_pair_t(const key_value_pair_t& o) : key(o.key), value(o.value) { }
261
0
    key_value_pair_t& operator=(const key_value_pair_t& o) {
262
0
        key = o.key;
263
0
        value = o.value;
264
0
        return *this;
265
0
    }
266
    key_value_pair_t(const KEY& k, const VALUE& v) : key(k), value(v)  { }
267
    explicit key_value_pair_t(const KEY& k) : key(k) { }
268
0
    inline bool operator < (const key_value_pair_t& o) const {
269
0
        return strictly_order_type(key, o.key);
270
0
    }
271
    inline const KEY& getKey() const {
272
        return key;
273
    }
274
    inline const VALUE& getValue() const {
275
        return value;
276
    }
277
};
278
279
template <typename K, typename V>
280
struct trait_trivial_ctor< key_value_pair_t<K, V> >
281
{ enum { value = aggregate_traits<K,V>::has_trivial_ctor }; };
282
template <typename K, typename V>
283
struct trait_trivial_dtor< key_value_pair_t<K, V> >
284
{ enum { value = aggregate_traits<K,V>::has_trivial_dtor }; };
285
template <typename K, typename V>
286
struct trait_trivial_copy< key_value_pair_t<K, V> >
287
{ enum { value = aggregate_traits<K,V>::has_trivial_copy }; };
288
template <typename K, typename V>
289
struct trait_trivial_move< key_value_pair_t<K, V> >
290
{ enum { value = aggregate_traits<K,V>::has_trivial_move }; };
291
292
// ---------------------------------------------------------------------------
293
294
/*
295
 * Hash codes.
296
 */
297
typedef uint32_t hash_t;
298
299
template <typename TKey>
300
hash_t hash_type(const TKey& key);
301
302
/* Built-in hash code specializations */
303
#define ANDROID_INT32_HASH(T) \
304
0
        template <> inline hash_t hash_type(const T& value) { return hash_t(value); }
Unexecuted instantiation: _ZN7android9hash_typeIbEEjRKT_
Unexecuted instantiation: _ZN7android9hash_typeIaEEjRKT_
Unexecuted instantiation: _ZN7android9hash_typeIhEEjRKT_
Unexecuted instantiation: _ZN7android9hash_typeIsEEjRKT_
Unexecuted instantiation: _ZN7android9hash_typeItEEjRKT_
Unexecuted instantiation: _ZN7android9hash_typeIiEEjRKT_
Unexecuted instantiation: _ZN7android9hash_typeIjEEjRKT_
305
#define ANDROID_INT64_HASH(T) \
306
0
        template <> inline hash_t hash_type(const T& value) { \
307
0
                return hash_t((value >> 32) ^ value); }
Unexecuted instantiation: _ZN7android9hash_typeIxEEjRKT_
Unexecuted instantiation: _ZN7android9hash_typeIyEEjRKT_
308
#define ANDROID_REINTERPRET_HASH(T, R) \
309
0
        template <> inline hash_t hash_type(const T& value) { \
310
0
            R newValue; \
311
0
            static_assert(sizeof(newValue) == sizeof(value), "size mismatch"); \
312
0
            memcpy(&newValue, &value, sizeof(newValue)); \
313
0
            return hash_type(newValue); \
314
0
        }
Unexecuted instantiation: _ZN7android9hash_typeIfEEjRKT_
Unexecuted instantiation: _ZN7android9hash_typeIdEEjRKT_
315
316
ANDROID_INT32_HASH(bool)
317
ANDROID_INT32_HASH(int8_t)
318
ANDROID_INT32_HASH(uint8_t)
319
ANDROID_INT32_HASH(int16_t)
320
ANDROID_INT32_HASH(uint16_t)
321
ANDROID_INT32_HASH(int32_t)
322
ANDROID_INT32_HASH(uint32_t)
323
ANDROID_INT64_HASH(int64_t)
324
ANDROID_INT64_HASH(uint64_t)
325
ANDROID_REINTERPRET_HASH(float, uint32_t)
326
ANDROID_REINTERPRET_HASH(double, uint64_t)
327
328
template <typename T> inline hash_t hash_type(T* const & value) {
329
    return hash_type(uintptr_t(value));
330
}
331
332
}  // namespace android
333
334
// ---------------------------------------------------------------------------
335
336
#endif // ANDROID_TYPE_HELPERS_H
/proc/self/cwd/system/core/libutils/include/utils/Vector.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2005 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef ANDROID_VECTOR_H
18
#define ANDROID_VECTOR_H
19
20
#include <stdint.h>
21
#include <sys/types.h>
22
23
#include <log/log.h>
24
#include <utils/TypeHelpers.h>
25
#include <utils/VectorImpl.h>
26
27
/*
28
 * Used to blacklist some functions from CFI.
29
 *
30
 */
31
#ifndef __has_attribute
32
#define __has_attribute(x) 0
33
#endif
34
35
#if __has_attribute(no_sanitize)
36
#define UTILS_VECTOR_NO_CFI __attribute__((no_sanitize("cfi")))
37
#else
38
#define UTILS_VECTOR_NO_CFI
39
#endif
40
41
// ---------------------------------------------------------------------------
42
43
namespace android {
44
45
template <typename TYPE>
46
class SortedVector;
47
48
/*!
49
 * The main templated vector class ensuring type safety
50
 * while making use of VectorImpl.
51
 * This is the class users want to use.
52
 *
53
 * DO NOT USE: please use std::vector
54
 */
55
56
template <class TYPE>
57
class Vector : private VectorImpl
58
{
59
public:
60
            typedef TYPE    value_type;
61
62
    /*!
63
     * Constructors and destructors
64
     */
65
66
                            Vector();
67
                            Vector(const Vector<TYPE>& rhs);
68
    explicit                Vector(const SortedVector<TYPE>& rhs);
69
    virtual                 ~Vector();
70
71
    /*! copy operator */
72
            const Vector<TYPE>&     operator = (const Vector<TYPE>& rhs) const;
73
            Vector<TYPE>&           operator = (const Vector<TYPE>& rhs);
74
75
            const Vector<TYPE>&     operator = (const SortedVector<TYPE>& rhs) const;
76
            Vector<TYPE>&           operator = (const SortedVector<TYPE>& rhs);
77
78
            /*
79
     * empty the vector
80
     */
81
82
    inline  void            clear()             { VectorImpl::clear(); }
83
84
    /*!
85
     * vector stats
86
     */
87
88
    //! returns number of items in the vector
89
    inline  size_t          size() const                { return VectorImpl::size(); }
90
    //! returns whether or not the vector is empty
91
    inline  bool            isEmpty() const             { return VectorImpl::isEmpty(); }
92
    //! returns how many items can be stored without reallocating the backing store
93
    inline  size_t          capacity() const            { return VectorImpl::capacity(); }
94
    //! sets the capacity. capacity can never be reduced less than size()
95
    inline  ssize_t         setCapacity(size_t size)    { return VectorImpl::setCapacity(size); }
96
97
    /*!
98
     * set the size of the vector. items are appended with the default
99
     * constructor, or removed from the end as needed.
100
     */
101
    inline  ssize_t         resize(size_t size)         { return VectorImpl::resize(size); }
102
103
    /*!
104
     * C-style array access
105
     */
106
107
    //! read-only C-style access
108
    inline  const TYPE*     array() const;
109
    //! read-write C-style access
110
            TYPE*           editArray();
111
112
    /*!
113
     * accessors
114
     */
115
116
    //! read-only access to an item at a given index
117
    inline  const TYPE&     operator [] (size_t index) const;
118
    //! alternate name for operator []
119
    inline  const TYPE&     itemAt(size_t index) const;
120
    //! stack-usage of the vector. returns the top of the stack (last element)
121
            const TYPE&     top() const;
122
123
    /*!
124
     * modifying the array
125
     */
126
127
    //! copy-on write support, grants write access to an item
128
            TYPE&           editItemAt(size_t index);
129
    //! grants right access to the top of the stack (last element)
130
            TYPE&           editTop();
131
132
            /*!
133
             * append/insert another vector
134
             */
135
136
    //! insert another vector at a given index
137
            ssize_t         insertVectorAt(const Vector<TYPE>& vector, size_t index);
138
139
    //! append another vector at the end of this one
140
            ssize_t         appendVector(const Vector<TYPE>& vector);
141
142
143
    //! insert an array at a given index
144
            ssize_t         insertArrayAt(const TYPE* array, size_t index, size_t length);
145
146
    //! append an array at the end of this vector
147
            ssize_t         appendArray(const TYPE* array, size_t length);
148
149
            /*!
150
             * add/insert/replace items
151
             */
152
153
    //! insert one or several items initialized with their default constructor
154
    inline  ssize_t         insertAt(size_t index, size_t numItems = 1);
155
    //! insert one or several items initialized from a prototype item
156
            ssize_t         insertAt(const TYPE& prototype_item, size_t index, size_t numItems = 1);
157
    //! pop the top of the stack (removes the last element). No-op if the stack's empty
158
    inline  void            pop();
159
    //! pushes an item initialized with its default constructor
160
    inline  void            push();
161
    //! pushes an item on the top of the stack
162
            void            push(const TYPE& item);
163
    //! same as push() but returns the index the item was added at (or an error)
164
    inline  ssize_t         add();
165
    //! same as push() but returns the index the item was added at (or an error)
166
            ssize_t         add(const TYPE& item);
167
    //! replace an item with a new one initialized with its default constructor
168
    inline  ssize_t         replaceAt(size_t index);
169
    //! replace an item with a new one
170
            ssize_t         replaceAt(const TYPE& item, size_t index);
171
172
    /*!
173
     * remove items
174
     */
175
176
    //! remove several items
177
    inline  ssize_t         removeItemsAt(size_t index, size_t count = 1);
178
    //! remove one item
179
    inline  ssize_t         removeAt(size_t index)  { return removeItemsAt(index); }
180
181
    /*!
182
     * sort (stable) the array
183
     */
184
185
     typedef int (*compar_t)(const TYPE* lhs, const TYPE* rhs);
186
     typedef int (*compar_r_t)(const TYPE* lhs, const TYPE* rhs, void* state);
187
188
     inline status_t        sort(compar_t cmp);
189
     inline status_t        sort(compar_r_t cmp, void* state);
190
191
     // for debugging only
192
     inline size_t getItemSize() const { return itemSize(); }
193
194
195
     /*
196
      * these inlines add some level of compatibility with STL. eventually
197
      * we should probably turn things around.
198
      */
199
     typedef TYPE* iterator;
200
     typedef TYPE const* const_iterator;
201
202
     inline iterator begin() { return editArray(); }
203
     inline iterator end()   { return editArray() + size(); }
204
     inline const_iterator begin() const { return array(); }
205
     inline const_iterator end() const   { return array() + size(); }
206
     inline void reserve(size_t n) { setCapacity(n); }
207
     inline bool empty() const{ return isEmpty(); }
208
     inline void push_back(const TYPE& item)  { insertAt(item, size(), 1); }
209
     inline void push_front(const TYPE& item) { insertAt(item, 0, 1); }
210
     inline iterator erase(iterator pos) {
211
         ssize_t index = removeItemsAt(static_cast<size_t>(pos-array()));
212
         return begin() + index;
213
     }
214
215
protected:
216
    virtual void    do_construct(void* storage, size_t num) const;
217
    virtual void    do_destroy(void* storage, size_t num) const;
218
    virtual void    do_copy(void* dest, const void* from, size_t num) const;
219
    virtual void    do_splat(void* dest, const void* item, size_t num) const;
220
    virtual void    do_move_forward(void* dest, const void* from, size_t num) const;
221
    virtual void    do_move_backward(void* dest, const void* from, size_t num) const;
222
};
223
224
// ---------------------------------------------------------------------------
225
// No user serviceable parts from here...
226
// ---------------------------------------------------------------------------
227
228
template<class TYPE> inline
229
Vector<TYPE>::Vector()
230
    : VectorImpl(sizeof(TYPE),
231
                ((traits<TYPE>::has_trivial_ctor   ? HAS_TRIVIAL_CTOR   : 0)
232
                |(traits<TYPE>::has_trivial_dtor   ? HAS_TRIVIAL_DTOR   : 0)
233
                |(traits<TYPE>::has_trivial_copy   ? HAS_TRIVIAL_COPY   : 0))
234
                )
235
0
{
236
0
}
237
238
template<class TYPE> inline
239
Vector<TYPE>::Vector(const Vector<TYPE>& rhs)
240
0
    : VectorImpl(rhs) {
241
0
}
242
243
template<class TYPE> inline
244
Vector<TYPE>::Vector(const SortedVector<TYPE>& rhs)
245
    : VectorImpl(static_cast<const VectorImpl&>(rhs)) {
246
}
247
248
template<class TYPE> inline
249
6
Vector<TYPE>::~Vector() {
250
6
    finish_vector();
251
6
}
_ZN7android6VectorINS_22SimpleSoftOMXComponent8PortInfoEED2Ev
Line
Count
Source
249
2
Vector<TYPE>::~Vector() {
250
2
    finish_vector();
251
2
}
_ZN7android6VectorINS_22SimpleSoftOMXComponent10BufferInfoEED2Ev
Line
Count
Source
249
4
Vector<TYPE>::~Vector() {
250
4
    finish_vector();
251
4
}
252
253
template<class TYPE> inline
254
0
Vector<TYPE>& Vector<TYPE>::operator = (const Vector<TYPE>& rhs) {
255
0
    VectorImpl::operator = (rhs);
256
0
    return *this;
257
0
}
258
259
template<class TYPE> inline
260
const Vector<TYPE>& Vector<TYPE>::operator = (const Vector<TYPE>& rhs) const {
261
    VectorImpl::operator = (static_cast<const VectorImpl&>(rhs));
262
    return *this;
263
}
264
265
template<class TYPE> inline
266
Vector<TYPE>& Vector<TYPE>::operator = (const SortedVector<TYPE>& rhs) {
267
    VectorImpl::operator = (static_cast<const VectorImpl&>(rhs));
268
    return *this;
269
}
270
271
template<class TYPE> inline
272
const Vector<TYPE>& Vector<TYPE>::operator = (const SortedVector<TYPE>& rhs) const {
273
    VectorImpl::operator = (rhs);
274
    return *this;
275
}
276
277
template<class TYPE> inline
278
const TYPE* Vector<TYPE>::array() const {
279
    return static_cast<const TYPE *>(arrayImpl());
280
}
281
282
template<class TYPE> inline
283
TYPE* Vector<TYPE>::editArray() {
284
    return static_cast<TYPE *>(editArrayImpl());
285
}
286
287
288
template<class TYPE> inline
289
const TYPE& Vector<TYPE>::operator[](size_t index) const {
290
    LOG_FATAL_IF(index>=size(),
291
            "%s: index=%u out of range (%u)", __PRETTY_FUNCTION__,
292
            int(index), int(size()));
293
    return *(array() + index);
294
}
295
296
template<class TYPE> inline
297
const TYPE& Vector<TYPE>::itemAt(size_t index) const {
298
    return operator[](index);
299
}
300
301
template<class TYPE> inline
302
const TYPE& Vector<TYPE>::top() const {
303
    return *(array() + size() - 1);
304
}
305
306
template<class TYPE> inline
307
TYPE& Vector<TYPE>::editItemAt(size_t index) {
308
    return *( static_cast<TYPE *>(editItemLocation(index)) );
309
}
310
311
template<class TYPE> inline
312
TYPE& Vector<TYPE>::editTop() {
313
    return *( static_cast<TYPE *>(editItemLocation(size()-1)) );
314
}
315
316
template<class TYPE> inline
317
ssize_t Vector<TYPE>::insertVectorAt(const Vector<TYPE>& vector, size_t index) {
318
    return VectorImpl::insertVectorAt(reinterpret_cast<const VectorImpl&>(vector), index);
319
}
320
321
template<class TYPE> inline
322
ssize_t Vector<TYPE>::appendVector(const Vector<TYPE>& vector) {
323
    return VectorImpl::appendVector(reinterpret_cast<const VectorImpl&>(vector));
324
}
325
326
template<class TYPE> inline
327
ssize_t Vector<TYPE>::insertArrayAt(const TYPE* array, size_t index, size_t length) {
328
    return VectorImpl::insertArrayAt(array, index, length);
329
}
330
331
template<class TYPE> inline
332
ssize_t Vector<TYPE>::appendArray(const TYPE* array, size_t length) {
333
    return VectorImpl::appendArray(array, length);
334
}
335
336
template<class TYPE> inline
337
ssize_t Vector<TYPE>::insertAt(const TYPE& item, size_t index, size_t numItems) {
338
    return VectorImpl::insertAt(&item, index, numItems);
339
}
340
341
template<class TYPE> inline
342
void Vector<TYPE>::push(const TYPE& item) {
343
    return VectorImpl::push(&item);
344
}
345
346
template<class TYPE> inline
347
ssize_t Vector<TYPE>::add(const TYPE& item) {
348
    return VectorImpl::add(&item);
349
}
350
351
template<class TYPE> inline
352
ssize_t Vector<TYPE>::replaceAt(const TYPE& item, size_t index) {
353
    return VectorImpl::replaceAt(&item, index);
354
}
355
356
template<class TYPE> inline
357
ssize_t Vector<TYPE>::insertAt(size_t index, size_t numItems) {
358
    return VectorImpl::insertAt(index, numItems);
359
}
360
361
template<class TYPE> inline
362
void Vector<TYPE>::pop() {
363
    VectorImpl::pop();
364
}
365
366
template<class TYPE> inline
367
void Vector<TYPE>::push() {
368
    VectorImpl::push();
369
}
370
371
template<class TYPE> inline
372
ssize_t Vector<TYPE>::add() {
373
    return VectorImpl::add();
374
}
375
376
template<class TYPE> inline
377
ssize_t Vector<TYPE>::replaceAt(size_t index) {
378
    return VectorImpl::replaceAt(index);
379
}
380
381
template<class TYPE> inline
382
ssize_t Vector<TYPE>::removeItemsAt(size_t index, size_t count) {
383
    return VectorImpl::removeItemsAt(index, count);
384
}
385
386
template<class TYPE> inline
387
status_t Vector<TYPE>::sort(Vector<TYPE>::compar_t cmp) {
388
    return VectorImpl::sort(reinterpret_cast<VectorImpl::compar_t>(cmp));
389
}
390
391
template<class TYPE> inline
392
status_t Vector<TYPE>::sort(Vector<TYPE>::compar_r_t cmp, void* state) {
393
    return VectorImpl::sort(reinterpret_cast<VectorImpl::compar_r_t>(cmp), state);
394
}
395
396
// ---------------------------------------------------------------------------
397
398
template<class TYPE>
399
0
UTILS_VECTOR_NO_CFI void Vector<TYPE>::do_construct(void* storage, size_t num) const {
400
0
    construct_type( reinterpret_cast<TYPE*>(storage), num );
401
0
}
Unexecuted instantiation: _ZNK7android6VectorINS_22SimpleSoftOMXComponent8PortInfoEE12do_constructEPvj
Unexecuted instantiation: _ZNK7android6VectorINS_22SimpleSoftOMXComponent10BufferInfoEE12do_constructEPvj
402
403
template<class TYPE>
404
4
void Vector<TYPE>::do_destroy(void* storage, size_t num) const {
405
4
    destroy_type( reinterpret_cast<TYPE*>(storage), num );
406
4
}
_ZNK7android6VectorINS_22SimpleSoftOMXComponent10BufferInfoEE10do_destroyEPvj
Line
Count
Source
404
2
void Vector<TYPE>::do_destroy(void* storage, size_t num) const {
405
2
    destroy_type( reinterpret_cast<TYPE*>(storage), num );
406
2
}
_ZNK7android6VectorINS_22SimpleSoftOMXComponent8PortInfoEE10do_destroyEPvj
Line
Count
Source
404
2
void Vector<TYPE>::do_destroy(void* storage, size_t num) const {
405
2
    destroy_type( reinterpret_cast<TYPE*>(storage), num );
406
2
}
407
408
template<class TYPE>
409
0
UTILS_VECTOR_NO_CFI void Vector<TYPE>::do_copy(void* dest, const void* from, size_t num) const {
410
0
    copy_type( reinterpret_cast<TYPE*>(dest), reinterpret_cast<const TYPE*>(from), num );
411
0
}
Unexecuted instantiation: _ZNK7android6VectorINS_22SimpleSoftOMXComponent10BufferInfoEE7do_copyEPvPKvj
Unexecuted instantiation: _ZNK7android6VectorINS_22SimpleSoftOMXComponent8PortInfoEE7do_copyEPvPKvj
412
413
template<class TYPE>
414
0
UTILS_VECTOR_NO_CFI void Vector<TYPE>::do_splat(void* dest, const void* item, size_t num) const {
415
0
    splat_type( reinterpret_cast<TYPE*>(dest), reinterpret_cast<const TYPE*>(item), num );
416
0
}
Unexecuted instantiation: _ZNK7android6VectorINS_22SimpleSoftOMXComponent10BufferInfoEE8do_splatEPvPKvj
Unexecuted instantiation: _ZNK7android6VectorINS_22SimpleSoftOMXComponent8PortInfoEE8do_splatEPvPKvj
417
418
template<class TYPE>
419
0
UTILS_VECTOR_NO_CFI void Vector<TYPE>::do_move_forward(void* dest, const void* from, size_t num) const {
420
0
    move_forward_type( reinterpret_cast<TYPE*>(dest), reinterpret_cast<const TYPE*>(from), num );
421
0
}
Unexecuted instantiation: _ZNK7android6VectorINS_22SimpleSoftOMXComponent10BufferInfoEE15do_move_forwardEPvPKvj
Unexecuted instantiation: _ZNK7android6VectorINS_22SimpleSoftOMXComponent8PortInfoEE15do_move_forwardEPvPKvj
422
423
template<class TYPE>
424
0
UTILS_VECTOR_NO_CFI void Vector<TYPE>::do_move_backward(void* dest, const void* from, size_t num) const {
425
0
    move_backward_type( reinterpret_cast<TYPE*>(dest), reinterpret_cast<const TYPE*>(from), num );
426
0
}
Unexecuted instantiation: _ZNK7android6VectorINS_22SimpleSoftOMXComponent10BufferInfoEE16do_move_backwardEPvPKvj
Unexecuted instantiation: _ZNK7android6VectorINS_22SimpleSoftOMXComponent8PortInfoEE16do_move_backwardEPvPKvj
427
428
}  // namespace android
429
430
// ---------------------------------------------------------------------------
431
432
#endif // ANDROID_VECTOR_H
/proc/self/cwd/system/core/libutils/include/utils/VectorImpl.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2005 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef ANDROID_VECTOR_IMPL_H
18
#define ANDROID_VECTOR_IMPL_H
19
20
#include <assert.h>
21
#include <stdint.h>
22
#include <sys/types.h>
23
#include <utils/Errors.h>
24
25
// ---------------------------------------------------------------------------
26
// No user serviceable parts in here...
27
// ---------------------------------------------------------------------------
28
29
namespace android {
30
31
/*!
32
 * Implementation of the guts of the vector<> class
33
 * this ensures backward binary compatibility and
34
 * reduces code size.
35
 * For performance reasons, we expose mStorage and mCount
36
 * so these fields are set in stone.
37
 *
38
 */
39
40
class VectorImpl
41
{
42
public:
43
    enum { // flags passed to the ctor
44
        HAS_TRIVIAL_CTOR    = 0x00000001,
45
        HAS_TRIVIAL_DTOR    = 0x00000002,
46
        HAS_TRIVIAL_COPY    = 0x00000004,
47
    };
48
49
                            VectorImpl(size_t itemSize, uint32_t flags);
50
                            VectorImpl(const VectorImpl& rhs);
51
    virtual                 ~VectorImpl();
52
53
    /*! must be called from subclasses destructor */
54
            void            finish_vector();
55
56
            VectorImpl&     operator = (const VectorImpl& rhs);    
57
            
58
    /*! C-style array access */
59
0
    inline  const void*     arrayImpl() const       { return mStorage; }
60
            void*           editArrayImpl();
61
            
62
    /*! vector stats */
63
0
    inline  size_t          size() const        { return mCount; }
64
0
    inline  bool            isEmpty() const     { return mCount == 0; }
65
            size_t          capacity() const;
66
            ssize_t         setCapacity(size_t size);
67
            ssize_t         resize(size_t size);
68
69
            /*! append/insert another vector or array */
70
            ssize_t         insertVectorAt(const VectorImpl& vector, size_t index);
71
            ssize_t         appendVector(const VectorImpl& vector);
72
            ssize_t         insertArrayAt(const void* array, size_t index, size_t length);
73
            ssize_t         appendArray(const void* array, size_t length);
74
            
75
            /*! add/insert/replace items */
76
            ssize_t         insertAt(size_t where, size_t numItems = 1);
77
            ssize_t         insertAt(const void* item, size_t where, size_t numItems = 1);
78
            void            pop();
79
            void            push();
80
            void            push(const void* item);
81
            ssize_t         add();
82
            ssize_t         add(const void* item);
83
            ssize_t         replaceAt(size_t index);
84
            ssize_t         replaceAt(const void* item, size_t index);
85
86
            /*! remove items */
87
            ssize_t         removeItemsAt(size_t index, size_t count = 1);
88
            void            clear();
89
90
            const void*     itemLocation(size_t index) const;
91
            void*           editItemLocation(size_t index);
92
93
            typedef int (*compar_t)(const void* lhs, const void* rhs);
94
            typedef int (*compar_r_t)(const void* lhs, const void* rhs, void* state);
95
            status_t        sort(compar_t cmp);
96
            status_t        sort(compar_r_t cmp, void* state);
97
98
protected:
99
            size_t          itemSize() const;
100
            void            release_storage();
101
102
    virtual void            do_construct(void* storage, size_t num) const = 0;
103
    virtual void            do_destroy(void* storage, size_t num) const = 0;
104
    virtual void            do_copy(void* dest, const void* from, size_t num) const = 0;
105
    virtual void            do_splat(void* dest, const void* item, size_t num) const = 0;
106
    virtual void            do_move_forward(void* dest, const void* from, size_t num) const = 0;
107
    virtual void            do_move_backward(void* dest, const void* from, size_t num) const = 0;
108
    
109
private:
110
        void* _grow(size_t where, size_t amount);
111
        void  _shrink(size_t where, size_t amount);
112
113
        inline void _do_construct(void* storage, size_t num) const;
114
        inline void _do_destroy(void* storage, size_t num) const;
115
        inline void _do_copy(void* dest, const void* from, size_t num) const;
116
        inline void _do_splat(void* dest, const void* item, size_t num) const;
117
        inline void _do_move_forward(void* dest, const void* from, size_t num) const;
118
        inline void _do_move_backward(void* dest, const void* from, size_t num) const;
119
120
            // These 2 fields are exposed in the inlines below,
121
            // so they're set in stone.
122
            void *      mStorage;   // base address of the vector
123
            size_t      mCount;     // number of items
124
125
    const   uint32_t    mFlags;
126
    const   size_t      mItemSize;
127
};
128
129
130
131
class SortedVectorImpl : public VectorImpl
132
{
133
public:
134
                            SortedVectorImpl(size_t itemSize, uint32_t flags);
135
    explicit                SortedVectorImpl(const VectorImpl& rhs);
136
    virtual                 ~SortedVectorImpl();
137
    
138
    SortedVectorImpl&     operator = (const SortedVectorImpl& rhs);    
139
140
    //! finds the index of an item
141
            ssize_t         indexOf(const void* item) const;
142
143
    //! finds where this item should be inserted
144
            size_t          orderOf(const void* item) const;
145
146
    //! add an item in the right place (or replaces it if there is one)
147
            ssize_t         add(const void* item);
148
149
    //! merges a vector into this one
150
            ssize_t         merge(const VectorImpl& vector);
151
            ssize_t         merge(const SortedVectorImpl& vector);
152
             
153
    //! removes an item
154
            ssize_t         remove(const void* item);
155
        
156
protected:
157
    virtual int             do_compare(const void* lhs, const void* rhs) const = 0;
158
159
private:
160
            ssize_t         _indexOrderOf(const void* item, size_t* order = nullptr) const;
161
162
            // these are made private, because they can't be used on a SortedVector
163
            // (they don't have an implementation either)
164
            ssize_t         add();
165
            void            pop();
166
            void            push();
167
            void            push(const void* item);
168
            ssize_t         insertVectorAt(const VectorImpl& vector, size_t index);
169
            ssize_t         appendVector(const VectorImpl& vector);
170
            ssize_t         insertArrayAt(const void* array, size_t index, size_t length);
171
            ssize_t         appendArray(const void* array, size_t length);
172
            ssize_t         insertAt(size_t where, size_t numItems = 1);
173
            ssize_t         insertAt(const void* item, size_t where, size_t numItems = 1);
174
            ssize_t         replaceAt(size_t index);
175
            ssize_t         replaceAt(const void* item, size_t index);
176
};
177
178
}  // namespace android
179
180
// ---------------------------------------------------------------------------
181
182
#endif // ANDROID_VECTOR_IMPL_H
/proc/self/cwd/system/libhidl/base/include/hidl/HidlInternal.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2016 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef ANDROID_HIDL_INTERNAL_H
18
#define ANDROID_HIDL_INTERNAL_H
19
20
#include <cstdint>
21
#include <dirent.h>
22
#include <functional>
23
#include <string>
24
#include <vector>
25
#include <utility>
26
27
namespace android {
28
namespace hardware {
29
namespace details {
30
31
// tag for pure interfaces (e.x. IFoo)
32
struct i_tag {};
33
34
// tag for server interfaces (e.x. BnHwFoo)
35
struct bnhw_tag {};
36
37
// tag for proxy interfaces (e.x. BpHwFoo)
38
struct bphw_tag {};
39
40
// tag for passthrough interfaces (e.x. BsFoo)
41
struct bs_tag {};
42
43
//Templated classes can use the below method
44
//to avoid creating dependencies on liblog.
45
void logAlwaysFatal(const char *message);
46
47
// Returns vndk version from "ro.vndk.version" with '-' as a prefix.
48
// If "ro.vndk.version" is not set or set to "current", it returns empty string.
49
std::string getVndkVersionStr();
50
51
// Explicitly invokes the parameterized element's destructor;
52
// intended to be used alongside the placement new operator.
53
template<typename T>
54
void destructElement(T* element) {
55
    if (element != nullptr) {
56
        element->~T();
57
    }
58
}
59
60
// HIDL client/server code should *NOT* use this class.
61
//
62
// hidl_pointer wraps a pointer without taking ownership,
63
// and stores it in a union with a uint64_t. This ensures
64
// that we always have enough space to store a pointer,
65
// regardless of whether we're running in a 32-bit or 64-bit
66
// process.
67
template<typename T>
68
struct hidl_pointer {
69
    hidl_pointer()
70
        : _pad(0) {
71
    }
72
    hidl_pointer(T* ptr) : hidl_pointer() { mPointer = ptr; }
73
    hidl_pointer(const hidl_pointer<T>& other) : hidl_pointer() { mPointer = other.mPointer; }
74
    hidl_pointer(hidl_pointer<T>&& other) noexcept : hidl_pointer() { *this = std::move(other); }
75
76
    hidl_pointer &operator=(const hidl_pointer<T>& other) {
77
        mPointer = other.mPointer;
78
        return *this;
79
    }
80
    hidl_pointer& operator=(hidl_pointer<T>&& other) noexcept {
81
        mPointer = other.mPointer;
82
        other.mPointer = nullptr;
83
        return *this;
84
    }
85
    hidl_pointer &operator=(T* ptr) {
86
        mPointer = ptr;
87
        return *this;
88
    }
89
90
    operator T*() const {
91
        return mPointer;
92
    }
93
    explicit operator void*() const { // requires explicit cast to avoid ambiguity
94
        return mPointer;
95
    }
96
    T& operator*() const {
97
        return *mPointer;
98
    }
99
    T* operator->() const {
100
        return mPointer;
101
    }
102
    T &operator[](size_t index) {
103
        return mPointer[index];
104
    }
105
    const T &operator[](size_t index) const {
106
        return mPointer[index];
107
    }
108
109
private:
110
    union {
111
        T* mPointer;
112
        uint64_t _pad;
113
    };
114
};
115
116
#define HAL_LIBRARY_PATH_SYSTEM_64BIT "/system/lib64/hw/"
117
#define HAL_LIBRARY_PATH_VNDK_SP_64BIT_FOR_VERSION "/system/lib64/vndk-sp%s/hw/"
118
#define HAL_LIBRARY_PATH_VENDOR_64BIT "/vendor/lib64/hw/"
119
#define HAL_LIBRARY_PATH_ODM_64BIT    "/odm/lib64/hw/"
120
#define HAL_LIBRARY_PATH_SYSTEM_32BIT "/system/lib/hw/"
121
#define HAL_LIBRARY_PATH_VNDK_SP_32BIT_FOR_VERSION "/system/lib/vndk-sp%s/hw/"
122
#define HAL_LIBRARY_PATH_VENDOR_32BIT "/vendor/lib/hw/"
123
#define HAL_LIBRARY_PATH_ODM_32BIT    "/odm/lib/hw/"
124
125
#if defined(__LP64__)
126
#define HAL_LIBRARY_PATH_SYSTEM HAL_LIBRARY_PATH_SYSTEM_64BIT
127
#define HAL_LIBRARY_PATH_VNDK_SP_FOR_VERSION HAL_LIBRARY_PATH_VNDK_SP_64BIT_FOR_VERSION
128
#define HAL_LIBRARY_PATH_VENDOR HAL_LIBRARY_PATH_VENDOR_64BIT
129
#define HAL_LIBRARY_PATH_ODM    HAL_LIBRARY_PATH_ODM_64BIT
130
#else
131
#define HAL_LIBRARY_PATH_SYSTEM HAL_LIBRARY_PATH_SYSTEM_32BIT
132
#define HAL_LIBRARY_PATH_VNDK_SP_FOR_VERSION HAL_LIBRARY_PATH_VNDK_SP_32BIT_FOR_VERSION
133
#define HAL_LIBRARY_PATH_VENDOR HAL_LIBRARY_PATH_VENDOR_32BIT
134
#define HAL_LIBRARY_PATH_ODM    HAL_LIBRARY_PATH_ODM_32BIT
135
#endif
136
137
// ----------------------------------------------------------------------
138
// Class that provides Hidl instrumentation utilities.
139
struct HidlInstrumentor {
140
    // Event that triggers the instrumentation. e.g. enter of an API call on
141
    // the server/client side, exit of an API call on the server/client side
142
    // etc.
143
    enum InstrumentationEvent {
144
        SERVER_API_ENTRY = 0,
145
        SERVER_API_EXIT,
146
        CLIENT_API_ENTRY,
147
        CLIENT_API_EXIT,
148
        SYNC_CALLBACK_ENTRY,
149
        SYNC_CALLBACK_EXIT,
150
        ASYNC_CALLBACK_ENTRY,
151
        ASYNC_CALLBACK_EXIT,
152
        PASSTHROUGH_ENTRY,
153
        PASSTHROUGH_EXIT,
154
    };
155
156
    // Signature of the instrumentation callback function.
157
    using InstrumentationCallback = std::function<void(
158
            const InstrumentationEvent event,
159
            const char *package,
160
            const char *version,
161
            const char *interface,
162
            const char *method,
163
            std::vector<void *> *args)>;
164
165
    explicit HidlInstrumentor(
166
            const std::string &package,
167
            const std::string &insterface);
168
    virtual ~HidlInstrumentor();
169
170
   public:
171
0
    const std::vector<InstrumentationCallback>& getInstrumentationCallbacks() {
172
0
        return mInstrumentationCallbacks;
173
0
    }
174
0
    bool isInstrumentationEnabled() { return mEnableInstrumentation; }
175
176
   protected:
177
    // Set mEnableInstrumentation based on system property
178
    // hal.instrumentation.enable, register/de-register instrumentation
179
    // callbacks if mEnableInstrumentation is true/false.
180
    void configureInstrumentation(bool log=true);
181
    // Function that lookup and dynamically loads the hidl instrumentation
182
    // libraries and registers the instrumentation callback functions.
183
    //
184
    // The instrumentation libraries should be stored under any of the following
185
    // directories: HAL_LIBRARY_PATH_SYSTEM, HAL_LIBRARY_PATH_VNDK_SP,
186
    // HAL_LIBRARY_PATH_VENDOR and HAL_LIBRARY_PATH_ODM.
187
    // The name of instrumentation libraries should follow pattern:
188
    // ^profilerPrefix(.*).profiler.so$
189
    //
190
    // Each instrumentation library is expected to implement the instrumentation
191
    // function called HIDL_INSTRUMENTATION_FUNCTION.
192
    //
193
    // A no-op for user build.
194
    void registerInstrumentationCallbacks(
195
            std::vector<InstrumentationCallback> *instrumentationCallbacks);
196
197
    // Utility function to determine whether a give file is a instrumentation
198
    // library (i.e. the file name follow the expected pattern).
199
    bool isInstrumentationLib(const dirent *file);
200
201
    // A list of registered instrumentation callbacks.
202
    std::vector<InstrumentationCallback> mInstrumentationCallbacks;
203
    // Flag whether to enable instrumentation.
204
    bool mEnableInstrumentation;
205
    // Prefix to lookup the instrumentation libraries.
206
    std::string mInstrumentationLibPackage;
207
    // Used for dlsym to load the profiling method for given interface.
208
    std::string mInterfaceName;
209
210
};
211
212
}  // namespace details
213
}  // namespace hardware
214
}  // namespace android
215
216
#endif  // ANDROID_HIDL_INTERNAL_H
/proc/self/cwd/system/libhidl/base/include/hidl/HidlSupport.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2016 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef ANDROID_HIDL_SUPPORT_H
18
#define ANDROID_HIDL_SUPPORT_H
19
20
#include <algorithm>
21
#include <array>
22
#include <iterator>
23
#include <cutils/native_handle.h>
24
#include <hidl/HidlInternal.h>
25
#include <hidl/Status.h>
26
#include <map>
27
#include <sstream>
28
#include <stddef.h>
29
#include <tuple>
30
#include <type_traits>
31
#include <utils/Errors.h>
32
#include <utils/RefBase.h>
33
#include <utils/StrongPointer.h>
34
#include <vector>
35
36
namespace android {
37
38
// this file is included by all hidl interface, so we must forward declare the
39
// IMemory and IBase types.
40
namespace hidl {
41
namespace memory {
42
namespace V1_0 {
43
44
struct IMemory;
45
46
}  // namespace V1_0
47
}  // namespace memory
48
}  // namespace hidl
49
50
namespace hidl {
51
namespace base {
52
namespace V1_0 {
53
54
struct IBase;
55
56
}  // namespace V1_0
57
}  // namespace base
58
}  // namespace hidl
59
60
namespace hardware {
61
62
namespace details {
63
// Return true on userdebug / eng builds and false on user builds.
64
bool debuggable();
65
} //  namespace details
66
67
// hidl_death_recipient is a callback interfaced that can be used with
68
// linkToDeath() / unlinkToDeath()
69
struct hidl_death_recipient : public virtual RefBase {
70
    virtual void serviceDied(uint64_t cookie,
71
            const ::android::wp<::android::hidl::base::V1_0::IBase>& who) = 0;
72
};
73
74
// hidl_handle wraps a pointer to a native_handle_t in a hidl_pointer,
75
// so that it can safely be transferred between 32-bit and 64-bit processes.
76
// The ownership semantics for this are:
77
// 1) The conversion constructor and assignment operator taking a const native_handle_t*
78
//    do not take ownership of the handle; this is because these operations are usually
79
//    just done for IPC, and cloning by default is a waste of resources. If you want
80
//    a hidl_handle to take ownership, call setTo(handle, true /*shouldOwn*/);
81
// 2) The copy constructor/assignment operator taking a hidl_handle *DO* take ownership;
82
//    that is because it's not intuitive that this class encapsulates a native_handle_t
83
//    which needs cloning to be valid; in particular, this allows constructs like this:
84
//    hidl_handle copy;
85
//    foo->someHidlCall([&](auto incoming_handle) {
86
//            copy = incoming_handle;
87
//    });
88
//    // copy and its enclosed file descriptors will remain valid here.
89
// 3) The move constructor does what you would expect; it only owns the handle if the
90
//    original did.
91
struct hidl_handle {
92
    hidl_handle();
93
    ~hidl_handle();
94
95
    hidl_handle(const native_handle_t *handle);
96
97
    // copy constructor.
98
    hidl_handle(const hidl_handle &other);
99
100
    // move constructor.
101
    hidl_handle(hidl_handle &&other) noexcept;
102
103
    // assignment operators
104
    hidl_handle &operator=(const hidl_handle &other);
105
106
    hidl_handle &operator=(const native_handle_t *native_handle);
107
108
    hidl_handle &operator=(hidl_handle &&other) noexcept;
109
110
    void setTo(native_handle_t* handle, bool shouldOwn = false);
111
112
    const native_handle_t* operator->() const;
113
114
    // implicit conversion to const native_handle_t*
115
    operator const native_handle_t *() const;
116
117
    // explicit conversion
118
    const native_handle_t *getNativeHandle() const;
119
120
    // offsetof(hidl_handle, mHandle) exposed since mHandle is private.
121
    static const size_t kOffsetOfNativeHandle;
122
123
private:
124
    void freeHandle();
125
126
    details::hidl_pointer<const native_handle_t> mHandle __attribute__ ((aligned(8)));
127
    bool mOwnsHandle __attribute ((aligned(8)));
128
};
129
130
struct hidl_string {
131
    hidl_string();
132
    ~hidl_string();
133
134
    // copy constructor.
135
    hidl_string(const hidl_string &);
136
    // copy from a C-style string. nullptr will create an empty string
137
    hidl_string(const char *);
138
    // copy the first length characters from a C-style string.
139
    hidl_string(const char *, size_t length);
140
    // copy from an std::string.
141
    hidl_string(const std::string &);
142
143
    // move constructor.
144
    hidl_string(hidl_string &&) noexcept;
145
146
    const char *c_str() const;
147
    size_t size() const;
148
    bool empty() const;
149
150
    // copy assignment operator.
151
    hidl_string &operator=(const hidl_string &);
152
    // copy from a C-style string.
153
    hidl_string &operator=(const char *s);
154
    // copy from an std::string.
155
    hidl_string &operator=(const std::string &);
156
    // move assignment operator.
157
    hidl_string &operator=(hidl_string &&other) noexcept;
158
    // cast to std::string.
159
    operator std::string() const;
160
161
    void clear();
162
163
    // Reference an external char array. Ownership is _not_ transferred.
164
    // Caller is responsible for ensuring that underlying memory is valid
165
    // for the lifetime of this hidl_string.
166
    //
167
    // size == strlen(data)
168
    void setToExternal(const char *data, size_t size);
169
170
    // offsetof(hidl_string, mBuffer) exposed since mBuffer is private.
171
    static const size_t kOffsetOfBuffer;
172
173
private:
174
    details::hidl_pointer<const char> mBuffer;
175
    uint32_t mSize;  // NOT including the terminating '\0'.
176
    bool mOwnsBuffer; // if true then mBuffer is a mutable char *
177
178
    // copy from data with size. Assume that my memory is freed
179
    // (through clear(), for example)
180
    void copyFrom(const char *data, size_t size);
181
    // move from another hidl_string
182
    void moveFrom(hidl_string &&);
183
};
184
185
// Use NOLINT to suppress missing parentheses warnings around OP.
186
#define HIDL_STRING_OPERATOR(OP)                                              \
187
0
    inline bool operator OP(const hidl_string& hs1, const hidl_string& hs2) { \
188
0
        return strcmp(hs1.c_str(), hs2.c_str()) OP 0; /* NOLINT */            \
189
0
    }                                                                         \
Unexecuted instantiation: _ZN7android8hardwareeqERKNS0_11hidl_stringES3_
Unexecuted instantiation: _ZN7android8hardwareneERKNS0_11hidl_stringES3_
Unexecuted instantiation: _ZN7android8hardwareltERKNS0_11hidl_stringES3_
Unexecuted instantiation: _ZN7android8hardwareleERKNS0_11hidl_stringES3_
Unexecuted instantiation: _ZN7android8hardwaregtERKNS0_11hidl_stringES3_
Unexecuted instantiation: _ZN7android8hardwaregeERKNS0_11hidl_stringES3_
190
0
    inline bool operator OP(const hidl_string& hs, const char* s) {           \
191
0
        return strcmp(hs.c_str(), s) OP 0; /* NOLINT */                       \
192
0
    }                                                                         \
Unexecuted instantiation: _ZN7android8hardwareeqERKNS0_11hidl_stringEPKc
Unexecuted instantiation: _ZN7android8hardwareneERKNS0_11hidl_stringEPKc
Unexecuted instantiation: _ZN7android8hardwareltERKNS0_11hidl_stringEPKc
Unexecuted instantiation: _ZN7android8hardwareleERKNS0_11hidl_stringEPKc
Unexecuted instantiation: _ZN7android8hardwaregtERKNS0_11hidl_stringEPKc
Unexecuted instantiation: _ZN7android8hardwaregeERKNS0_11hidl_stringEPKc
193
0
    inline bool operator OP(const char* s, const hidl_string& hs) {           \
194
0
        return strcmp(s, hs.c_str()) OP 0; /* NOLINT */                       \
195
0
    }
Unexecuted instantiation: _ZN7android8hardwareeqEPKcRKNS0_11hidl_stringE
Unexecuted instantiation: _ZN7android8hardwareneEPKcRKNS0_11hidl_stringE
Unexecuted instantiation: _ZN7android8hardwareltEPKcRKNS0_11hidl_stringE
Unexecuted instantiation: _ZN7android8hardwareleEPKcRKNS0_11hidl_stringE
Unexecuted instantiation: _ZN7android8hardwaregtEPKcRKNS0_11hidl_stringE
Unexecuted instantiation: _ZN7android8hardwaregeEPKcRKNS0_11hidl_stringE
196
197
HIDL_STRING_OPERATOR(==)
198
HIDL_STRING_OPERATOR(!=)
199
HIDL_STRING_OPERATOR(<)
200
HIDL_STRING_OPERATOR(<=)
201
HIDL_STRING_OPERATOR(>)
202
HIDL_STRING_OPERATOR(>=)
203
204
#undef HIDL_STRING_OPERATOR
205
206
// Send our content to the output stream
207
std::ostream& operator<<(std::ostream& os, const hidl_string& str);
208
209
210
// hidl_memory is a structure that can be used to transfer
211
// pieces of shared memory between processes. The assumption
212
// of this object is that the memory remains accessible as
213
// long as the file descriptors in the enclosed mHandle
214
// - as well as all of its cross-process dups() - remain opened.
215
struct hidl_memory {
216
217
0
    hidl_memory() : mHandle(nullptr), mSize(0), mName("") {
218
0
    }
219
220
    /**
221
     * Creates a hidl_memory object whose handle has the same lifetime
222
     * as the handle moved into it.
223
     */
224
    hidl_memory(const hidl_string& name, hidl_handle&& handle, size_t size)
225
0
        : mHandle(std::move(handle)), mSize(size), mName(name) {}
226
227
    /**
228
     * Creates a hidl_memory object, but doesn't take ownership of
229
     * the passed in native_handle_t; callers are responsible for
230
     * making sure the handle remains valid while this object is
231
     * used.
232
     */
233
    hidl_memory(const hidl_string &name, const native_handle_t *handle, size_t size)
234
      :  mHandle(handle),
235
         mSize(size),
236
         mName(name)
237
0
    {}
238
239
    // copy constructor
240
0
    hidl_memory(const hidl_memory& other) {
241
0
        *this = other;
242
0
    }
243
244
    // copy assignment
245
0
    hidl_memory &operator=(const hidl_memory &other) {
246
0
        if (this != &other) {
247
0
            mHandle = other.mHandle;
248
0
            mSize = other.mSize;
249
0
            mName = other.mName;
250
0
        }
251
0
252
0
        return *this;
253
0
    }
254
255
    // move constructor
256
0
    hidl_memory(hidl_memory&& other) noexcept {
257
0
        *this = std::move(other);
258
0
    }
259
260
    // move assignment
261
0
    hidl_memory &operator=(hidl_memory &&other) noexcept {
262
0
        if (this != &other) {
263
0
            mHandle = std::move(other.mHandle);
264
0
            mSize = other.mSize;
265
0
            mName = std::move(other.mName);
266
0
            other.mSize = 0;
267
0
        }
268
0
269
0
        return *this;
270
0
    }
271
272
273
0
    ~hidl_memory() {
274
0
    }
275
276
0
    const native_handle_t* handle() const {
277
0
        return mHandle;
278
0
    }
279
280
0
    const hidl_string &name() const {
281
0
        return mName;
282
0
    }
283
284
0
    uint64_t size() const {
285
0
        return mSize;
286
0
    }
287
288
    // @return true if it's valid
289
0
    inline bool valid() const { return handle() != nullptr; }
290
291
    // offsetof(hidl_memory, mHandle) exposed since mHandle is private.
292
    static const size_t kOffsetOfHandle;
293
    // offsetof(hidl_memory, mName) exposed since mHandle is private.
294
    static const size_t kOffsetOfName;
295
296
private:
297
    hidl_handle mHandle __attribute__ ((aligned(8)));
298
    uint64_t mSize __attribute__ ((aligned(8)));
299
    hidl_string mName __attribute__ ((aligned(8)));
300
};
301
302
// HidlMemory is a wrapper class to support sp<> for hidl_memory. It also
303
// provides factory methods to create an instance from hidl_memory or
304
// from a opened file descriptor. The number of factory methods can be increase
305
// to support other type of hidl_memory without break the ABI.
306
class HidlMemory : public virtual hidl_memory, public virtual ::android::RefBase {
307
public:
308
    static sp<HidlMemory> getInstance(const hidl_memory& mem);
309
310
    static sp<HidlMemory> getInstance(hidl_memory&& mem);
311
312
    static sp<HidlMemory> getInstance(const hidl_string& name, hidl_handle&& handle, uint64_t size);
313
    // @param fd, shall be opened and points to the resource.
314
    // @note this method takes the ownership of the fd and will close it in
315
    //     destructor
316
    // @return nullptr in failure with the fd closed
317
    static sp<HidlMemory> getInstance(const hidl_string& name, int fd, uint64_t size);
318
319
    virtual ~HidlMemory();
320
321
protected:
322
    HidlMemory();
323
    HidlMemory(const hidl_string& name, hidl_handle&& handle, size_t size);
324
};
325
////////////////////////////////////////////////////////////////////////////////
326
327
template<typename T>
328
struct hidl_vec {
329
    hidl_vec()
330
        : mBuffer(nullptr),
331
          mSize(0),
332
          mOwnsBuffer(true) {
333
        static_assert(hidl_vec<T>::kOffsetOfBuffer == 0, "wrong offset");
334
    }
335
336
    // Note, does not initialize primitive types.
337
    hidl_vec(size_t size) : hidl_vec() { resize(size); }
338
339
    hidl_vec(const hidl_vec<T> &other) : hidl_vec() {
340
        *this = other;
341
    }
342
343
    hidl_vec(hidl_vec<T> &&other) noexcept
344
    : mOwnsBuffer(false) {
345
        *this = std::move(other);
346
    }
347
348
    hidl_vec(const std::initializer_list<T> list)
349
            : mOwnsBuffer(true) {
350
        if (list.size() > UINT32_MAX) {
351
            details::logAlwaysFatal("hidl_vec can't hold more than 2^32 elements.");
352
        }
353
        mSize = static_cast<uint32_t>(list.size());
354
        mBuffer = new T[mSize];
355
356
        size_t idx = 0;
357
        for (auto it = list.begin(); it != list.end(); ++it) {
358
            mBuffer[idx++] = *it;
359
        }
360
    }
361
362
    hidl_vec(const std::vector<T> &other) : hidl_vec() {
363
        *this = other;
364
    }
365
366
    template <typename InputIterator,
367
              typename = typename std::enable_if<std::is_convertible<
368
                  typename std::iterator_traits<InputIterator>::iterator_category,
369
                  std::input_iterator_tag>::value>::type>
370
    hidl_vec(InputIterator first, InputIterator last) : mOwnsBuffer(true) {
371
        auto size = std::distance(first, last);
372
        if (size > static_cast<int64_t>(UINT32_MAX)) {
373
            details::logAlwaysFatal("hidl_vec can't hold more than 2^32 elements.");
374
        }
375
        if (size < 0) {
376
            details::logAlwaysFatal("size can't be negative.");
377
        }
378
        mSize = static_cast<uint32_t>(size);
379
        mBuffer = new T[mSize];
380
381
        size_t idx = 0;
382
        for (; first != last; ++first) {
383
            mBuffer[idx++] = static_cast<T>(*first);
384
        }
385
    }
386
387
    ~hidl_vec() {
388
        if (mOwnsBuffer) {
389
            delete[] mBuffer;
390
        }
391
        mBuffer = nullptr;
392
    }
393
394
    // Reference an existing array, optionally taking ownership. It is the
395
    // caller's responsibility to ensure that the underlying memory stays
396
    // valid for the lifetime of this hidl_vec.
397
    void setToExternal(T *data, size_t size, bool shouldOwn = false) {
398
        if (mOwnsBuffer) {
399
            delete [] mBuffer;
400
        }
401
        mBuffer = data;
402
        if (size > UINT32_MAX) {
403
            details::logAlwaysFatal("external vector size exceeds 2^32 elements.");
404
        }
405
        mSize = static_cast<uint32_t>(size);
406
        mOwnsBuffer = shouldOwn;
407
    }
408
409
    T *data() {
410
        return mBuffer;
411
    }
412
413
    const T *data() const {
414
        return mBuffer;
415
    }
416
417
    T *releaseData() {
418
        if (!mOwnsBuffer && mSize > 0) {
419
            resize(mSize);
420
        }
421
        mOwnsBuffer = false;
422
        return mBuffer;
423
    }
424
425
    hidl_vec &operator=(hidl_vec &&other) noexcept {
426
        if (mOwnsBuffer) {
427
            delete[] mBuffer;
428
        }
429
        mBuffer = other.mBuffer;
430
        mSize = other.mSize;
431
        mOwnsBuffer = other.mOwnsBuffer;
432
        other.mOwnsBuffer = false;
433
        return *this;
434
    }
435
436
    hidl_vec &operator=(const hidl_vec &other) {
437
        if (this != &other) {
438
            if (mOwnsBuffer) {
439
                delete[] mBuffer;
440
            }
441
            copyFrom(other, other.mSize);
442
        }
443
444
        return *this;
445
    }
446
447
    // copy from an std::vector.
448
    hidl_vec &operator=(const std::vector<T> &other) {
449
        if (mOwnsBuffer) {
450
            delete[] mBuffer;
451
        }
452
        copyFrom(other, other.size());
453
        return *this;
454
    }
455
456
    // cast to an std::vector.
457
    operator std::vector<T>() const {
458
        std::vector<T> v(mSize);
459
        for (size_t i = 0; i < mSize; ++i) {
460
            v[i] = mBuffer[i];
461
        }
462
        return v;
463
    }
464
465
    // equality check, assuming that T::operator== is defined.
466
    bool operator==(const hidl_vec &other) const {
467
        if (mSize != other.size()) {
468
            return false;
469
        }
470
        for (size_t i = 0; i < mSize; ++i) {
471
            if (!(mBuffer[i] == other.mBuffer[i])) {
472
                return false;
473
            }
474
        }
475
        return true;
476
    }
477
478
    // inequality check, assuming that T::operator== is defined.
479
    inline bool operator!=(const hidl_vec &other) const {
480
        return !((*this) == other);
481
    }
482
483
    size_t size() const {
484
        return mSize;
485
    }
486
487
    T &operator[](size_t index) {
488
        return mBuffer[index];
489
    }
490
491
    const T &operator[](size_t index) const {
492
        return mBuffer[index];
493
    }
494
495
    // Does not initialize primitive types if new size > old size.
496
    void resize(size_t size) {
497
        if (size > UINT32_MAX) {
498
            details::logAlwaysFatal("hidl_vec can't hold more than 2^32 elements.");
499
        }
500
        T *newBuffer = new T[size];
501
502
        for (size_t i = 0; i < std::min(static_cast<uint32_t>(size), mSize); ++i) {
503
            newBuffer[i] = mBuffer[i];
504
        }
505
506
        if (mOwnsBuffer) {
507
            delete[] mBuffer;
508
        }
509
        mBuffer = newBuffer;
510
511
        mSize = static_cast<uint32_t>(size);
512
        mOwnsBuffer = true;
513
    }
514
515
    // offsetof(hidl_string, mBuffer) exposed since mBuffer is private.
516
    static const size_t kOffsetOfBuffer;
517
518
private:
519
    // Define std interator interface for walking the array contents
520
    template<bool is_const>
521
    class iter : public std::iterator<
522
            std::random_access_iterator_tag, /* Category */
523
            T,
524
            ptrdiff_t, /* Distance */
525
            typename std::conditional<is_const, const T *, T *>::type /* Pointer */,
526
            typename std::conditional<is_const, const T &, T &>::type /* Reference */>
527
    {
528
        using traits = std::iterator_traits<iter>;
529
        using ptr_type = typename traits::pointer;
530
        using ref_type = typename traits::reference;
531
        using diff_type = typename traits::difference_type;
532
    public:
533
        iter(ptr_type ptr) : mPtr(ptr) { }
534
        inline iter &operator++()    { mPtr++; return *this; }
535
        inline iter  operator++(int) { iter i = *this; mPtr++; return i; }
536
        inline iter &operator--()    { mPtr--; return *this; }
537
        inline iter  operator--(int) { iter i = *this; mPtr--; return i; }
538
        inline friend iter operator+(diff_type n, const iter &it) { return it.mPtr + n; }
539
        inline iter  operator+(diff_type n) const { return mPtr + n; }
540
        inline iter  operator-(diff_type n) const { return mPtr - n; }
541
        inline diff_type operator-(const iter &other) const { return mPtr - other.mPtr; }
542
        inline iter &operator+=(diff_type n) { mPtr += n; return *this; }
543
        inline iter &operator-=(diff_type n) { mPtr -= n; return *this; }
544
        inline ref_type operator*() const  { return *mPtr; }
545
        inline ptr_type operator->() const { return mPtr; }
546
        inline bool operator==(const iter &rhs) const { return mPtr == rhs.mPtr; }
547
        inline bool operator!=(const iter &rhs) const { return mPtr != rhs.mPtr; }
548
        inline bool operator< (const iter &rhs) const { return mPtr <  rhs.mPtr; }
549
        inline bool operator> (const iter &rhs) const { return mPtr >  rhs.mPtr; }
550
        inline bool operator<=(const iter &rhs) const { return mPtr <= rhs.mPtr; }
551
        inline bool operator>=(const iter &rhs) const { return mPtr >= rhs.mPtr; }
552
        inline ref_type operator[](size_t n) const { return mPtr[n]; }
553
    private:
554
        ptr_type mPtr;
555
    };
556
public:
557
    using iterator       = iter<false /* is_const */>;
558
    using const_iterator = iter<true  /* is_const */>;
559
560
    iterator begin() { return data(); }
561
    iterator end() { return data()+mSize; }
562
    const_iterator begin() const { return data(); }
563
    const_iterator end() const { return data()+mSize; }
564
565
private:
566
    details::hidl_pointer<T> mBuffer;
567
    uint32_t mSize;
568
    bool mOwnsBuffer;
569
570
    // copy from an array-like object, assuming my resources are freed.
571
    template <typename Array>
572
    void copyFrom(const Array &data, size_t size) {
573
        mSize = static_cast<uint32_t>(size);
574
        mOwnsBuffer = true;
575
        if (mSize > 0) {
576
            mBuffer = new T[size];
577
            for (size_t i = 0; i < size; ++i) {
578
                mBuffer[i] = data[i];
579
            }
580
        } else {
581
            mBuffer = nullptr;
582
        }
583
    }
584
};
585
586
template <typename T>
587
const size_t hidl_vec<T>::kOffsetOfBuffer = offsetof(hidl_vec<T>, mBuffer);
588
589
////////////////////////////////////////////////////////////////////////////////
590
591
namespace details {
592
593
    template<size_t SIZE1, size_t... SIZES>
594
    struct product {
595
        static constexpr size_t value = SIZE1 * product<SIZES...>::value;
596
    };
597
598
    template<size_t SIZE1>
599
    struct product<SIZE1> {
600
        static constexpr size_t value = SIZE1;
601
    };
602
603
    template<typename T, size_t SIZE1, size_t... SIZES>
604
    struct std_array {
605
        using type = std::array<typename std_array<T, SIZES...>::type, SIZE1>;
606
    };
607
608
    template<typename T, size_t SIZE1>
609
    struct std_array<T, SIZE1> {
610
        using type = std::array<T, SIZE1>;
611
    };
612
613
    template<typename T, size_t SIZE1, size_t... SIZES>
614
    struct accessor {
615
616
        using std_array_type = typename std_array<T, SIZE1, SIZES...>::type;
617
618
        explicit accessor(T *base)
619
            : mBase(base) {
620
        }
621
622
        accessor<T, SIZES...> operator[](size_t index) {
623
            return accessor<T, SIZES...>(
624
                    &mBase[index * product<SIZES...>::value]);
625
        }
626
627
        accessor &operator=(const std_array_type &other) {
628
            for (size_t i = 0; i < SIZE1; ++i) {
629
                (*this)[i] = other[i];
630
            }
631
            return *this;
632
        }
633
634
    private:
635
        T *mBase;
636
    };
637
638
    template<typename T, size_t SIZE1>
639
    struct accessor<T, SIZE1> {
640
641
        using std_array_type = typename std_array<T, SIZE1>::type;
642
643
        explicit accessor(T *base)
644
            : mBase(base) {
645
        }
646
647
        T &operator[](size_t index) {
648
            return mBase[index];
649
        }
650
651
        accessor &operator=(const std_array_type &other) {
652
            for (size_t i = 0; i < SIZE1; ++i) {
653
                (*this)[i] = other[i];
654
            }
655
            return *this;
656
        }
657
658
    private:
659
        T *mBase;
660
    };
661
662
    template<typename T, size_t SIZE1, size_t... SIZES>
663
    struct const_accessor {
664
665
        using std_array_type = typename std_array<T, SIZE1, SIZES...>::type;
666
667
        explicit const_accessor(const T *base)
668
            : mBase(base) {
669
        }
670
671
        const_accessor<T, SIZES...> operator[](size_t index) const {
672
            return const_accessor<T, SIZES...>(
673
                    &mBase[index * product<SIZES...>::value]);
674
        }
675
676
        operator std_array_type() {
677
            std_array_type array;
678
            for (size_t i = 0; i < SIZE1; ++i) {
679
                array[i] = (*this)[i];
680
            }
681
            return array;
682
        }
683
684
    private:
685
        const T *mBase;
686
    };
687
688
    template<typename T, size_t SIZE1>
689
    struct const_accessor<T, SIZE1> {
690
691
        using std_array_type = typename std_array<T, SIZE1>::type;
692
693
        explicit const_accessor(const T *base)
694
            : mBase(base) {
695
        }
696
697
        const T &operator[](size_t index) const {
698
            return mBase[index];
699
        }
700
701
        operator std_array_type() {
702
            std_array_type array;
703
            for (size_t i = 0; i < SIZE1; ++i) {
704
                array[i] = (*this)[i];
705
            }
706
            return array;
707
        }
708
709
    private:
710
        const T *mBase;
711
    };
712
713
}  // namespace details
714
715
////////////////////////////////////////////////////////////////////////////////
716
717
// A multidimensional array of T's. Assumes that T::operator=(const T &) is defined.
718
template<typename T, size_t SIZE1, size_t... SIZES>
719
struct hidl_array {
720
721
    using std_array_type = typename details::std_array<T, SIZE1, SIZES...>::type;
722
723
    hidl_array() = default;
724
725
    // Copies the data from source, using T::operator=(const T &).
726
    hidl_array(const T *source) {
727
        for (size_t i = 0; i < elementCount(); ++i) {
728
            mBuffer[i] = source[i];
729
        }
730
    }
731
732
    // Copies the data from the given std::array, using T::operator=(const T &).
733
    hidl_array(const std_array_type &array) {
734
        details::accessor<T, SIZE1, SIZES...> modifier(mBuffer);
735
        modifier = array;
736
    }
737
738
    T *data() { return mBuffer; }
739
    const T *data() const { return mBuffer; }
740
741
    details::accessor<T, SIZES...> operator[](size_t index) {
742
        return details::accessor<T, SIZES...>(
743
                &mBuffer[index * details::product<SIZES...>::value]);
744
    }
745
746
    details::const_accessor<T, SIZES...> operator[](size_t index) const {
747
        return details::const_accessor<T, SIZES...>(
748
                &mBuffer[index * details::product<SIZES...>::value]);
749
    }
750
751
    // equality check, assuming that T::operator== is defined.
752
    bool operator==(const hidl_array &other) const {
753
        for (size_t i = 0; i < elementCount(); ++i) {
754
            if (!(mBuffer[i] == other.mBuffer[i])) {
755
                return false;
756
            }
757
        }
758
        return true;
759
    }
760
761
    inline bool operator!=(const hidl_array &other) const {
762
        return !((*this) == other);
763
    }
764
765
    using size_tuple_type = std::tuple<decltype(SIZE1), decltype(SIZES)...>;
766
767
    static constexpr size_tuple_type size() {
768
        return std::make_tuple(SIZE1, SIZES...);
769
    }
770
771
    static constexpr size_t elementCount() {
772
        return details::product<SIZE1, SIZES...>::value;
773
    }
774
775
    operator std_array_type() const {
776
        return details::const_accessor<T, SIZE1, SIZES...>(mBuffer);
777
    }
778
779
private:
780
    T mBuffer[elementCount()];
781
};
782
783
// An array of T's. Assumes that T::operator=(const T &) is defined.
784
template<typename T, size_t SIZE1>
785
struct hidl_array<T, SIZE1> {
786
787
    using std_array_type = typename details::std_array<T, SIZE1>::type;
788
789
    hidl_array() = default;
790
791
    // Copies the data from source, using T::operator=(const T &).
792
    hidl_array(const T *source) {
793
        for (size_t i = 0; i < elementCount(); ++i) {
794
            mBuffer[i] = source[i];
795
        }
796
    }
797
798
    // Copies the data from the given std::array, using T::operator=(const T &).
799
    hidl_array(const std_array_type &array) : hidl_array(array.data()) {}
800
801
    T *data() { return mBuffer; }
802
    const T *data() const { return mBuffer; }
803
804
    T &operator[](size_t index) {
805
        return mBuffer[index];
806
    }
807
808
    const T &operator[](size_t index) const {
809
        return mBuffer[index];
810
    }
811
812
    // equality check, assuming that T::operator== is defined.
813
    bool operator==(const hidl_array &other) const {
814
        for (size_t i = 0; i < elementCount(); ++i) {
815
            if (!(mBuffer[i] == other.mBuffer[i])) {
816
                return false;
817
            }
818
        }
819
        return true;
820
    }
821
822
    inline bool operator!=(const hidl_array &other) const {
823
        return !((*this) == other);
824
    }
825
826
    static constexpr size_t size() { return SIZE1; }
827
    static constexpr size_t elementCount() { return SIZE1; }
828
829
    // Copies the data to an std::array, using T::operator=(T).
830
    operator std_array_type() const {
831
        std_array_type array;
832
        for (size_t i = 0; i < SIZE1; ++i) {
833
            array[i] = mBuffer[i];
834
        }
835
        return array;
836
    }
837
838
private:
839
    T mBuffer[SIZE1];
840
};
841
842
// ----------------------------------------------------------------------
843
// Version functions
844
struct hidl_version {
845
public:
846
0
    constexpr hidl_version(uint16_t major, uint16_t minor) : mMajor(major), mMinor(minor) {}
847
848
0
    bool operator==(const hidl_version& other) const {
849
0
        return (mMajor == other.get_major() && mMinor == other.get_minor());
850
0
    }
851
852
0
    bool operator!=(const hidl_version& other) const {
853
0
        return !(*this == other);
854
0
    }
855
856
0
    bool operator<(const hidl_version& other) const {
857
0
        return (mMajor < other.get_major() ||
858
0
                (mMajor == other.get_major() && mMinor < other.get_minor()));
859
0
    }
860
861
0
    bool operator>(const hidl_version& other) const {
862
0
        return other < *this;
863
0
    }
864
865
0
    bool operator<=(const hidl_version& other) const {
866
0
        return !(*this > other);
867
0
    }
868
869
0
    bool operator>=(const hidl_version& other) const {
870
0
        return !(*this < other);
871
0
    }
872
873
0
    constexpr uint16_t get_major() const { return mMajor; }
874
0
    constexpr uint16_t get_minor() const { return mMinor; }
875
876
private:
877
    uint16_t mMajor;
878
    uint16_t mMinor;
879
};
880
881
0
inline android::hardware::hidl_version make_hidl_version(uint16_t major, uint16_t minor) {
882
0
    return hidl_version(major,minor);
883
0
}
884
885
///////////////////// toString functions
886
887
std::string toString(const void *t);
888
889
// toString alias for numeric types
890
template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
891
0
inline std::string toString(T t) {
892
0
    return std::to_string(t);
893
0
}
Unexecuted instantiation: _ZN7android8hardware8toStringIyyEENSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEET_
Unexecuted instantiation: _ZN7android8hardware8toStringIjjEENSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEET_
Unexecuted instantiation: _ZN7android8hardware8toStringIiiEENSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEET_
Unexecuted instantiation: _ZN7android8hardware8toStringIxxEENSt3__112basic_stringIcNS2_11char_traitsIcEENS2_9allocatorIcEEEET_
894
895
namespace details {
896
897
template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
898
0
inline std::string toHexString(T t, bool prefix = true) {
899
0
    std::ostringstream os;
900
0
    if (prefix) { os << std::showbase; }
901
0
    os << std::hex << t;
902
0
    return os.str();
903
0
}
Unexecuted instantiation: _ZN7android8hardware7details11toHexStringIiiEENSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEET_b
Unexecuted instantiation: _ZN7android8hardware7details11toHexStringIjjEENSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEET_b
Unexecuted instantiation: _ZN7android8hardware7details11toHexStringIyyEENSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEET_b
904
905
template<>
906
0
inline std::string toHexString(uint8_t t, bool prefix) {
907
0
    return toHexString(static_cast<int32_t>(t), prefix);
908
0
}
909
910
template<>
911
0
inline std::string toHexString(int8_t t, bool prefix) {
912
0
    return toHexString(static_cast<int32_t>(t), prefix);
913
0
}
914
915
template<typename Array>
916
std::string arrayToString(const Array &a, size_t size);
917
918
template<size_t SIZE1>
919
std::string arraySizeToString() {
920
    return std::string{"["} + toString(SIZE1) + "]";
921
}
922
923
template<size_t SIZE1, size_t SIZE2, size_t... SIZES>
924
std::string arraySizeToString() {
925
    return std::string{"["} + toString(SIZE1) + "]" + arraySizeToString<SIZE2, SIZES...>();
926
}
927
928
template<typename T, size_t SIZE1>
929
std::string toString(details::const_accessor<T, SIZE1> a) {
930
    return arrayToString(a, SIZE1);
931
}
932
933
template<typename Array>
934
std::string arrayToString(const Array &a, size_t size) {
935
    using android::hardware::toString;
936
    std::string os;
937
    os += "{";
938
    for (size_t i = 0; i < size; ++i) {
939
        if (i > 0) {
940
            os += ", ";
941
        }
942
        os += toString(a[i]);
943
    }
944
    os += "}";
945
    return os;
946
}
947
948
template<typename T, size_t SIZE1, size_t SIZE2, size_t... SIZES>
949
std::string toString(details::const_accessor<T, SIZE1, SIZE2, SIZES...> a) {
950
    return arrayToString(a, SIZE1);
951
}
952
953
}  //namespace details
954
955
0
inline std::string toString(const void *t) {
956
0
    return details::toHexString(reinterpret_cast<uintptr_t>(t));
957
0
}
958
959
// debug string dump. There will be quotes around the string!
960
0
inline std::string toString(const hidl_string &hs) {
961
0
    return std::string{"\""} + hs.c_str() + "\"";
962
0
}
963
964
// debug string dump
965
0
inline std::string toString(const hidl_handle &hs) {
966
0
    return toString(hs.getNativeHandle());
967
0
}
968
969
0
inline std::string toString(const hidl_memory &mem) {
970
0
    return std::string{"memory {.name = "} + toString(mem.name()) + ", .size = "
971
0
              + toString(mem.size())
972
0
              + ", .handle = " + toString(mem.handle()) + "}";
973
0
}
974
975
0
inline std::string toString(const sp<hidl_death_recipient> &dr) {
976
0
    return std::string{"death_recipient@"} + toString(dr.get());
977
0
}
978
979
// debug string dump, assuming that toString(T) is defined.
980
template<typename T>
981
std::string toString(const hidl_vec<T> &a) {
982
    std::string os;
983
    os += "[" + toString(a.size()) + "]";
984
    os += details::arrayToString(a, a.size());
985
    return os;
986
}
987
988
template<typename T, size_t SIZE1>
989
std::string toString(const hidl_array<T, SIZE1> &a) {
990
    return details::arraySizeToString<SIZE1>()
991
            + details::toString(details::const_accessor<T, SIZE1>(a.data()));
992
}
993
994
template<typename T, size_t SIZE1, size_t SIZE2, size_t... SIZES>
995
std::string toString(const hidl_array<T, SIZE1, SIZE2, SIZES...> &a) {
996
    return details::arraySizeToString<SIZE1, SIZE2, SIZES...>()
997
            + details::toString(details::const_accessor<T, SIZE1, SIZE2, SIZES...>(a.data()));
998
}
999
1000
namespace details {
1001
// Never instantiated. Used as a placeholder for template variables.
1002
template <typename T>
1003
struct hidl_invalid_type;
1004
1005
// HIDL generates specializations of this for enums. See hidl_enum_range.
1006
template <typename T, typename = std::enable_if_t<std::is_enum<T>::value>>
1007
constexpr hidl_invalid_type<T> hidl_enum_values;
1008
}  // namespace details
1009
1010
/**
1011
 * Every HIDL generated enum supports this function.
1012
 * E.x.: for(const auto v : hidl_enum_range<Enum>) { ... }
1013
 */
1014
template <typename T, typename = std::enable_if_t<std::is_enum<T>::value>>
1015
struct hidl_enum_range {
1016
    constexpr auto begin() const { return std::begin(details::hidl_enum_values<T>); }
1017
    constexpr auto cbegin() const { return begin(); }
1018
    constexpr auto rbegin() const { return std::rbegin(details::hidl_enum_values<T>); }
1019
    constexpr auto crbegin() const { return rbegin(); }
1020
    constexpr auto end() const { return std::end(details::hidl_enum_values<T>); }
1021
    constexpr auto cend() const { return end(); }
1022
    constexpr auto rend() const { return std::rend(details::hidl_enum_values<T>); }
1023
    constexpr auto crend() const { return rend(); }
1024
};
1025
1026
template <typename T, typename = std::enable_if_t<std::is_enum<T>::value>>
1027
struct hidl_enum_iterator {
1028
    static_assert(!std::is_enum<T>::value,
1029
                  "b/78573628: hidl_enum_iterator was renamed to hidl_enum_range because it is not "
1030
                  "actually an iterator. Please use that type instead.");
1031
};
1032
1033
/**
1034
 * Bitfields in HIDL are the underlying type of the enumeration.
1035
 */
1036
template <typename Enum>
1037
using hidl_bitfield = typename std::underlying_type<Enum>::type;
1038
1039
}  // namespace hardware
1040
}  // namespace android
1041
1042
1043
#endif  // ANDROID_HIDL_SUPPORT_H
/proc/self/cwd/system/libhidl/base/include/hidl/Status.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2015 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef ANDROID_HARDWARE_BINDER_STATUS_H
18
#define ANDROID_HARDWARE_BINDER_STATUS_H
19
20
#include <cstdint>
21
#include <sstream>
22
23
#include <hidl/HidlInternal.h>
24
#include <utils/Errors.h>
25
#include <utils/StrongPointer.h>
26
27
namespace android {
28
namespace hardware {
29
30
// An object similar in function to a status_t except that it understands
31
// how exceptions are encoded in the prefix of a Parcel. Used like:
32
//
33
//     Parcel data;
34
//     Parcel reply;
35
//     status_t status;
36
//     binder::Status remote_exception;
37
//     if ((status = data.writeInterfaceToken(interface_descriptor)) != OK ||
38
//         (status = data.writeInt32(function_input)) != OK) {
39
//         // We failed to write into the memory of our local parcel?
40
//     }
41
//     if ((status = remote()->transact(transaction, data, &reply)) != OK) {
42
//        // Something has gone wrong in the binder driver or libbinder.
43
//     }
44
//     if ((status = remote_exception.readFromParcel(reply)) != OK) {
45
//         // The remote didn't correctly write the exception header to the
46
//         // reply.
47
//     }
48
//     if (!remote_exception.isOk()) {
49
//         // The transaction went through correctly, but the remote reported an
50
//         // exception during handling.
51
//     }
52
//
53
class Status final {
54
public:
55
    // Keep the exception codes in sync with android/os/Parcel.java.
56
    enum Exception {
57
        EX_NONE = 0,
58
        EX_SECURITY = -1,
59
        EX_BAD_PARCELABLE = -2,
60
        EX_ILLEGAL_ARGUMENT = -3,
61
        EX_NULL_POINTER = -4,
62
        EX_ILLEGAL_STATE = -5,
63
        EX_NETWORK_MAIN_THREAD = -6,
64
        EX_UNSUPPORTED_OPERATION = -7,
65
66
        // This is special and Java specific; see Parcel.java.
67
        EX_HAS_REPLY_HEADER = -128,
68
        // This is special, and indicates to C++ binder proxies that the
69
        // transaction has failed at a low level.
70
        EX_TRANSACTION_FAILED = -129,
71
    };
72
73
    // A more readable alias for the default constructor.
74
    static Status ok();
75
    // Authors should explicitly pick whether their integer is:
76
    //  - an exception code (EX_* above)
77
    //  - status_t
78
    //
79
    // Prefer a generic exception code when possible or a status_t
80
    // for low level transport errors. Service specific errors
81
    // should be at a higher level in HIDL.
82
    static Status fromExceptionCode(int32_t exceptionCode);
83
    static Status fromExceptionCode(int32_t exceptionCode,
84
                                    const char *message);
85
    static Status fromStatusT(status_t status);
86
87
    Status() = default;
88
    ~Status() = default;
89
90
    // Status objects are copyable and contain just simple data.
91
    Status(const Status& status) = default;
92
    Status(Status&& status) = default;
93
    Status& operator=(const Status& status) = default;
94
95
    // Set one of the pre-defined exception types defined above.
96
    void setException(int32_t ex, const char *message);
97
    // Setting a |status| != OK causes generated code to return |status|
98
    // from Binder transactions, rather than writing an exception into the
99
    // reply Parcel.  This is the least preferable way of reporting errors.
100
    void setFromStatusT(status_t status);
101
102
    // Get information about an exception.
103
0
    int32_t exceptionCode() const  { return mException; }
104
0
    const char *exceptionMessage() const { return mMessage.c_str(); }
105
0
    status_t transactionError() const {
106
0
        return mException == EX_TRANSACTION_FAILED ? mErrorCode : OK;
107
0
    }
108
109
0
    bool isOk() const { return mException == EX_NONE; }
110
111
    // For debugging purposes only
112
    std::string description() const;
113
114
private:
115
    Status(int32_t exceptionCode, int32_t errorCode);
116
    Status(int32_t exceptionCode, int32_t errorCode, const char *message);
117
118
    // If |mException| == EX_TRANSACTION_FAILED, generated code will return
119
    // |mErrorCode| as the result of the transaction rather than write an
120
    // exception to the reply parcel.
121
    //
122
    // Otherwise, we always write |mException| to the parcel.
123
    // If |mException| !=  EX_NONE, we write |mMessage| as well.
124
    int32_t mException = EX_NONE;
125
    int32_t mErrorCode = 0;
126
    std::string mMessage;
127
};  // class Status
128
129
// For gtest output logging
130
std::ostream& operator<< (std::ostream& stream, const Status& s);
131
132
template<typename T> class Return;
133
134
namespace details {
135
    class return_status {
136
    private:
137
        Status mStatus {};
138
        mutable bool mCheckedStatus = false;
139
140
        template <typename T, typename U>
141
        friend Return<U> StatusOf(const Return<T> &other);
142
    protected:
143
        void assertOk() const;
144
    public:
145
0
        return_status() {}
146
0
        return_status(const Status& s) : mStatus(s) {}
147
148
        return_status(const return_status &) = delete;
149
        return_status &operator=(const return_status &) = delete;
150
151
0
        return_status(return_status&& other) noexcept { *this = std::move(other); }
152
        return_status& operator=(return_status&& other) noexcept;
153
154
        ~return_status();
155
156
0
        bool isOkUnchecked() const {
157
0
            // someone else will have to check
158
0
            return mStatus.isOk();
159
0
        }
160
161
0
        bool isOk() const {
162
0
            mCheckedStatus = true;
163
0
            return mStatus.isOk();
164
0
        }
165
166
        // Check if underlying error is DEAD_OBJECT.
167
        // Check mCheckedStatus only if this method returns true.
168
0
        bool isDeadObject() const {
169
0
            bool dead = mStatus.transactionError() == DEAD_OBJECT;
170
0
171
0
            // This way, if you only check isDeadObject your process will
172
0
            // only be killed for more serious unchecked errors
173
0
            if (dead) {
174
0
                mCheckedStatus = true;
175
0
            }
176
0
177
0
            return dead;
178
0
        }
179
180
        // For debugging purposes only
181
0
        std::string description() const {
182
0
            // Doesn't consider checked.
183
0
            return mStatus.description();
184
0
        }
185
    };
186
}  // namespace details
187
188
template<typename T> class Return : public details::return_status {
189
private:
190
    T mVal {};
191
public:
192
    Return(T v) : details::return_status(), mVal{v} {}
193
    Return(Status s) : details::return_status(s) {}
194
195
    // move-able.
196
    // precondition: "this" has checked status
197
    // postcondition: other is safe to destroy after moving to *this.
198
    Return(Return&& other) noexcept = default;
199
    Return& operator=(Return&&) noexcept = default;
200
201
    ~Return() = default;
202
203
    operator T() const {
204
        assertOk();
205
        return mVal;
206
    }
207
208
    T withDefault(T t) {
209
        return isOk() ? mVal : t;
210
    }
211
};
212
213
template<typename T> class Return<sp<T>> : public details::return_status {
214
private:
215
    sp<T> mVal {};
216
public:
217
    Return(sp<T> v) : details::return_status(), mVal{v} {}
218
    Return(T* v) : details::return_status(), mVal{v} {}
219
    // Constructors matching a different type (that is related by inheritance)
220
    template<typename U> Return(sp<U> v) : details::return_status(), mVal{v} {}
221
    template<typename U> Return(U* v) : details::return_status(), mVal{v} {}
222
    Return(Status s) : details::return_status(s) {}
223
224
    // move-able.
225
    // precondition: "this" has checked status
226
    // postcondition: other is safe to destroy after moving to *this.
227
    Return(Return&& other) noexcept = default;
228
    Return& operator=(Return&&) noexcept = default;
229
230
    ~Return() = default;
231
232
    operator sp<T>() const {
233
        assertOk();
234
        return mVal;
235
    }
236
237
    sp<T> withDefault(sp<T> t) {
238
        return isOk() ? mVal : t;
239
    }
240
};
241
242
243
template<> class Return<void> : public details::return_status {
244
public:
245
0
    Return() : details::return_status() {}
246
0
    Return(const Status& s) : details::return_status(s) {}
247
248
    // move-able.
249
    // precondition: "this" has checked status
250
    // postcondition: other is safe to destroy after moving to *this.
251
    Return(Return &&) = default;
252
    Return &operator=(Return &&) = default;
253
254
    ~Return() = default;
255
};
256
257
0
static inline Return<void> Void() {
258
0
    return Return<void>();
259
0
}
260
261
namespace details {
262
// Create a Return<U> from the Status of Return<T>. The provided
263
// Return<T> must have an error status and have it checked.
264
template <typename T, typename U>
265
Return<U> StatusOf(const Return<T> &other) {
266
    if (other.mStatus.isOk() || !other.mCheckedStatus) {
267
        details::logAlwaysFatal("cannot call statusOf on an OK Status or an unchecked status");
268
    }
269
    return Return<U>{other.mStatus};
270
}
271
}  // namespace details
272
273
}  // namespace hardware
274
}  // namespace android
275
276
#endif // ANDROID_HARDWARE_BINDER_STATUS_H